我正在旋转一个三角形,前提是它不接触渲染部分(我认为这个问题不能用相机解决) 我希望在上述状态下旋转的轴是中心(基于世界坐标(0,0))而不是局部空间。当三角形不在0,0时
这是我的密码
import glfw
from OpenGL.GL import *
from OpenGL.GLU import *
import numpy as np
def render(T):
glClear(GL_COLOR_BUFFER_BIT)
glLoadIdentity()
# draw cooridnate
glBegin(GL_LINES)
glColor3ub(255, 0, 0)
glVertex2fv(np.array([0.,0.]))
glVertex2fv(np.array([1.,0.]))
glColor3ub(0, 255, 0)
glVertex2fv(np.array([0.,0.]))
glVertex2fv(np.array([0.,1.]))
glEnd()
# draw triangle
glBegin(GL_TRIANGLES)
glColor3ub(255, 255, 255)
glVertex2fv( (T @ np.array([.0,.5,1.]))[:-1] )
glVertex2fv( (T @ np.array([.0,.0,1.]))[:-1] )
glVertex2fv( (T @ np.array([.5,.0,1.]))[:-1] )
glEnd()
def main():
if not glfw.init():
return
window = glfw.create_window(480,480,"1234", None,None)
if not window:
glfw.terminate()
return
glfw.make_context_current(window)
glfw.swap_interval(1)
while not glfw.window_should_close(window):
glfw.poll_events()
t = glfw.get_time()
s= np.sin(t)
q = np.array([[np.cos(t),-np.sin(t),.3],
[np.sin(t), np.cos(t),.3],
[0., 0., 0.]])
#th = np.radians(60)
#R = np.array([[np.cos(th), -np.sin(th),0.],
# [np.sin(th), np.cos(th),0.],
# [0., 0., 1.]])
#T = np.array([[1.,0.,.4],
# [0.,1.,.1],
# [0.,0.,1.]])
render(q)
glfw.swap_buffers(window)
glfw.terminate()
if __name__ == "__main__":
main()
->;这是我的当前状态,但不是世界空间(0,0)
如果要围绕轴心点旋转和移动对象,请执行以下操作:
相关问题 更多 >
编程相关推荐