void draw_actor( void ) { GLfloat material_Ka[4] = { actor_Ka(0), actor_Ka(1), actor_Ka(2), 1.0 }; GLfloat material_Kd[4] = { actor_Kd(0), actor_Kd(1), actor_Kd(2), 1.0 }; GLfloat material_Ks[4] = { actor_Ks(0), actor_Ks(1), actor_Ks(2), 1.0 }; GLfloat material_Ke[4] = { actor_Ke(0), actor_Ke(1), actor_Ke(2), 1.0 }; GLfloat material_Se = 10; glPushMatrix(); glMaterialfv(GL_FRONT, GL_AMBIENT, material_Ka); glMaterialfv(GL_FRONT, GL_DIFFUSE, material_Kd); glMaterialfv(GL_FRONT, GL_SPECULAR, material_Ks); glMaterialfv(GL_FRONT, GL_EMISSION, material_Ke); glMaterialf(GL_FRONT, GL_SHININESS, material_Se); glLoadMatrixd( actor_transform.arrayOpenGL() ); /* glBegin(GL_TRIANGLES); glVertex3d( 1.0, 0.0, 0.0); glVertex3d(-1.0, 1.0, 0.0); glVertex3d(-1.0,-1.0, 0.0); glEnd(); */ glutSolidTeapot( 1.0 ); glPopMatrix(); }
void draw_motivator( ) { glPushMatrix(); glLoadIdentity(); Matrix4 transform = Matrix4::translationMatrix( motivator.position ); glLoadMatrixd( transform.arrayOpenGL() ); draw_mesh( motivator_mesh ); glPopMatrix(); }
//------------------------------------------------------------------------------ // Drawing Operations //------------------------------------------------------------------------------ /// Draws a mesh void draw( Mesh* mesh, Matrix4& transform ) { Matrix3 R = transform.rotation(); // backface cull Vector3 view = scene.camera.position - scene.camera.viewpoint; for( unsigned int poly_id = 0; poly_id < mesh->polygonCount( ); poly_id++ ) { Polygon* poly = mesh->polygon( poly_id ); Vector3 normal = R * poly->normal; if( Vector3::dot( view, normal ) >= 0.0 ) { Vertex* v = mesh->vertex( poly->getVertex( 0 ) ); Vector3 pt = Vector3( v->position.x(), v->position.y(), v->position.z() ); if( Vector3::dot( scene.camera.position - pt, normal ) >= 0.0 ) poly->backface = true; else poly->backface = false; } else { poly->backface = false; } } glLoadMatrixd( transform.arrayOpenGL() ); glBegin( GL_TRIANGLES ); for( unsigned int poly_id = 0; poly_id < mesh->polygonCount( ); poly_id++ ) { // Select the current polygon Polygon* poly = mesh->polygon( poly_id ); if(BACKFACE_CULL) if( poly->backface ) continue; /* GLfloat *material_Ka, *material_Kd, *material_Ks, *material_Ke, material_Se; if( poly->material != NULL ) { material_Ka = (GLfloat*)poly->material->ambient.arrayOpenGL(); material_Kd = (GLfloat*)poly->material->diffuse.arrayOpenGL(); material_Ks = (GLfloat*)poly->material->specular.arrayOpenGL(); material_Ke = (GLfloat*)poly->material->emissive.arrayOpenGL(); material_Se = (GLfloat)poly->material->shininess; glMaterialfv(GL_FRONT, GL_AMBIENT, material_Ka); glMaterialfv(GL_FRONT, GL_DIFFUSE, material_Kd); glMaterialfv(GL_FRONT, GL_SPECULAR, material_Ks); glMaterialfv(GL_FRONT, GL_EMISSION, material_Ke); glMaterialf(GL_FRONT, GL_SHININESS, material_Se); } */ glColor3d( 0.6, 0.0, 0.0 ); Vertex *v0, *v1, *v2; unsigned int verts = poly->numVertices( ); if( verts < 3 ) continue; // sanity check -> malformed poly & bad juju // the model is not tessellated, so have to tessellate for OpenGL // If poly is non-convex this won't work, but assume convex. // Select the first vertex as the root of all triangles in the poly v0 = mesh->vertex( poly->getVertex( 0 ) ); // Iterate over the rest of the vertices in the polygon up to the n-1 vert for( unsigned int poly_vert = 1; poly_vert < verts - 1; poly_vert++ ) { // select the current vertex v1 = mesh->vertex( poly->getVertex( poly_vert ) ); // and the next vertex (for n-1 case this will be n so closes the poly) v2 = mesh->vertex( poly->getVertex( poly_vert + 1 ) ); glVertex3d( v0->position.x(), v0->position.y(), v0->position.z() ); glNormal3d( v0->normal.x(), v0->normal.y(), v0->normal.z() ); //glNormal3d( poly->normal.x(), poly->normal.y(), poly->normal.z() ); glVertex3d( v1->position.x(), v1->position.y(), v1->position.z() ); glNormal3d( v1->normal.x(), v1->normal.y(), v1->normal.z() ); //glNormal3d( poly->normal.x(), poly->normal.y(), poly->normal.z() ); glVertex3d( v2->position.x(), v2->position.y(), v2->position.z() ); glNormal3d( v2->normal.x(), v2->normal.y(), v2->normal.z() ); //glNormal3d( poly->normal.x(), poly->normal.y(), poly->normal.z() ); } } glEnd(); }