ya2 · news · projects · code · about

configuration
[pmachines.git] / pmachines / items / box.py
index cb8c5efcab81d495618a0e85bd348f149e314eb1..c0419bba0ce8b84840c7f8f6f2d8d28a9d29e889 100644 (file)
@@ -16,7 +16,7 @@ class Box:
         model.reparent_to(self._np)
         self._set_outline_model()
         self._start_drag_pos = None
         model.reparent_to(self._np)
         self._set_outline_model()
         self._start_drag_pos = None
-        self._start_rot_info = None
+        self._prev_rot_info = None
         taskMgr.add(self.on_frame, 'on_frame')
 
     def _set_outline_model(self):
         taskMgr.add(self.on_frame, 'on_frame')
 
     def _set_outline_model(self):
@@ -44,27 +44,28 @@ class Box:
         loader.load_sfx('assets/audio/sfx/grab.ogg').play()
 
     def on_click_r(self, pos):
         loader.load_sfx('assets/audio/sfx/grab.ogg').play()
 
     def on_click_r(self, pos):
-        self._start_rot_info = pos, self._np.get_pos(), self._np.get_r()
+        self._prev_rot_info = pos, self._np.get_pos(), self._np.get_r()
         loader.load_sfx('assets/audio/sfx/grab.ogg').play()
 
     def on_release(self):
         loader.load_sfx('assets/audio/sfx/grab.ogg').play()
 
     def on_release(self):
-        if self._start_drag_pos or self._start_rot_info:
+        if self._start_drag_pos or self._prev_rot_info:
             loader.load_sfx('assets/audio/sfx/release.ogg').play()
             loader.load_sfx('assets/audio/sfx/release.ogg').play()
-        self._start_drag_pos = self._start_rot_info = None
+        self._start_drag_pos = self._prev_rot_info = None
 
     def on_mouse_on(self):
         self._outline_model.show()
 
     def on_mouse_off(self):
 
     def on_mouse_on(self):
         self._outline_model.show()
 
     def on_mouse_off(self):
-        if self._start_drag_pos or self._start_rot_info: return
+        if self._start_drag_pos or self._prev_rot_info: return
         self._outline_model.hide()
 
     def on_mouse_move(self, pos):
         if self._start_drag_pos:
             d_pos =  pos - self._start_drag_pos[0]
             self._np.set_pos(self._start_drag_pos[1] + d_pos)
         self._outline_model.hide()
 
     def on_mouse_move(self, pos):
         if self._start_drag_pos:
             d_pos =  pos - self._start_drag_pos[0]
             self._np.set_pos(self._start_drag_pos[1] + d_pos)
-        if self._start_rot_info:
-            start_vec = self._start_rot_info[0] - self._start_rot_info[1]
-            curr_vec = pos - self._start_rot_info[1]
+        if self._prev_rot_info:
+            start_vec = self._prev_rot_info[0] - self._prev_rot_info[1]
+            curr_vec = pos - self._prev_rot_info[1]
             d_angle = curr_vec.signed_angle_deg(start_vec, (0, -1, 0))
             d_angle = curr_vec.signed_angle_deg(start_vec, (0, -1, 0))
-            self._np.set_r(self._start_rot_info[2] + d_angle)
+            self._np.set_r(self._prev_rot_info[2] + d_angle)
+            self._prev_rot_info = pos, self._np.get_pos(), self._np.get_r()