我正在尝试使用pygame和pyopengl,在主窗口中我有两个视口 一个大地图和一个小地图(都呈现相同的框架)。我需要两个贴图围绕一个不是0,0,0的中心旋转(假设我需要旋转的中心是-130,0,60,这需要是一个常量点)
我还需要一个视图来查看距离glTranslatef(0, 0, -1000)
第二个视图是glTranslatef(1, 1, -200)
两个距离都是常数
我试着用
gluLookAt()
glOrtho()
但它不会改变旋转。。。。大约0,0,0 或者我可能用错了。你知道吗
代码如下所示:
pygame.init()
display = (1700, 1000)
pygame.display.set_mode(display, DOUBLEBUF | OPENGL)
gluPerspective(50, (display[0] / display[1]), 0.1, 5000)
glTranslatef(0, 0, -1000) # this is the view distance i want from map 1
while True:
##### i use this function to zoom in and out with mouse Wheel
##### also the zoom in/out zooms to 0,0,0 and i need (-130,0,60)
if move_camera_distance:
if zoom_in:
glScalef(0.8,0.8,0.8)
elif zoom_out:
glScalef(1.2, 1.2, 1.2)
move_camera_distance = False
zoom_in = False
zoom_out = False
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
###### Map 1
###### Need to rotate around (-130,0,60)
###### distance from camera need to be (0,0,-1000)
glViewport(1, 1, display[0], display[1]) # splits the screen
glCallList(obj.gl_list)
DrawBuffer(bufferObj, noPoints, noCirclePoints, noCrossPoints)
###### Map 2
###### Need to rotate around (-130,0,60)
###### distance from camera need to be (0,0,-300)
glViewport(1300, 650, 400, 400) # splits the screen
glCallList(obj.gl_list)
DrawBuffer(bufferObj, noPoints, noCirclePoints, noCrossPoints)
pygame.display.flip()
pygame.time.wait(10)
我得到的输出是两个贴图,都是围绕0,0,0旋转的,都是从(0,0,-1000)的距离开始的,如果我在While循环中改变任何东西,它们都会一起改变。 谢谢你的帮助。你知道吗
注意,当前矩阵可以通过^{} 存储到矩阵堆栈,并通过} )。你知道吗
glPopMatrix
从矩阵堆栈恢复。有不同的矩阵模式和矩阵堆栈(例如GL_MODELVIEW
,GL_PROJECTION
)。参见(^{在初始化时设置投影矩阵,并为不同的视图设置不同的modelview矩阵:
要围绕点旋转模型,必须:
在程序中,这些操作必须以相反的顺序应用,因为像^{} 和^{} 这样的操作定义了一个矩阵,并将该矩阵乘以当前矩阵:
在绘制对象之前立即执行此操作。你知道吗
在绘制缓冲区之前尝试调用
glLoadIdentity
相关问题 更多 >
编程相关推荐