[Bf-blender-cvs] [7f8d620e20c] master: Cleanup: trackball direction calculation

Campbell Barton noreply at git.blender.org
Sat Aug 3 17:49:27 CEST 2019


Commit: 7f8d620e20c2369838c9bc528fde0b785b345afc
Author: Campbell Barton
Date:   Sun Aug 4 01:18:23 2019 +1000
Branches: master
https://developer.blender.org/rB7f8d620e20c2369838c9bc528fde0b785b345afc

Cleanup: trackball direction calculation

Remove z axis flipping, only needed because x & y were flipped.

===================================================================

M	source/blender/editors/space_view3d/view3d_edit.c

===================================================================

diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 826eddc63d1..af862345824 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -185,28 +185,23 @@ typedef struct ViewOpsData {
 
 #define TRACKBALLSIZE (1.1f)
 
-static void calctrackballvec(const rcti *rect, const int event_xy[2], float vec[3])
+static void calctrackballvec(const rcti *rect, const int event_xy[2], float r_dir[3])
 {
   const float radius = TRACKBALLSIZE;
   const float t = radius / (float)M_SQRT2;
-  float x, y, z, d;
 
-  /* normalize x and y */
-  x = BLI_rcti_cent_x(rect) - event_xy[0];
-  x /= (float)(BLI_rcti_size_x(rect) / 4);
-  y = BLI_rcti_cent_y(rect) - event_xy[1];
-  y /= (float)(BLI_rcti_size_y(rect) / 2);
-  d = sqrtf(x * x + y * y);
-  if (d < t) { /* Inside sphere */
-    z = sqrtf(radius * radius - d * d);
+  /* Normalize x and y. */
+  r_dir[0] = (event_xy[0] - BLI_rcti_cent_x(rect)) / ((float)BLI_rcti_size_x(rect) / 4.0);
+  r_dir[1] = (event_xy[1] - BLI_rcti_cent_x(rect)) / ((float)BLI_rcti_size_y(rect) / 2.0);
+  const float d = len_v2(r_dir);
+  if (d < t) {
+    /* Inside sphere. */
+    r_dir[2] = sqrtf(SQUARE(radius) - SQUARE(d));
   }
-  else { /* On hyperbola */
-    z = t * t / d;
+  else {
+    /* On hyperbola. */
+    r_dir[2] = SQUARE(t) / d;
   }
-
-  vec[0] = x;
-  vec[1] = y;
-  vec[2] = -z; /* yah yah! */
 }
 
 /**



More information about the Bf-blender-cvs mailing list