Ejemplo n.º 1
0
void draw_robot(struct Vertex position, double heading)
{
    translate_robot(position);
    rotate_robot(heading);

    draw_bumper();
    draw_wheels();
    draw_body();
}
Ejemplo n.º 2
0
void Crowd::draw_crowds(GLfloat* crowdAnglesClapping, GLfloat* crowdAnglesUpHands)
{
	int crowdType;

	// Create new display list for crowd clapping man
	glNewList(CROWD_CLAPPING_LIST, GL_COMPILE);
		glPushMatrix();
			draw_body(crowdAnglesClapping);
		glPopMatrix();
	glEndList();

	// Create new display list for crowd man
	glNewList(CROWD_HANDS_UP_LIST, GL_COMPILE);
		glPushMatrix();
			draw_body(crowdAnglesUpHands);
		glPopMatrix();
	glEndList();
	
	// Create new display list for crowd row
	glNewList(CROWD_ROW_LIST, GL_COMPILE);
		GLdouble deltaTribuneX = (TRIBUNES_SIZE * TRIBUNES_Z_SCALE) / NUMBER_OF_STAIRS;
		GLdouble deltaTribuneY = TRIBUNES_SIZE * TRIBUNES_Y_SCALE;
		GLdouble deltaScaleZ = 1 - 1.0 / NUMBER_OF_STAIRS;
		GLdouble deltaTribuneZ = (TRIBUNES_SIZE * TRIBUNES_Z_SCALE) / NUMBER_OF_STAIRS;

		glPushMatrix();
			glTranslatef((-TRIBUNES_SIZE / 2) -25,
						 FLOOR_Y_T + ((TRIBUNES_SIZE / 2) * TRIBUNES_Y_SCALE) + 40,
						 FRONT_Z_WALL_T - ((TRIBUNES_SIZE / 2) * TRIBUNES_Z_SCALE) - 80);

			glRotatef(180., 0., 1., 0.);
			int currColor = 0;

			// Draw next stairs
			for (int currStair = 1; currStair < NUMBER_OF_STAIRS + 1; currStair++) {
				crowdType = CROWD_CLAPPING_LIST;
				glScalef(1., 1., deltaScaleZ);

				// Draw row of crowd
				for (int i = 1; i <= NUMBER_OF_CROWD_IN_ROW; i++)
				{
					glTranslatef(-CrowdDistance , 0., 0.);
					
					// Draw the current crowd man with random color
					glPushMatrix();
						
						// Draw the hands up crowd randomaly
						if (currColor + NUMBER_OF_CROWD_COLORS/3 >= (NUMBER_OF_CROWD_COLORS * 3)) {
							currColor = 0;
							crowdType = CROWD_HANDS_UP_LIST;
						}

						glColor3f(crowdColors[currColor], crowdColors[currColor + 1], crowdColors[currColor+2]);
						currColor++;

						glCallList(crowdType);
					glPopMatrix();
				}

				glTranslatef(NUMBER_OF_CROWD_IN_ROW * CrowdDistance, deltaTribuneY, -30 * currStair);
			}

		glPopMatrix();
	glEndList();

	// Draw the four tribunes with crowds, every time rotate by 90 degrees
	glPushMatrix();
		glCallList(CROWD_ROW_LIST);
		glRotatef(90., 0., 1., 0.);
		glCallList(CROWD_ROW_LIST);
		glRotatef(90., 0., 1., 0.);
		glCallList(CROWD_ROW_LIST);
		glRotatef(90., 0., 1., 0.);
		glCallList(CROWD_ROW_LIST);
	glPopMatrix();
}
Ejemplo n.º 3
0
//------------------------------------------------------------------------------
/// Registered OpenGL Display Callback Function
void display(void)
{
    // recompute the camera projection in case it was moved
    camera.project();
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity( );
    glLoadMatrixd( camera.projection.arrayOpenGL() );

    // now process the scene
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity( );

    glClear (GL_COLOR_BUFFER_BIT);
    glEnable(GL_LIGHTING);
    glEnable(GL_DEPTH_TEST);

    GLfloat LightAmbient[] =  { 0.4f, 0.4f, 0.4f, 1.0f};
    GLfloat LightDiffuse[] =  { 0.3f, 0.3f, 0.3f, 1.0f};
    GLfloat LightSpecular[] = { 0.4f, 0.4f, 0.4f, 1.0f};
    //GLfloat LightSpecular[] = { 0.0f, 0.0f, 0.0f, 1.0f};
    //GLfloat LightPosition[] = { 5.0f, 5.0f, 5.0f, 1.0f};
    GLfloat LightPosition[] = { 0.0f, 5.0f, 0.0f, 1.0f};

    glClearColor( 0.25, 0.25, 0.25, 0.0 );
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, LightSpecular);
    glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
    glEnable(GL_LIGHT0);
    glShadeModel(GL_SMOOTH);

    draw_motivator();

    // Draw from the master boid list
    for( std::vector<Boid*>::iterator it = boids.begin(); it != boids.end(); it++ ) {
        Boid* boid = (*it);
        draw_body( boid->body );
    }

    /*
    // Draw Flocks
    Flock *flock;
    Boid *boid;

    for( std::vector<Flock*>::iterator it = flocks.begin(); it != flocks.end(); it++ ) {
        flock = (*it);
        for( std::vector<Boid*>::iterator bit = flock->members.begin(); bit != flock->members.end(); bit++ ) {
            boid = (*bit);
            draw_body( boid->body );
        }
    }
    */

    /*
    if( opt_draw_actor )
        //draw_articulatedbody( articulatedbody );
        draw_body( *boid );
*/
    /*
    if( opt_draw_trajectories ) {
        draw_trajectory( articulatedbody.trajectory, NULL );
        unsigned int num_ctlpts = articulatedbody.trajectory.controlpoints.size();
        for( unsigned int i = 0; i < num_ctlpts; i++ ) {
            ControlPoint cp = articulatedbody.trajectory.controlpoints.at( i );

            Matrix4 T = Matrix4::translationMatrix( cp.position );
            glLoadMatrixd( T.arrayOpenGL() );

            draw_mesh( mesh_controlpt );
        }
    }
    */
    glutSwapBuffers();

    if( GENERATE_MOVIE ) {
        sprintf( filename, "%s_%.04d.tif",filetitle.c_str(), frame_id );
        printf( "%s\n", filename );
        Utilities::writetiff( filename, "movie", 0, 0, Width, Height, COMPRESSION_NONE );
    }
}
Ejemplo n.º 4
0
		void phys2d_system_drawer::draw_system(Wt::WPainter& painter, options_t const& options)
		{
			size_t const Margin = 0;

			Wt::WPaintDevice* device = painter.device();

			Wt::WLength dev_width = device->width();
			Wt::WLength dev_height = device->height();
			size_t avail_size = (size_t)std::min(dev_width.toPixels() - 2 * Margin, dev_height.toPixels() - 2 * Margin);

			painter.save();

			Wt::WPen pen(Wt::GlobalColor::lightGray);
			painter.setPen(pen);

			double const scale = (avail_size / 25.0) * options.zoom;

			size_t const GridDim = 5;
			double const GridSquareSize = avail_size / GridDim;

			// TODO: Hack - locking onto first agent
//			auto agent_ptr = dynamic_cast<object const*>(m_sys.m_agents.front().agent.get());
			b2Vec2 grid_ref_pos = b2Vec2(0, 0);//agent_ptr->get_position();

			double x_off = std::fmod(-grid_ref_pos.x * scale, GridSquareSize);
			if(x_off < 0.0)
			{
				x_off += GridSquareSize;
			}
			double y_off = std::fmod(-grid_ref_pos.y * -scale, GridSquareSize);
			if(y_off < 0.0)
			{
				y_off += GridSquareSize;
			}

			for(size_t i = 0; i < dev_width.toPixels() / GridSquareSize; ++i)
			{
				painter.drawLine(
					x_off + i * GridSquareSize,
					0.0,
					x_off + i * GridSquareSize,
					dev_height.toPixels()
					);
			}

			for(size_t i = 0; i < dev_height.toPixels() / GridSquareSize; ++i)
			{
				painter.drawLine(
					0.0,
					y_off + i * GridSquareSize,
					dev_width.toPixels(),
					y_off + i * GridSquareSize
					);
			}

			painter.translate(dev_width.toPixels() / 2, dev_height.toPixels() / 2);
			painter.scale(scale, -scale);
			painter.translate(-grid_ref_pos.x, -grid_ref_pos.y);

			pen = Wt::WPen(Wt::GlobalColor::black);
			painter.setPen(pen);
			Wt::WBrush br(Wt::GlobalColor::white);
			painter.setBrush(br);

			painter.save();

			auto world = m_sys.get_world();
			auto body = world->GetBodyList();
			while(body)
			{
				draw_body(body, painter);

				body = body->GetNext();
			}

			/* TODO: maybe use visitor pattern for entity specific drawing
			http://programmers.stackexchange.com/questions/185525/design-pattern-for-polymorphic-behaviour-while-allowing-library-separation

			m_sys.m_scenario->draw_fixed_objects(painter);

			//phys_system::const_agent_range agents = m_sys.get_agent_range();
			//for(auto it = agents.first; it != agents.second; ++it)
			for(auto const& agent : m_sys.m_agents)
			{
				//(*it)->draw(painter);
				agent.agent->draw(painter);
			}
*/
			painter.restore();
			painter.restore();

			Wt::WFont font = painter.font();
			//font.setFamily(Wt::WFont::Default);
			font.setSize(20);
			painter.setFont(font);
			pen.setColor(Wt::GlobalColor::blue);
			painter.setPen(pen);
			auto rc = Wt::WRectF(
				0,
				0,
				dev_width.toPixels(),
				30
				);
			std::stringstream text;
			text.precision(2);
			std::fixed(text);
			text << m_sys.get_time() << "s";
			painter.drawText(rc, Wt::AlignLeft | Wt::AlignMiddle, text.str());
		}
