【发布时间】:2020-07-20 13:42:45
【问题描述】:
我正在尝试通过引用此来源 https://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Arcball 和 https://www.khronos.org/opengl/wiki/Object_Mouse_Trackball 来实现轨迹球
但在获得旋转轴后,它似乎没有正确转动
这是我的代码的一些 sn-p
def compute_z(x, y):
# compute z from sphere model
# sphere size = 1
z = math.sqrt(abs(1 - math.pow(x,2) - math.pow(y,2)))
return z
def get_rotation_axis(vect_1, vect_2):
# determine rotation direction
axis = np.cross(vect_1, vect_2)
return axis
这里是主要的
while True:
mouse_pos = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.MOUSEMOTION:
if arcball_on:
cur_mx = mouse_pos[0]
cur_my = mouse_pos[1]
last_conv = convert_range(last_mx, last_my)
cur_conv = convert_range(cur_mx, cur_my)
a = (last_conv[0], last_conv[1], compute_z(last_conv[0], last_conv[1]))
b = (cur_conv[0], cur_conv[1], compute_z(cur_conv[0], cur_conv[1]))
angle = compute_angle(a, b)
axis = get_rotation_axis(a, b)
print(axis)
glRotatef(angle, axis[0], axis[1], -axis[2])
【问题讨论】:
标签: python python-3.x opengl pygame pyopengl