void VruiSoundTest::display(GLContextData& contextData) const { /* Get the data item: */ GLDataItem* dataItem=contextData.retrieveDataItem<GLDataItem>(this); /* Set up OpenGL state: */ glPushAttrib(GL_LIGHTING_BIT); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE); /* Draw several spheres at "random" positions: */ glPushMatrix(); glTranslate(positions[0]-Vrui::Point::origin); glColor3f(0.0f,1.0f,0.0f); glCallList(dataItem->displayListId); glPopMatrix(); glPushMatrix(); glTranslate(positions[1]-Vrui::Point::origin); glColor3f(1.0f,0.0f,0.0f); glCallList(dataItem->displayListId); glPopMatrix(); glPushMatrix(); glTranslate(positions[2]-Vrui::Point::origin); glColor3f(0.0f,0.0f,1.0f); glCallList(dataItem->displayListId); glPopMatrix(); /* Reset OpenGL state: */ glPopAttrib(); }
void BiovisionDisplay::draw(const KinematicModel<BiovisionJoint> &model, const Vector3D &colour, bool drawAxis) { for(int i = 0; i < model.njoints(); i++) { const BiovisionJoint &joint = model.joints(i); if(drawAxis) { glPushMatrix(); glTranslate(joint.global_position()); glRotate(joint.global_orientation()); glBegin(GL_LINES); glColor3f(1.0, 0.0, 0.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(20.0, 0., 0.0); glColor3f(0.0, 1.0, 0.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 20.0, 0.0); glColor3f(0.0, 0.0, 1.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 0.0, 20.0); glEnd(); glPopMatrix(); } if(joint.parent() >= 0) { glBegin(GL_LINES); glVertex(joint.global_position()); glVertex(model.getParent(joint).global_position()); glEnd(); Vector3D global_direction = (joint.global_position()-model.getParent(joint).global_position()).direction(); double length = joint.local_position().length(); glColor(colour); glPushMatrix(); glTranslate(joint.global_position()); glTranslate(-global_direction*length*0.5); //align bone Vector3D zAxis = Vector3D(0.0, 0.0, 1.0); Vector3D newAxis = zAxis ^ global_direction; double newAngle = acos(zAxis *global_direction); glRotateRad(newAngle, newAxis); //draw bone GLUquadricObj *qobj = gluNewQuadric(); gluQuadricDrawStyle(qobj, GLU_FILL); gluQuadricNormals(qobj, GLU_SMOOTH); glScalef(0.25, 0.25, 1.0); gluSphere(qobj, length*0.5, 20, 20); gluDeleteQuadric(qobj); glPopMatrix(); } } }
void ShowLEDs::display(GLContextData& contextData) const { glPushAttrib(GL_ENABLE_BIT|GL_POINT_BIT); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE); /* Draw the IMU as a sphere: */ glPushMatrix(); glTranslate(hmdModel.getIMU()-HMDModel::Point::origin); glColor3f(0.5f,0.5f,1.0f); glDrawSphereIcosahedron(0.005,4); glPopMatrix(); /* Draw the markers as spheres: */ for(unsigned int markerIndex=0;markerIndex<hmdModel.getNumMarkers();++markerIndex) { glPushMatrix(); glTranslate(hmdModel.getMarkerPos(markerIndex)-HMDModel::Point::origin); glColor3f(1.0f,0.5f,0.5f); glDrawSphereIcosahedron(0.005,4); glPopMatrix(); } glDisable(GL_LIGHTING); glPointSize(3.0f); glLineWidth(3.0f); /* Draw the markers emission direction vectors: */ glColor3f(0.5f,1.0f,5.0f); glBegin(GL_LINES); for(unsigned int markerIndex=0;markerIndex<hmdModel.getNumMarkers();++markerIndex) { glVertex(hmdModel.getMarkerPos(markerIndex)); glVertex(hmdModel.getMarkerPos(markerIndex)+hmdModel.getMarkerDir(markerIndex)*HMDModel::Scalar(0.03)); } glEnd(); /* Draw the markers' IDs: */ glLineWidth(2.0f); glColor3f(1.0f,1.0f,1.0f); HMDModel::Point head=HMDModel::Point(Vrui::getHeadPosition()); for(unsigned int markerIndex=0;markerIndex<hmdModel.getNumMarkers();++markerIndex) { /* Intersect a ray from the head position to the marker position with the marker sphere: */ Geometry::Sphere<HMDModel::Scalar,3> marker(hmdModel.getMarkerPos(markerIndex),HMDModel::Scalar(0.0075)); Geometry::Ray<HMDModel::Scalar,3> ray(head,marker.getCenter()-head); Geometry::Sphere<HMDModel::Scalar,3>::HitResult hr=marker.intersectRay(ray); HMDModel::Point labelPos=ray(hr.getParameter()); glPushMatrix(); Vrui::Vector up=Vrui::getInverseNavigationTransformation().transform(Vrui::getUpDirection()); Vrui::Vector x=Vrui::Vector(ray.getDirection())^up; glMultMatrix(Vrui::ONTransform::rotateAround(labelPos,Vrui::Rotation::fromBaseVectors(x,up))); numberRenderer.drawNumber(GLNumberRenderer::Vector(labelPos.getComponents()),markerIndex,contextData,0,0); glPopMatrix(); } glPopAttrib(); }
void TTrackball::OnIdle(wxIdleEvent& event) { long elapsed = wxGetElapsedTime(false); // 'elapsed' can be less than 'previous' if the timer gets reset somewhere else. if (elapsed < previous) { previous = elapsed; } // Animate the shader if at least one millisecond has elapsed. else if (elapsed - previous > 0) { canvas->Animate(elapsed - previous); previous = elapsed; } // // When not showing frames per second, wait enough between frames to not exceed a maximum frame rate. // The proper way of doing this is wait-for-vertical-sync, accessible via the display applet. // (Some older 3Dlabs products do not support the wglSwapControl extension.) // // If wglSwapInterval isn't available, wait for some time to elapse. if (wxGetApp().CapFps() && !wglSwapIntervalEXT) { if (!inertiaTheta || elapsed < Delay) { event.RequestMore(); event.Skip(); return; } // Reset timer. wxGetElapsedTime(true); previous = 0; } else { // Recalculate the fps every second. if (elapsed > 1000) { // Reset timer. wxGetElapsedTime(true); previous = 0; // Update the fps display counter on the status bar. wxGetApp().UpdateFps((float) frames * 1000.0f / (float) elapsed); frames = 0; } ++frames; } // Continue spinning the model. glLoadIdentity(); vec3 offset = wxGetApp().Frame()->GetCenter(); glTranslate(offset); glRotatef(-inertiaTheta, inertiaAxis.x, inertiaAxis.y, inertiaAxis.z); glTranslate(-offset); glMultMatrixf((float*) &xform); glGetFloatv(GL_MODELVIEW_MATRIX, (float*) &xform); canvas->Update(); event.Skip(); }
void FiberApplication::drawArrow(const Vrui::Point& to, Vrui::Scalar radius) const { Vrui::Scalar tipHeight=radius*Vrui::Scalar(6.0); Vrui::Scalar shaftLength=Geometry::dist(Vrui::Point::origin,to)-tipHeight; glPushMatrix(); glTranslate(Vrui::Point::origin-Vrui::Point::origin); glRotate(Vrui::Rotation::rotateFromTo(Vrui::Vector(0,0,1),to-Vrui::Point::origin)); glTranslate(Vrui::Vector(0,0,Math::div2(shaftLength))); glDrawCylinder(radius,shaftLength,24); glTranslate(Vrui::Vector(0,0,Math::div2(shaftLength)+tipHeight*Vrui::Scalar(0.25))); glDrawCone(radius*Vrui::Scalar(2),tipHeight,24); glPopMatrix(); }
METHODPREFIX void glMultMatrix( const Geometry::TranslationTransformation<ScalarParam,3>& t) { glTranslate(t.getTranslation().getComponents()); }
void GhostUnit::glRenderAction(GLContextData& contextData) const { glPushMatrix(); glTranslate(sourceOffset); sourceUnit->glRenderAction(contextData); glPopMatrix(); }
//--------------------------------------------------------- void Target::Draw() { //just an "X" glPushMatrix(); glDisable(GL_LIGHTING); glTranslate(m_position); glRotatef(m_angle,0,0,1); glScalef(m_size,m_size,m_size); glBegin(GL_LINES); glColor3f( .8,.4,.1); glVertex3f(-5, 5, 0); glVertex3f( 5,-5, 0); glEnd(); glBegin(GL_LINES); glColor3f( .8,.4,.1); glVertex3f( 5, 5, 0); glVertex3f(-5,-5, 0); glEnd(); glEnable(GL_LIGHTING); glPopMatrix(); }
void GlyphRenderer::renderGlyph(const Glyph& glyph,const OGTransform& transformation,const GlyphRenderer::DataItem* contextDataItem) const { /* Check if the glyph is enabled: */ if(glyph.enabled) { if(glyph.glyphType==Glyph::CURSOR) { /**************************** Render a texture-based glyph: ****************************/ /* Align the glyph texture with the current window's current screen: */ const DisplayState& ds=getDisplayState(contextDataItem->contextData); glPushMatrix(); glTranslate(transformation.getTranslation()); glRotate(ds.screen->getScreenTransformation().getRotation()); /* Draw the glyph texture: */ glCallList(contextDataItem->glyphDisplayLists+glyph.glyphType); glPopMatrix(); } else { /* Render a 3D glyph: */ glPushMatrix(); glMultMatrix(transformation); glMaterial(GLMaterialEnums::FRONT,glyph.glyphMaterial); glCallList(contextDataItem->glyphDisplayLists+glyph.glyphType); glPopMatrix(); } } }
void MyCar::drawCar() { glPushMatrix(); //glScalef(0.7, 0.7, 0.7); glTranslatef(-2.0, 1.3, 0); glMateriali(GL_FRONT, GL_SHININESS, 55); glPushMatrix(); float d = mesh.bbox.Diag(); glScale(3 / d); glRotatef(90, 0, 1, 0); glRotatef(-90, 1, 0, 0); vcg::Point4f spotpos = vcg::Point4f(-0.9, 0.3, -4, 1.0); vcg::Point4f spotpos2 = vcg::Point4f(0.9, 0.3, -4, 1.0); vcg::Point4f spotdir = vcg::Point4f(0.0, 0.0, -1.0, 0.0); glLightfv(GL_LIGHT1, GL_POSITION, &spotpos[0]); glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, &spotdir[0]); glLightfv(GL_LIGHT2, GL_POSITION, &spotpos2[0]); glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, &spotdir[0]); glTranslate(-(_car.m->bbox.Center())); glDisable(GL_TEXTURE_2D); glEnable(GL_COLOR_MATERIAL); _car.Draw<vcg::GLW::DMSmooth, vcg::GLW::CMPerFace, vcg::GLW::TMNone > (); glPopMatrix(); glDisable(GL_COLOR_MATERIAL); glEnable(GL_TEXTURE_2D); }
void GameOverPanel::render(Scene& parent) { SDL_Window * win = parent.app().getWindow(); int width, height; SDL_GetWindowSize(win, &width, &height); Rect rect = getBoundingRect(win); glPushAttrib(GL_ENABLE_BIT); { glMatrixMode(GL_PROJECTION); glDisable(GL_LIGHTING); glPushMatrix(); { glLoadIdentity(); glOrtho(0, width, 0, height, -1, 1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); { glLoadIdentity(); glBindTexture(texture); float alpha = 0; float translateY = 0; if(animTime > coolDownTime) { float diff = (animTime - coolDownTime) / (animTotalTime - coolDownTime); if(diff > 1) diff = 1; alpha = diff; translateY = translationYLength * (1 - diff) * (1 - diff); } glTranslate(Vector3::down * translateY); glColor(Vector3::one, alpha); glBegin(GL_QUADS); { glTexCoord2f(0, 0); glVertex2f(rect.left(), height - rect.top()); glTexCoord2f(0, 1); glVertex2f(rect.left(), height - rect.bottom()); glTexCoord2f(1, 1); glVertex2f(rect.right(), height - rect.bottom()); glTexCoord2f(1, 0); glVertex2f(rect.right(), height - rect.top()); } glEnd(); } glPopMatrix(); } glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); } glPopAttrib(); if(animTime < animTotalTime) { animTime += parent.app().getFrameTime(); } }
void glLoadMatrix(const Geometry::OrthogonalTransformation<ScalarParam,3>& t) { glLoadIdentity(); glTranslate(t.getTranslation()); glRotate(t.getRotation()); glScale(t.getScaling(),t.getScaling(),t.getScaling()); }
void SplatterSystem::draw( const QMatrix4x4 & modelView ) { mParticleMaterial->bind(); mParticleSystem->draw( modelView ); mParticleMaterial->release(); mSplatterMaterial->bind(); glEnable( GL_BLEND ); glBlendFunc( GL_DST_COLOR, GL_ZERO ); glMatrixMode( GL_TEXTURE ); for( int i = 0; i < mSplatters.size(); ++i ) { if( mSplatters[i].fade <= 0.0f ) continue; QVector4D c = Interpolation::linear( QVector4D(1.0f,1.0f,1.0f,1.0f), mSplatterMaterial->constData()->emission(), sqrtf(mSplatters[i].fade) ); mSplatterMaterial->overrideEmission( c ); glPushMatrix(); QRectF mapRect = mTerrain->toMapF( mSplatters[i].rect ); // rotate around center of texture in 90 deg. steps glTranslate( 0.5f, 0.5f, 0.0f ); glRotate( mSplatters[i].rotation*90.0f, 0.0f, 0.0f, 1.0f ); glTranslate( -0.5f, -0.5f, 0.0f ); // transform texture coordinates to terrain patch float sizeFactor = powf( mSplatters[i].fade, mSplatterDriftFactor ); QSizeF border = ( sizeFactor * mapRect.size() ) / 2.0f; glScale( 1.0/(mapRect.size().width()*(1.0f-sizeFactor)), 1.0/(mapRect.size().height()*(1.0f-sizeFactor)), 1.0 ); glTranslate( -mapRect.x()-border.width(), -mapRect.y()-border.height(), 0.0 ); float fX( mapRect.x()-(int)mapRect.x() ); float fY( mapRect.y()-(int)mapRect.y() ); QRect drawRect ( floorf(mapRect.x()), floorf(mapRect.y()), ceilf(mapRect.width()+fX), ceilf(mapRect.height()+fY) ); mTerrain->drawPatchMap( drawRect ); glPopMatrix(); } glMatrixMode( GL_MODELVIEW); glDisable( GL_BLEND ); mSplatterMaterial->release(); }
METHODPREFIX void glMultMatrix( const Geometry::OrthonormalTransformation<ScalarParam,3>& t) { glTranslate(t.getTranslation().getComponents()); glRotate(Math::deg(t.getRotation().getAngle()),t.getRotation().getAxis().getComponents()); }
const gfx::RenderInfo* SimTree::render(bool effects) { glPushMatrix(); glTranslate(mtx.pos()); plant->render(); glPopMatrix(); return 0; }
void DefaultIcon::display ( GLContextData& contextData ) const { glMaterial ( GLMaterialEnums::FRONT_AND_BACK, GLMaterial ( Vrui::getUiBgColor ( ) ) ) ; glPushMatrix ( ) ; glTranslate ( 0.0f, 0.0f, 0.0f ) ; glRotate ( Vrui::Scalar ( 50.0 ), Vrui::Vector ( -1.0, -1.0, 1.0 ) ) ; glDrawCone ( 0.75, 1.5, 10 ) ; glPopMatrix ( ) ; }
METHODPREFIX void glLoadMatrix( const Geometry::OrthogonalTransformation<ScalarParam,3>& t) { glLoadIdentity(); glTranslate(t.getTranslation().getComponents()); glRotate(Math::deg(t.getRotation().getAngle()),t.getRotation().getAxis().getComponents()); glScale(t.getScaling()); }
void Torch::draw2Self() { if( world()->landscape()->drawingReflection() || world()->landscape()->drawingRefraction() ) return; const unsigned char samplingPoints = 16; unsigned char visiblePoints; glPushMatrix(); glTranslate( mFlarePosition ); glScale( 0.3f ); visiblePoints = mOcclusionTest.randomPointsOnUnitSphereVisible( samplingPoints ); glPopMatrix(); if( !visiblePoints ) return; glPushAttrib( GL_VIEWPORT_BIT | GL_DEPTH_BUFFER_BIT | GL_CURRENT_BIT ); glDepthMask( GL_FALSE ); glDisable( GL_CULL_FACE ); glDisable( GL_DEPTH_TEST ); glDisable( GL_LIGHTING ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE ); mMaterial->bind(); glColor( ((float)visiblePoints/(float)samplingPoints)*mColor ); sQuadVertexBuffer.bind(); glClientActiveTexture( GL_TEXTURE0 ); glEnableClientState( GL_VERTEX_ARRAY ); glEnableClientState( GL_TEXTURE_COORD_ARRAY ); glVertexPointer( 3, GL_FLOAT, 5*sizeof(GLfloat), (void*)0 ); glTexCoordPointer( 2, GL_FLOAT, 5*sizeof(GLfloat), (void*)(3*sizeof(GLfloat)) ); QMatrix4x4 flareCenter = modelViewMatrix(); flareCenter.translate( mFlarePosition ); Bilboard::begin( flareCenter ); glScale( mFlareSize ); glRotate( mFlareRotation, QVector3D(0,0,1) ); glDrawArrays( GL_QUADS, 0, 4 ); glRotate( -mFlareRotation*2.7f, QVector3D(0,0,1) ); glDrawArrays( GL_QUADS, 0, 4 ); Bilboard::end(); glDisableClientState( GL_TEXTURE_COORD_ARRAY ); glDisableClientState( GL_VERTEX_ARRAY ); sQuadVertexBuffer.release(); mMaterial->release(); glDisable( GL_BLEND ); glPopAttrib(); }
void MapOutliner::visitGroup(GroupElement* e) { for (unsigned i = 0; i < e->children.size(); i++) { // maybe not so hot if we start recursing out the wazoo. glPushMatrix(); glTranslate(e->pos); // TODO: draw something to indicate where the group's origin is e->children[i]->handleVisitor(*this); glPopMatrix(); } }
void MapOutliner::visitGeometry(GeometryElement* e) { glBindTexture(GL_TEXTURE_2D, 0); // Draw a big red dot at the center of the node glColor3f(1, 0, 0); glPointSize(9); glBegin(GL_POINTS); glVertex(e->pos); glEnd(); glPushMatrix(); glTranslate(e->pos); /* PlanarMap& pm = e->geometry; glBegin(GL_POINTS); for (size_t i = 0; i < pm.getVertexCount(); ++i) { glVertex(pm.getVertex(i).pos); } glEnd(); */ /* // Draw segments in blue glColor3f(0, 0, 1); for (unsigned i = 0; i < e->tris.size(); i++) { const GeometryElement::Triangle& t = e->tris[i]; glBegin(GL_LINE_LOOP); for (unsigned j = 0; j < 3; j++) { const unsigned idx = t.vert[j]; glVertex(e->vertices[idx].pos); } glEnd(); } // Draw points as green dots glColor3f(0, 1, 0); glPointSize(3); glBegin(GL_POINTS); for (unsigned i = 0; i < e->vertices.size(); i++) { glVertex(e->vertices[i].pos); } glEnd(); */ glPopMatrix(); }
void Triangle::glRenderAction(GLContextData& contextData) const { /* Retrieve data item from GL context: */ TriangleRenderer::DataItem* dataItem=contextData.retrieveDataItem<TriangleRenderer::DataItem>(unitRenderer); /* Move model coordinate system to triangle's position and orientation: */ glPushMatrix(); glTranslate(position.getComponents()); glRotate(orientation); /* Render triangle: */ glCallList(dataItem->displayListId); /* Reset model coordinates: */ glPopMatrix(); }
void WalkNavigationTool::display(GLContextData& contextData) const { if(factory->drawMovementCircles) { /* Get a pointer to the context entry: */ WalkNavigationToolFactory::DataItem* dataItem=contextData.retrieveDataItem<WalkNavigationToolFactory::DataItem>(factory); /* Translate to the center point: */ glPushMatrix(); glTranslate(centerPoint-Point::origin); /* Execute the tool model display list: */ glCallList(dataItem->modelListId); glPopMatrix(); } }
//--------------------------------------------------------- void Bullet::Draw() { glPushMatrix(); glDisable(GL_LIGHTING); glTranslate(m_position); glRotatef(m_angle,0,0,1); glScalef(m_size,m_size,m_size); glBegin(GL_LINES); glColor3f(.5, 1, 1); glVertex3f(4.0,0,0); glColor3f(0.,.3,.3); glVertex3f(0.0,0,0); glEnd(); glEnable(GL_LIGHTING); glPopMatrix(); }
void GlyphRenderer::renderGlyph(const Glyph& glyph,const OGTransform& transformation,const GlyphRenderer::DataItem* contextDataItem) const { /* Check if the glyph is enabled: */ if(glyph.enabled) { if(glyph.glyphType==Glyph::CURSOR) { /**************************** Render a texture-based glyph: ****************************/ /* Project the given transformation's origin onto the current window's current screen: */ const DisplayState& ds=getDisplayState(contextDataItem->contextData); Point to=transformation.getOrigin(); Ray ray(to,to-ds.viewer->getHeadPosition()); ONTransform st=ds.screen->getScreenTransformation(); Point sto=st.getOrigin(); Vector screenNormal=st.getDirection(2); Scalar screenOffset=screenNormal*sto; Scalar divisor=screenNormal*ray.getDirection(); if(divisor!=Scalar(0)) { Scalar lambda=(screenOffset-screenNormal*ray.getOrigin())/divisor; glPushMatrix(); glTranslate(ray(lambda)-sto); glMultMatrix(st); glCallList(contextDataItem->glyphDisplayLists+glyph.glyphType); glPopMatrix(); } } else { /* Render a 3D glyph: */ glPushMatrix(); glMultMatrix(transformation); glMaterial(GLMaterialEnums::FRONT,glyph.glyphMaterial); glCallList(contextDataItem->glyphDisplayLists+glyph.glyphType); glPopMatrix(); } } }
void GLWidget::paintGL () { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(40, GLWidget::width()/(float)GLWidget::height(), 0.1, 100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0,0,3.5f, 0,0,0, 0,1,0); track.center=vcg::Point3f(0, 0, 0); track.radius= 1; track.GetView(); glPushMatrix(); track.Apply(false); glPushMatrix(); if(mesh.vert.size()>0) { vcg::glScale(2.0f/mesh.bbox.Diag()); glTranslate(-mesh.bbox.Center()); glWrap.Draw(GLW::DrawMode(drawmode),GLW::CMNone,GLW::TMNone); } glPopMatrix(); track.DrawPostApply(); glPopMatrix(); if(hasToPick) { hasToPick=false; Point3f pp; if(Pick<Point3f>(pointToPick[0],pointToPick[1],pp)) { track.Translate(-pp); track.Scale(1.25f); QCursor::setPos(mapToGlobal(QPoint(width()/2+2,height()/2+2))); } } TwDraw(); }
void drawgeom(const GeometricPrimitive3D& geom) { switch(geom.type) { case GeometricPrimitive3D::Point: { glBegin(GL_POINTS); glVertex3v(*AnyCast<Vector3>(&geom.data)); glEnd(); } break; case GeometricPrimitive3D::Segment: { const Segment3D* seg=AnyCast<Segment3D>(&geom.data); glBegin(GL_LINES); glVertex3v(seg->a); glVertex3v(seg->b); glEnd(); } break; /* case GeometricPrimitive3D::Circle: { const Circle3D* circle = AnyCast<Circle3D>(&geom.data); glPushMatrix(); glTranslate(circle->center); drawCircle(circle->axis,circle->radius); glPopMatrix(); } break; */ /* case GeometricPrimitive3D::AABB: { const AABB3D* aabb=AnyCast<AABB3D>(&geom.data); drawBoundingBox(aabb->bmin,aabb->bmax); } break; */ case GeometricPrimitive3D::Box: { const Box3D* box=AnyCast<Box3D>(&geom.data); Matrix4 m; box->getBasis(m); glPushMatrix(); glMultMatrix(m); drawBoxCorner(box->dims.x,box->dims.y,box->dims.z); glPopMatrix(); break; } case GeometricPrimitive3D::Triangle: { const Triangle3D* tri=AnyCast<Triangle3D>(&geom.data); drawTriangle(tri->a,tri->b,tri->c); break; } case GeometricPrimitive3D::Polygon: { const Polygon3D* p=AnyCast<Polygon3D>(&geom.data); Plane3D plane; p->getPlane(0,plane); glNormal3v(plane.normal); glBegin(GL_TRIANGLE_FAN); glVertex3v(p->vertices[0]); for(size_t i=1;i+1<p->vertices.size();i++) { glVertex3v(p->vertices[i]); glVertex3v(p->vertices[i+1]); } glEnd(); break; } case GeometricPrimitive3D::Sphere: { const Sphere3D* s=AnyCast<Sphere3D>(&geom.data); glPushMatrix(); glTranslate(s->center); drawSphere(s->radius,32,32); glPopMatrix(); break; } case GeometricPrimitive3D::Cylinder: { const Cylinder3D* s=AnyCast<Cylinder3D>(&geom.data); glPushMatrix(); glTranslate(s->center); drawCylinder(s->axis*s->height,s->radius,32); glPopMatrix(); break; } break; default: fprintf(stderr,"draw: Unsupported geometry type\n"); return; } }
void TTrackball::OnMouse(wxMouseEvent& event) { vec3 cursor = canvas->GetWorldSpace(event.GetX(), event.GetY()); if (event.LeftDown()) { if (!event.ControlDown()) Stop(); vStart = cursor; memcpy((float*) &mStart, (float*) &xform, sizeof(xform)); startZoom = canvas->GetZoom(); vPrev = cursor; validStart = true; } else if (event.LeftUp() && validStart) { float theta = 180 * vInc.magnitude(); if (theta < -InertiaThreshold || theta > InertiaThreshold) { inertiaAxis = cross(vStart, cursor); if (inertiaAxis.magnitude()) { inertiaAxis.unitize(); inertiaTheta = theta; } } else if (!event.ControlDown()) { Stop(); } validStart = false; } else if (event.Moving() && event.LeftIsDown()) { if (!validStart) { vInc = vec3(0, 0, 0); } else { if (event.ControlDown()) { float delta = cursor.y - vStart.y; if (delta) { canvas->SetZoom(startZoom + delta); canvas->Update(); } } else { float theta = 180 * (cursor - vStart).magnitude(); if (theta) { vec3 axis = cross(vStart, cursor); axis.unitize(); glLoadIdentity(); vec3 offset = wxGetApp().Frame()->GetCenter(); glTranslate(offset); glRotatef(-theta, axis.x, axis.y, axis.z); glTranslate(-offset); glMultMatrixf((float*) &mStart); glGetFloatv(GL_MODELVIEW_MATRIX, (float*) &xform); canvas->Update(); } } vInc = cursor - vPrev; } vPrev = cursor; } // Right mouse button zooms. else if (event.RightDown()) { vStart = cursor; startZoom = canvas->GetZoom(); validStart = true; } else if (event.RightUp() && validStart) { validStart = false; } else if (event.Moving() && event.RightIsDown()) { if (validStart) { float delta = cursor.y - vStart.y; if (delta) { canvas->SetZoom(startZoom + delta); canvas->Update(); } } } event.Skip(); }
static void GlesCube11_DrawCube2(Evas_Object *obj) { ELEMENTARY_GLVIEW_USE(obj); appdata_s *ad = (appdata_s *)evas_object_data_get(obj, APPDATA_KEY); static const GlUnit VERTICES[] = { ONEN, ONEN, ONEP, ONEP, ONEN, ONEP, ONEN, ONEP, ONEP, ONEP, ONEP, ONEP, ONEN, ONEN, ONEN, ONEN, ONEP, ONEN, ONEP, ONEN, ONEN, ONEP, ONEP, ONEN, ONEN, ONEN, ONEP, ONEN, ONEP, ONEP, ONEN, ONEN, ONEN, ONEN, ONEP, ONEN, ONEP, ONEN, ONEN, ONEP, ONEP, ONEN, ONEP, ONEN, ONEP, ONEP, ONEP, ONEP, ONEN, ONEP, ONEP, ONEP, ONEP, ONEP, ONEN, ONEP, ONEN, ONEP, ONEP, ONEN, ONEN, ONEN, ONEP, ONEN, ONEN, ONEN, ONEP, ONEN, ONEP, ONEP, ONEN, ONEN }; static const GlUnit TEXTURE_COORD[] = { ONEP, ZERO, ZERO, ZERO, ONEP, ONEP, ZERO, ONEP, ONEP, ZERO, ZERO, ZERO, ONEP, ONEP, ZERO, ONEP, ONEP, ZERO, ZERO, ZERO, ONEP, ONEP, ZERO, ONEP, ONEP, ZERO, ZERO, ZERO, ONEP, ONEP, ZERO, ONEP, ONEP, ZERO, ZERO, ZERO, ONEP, ONEP, ZERO, ONEP, ONEP, ZERO, ZERO, ZERO, ONEP, ONEP, ZERO, ONEP }; glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_TFIXED, 0, VERTICES); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_TFIXED, 0, TEXTURE_COORD); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, ad->tex_ids[ad->current_tex_index]); glMatrixMode(GL_MODELVIEW); { const float Z_POS_INC = 0.01f; static float zPos = -5.0f; static float zPosInc = Z_POS_INC; zPos += zPosInc; if (zPos < -8.0f) { zPosInc = Z_POS_INC; ad->current_tex_index = 1 - ad->current_tex_index; } if (zPos > -5.0f) { zPosInc = -Z_POS_INC; } glLoadIdentity(); glTranslate(0, GetGlUnit(1.2f), GetGlUnit(zPos)); { static int angle = 0; angle = (angle + 1) % (360 * 3); glRotate(GetGlUnit(angle) / 3, 0, 0, GetGlUnit(1.0f)); glRotate(GetGlUnit(angle), 0, GetGlUnit(1.0f), 0); } } for(int i = 0; i < 6; i++) { glDrawArrays(GL_TRIANGLE_STRIP, 4 * i, 4); } glDisable(GL_TEXTURE_2D); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); }
//--------------------------------------------------------- void Ship::Draw() { //just a triangle glPushMatrix(); glDisable(GL_LIGHTING); glTranslate(m_position); glRotatef(m_angle,0,0,1); glScalef(m_size,m_size,m_size); if(m_invincibilityTimer > 0) { //blinking dashed lines static unsigned short flag; //rolling dashed line if(flag == 0xff00) flag = 0x0ff0; else if(flag == 0x0ff0) flag = 0x00ff; else if(flag == 0x00ff) flag = 0xf00f; else flag = 0xff00; glEnable(GL_LINE_STIPPLE); glLineStipple (1, flag); glBegin(GL_LINE_LOOP); glColor3f(.8,.8,.8); glVertex3f(-3,-2,0); glVertex3f( 4,0,0); glVertex3f(-3,2,0); glEnd(); glDisable(GL_LINE_STIPPLE); } else { //solid triangle glBegin(GL_LINE_LOOP); glColor3f(.8,.8,.8); glVertex3f(-3,-2,0); glVertex3f( 4,0,0); glVertex3f(-3,2,0); glEnd(); } if(m_thrust) { glColor3f(.8,.4,.1); glBegin(GL_LINE_STRIP); glVertex3f(-2,-1,0); glVertex3f(-4,0,0); glVertex3f(-2,1,0); glEnd(); } if(m_revThrust) { glColor3f(.8,.4,.1); glBegin(GL_LINE_STRIP); glVertex3f(3, 1,0); glVertex3f(5, 0,0); glVertex3f(3,-1,0); glEnd(); } if(m_tractor) { glColor3f(.1,.9,.1); glBegin(GL_LINE_STRIP); glVertex3f(0, MAX_TRACTOR_POWER,0); glVertex3f(0, 0,0); glEnd(); } glEnable(GL_LIGHTING); glPopMatrix(); }
static void GlesCube11_DrawCube1(Evas_Object *obj) { ELEMENTARY_GLVIEW_USE(obj); appdata_s *ad = (appdata_s *)evas_object_data_get(obj, APPDATA_KEY); static const GlUnit VERTICES[] = { ONEN, ONEP, ONEN, // 0 ONEP, ONEP, ONEN, // 1 ONEN, ONEN, ONEN, // 2 ONEP, ONEN, ONEN, // 3 ONEN, ONEP, ONEP, // 4 ONEP, ONEP, ONEP, // 5 ONEN, ONEN, ONEP, // 6 ONEP, ONEN, ONEP // 7 }; static const GlUnit VERTEX_COLOR[] = { ONEP, ZERO, ONEP, ONEP, ONEP, ONEP, ZERO, ONEP, ZERO, ONEP, ONEP, ONEP, ONEP, ZERO, ZERO, ONEP, ZERO, ZERO, ONEP, ONEP, ZERO, ONEP, ZERO, ONEP, ONEP, ONEP, ONEP, ONEP, ZERO, ZERO, ZERO, ONEP }; static const unsigned short INDEX_BUFFER[] = { 0, 1, 2, 2, 1, 3, 1, 5, 3, 3, 5, 7, 5, 4, 7, 7, 4, 6, 4, 0, 6, 6, 0, 2, 4, 5, 0, 0, 5, 1, 2, 3, 6, 6, 3, 7 }; glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_TFIXED, 0, VERTICES); glEnableClientState(GL_COLOR_ARRAY); glColorPointer(4, GL_TFIXED, 0, VERTEX_COLOR); glMatrixMode(GL_MODELVIEW); { glLoadIdentity(); glTranslate(0, GetGlUnit(-0.7f), GetGlUnit(-5.0f)); { static int angle = 0; angle = (angle + 1) % (360 * 3); glRotate(GetGlUnit(angle) / 3, GetGlUnit(1.0f), 0, 0); glRotate(GetGlUnit(angle), 0, 0, GetGlUnit(1.0f)); } } glDrawElements(GL_TRIANGLES, 6 * (3 * 2), GL_UNSIGNED_SHORT, &INDEX_BUFFER[0]); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); }