void Frog::drawLimb(float * begin, float * length) { Sphere joint; Cylinder limb; float end[3] = {begin[0] + length[0], begin[1] + length[1], begin[2] + length[2]}; float mag = sqrt(length[0]*length[0] + length[1]*length[1] + length[2]*length[2]); float norm[3] = {length[0]/mag, length[1]/mag, length[2]/mag}; float cross[3] = {norm[2], 0, -1*norm[0]}; float angle = acos(norm[1]) * 180 / 3.14159f; glColor3f(color[0], color[1], color[2]); glPushMatrix(); glTranslatef(begin[0], begin[1], begin[2]); glRotatef(angle, cross[0], cross[1], cross[2]); glScalef(.1, mag, .1); limb.draw(); glPopMatrix(); glColor3f(color[0], color[1], color[2]); glPushMatrix(); glTranslatef(begin[0], begin[1], begin[2]); glScalef(.1, .1, .1); joint.draw(); glPopMatrix(); glPushMatrix(); glTranslatef(end[0], end[1], end[2]); glScalef(.1, .1, .1); joint.draw(); glPopMatrix(); }
// draws solid Cylinder and wire Cylinder together. The wire color is always black //pre scene camera and an instance of Cylinder class exists //post Cylinder is drawn //usage myCylinder.drawCylinder(color); void drawCylinder(vec4 color) { glUniform4fv( model_color, 1,color ); myCylinder.draw(); glUniform4fv( model_color, 1,vec4(0,0,0,1) ); myWireCylinder.draw(); }
static void draw (void) { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glMatrixMode(GL_MODELVIEW); glPushMatrix(); if(bRendered) glEnable(GL_TEXTURE_2D); else glDisable(GL_TEXTURE_2D); if(bWireframe) { glLineWidth( 2.0 ); glPolygonMode(GL_FRONT, GL_LINE); } else glPolygonMode(GL_FRONT, GL_FILL); glRotatef(5, 1,0,0); camera.transform(sky); sun.transform(); if(bDrawGrid) draw_axis(); glColor3f(0.9,0.9,0.9); // Cylinder building glPushMatrix(); glTranslatef(0, 0, -100); glRotatef(40, 0, 1, 0); spLight.transform(); // Update spot light cylinder.draw(); step1.draw(); step2.draw(); glPopMatrix(); // Right cuboid building glPushMatrix(); glTranslatef(100, 25, 25); build_right.draw(); glTranslatef(-75, 0, 150); glRotatef( 90, 0, 1, 0 ); build_right.draw(); glPopMatrix(); // Front timber building glPushMatrix(); glTranslatef(20, 15, 0); build_front.draw(); glPopMatrix(); // Foundations glPushMatrix(); glTranslatef(0, -15, 0); foundation.draw(); glTranslatef(-325, 0, 0); foundation.draw(); glPopMatrix(); // Water glPushMatrix(); glTranslatef(-160,-10,0); water.draw(); glPopMatrix(); glPopMatrix(); glutSwapBuffers(); Sleep(1); // Frame limiter }