Source

kinect-viewer / trackball.c

Diff from to

File trackball.c

 
 #include <math.h>
 
-static const float kTol = 0.001;
-static const float kRad2Deg = 180. / 3.1415927;
-static const float kDeg2Rad = 3.1415927 / 180.;
+static const float kTol = 0.001F;
+static const float kRad2Deg = 180.F / 3.1415927F;
+static const float kDeg2Rad = 3.1415927F / 180.F;
 
 float gRadiusTrackball;
 float gStartPtTrackball[3];
 float gEndPtTrackball[3];
-long gXCenterTrackball = 0, gYCenterTrackball = 0;
+int gXCenterTrackball = 0, gYCenterTrackball = 0;
 
 // mouse positon and view size as inputs
 void startTrackball (long x, long y, long originX, long originY, long width, long height)
        to the center.  The axis of rotation is the cross product of these two vectors,
        and the angle of rotation is the angle between the two vectors.
      */
-    nx = width;
-    ny = height;
+    nx = (float) width;
+    ny = (float) height;
     if (nx > ny)
-        gRadiusTrackball = ny * 0.5;
+        gRadiusTrackball = ny * 0.5F;
     else
-        gRadiusTrackball = nx * 0.5;
+        gRadiusTrackball = nx * 0.5F;
     // Figure the center of the view.
-    gXCenterTrackball = originX + width * 0.5;
-    gYCenterTrackball = originY + height * 0.5;
+    gXCenterTrackball = (int) (originX + width * 0.5);
+    gYCenterTrackball = (int) (originY + height * 0.5);
     
     // Compute the starting vector from the surface of the ball to its center.
-    gStartPtTrackball [0] = x - gXCenterTrackball;
-    gStartPtTrackball [1] = y - gYCenterTrackball;
+    gStartPtTrackball [0] = (float) x - gXCenterTrackball;
+    gStartPtTrackball [1] = (float) y - gYCenterTrackball;
     xxyy = gStartPtTrackball [0] * gStartPtTrackball[0] + gStartPtTrackball [1] * gStartPtTrackball [1];
     if (xxyy > gRadiusTrackball * gRadiusTrackball) {
         // Outside the sphere.
-        gStartPtTrackball[2] = 0.;
+        gStartPtTrackball[2] = 0.F;
     } else
-        gStartPtTrackball[2] = sqrt (gRadiusTrackball * gRadiusTrackball - xxyy);
+        gStartPtTrackball[2] = sqrtf(gRadiusTrackball * gRadiusTrackball - xxyy);
     
 }
 
     float cosAng, sinAng;
     float ls, le, lr;
     
-    gEndPtTrackball[0] = x - gXCenterTrackball;
-    gEndPtTrackball[1] = y - gYCenterTrackball;
+    gEndPtTrackball[0] = (float) x - gXCenterTrackball;
+    gEndPtTrackball[1] = (float) y - gYCenterTrackball;
     if (fabs (gEndPtTrackball [0] - gStartPtTrackball [0]) < kTol && fabs (gEndPtTrackball [1] - gStartPtTrackball [1]) < kTol)
         return; // Not enough change in the vectors to have an action.
 
     xxyy = gEndPtTrackball [0] * gEndPtTrackball [0] + gEndPtTrackball [1] * gEndPtTrackball [1];
     if (xxyy > gRadiusTrackball * gRadiusTrackball) {
         // Outside the sphere.
-        gEndPtTrackball [2] = 0.;
+        gEndPtTrackball [2] = 0.F;
     } else
-        gEndPtTrackball[ 2] = sqrt (gRadiusTrackball * gRadiusTrackball - xxyy);
+        gEndPtTrackball[ 2] = sqrtf (gRadiusTrackball * gRadiusTrackball - xxyy);
         
     // Take the cross product of the two vectors. r = s X e
     rot[1] =  gStartPtTrackball[1] * gEndPtTrackball[2] - gStartPtTrackball[2] * gEndPtTrackball[1];
     
     // cos(a) = (s . e) / (||s|| ||e||)
     cosAng = gStartPtTrackball[0] * gEndPtTrackball[0] + gStartPtTrackball[1] * gEndPtTrackball[1] + gStartPtTrackball[2] * gEndPtTrackball[2]; // (s . e)
-    ls = sqrt(gStartPtTrackball[0] * gStartPtTrackball[0] + gStartPtTrackball[1] * gStartPtTrackball[1] + gStartPtTrackball[2] * gStartPtTrackball[2]);
-    ls = 1. / ls; // 1 / ||s||
-    le = sqrt(gEndPtTrackball[0] * gEndPtTrackball[0] + gEndPtTrackball[1] * gEndPtTrackball[1] + gEndPtTrackball[2] * gEndPtTrackball[2]);
-    le = 1. / le; // 1 / ||e||
+    ls = sqrtf(gStartPtTrackball[0] * gStartPtTrackball[0] + gStartPtTrackball[1] * gStartPtTrackball[1] + gStartPtTrackball[2] * gStartPtTrackball[2]);
+    ls = 1.F / ls; // 1 / ||s||
+    le = sqrtf(gEndPtTrackball[0] * gEndPtTrackball[0] + gEndPtTrackball[1] * gEndPtTrackball[1] + gEndPtTrackball[2] * gEndPtTrackball[2]);
+    le = 1.F / le; // 1 / ||e||
     cosAng = cosAng * ls * le;
     
     // sin(a) = ||(s X e)|| / (||s|| ||e||)
-    sinAng = lr = sqrt(rot[1] * rot[1] + rot[2] * rot[2] + rot[3] * rot[3]); // ||(s X e)||;
+    sinAng = lr = sqrtf(rot[1] * rot[1] + rot[2] * rot[2] + rot[3] * rot[3]); // ||(s X e)||;
                                 // keep this length in lr for normalizing the rotation vector later.
     sinAng = sinAng * ls * le;
     rot[0] = (float) atan2 (sinAng, cosAng) * kRad2Deg; // GL rotations are in degrees.
     
     // Normalize the rotation axis.
-    lr = 1. / lr;
+    lr = 1.F / lr;
     rot[1] *= lr; rot[2] *= lr; rot[3] *= lr;
     
     // returns rotate
     // {angle, x, y, z}, the corresponding quaternion looks like this:
     // {{v}, cos(angle/2)}, where {v} is {x, y, z} / sin(angle/2).
     
-    ang2 = A[0] * kDeg2Rad * 0.5;  // Convert from degrees ot radians, get the half-angle.
-    sinAng2 = sin(ang2);
+    ang2 = A[0] * kDeg2Rad * 0.5F;  // Convert from degrees ot radians, get the half-angle.
+    sinAng2 = sinf(ang2);
     q[0] = A[1] * sinAng2; q[1] = A[2] * sinAng2; q[2] = A[3] * sinAng2;
-    q[3] = cos(ang2);
+    q[3] = cosf(ang2);
 }
 
 void addToRotationTrackball (float * dA, float * A)