Example #1
0
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();
}
void Glyph::render(int glyphType,GLfloat glyphSize)
	{
	switch(glyphType)
		{
		case CONE:
			glRotatef(-90.0f,1.0f,0.0f,0.0f);
			glTranslatef(0.0f,0.0f,-0.75f*glyphSize);
			glDrawCone(0.25f*glyphSize,glyphSize,16);
			break;
		
		case CUBE:
			glDrawCube(glyphSize);
			break;
		
		case SPHERE:
			glDrawSphereIcosahedron(0.5f*glyphSize,8);
			break;
		
		case CROSSBALL:
			glDrawSphereIcosahedron(0.4f*glyphSize,8);
			glDrawCylinder(0.125f*glyphSize,1.1f*glyphSize,16);
			glRotatef(90.0f,1.0f,0.0f,0.0f);
			glDrawCylinder(0.125f*glyphSize,1.1f*glyphSize,16);
			glRotatef(90.0f,0.0f,1.0f,0.0f);
			glDrawCylinder(0.125f*glyphSize,1.1f*glyphSize,16);
			break;
		
		case BOX:
			{
			#if 1
			glDrawWireframeCube(glyphSize,glyphSize*0.075f,glyphSize*0.15f);
			#else
			GLfloat gs=glyphSize*0.5f;
			glPushAttrib(GL_ENABLE_BIT|GL_POINT_BIT|GL_LINE_BIT);
			glDisable(GL_LIGHTING);
			glPointSize(5.0f);
			glBegin(GL_POINTS);
			glVertex3f(-gs,-gs,-gs);
			glVertex3f( gs,-gs,-gs);
			glVertex3f(-gs, gs,-gs);
			glVertex3f( gs, gs,-gs);
			glVertex3f(-gs,-gs, gs);
			glVertex3f( gs,-gs, gs);
			glVertex3f(-gs, gs, gs);
			glVertex3f( gs, gs, gs);
			glEnd();
			glLineWidth(3.0f);
			glBegin(GL_LINE_STRIP);
			glVertex3f(-gs,-gs,-gs);
			glVertex3f( gs,-gs,-gs);
			glVertex3f( gs, gs,-gs);
			glVertex3f(-gs, gs,-gs);
			glVertex3f(-gs,-gs,-gs);
			glVertex3f(-gs,-gs, gs);
			glVertex3f( gs,-gs, gs);
			glVertex3f( gs, gs, gs);
			glVertex3f(-gs, gs, gs);
			glVertex3f(-gs,-gs, gs);
			glEnd();
			glBegin(GL_LINES);
			glVertex3f( gs,-gs,-gs);
			glVertex3f( gs,-gs, gs);
			glVertex3f( gs, gs,-gs);
			glVertex3f( gs, gs, gs);
			glVertex3f(-gs, gs,-gs);
			glVertex3f(-gs, gs, gs);
			glEnd();
			glPopAttrib();
			#endif
			break;
			}
		}
	}
