Python opengl glulookat()到glrotate+;gltranslate

Python opengl glulookat()到glrotate+;gltranslate,python,opengl,pyopengl,Python,Opengl,Pyopengl,我需要这个结果 但这只是相似的结果,不会出现。 这是我的结果。我在那里做了一些改变,但没有达到预期的效果 我有消息说这件事。所以我使用旋转x,y 36.264和旋转xz 45度。但我不能解决这个问题 我应该修正什么?将模型相对于相机位置平移(-3,-3,-3),围绕y轴旋转-45°,最后围绕x轴旋转35.264°(atan(1/sqrt(2)): glRotatef(35.264,1,0,0) glRotatef(-45,0,1,0) glTranslatef(-3,-3,-3) 当上

我需要这个结果 但这只是相似的结果,不会出现。

这是我的结果。我在那里做了一些改变,但没有达到预期的效果

我有消息说这件事。所以我使用旋转x,y 36.264和旋转xz 45度。但我不能解决这个问题


我应该修正什么?

将模型相对于相机位置平移(-3,-3,-3),围绕y轴旋转-45°,最后围绕x轴旋转35.264°(atan(1/sqrt(2)):

glRotatef(35.264,1,0,0)
glRotatef(-45,0,1,0)
glTranslatef(-3,-3,-3)

当上方向向量为(0,1,0)时:

e=[3,3,3]
c=[0,0,0]
gluLookAt(3,3,3,0,0,0,0,1,0)
一般做法是:

服务水平=c[0]-e[0],c[1]-e[1],c[2]-e[2] rot_y=数学学位(数学atan2(服务水平[0],-服务水平[2])) len_xz=数学形低气压(服务水平[0],服务水平[2]) rot_x=数学学位(数学atan2(los[1],len_xz)) glRotatef(rot_x,-1,0,0) glRotatef(rot_y,0,1,0) GLTRANSTEF(服务水平[0]、服务水平[1]、服务水平[2])
import glfw 
import numpy as np 
from OpenGL.GL import * 
from OpenGL.GLU import * 
gCamAng = 0. 
gCamHeight = 1. 
def drawUnitCube(): 
  glBegin(GL_QUADS) 
  glVertex3f( 0.5, 0.5,-0.5) 
  glVertex3f(-0.5, 0.5,-0.5) 
  glVertex3f(-0.5, 0.5, 0.5) 
  glVertex3f( 0.5, 0.5, 0.5) 
   
  glVertex3f( 0.5,-0.5, 0.5) 
  glVertex3f(-0.5,-0.5, 0.5) 
  glVertex3f(-0.5,-0.5,-0.5) 
  glVertex3f( 0.5,-0.5,-0.5) 
   
  glVertex3f( 0.5, 0.5, 0.5) 
  glVertex3f(-0.5, 0.5, 0.5) 
  glVertex3f(-0.5,-0.5, 0.5) 
  glVertex3f( 0.5,-0.5, 0.5) 
   
  glVertex3f( 0.5,-0.5,-0.5) 
  glVertex3f(-0.5,-0.5,-0.5) 
  glVertex3f(-0.5, 0.5,-0.5) 
  glVertex3f( 0.5, 0.5,-0.5) 
  glVertex3f(-0.5, 0.5, 0.5) 
  glVertex3f(-0.5, 0.5,-0.5) 
  glVertex3f(-0.5,-0.5,-0.5) 
  glVertex3f(-0.5,-0.5, 0.5) 
   
  glVertex3f( 0.5, 0.5,-0.5) 
  glVertex3f( 0.5, 0.5, 0.5) 
  glVertex3f( 0.5,-0.5, 0.5) 
  glVertex3f( 0.5,-0.5,-0.5) 
  glEnd() 
   
def drawCubeArray(): 
  for i in range(5): 
      for j in range(5): 
          for k in range(5): 
              glPushMatrix() 
              glTranslatef(i,j,-k-1) 
              glScalef(.5,.5,.5) 
              drawUnitCube() 
              glPopMatrix() 
def drawFrame(): 
  glBegin(GL_LINES) 
  glColor3ub(255, 0, 0) 
  glVertex3fv(np.array([0.,0.,0.])) 
  glVertex3fv(np.array([1.,0.,0.])) 
  glColor3ub(0, 255, 0) 
  glVertex3fv(np.array([0.,0.,0.])) 
  glVertex3fv(np.array([0.,1.,0.])) 
  glColor3ub(0, 0, 255) 
  glVertex3fv(np.array([0.,0.,0])) 
  glVertex3fv(np.array([0.,0.,1.])) 
  glEnd() 
def render(): 
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) 
  glEnable(GL_DEPTH_TEST) 
  glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ) 
  glLoadIdentity() 
  gluPerspective(45, 1, 1,10) 
   
  #gluLookAt(3,3,3, 0,0,0, 0,1,0) 
   
  glRotatef(36.264,0,-1,-1) 
  glRotatef(45,1,0,1) 
  glTranslatef(-3,-3,-3) 
  drawFrame() 
  glColor3ub(255, 255, 255) 
  drawCubeArray() 
   
def main(): 
  if not glfw.init(): 
      return 
  window=glfw.create_window(480,480,"1",None,None) 
  if not window: 
      glfw.terminate() 
      return 
  glfw.make_context_current(window) 
   
  while not glfw.window_should_close(window): 
      glfw.poll_events() 
      render() 
      glfw.swap_buffers(window) 
  glfw.terminate() 
  return 
if __name__=="__main__": 
  main()