2011-07-05 28 views
0

OpenGLでは、シーンの左下にあるVTK(vtkaxesactorクラス)のようなx-y-z軸を表示する必要があります。OpenGLのvtkaxesactorタイプの軸

フォアグラウンドで3軸(x、y、z)の色のついた軸を探していますが、回転すると向きが変わりますが、ズーミングには無関心です。

これを行うGLUTクラスはありますか?これをどうやって実装していないのですか?

EDIT次datenwolfのコメントは:

私はX、Y、Zパンや変換の範囲を追跡します。 (私は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 

     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] 

これは仕事になりますが、これは最善の方法ですか?

答えて

1

GLUTクラス?あなたはGLUTがクラスを使用していないことを認識していますか?なぜそんなに複雑なのか、それらの軸を描くだけです。表示機能の最後に、以下を追加します。

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(); 
} 
関連する問題