Example #3
0
void glDrawShape(ors::Shape *s) {
  //set name (for OpenGL selection)
  glPushName((s->index <<2) | 1);
  glColor(s->color[0], s->color[1], s->color[2], orsDrawAlpha);

  double scale=.33*(s->size[0]+s->size[1]+s->size[2] + 2.*s->size[3]); //some scale
  if(!scale) scale=1.;
  scale*=.3;

  double GLmatrix[16];
  s->X.getAffineMatrixGL(GLmatrix);
  glLoadMatrixd(GLmatrix);

  if(!orsDrawShapes) {
    glDrawAxes(scale);
    glColor(0, 0, .5);
    glDrawSphere(.1*scale);
  }
  if(orsDrawShapes) {
    switch(s->type) {
      case ors::noneST: break;
      case ors::boxST:
        if(orsDrawMeshes && s->mesh.V.N) s->mesh.glDraw();
        else glDrawBox(s->size[0], s->size[1], s->size[2]);
        break;
      case ors::sphereST:
        if(orsDrawMeshes && s->mesh.V.N) s->mesh.glDraw();
        else glDrawSphere(s->size[3]);
        break;
      case ors::cylinderST:
        if(orsDrawMeshes && s->mesh.V.N) s->mesh.glDraw();
        else glDrawCylinder(s->size[3], s->size[2]);
        break;
      case ors::cappedCylinderST:
        if(orsDrawMeshes && s->mesh.V.N) s->mesh.glDraw();
        else glDrawCappedCylinder(s->size[3], s->size[2]);
        break;
      case ors::markerST:
        if(orsDrawMarkers){
          glDrawDiamond(s->size[0]/5., s->size[0]/5., s->size[0]/5.); glDrawAxes(s->size[0]);
        }
        break;
      case ors::meshST:
        CHECK(s->mesh.V.N, "mesh needs to be loaded to draw mesh object");
        s->mesh.glDraw();
        break;
      case ors::pointCloudST:
        CHECK(s->mesh.V.N, "mesh needs to be loaded to draw point cloud object");
        glDrawPointCloud(s->mesh.V, NoArr);
        break;
      default: HALT("can't draw that geom yet");
    }
  }
  if(orsDrawZlines) {
    glColor(0, .7, 0);
    glBegin(GL_LINES);
    glVertex3d(0., 0., 0.);
    glVertex3d(0., 0., -s->X.pos.z);
    glEnd();
  }

  glColor(1,1,1);
  if(orsDrawBodyNames && s->body) glDrawText(s->body->name, 0, 0, 0);

  glPopName();
}
Example #4
0
void glDrawHalfBond( GLUquadric *pObj, const Vector3D& p1, const Vector3D&p2, double thickness, float renderDetailLevel)
{
    Vector3D middle = (p1 + p2) / 2;
    glDrawCylinder(pObj, p2, middle, thickness, renderDetailLevel);
}
Example #5
0
/// GL routine to draw a ors::KinematicWorld
void ors::KinematicWorld::glDraw() {
  uint i=0;
  ors::Transformation f;
  double GLmatrix[16];

  glPushMatrix();

  //bodies
  if(orsDrawBodies) for(Shape *s: shapes) {
    glDrawShape(s);
    i++;
    if(orsDrawLimit && i>=orsDrawLimit) break;
  }

  //joints
  if(orsDrawJoints) for(Joint *e: joints) {
    //set name (for OpenGL selection)
    glPushName((e->index <<2) | 2);

    double s=e->A.pos.length()+e->B.pos.length(); //some scale
    s*=.25;

    //from body to joint
    f=e->from->X;
    f.getAffineMatrixGL(GLmatrix);
    glLoadMatrixd(GLmatrix);
    glColor(1, 1, 0);
    //glDrawSphere(.1*s);
    glBegin(GL_LINES);
    glVertex3f(0, 0, 0);
    glVertex3f(e->A.pos.x, e->A.pos.y, e->A.pos.z);
    glEnd();

    //joint frame A
    f.appendTransformation(e->A);
    f.getAffineMatrixGL(GLmatrix);
    glLoadMatrixd(GLmatrix);
    glDrawAxes(s);
    glColor(1, 0, 0);
    glRotatef(90, 0, 1, 0);  glDrawCylinder(.05*s, .3*s);  glRotatef(-90, 0, 1, 0);

    //joint frame B
    f.appendTransformation(e->Q);
    f.getAffineMatrixGL(GLmatrix);
    glLoadMatrixd(GLmatrix);
    glDrawAxes(s);

    //from joint to body
    glColor(1, 0, 1);
    glBegin(GL_LINES);
    glVertex3f(0, 0, 0);
    glVertex3f(e->B.pos.x, e->B.pos.y, e->B.pos.z);
    glEnd();
    glTranslatef(e->B.pos.x, e->B.pos.y, e->B.pos.z);
    //glDrawSphere(.1*s);

    glPopName();
    i++;
    if(orsDrawLimit && i>=orsDrawLimit) break;
  }

  //proxies
  if(orsDrawProxies) for(Proxy *proxy: proxies) {
    glLoadIdentity();
    if(!proxy->colorCode) glColor(.75,.75,.75);
    else glColor(proxy->colorCode);
    glBegin(GL_LINES);
    glVertex3dv(proxy->posA.p());
    glVertex3dv(proxy->posB.p());
    glEnd();
    ors::Transformation f;
    f.pos=proxy->posA;
    f.rot.setDiff(ors::Vector(0, 0, 1), proxy->posA-proxy->posB);
    f.getAffineMatrixGL(GLmatrix);
    glLoadMatrixd(GLmatrix);
    glDisable(GL_CULL_FACE);
    glDrawDisk(.02);
    glEnable(GL_CULL_FACE);

    f.pos=proxy->posB;
    f.getAffineMatrixGL(GLmatrix);
    glLoadMatrixd(GLmatrix);
    glDrawDisk(.02);
  }

  glPopMatrix();
}