Ejemplo n.º 5
0
void GreenInvader::draw(float x, float y, int debug){

	_x = x;
	_y = y;

	GreenInvader inv;
	
	glPushMatrix();

	glTranslated(x, y, 0.0f);

	glPushMatrix();

		GLfloat material[] = {0.5,1.0,0,1};
		GLfloat specular[] = {0,0,0,0};
		GLfloat emission[] = {0,0,0,0};
		GLfloat shininess[] = {0};
		glMaterialfv(GL_FRONT, GL_AMBIENT, material);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, material);
		glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
		glMaterialfv(GL_FRONT, GL_EMISSION, emission);
		glMaterialfv(GL_FRONT, GL_SHININESS, shininess);
		glColor3f(0.5f, 1.0f, 0.0f);

	glPushMatrix();
		if (debug)
		glutWireSphere(_radius, 13, 5);
	glPopMatrix();

	glPushMatrix();
	draw_legs(); // pernas
	glPopMatrix();

	glPushMatrix();
	glScalef(2, 1, 2);
	glTranslated(0,-2,0);
	glutSolidCube(1);
	glPopMatrix();
	glPushMatrix();
	glScalef(6, 1, 2);
	glTranslated(0,-1,0); //base do corpo
	glutSolidCube(1);
	glPopMatrix();

	glPushMatrix();
	draw_body();	//corpo
	glPopMatrix();

	glPushMatrix();
	draw_head(); //cabeca
	glPopMatrix();

		GLfloat eye_ambient[] = {0,0,0,1};
		GLfloat eye_diffuse[] = {0,0,0,1};
		GLfloat eye_specular[] = {0,0,0,0};
		GLfloat eye_emission[] = {0,0,0,0};
		GLfloat eye_shininess[] = {0};
		glMaterialfv(GL_FRONT, GL_AMBIENT, eye_ambient);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, eye_ambient);
		glMaterialfv(GL_FRONT, GL_SPECULAR, eye_specular);
		glMaterialfv(GL_FRONT, GL_EMISSION, eye_emission);
		glMaterialfv(GL_FRONT, GL_SHININESS, eye_shininess);
		glColor3f(0.0f, 0.0f, 0.0f); //preto

	glPushMatrix();
	draw_eyes(); //olhos
	glPopMatrix();

	glPopMatrix();

	glPopMatrix();


}
Ejemplo n.º 6
0
void draw_object(){
	
	glPushMatrix();

	glPushMatrix();					
	glTranslatef(0,bally,ballz);	//which is used for ball animation
	glTranslatef(0,5,50);
	draw_ball();
	glPopMatrix ();					
	glTranslatef(posx,0.0,posz);	//robot's animation
	glTranslatef(0,19.0,0);
	draw_body();					//draw a man's body
	draw_body2();
	glPushMatrix();					
	glPushMatrix();					
	glPushMatrix();					
	glPushMatrix();					
	glTranslatef(0.0,17.0,0.0);
	glRotatef(-90,1.0,0.0,0.0);
	draw_head();					//draw a man's head
	
	glPopMatrix();					
	
	
	glTranslatef(-8.0,12.0,0.0);
	glRotatef(theta_arm_left,1.0,0.0,0.0); //the left arm will rotate during the animation
	draw_arm();								//draw the left arm
	glTranslatef(0.0,-12.0,0.0);
	draw_palm();							//draw the left palm

	glPopMatrix();					
	
	glTranslatef(8.0,12.0,0.0);
	glRotatef(theta_arm_right,1.0,0.0,0.0);//the right arm will rotate in the opposite direction with the left arm
	glScalef(-1.0,1.0,1.0);
	
	draw_arm();								//draw the right arm
	glTranslatef(0.0,-12.0,0.0);
	draw_palm();							//draw the right palm
	
	glPopMatrix();					
	
	
	glTranslatef(-3.0,0.0,0.0);
	glRotatef(theta_thigh_left,1.0,0.0,0.0);
	draw_thigh();							//draw the left thigh
	glTranslatef(0.0,-8.0,0.0);
	glRotatef(theta_shank_left,1.0,0.0,0.0);
	draw_shank();							//draw the left shank
	glTranslatef(0.0,-11.0,0.0);
	draw_foot();							//draw the left foot

	glPopMatrix();					
	

	glTranslatef(3.0,0.0,0.0);
	glRotatef(theta_thigh_right,1.0,0.0,0.0);
	draw_thigh();							//draw the left thigh
	glTranslatef(0.0,-8.0,0.0);
	glRotatef(theta_shank_right,1.0,0.0,0.0);
	draw_shank();							//draw the left shank
	glTranslatef(0.0,-11.0,0.0);
	draw_foot();							//draw the left foot

	glPopMatrix();
	
}