开发者

vtkaxesactor type axes in OpenGL

I need to display x-y-z axes like in VTK (vtkaxesactor class) in OpenGL, Which comes on the lower left of the scene.

I am looking for a 3(x,y,z) coloured axes in the foreground, that gives a sense of orientation when rotated, but remains agnostic to zooming.

Is there a GLUT class which does this? If not how does one implement this?

EDIT following datenwolf 's comment:

I keep track of the extent of x,y,z pan and translate. (I use pyopengl)

def renderAxis(self):

        glViewport(0,0,self.width()/8,self.height()/8)
        self.translate([-1*self.xpan,-1*self.ypan,-1*self.zpan])

        glMatrixMode(GL_MODELVIEW)
        glLineWidth(2)
        glBegin(GL_LINES)
        glColor(1, 0, 0)    #Xaxis, Red color
        glVertex3f(0, 0, 0)
        glVertex3f(0.15, 0, 0)
        glColor(0, 1, 0)    #Yaxis, Green color
        glVertex3f(0, 0, 0)
        glVertex3f(0, 0.15, 0)
        glColor(0, 0, 1)    #Zaxis, Blue color
        glVertex3f(0, 0, 0)
        glVertex3f(0, 0, 0.15)
        glEnd()

        glutInit()
        glColor(1,0,0)
        glRasterPos3f(0.16, 0.0, 0.0)
        glutBitmapCharacter(GLUT_BITMAP_8_BY_13,88)#ascii x
        glColor(0,1,0)
        glRasterPos3f(0.0, 0.16, 0.0)
        glutBitmapCharacter(GLUT_BITMAP_8_BY_13,89)#ascii y
        glColor(0,0,1)
        glRasterPos3f(0.0, 0.0, 0.16)
        glutBitmapCharacter(GLUT_BITMAP_8_BY_13,90)#ascii z

       开发者_如何学JAVA self.translate([self.xpan,self.ypan,self.zpan])
        glViewport(0,0,self.width(),self.height())

   def translate(self, _trans):
        self.makeCurrent()
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        glTranslated(_trans[0], _trans[1], _trans[2])
        glMultMatrixd(self.modelview_matrix_)
        self.modelview_matrix_ = glGetDoublev(GL_MODELVIEW_MATRIX)
        self.translate_vector_[0] = self.modelview_matrix_[3][0]
        self.translate_vector_[1] = self.modelview_matrix_[3][1]
        self.translate_vector_[2] = self.modelview_matrix_[3][2]

This does the job, however i doubt if this is the best possible way to go about.


GLUT class? You do realize that GLUT doesn't use classes? Also why so complicated, just draw those axes. At the end of your display function add the following:

void display(void)
{
     /* ... */
     glMatrixMode(GL_MODELVIEW);
     GLfloat modelview[16];
     glGetFloatfv(GL_MODELVIEW_MATRIX, modelview);
     modelview[12] = modelview[13] = modelview[14] = 0.;
     modelview[15] = 1.;
     glLoadMatrixf(modelview);

     glViewport(0, 0, mini_axis_width, mini_axis_height);

     GLfloat miniaxis[] = {
          0., 0., 0., 1., 0., 0.,
          1., 0., 0., 1., 0., 0.,

          0., 0., 0., 0., 1., 0.,
          0., 1., 0., 0., 1., 0.,

          0., 0., 0., 0., 0., 1.,
          0., 0., 1., 0., 0., 1.,
     };

     glEnableClientState(GL_VERTEX_ARRAY);
     glEnableClientState(GL_COLOR_ARRAY);
     glVertexPointer(3, GL_FLOAT, 6*sizeof(GLfloat), miniaxis);
     glColorPointer(3, GL_FLOAT, 6*sizeof(GLfloat), miniaxis+3);
     glDrawArrays(GL_LINES, 0, 6);

     SwapBuffers();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