/* Draws the complete crank. Piston also gets drawn through the crank bell function. */ void draw_crank(void) { glPushMatrix(); glRotatef(crank_angle, 1.0, 0.0, 0.0); glPushMatrix(); glRotatef(90, 0.0, 1.0, 0.0); glTranslatef(0.0, 0.0, -1.0); myCylinder(obj, 0.08, 0.0, 1.4); glPopMatrix(); glPushMatrix(); glTranslatef(0.28, 0.0, 0.0); draw_crankbell(); glPopMatrix(); glPushMatrix(); glTranslatef(-0.77, 0.0, 0.0); if (shaded) { if (texture) glCallList(list_flywheel_texture); else glCallList(list_flywheel_shaded); } else draw_flywheel(); glPopMatrix(); glPopMatrix(); }
/* Draws the flywheel. */ void draw_flywheel(void) { glPushMatrix(); glColor4f(0.5, 0.5, 1.0, 1.0); glRotatef(90, 0.0, 1.0, 0.0); myCylinder(obj, 0.625, 0.08, 0.5); glPopMatrix(); }
/* Draws a piston. */ void draw_piston(void) { glPushMatrix(); glColor4f(0.3, 0.6, 0.9, 1.0); glPushMatrix(); glRotatef(90, 0.0, 1.0, 0.0); glTranslatef(0.0, 0.0, -0.07); myCylinder(obj, 0.125, 0.06, 0.12); glPopMatrix(); glRotatef(-90, 1.0, 0.0, 0.0); glTranslatef(0.0, 0.0, 0.05); myCylinder(obj, 0.06, 0.0, 0.6); glTranslatef(0.0, 0.0, 0.6); myCylinder(obj, 0.2, 0.0, 0.5); glPopMatrix(); }
GL_Window::GL_Window(int x, int y, int w, int h, const char *label): Fl_Gl_Window(x, y, w, h, label) { _gw = new osgViewer::GraphicsWindowEmbedded(x,y,w,h); root = new osg::Group; geode = new osg::Geode; osg::ref_ptr<osg::Capsule> myCapsule (new osg::Capsule(osg::Vec3f(),1,2)); osg::ref_ptr<osg::Box> myBox (new osg::Box(osg::Vec3f(),2,2,2)); osg::ref_ptr<osg::Cylinder> myCylinder (new osg::Cylinder(osg::Vec3f(),.75,2.5)); osg::ref_ptr<osg::Sphere> mySphere (new osg::Sphere(osg::Vec3f(),1.5)); osg::ref_ptr<osg::Cone> myCone (new osg::Cone(osg::Vec3f(),1,2)); shape_vec.push_back(new osg::ShapeDrawable(myBox.get())); shape_vec.push_back(new osg::ShapeDrawable(myCapsule.get())); shape_vec.push_back(new osg::ShapeDrawable(myCone.get())); shape_vec.push_back(new osg::ShapeDrawable(myCylinder.get())); shape_vec.push_back(new osg::ShapeDrawable(mySphere.get())); geode->addDrawable(shape_vec[1].get()); // default shape to pick from root->addChild(geode.get()); stateset = geode->getOrCreateStateSet(); // initial material properties diffuse_color.set(1, 1, 1, 1.0); specular_color.set(1,1,1,1); ambient_color.set(1,1,1,1); shininess = 10; alpha = 1; // apply the properties to the material material = new osg::Material; material->setDiffuse(osg::Material::FRONT, diffuse_color); material->setSpecular(osg::Material::FRONT, specular_color); material->setShininess(osg::Material::FRONT, shininess); material->setAmbient(osg::Material::FRONT, ambient_color); stateset->setAttribute(material.get()); //stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF); texture = new osg::Texture2D; getCamera()->setViewport(new osg::Viewport(0,0,w,h)); getCamera()->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(w)/static_cast<double>(h), 1.0f, 10000.0f); getCamera()->setGraphicsContext(_gw.get()); setSceneData(root.get()); setCameraManipulator(new osgGA::TrackballManipulator); addEventHandler(new osgViewer::StatsHandler); setThreadingModel(osgViewer::Viewer::SingleThreaded); }
/* Draws the engine pole and the pivot pole for the cylinder head. */ void draw_engine_pole(void) { glPushMatrix(); glColor4f(0.9, 0.9, 0.9, 1.0); myBox(0.5, 3.0, 0.5); glColor3f(0.5, 0.1, 0.5); glRotatef(90, 0.0, 1.0, 0.0); glTranslatef(0.0, 0.9, -0.4); myCylinder(obj, 0.1, 0.0, 2); glPopMatrix(); }
void robot(double y){ glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, matWhite_shininess); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, matWhite_specular); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, matWhite_diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, matWhite_ambient); glPushMatrix(); glTranslated(robotWheelX,robotWheelRadius,robotBodyZ+.01); myCylinder(robotWheelRadius,robotWheelHeight,robotWHeelSlices,TRUE); glPopMatrix(); glPushMatrix(); glTranslated(-robotWheelX,robotWheelRadius,robotBodyZ+0.01); myCylinder(robotWheelRadius,robotWheelHeight,robotWHeelSlices,TRUE); glPopMatrix(); glPushMatrix(); glTranslated(robotWheelX,robotWheelRadius,-robotBodyZ -robotWheelHeight-.01); myCylinder(robotWheelRadius,robotWheelHeight,robotWHeelSlices,TRUE); glPopMatrix(); glPushMatrix(); glTranslated(-robotWheelX,robotWheelRadius,-robotBodyZ -robotWheelHeight-.01); myCylinder(robotWheelRadius,robotWheelHeight,robotWHeelSlices,TRUE); glPopMatrix(); glPushMatrix(); glTranslated(0,y,0); glPushMatrix(); glTranslated(robotLightX,0,robotLightZ); robotLight(robotLightHeight,robotLightRadius,robotLightOuterRadius); glPopMatrix(); robotBody(robotBodyX,robotBodyY,robotBodyZ); glPopMatrix(); }
/* Draws the cylinder head at the appropreate angle, doing the necesary translations for the rotation. */ void draw_cylinder_head(void) { glPushMatrix(); glColor4f(0.5, 1.0, 0.5, 0.1); glRotatef(90, 1.0, 0.0, 0.0); glTranslatef(0, 0.0, 0.4); glRotatef(head_angle, 1, 0, 0); glTranslatef(0, 0.0, -0.4); myCylinder(obj, 0.23, 0.21, 1.6); glRotatef(180, 1.0, 0.0, 0.0); gluDisk(obj, 0, 0.23, 20, 1); glPopMatrix(); }
/* Draws the crank bell, and the pivot pin for the piston. Also calls the appropreate display list of a piston doing the nesacary rotations before hand. */ void draw_crankbell(void) { glPushMatrix(); glColor4f(1.0, 0.5, 0.5, 1.0); glRotatef(90, 0.0, 1.0, 0.0); myCylinder(obj, 0.3, 0.08, 0.12); glColor4f(0.5, 0.1, 0.5, 1.0); glTranslatef(0.0, 0.2, 0.0); myCylinder(obj, 0.06, 0.0, 0.34); glTranslatef(0.0, 0.0, 0.22); glRotatef(90, 0.0, 1.0, 0.0); glRotatef(crank_angle - head_angle, 1.0, 0.0, 0.0); if (shaded) { if (texture) glCallList(list_piston_texture); else glCallList(list_piston_shaded); } else draw_piston(); glPopMatrix(); }
void batter(double x, double y, double z){ /* 色 */ GLfloat white[] = { 1.f, 1.f, 1.f, 1.f }; GLfloat blue[] = { 0.f, 0.0f, 1.0f, 1.f }; GLfloat beige[] = { 1.f, 0.9f, 0.7f, 1.f }; GLfloat black[] = { 0.f, 0.f, 0.f, 0.f }; /* 腕と手 */ glPushMatrix(); glTranslated(x + 0.1, y + 0.58, z); glRotated(-90, 1.0, 0.0, 0.0); glRotated(bat_angle - 70, 0.0, 0.0, 1.0); glTranslated(-0.1, -0.24, 0); glEnable(GL_NORMALIZE); glScalef(0.3f, 1.f, 0.3f); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, blue); displaySphere(0.2f, 0.9f, 0.6f, 0.6f, 0.2f, 0.2f, 0.2f, 10.f);/* 腕 */ glTranslated(0, -0.2, 0); glScalef(1.f, 0.3f, 1.f); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, beige); displaySphere(0.3f, 0.6f, 0.2f, 0.1f, 1.f, 1.f, 1.f, 100.f); /* 手 */ glDisable(GL_NORMALIZE); glPopMatrix(); glPushMatrix(); glTranslated(x + 0.3, y + 0.58, z); glRotated(-90, 1.0, 0.0, 0.0); glRotated(bat_angle - 110, 0.0, 0.0, 1.0); glTranslated(0.2, -0.4, 0); //glTranslated(0, -0.2, 0); glEnable(GL_NORMALIZE); glScalef(0.3f, 1.f, 0.3f); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, blue); displaySphere(0.2f, 0.9f, 0.6f, 0.6f, 0.2f, 0.2f, 0.2f, 10.f);/* 腕 */ glTranslated(0, -0.2, 0); glScalef(1.f, 0.3f, 1.f); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, beige); displaySphere(0.3f, 0.6f, 0.2f, 0.1f, 1.f, 1.f, 1.f, 100.f); /* 手 */ glDisable(GL_NORMALIZE); glPopMatrix(); /* 胴体 */ glPushMatrix(); glTranslated(x + 0.16, y, z - 0.1); myCylinder(0.15, 0.6, 1000); glPopMatrix(); /* 頭 */ glPushMatrix(); glTranslated(x+0.18, y + 0.8, z - 0.1); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, beige); displaySphere(0.2f, 0.6f, 0.2f, 0.1f, 1.f, 1.f, 1.f, 100.f);/* 顔面 */ glPopMatrix(); glPushMatrix(); glTranslated(x+0.18, y + 0.88, z - 0.1); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, white); //glScalef(1.f, 0.3f, 1.f); //はちまきっぽいなんか glScalef(1.f, 0.7f, 1.f); displaySphere(0.21f, 0.6f, 0.2f, 0.1f, 1.f, 1.f, 1.f, 100.f);/* 帽子 */ glPopMatrix(); glPushMatrix(); glTranslated(x+0.18, y + 0.8, z - 0.2); glScalef(0.3f, 0.07f, 1.f); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, black); glNormal3d(0.0, 0.0, 1.0); displaySphere(0.8f, 0.6f, 0.2f, 0.1f, 1.f, 1.f, 1.f, 100.f);/* 帽子のつば */ glPopMatrix(); }