我正在尝试通过参考此来源https://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Arcball和https://www.khronos.org/opengl/wiki/Object_Mouse_Trackball来实现轨迹球
但是在获得旋转轴后它似乎没有正确转动
这是我的代码片段
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])
慕妹3146593
相关分类