Hi
I’m using this code to rotate camera with right mouse button drag:
def mouse_task(self, task):
is_down = self.mouseWatcherNode.is_button_down
left_mouse = MouseButton.one()
right_mouse = MouseButton.three()
dt = globalClock.get_dt()
pointer = self.win.get_pointer(0)
x = pointer.get_x()
y = pointer.get_y()
if self.mouseWatcherNode.has_mouse():
if is_down(left_mouse):
print("mouse left is down:", self.mouseWatcherNode.get_mouse())
if is_down(right_mouse):
if not self.is_mouse_down:
# Remember mouse position
self.mouse_start_x = x
self.mouse_start_y = y
self.is_mouse_down = True
else:
yaw = self.camera.get_h() + (self.mouse_start_x - x) * dt * 10
pitch = self.camera.get_p() + (self.mouse_start_y - y) * dt * 10
pitch = max(-1 * self.max_pitch, min(self.max_pitch, pitch))
# print("mouse: %s, %s" % (x, y))
self.camera.setHpr(yaw, pitch, 0)
print(self.camera.get_hpr())
# Remember mouse position
self.mouse_start_x = x
self.mouse_start_y = y
else:
self.is_mouse_down = False
self.mouse_start_x = None
self.mouse_start_y = None
return Task.cont
It works but at some point camera heading(yaw) gets jumpy! specially when i drag mouse from the left edge of the window to right it jumps at ~-40 into ~-52.7 even though i tried to drag slowly.
This is all package: room.zip (2.96 MB)
Forgive my stupid model