Browse Source

trackball: int to double

Former-commit-id: 259e0bb4dfd3c86b781cdd8c9d1de83a7c7ba7c7
Alec Jacobson (jalec 11 years ago
parent
commit
2b40471f2b
2 changed files with 43 additions and 41 deletions
  1. 25 23
      include/igl/trackball.cpp
  2. 18 18
      include/igl/trackball.h

+ 25 - 23
include/igl/trackball.cpp

@@ -16,20 +16,21 @@
 #include <cstdlib>
 #include <cassert>
 #include <algorithm>
+#include <iostream>
 
 // Utility IGL_INLINE functions
 template <typename Q_type>
-static IGL_INLINE Q_type _QuatD(int w, int h)
+static IGL_INLINE Q_type _QuatD(double w, double h)
 {
   return (Q_type)(abs(w) < abs(h) ? abs(w) : abs(h)) - 4;
 }
 template <typename Q_type>
-static IGL_INLINE Q_type _QuatIX(int x, int w, int h)
+static IGL_INLINE Q_type _QuatIX(double x, double w, double h)
 {
   return (2.0f*(Q_type)x - (Q_type)w - 1.0f)/_QuatD<Q_type>(w, h);
 }
 template <typename Q_type>
-static IGL_INLINE Q_type _QuatIY(int y, int w, int h)
+static IGL_INLINE Q_type _QuatIY(double y, double w, double h)
 {
   return (-2.0f*(Q_type)y + (Q_type)h - 1.0f)/_QuatD<Q_type>(w, h);
 }
@@ -39,13 +40,13 @@ static IGL_INLINE Q_type _QuatIY(int y, int w, int h)
 // http://www.antisphere.com/Wiki/tools:anttweakbar
 template <typename Q_type>
 IGL_INLINE void igl::trackball(
-  const int w,
-  const int h,
+  const double w,
+  const double h,
   const Q_type speed_factor,
-  const int down_mouse_x,
-  const int down_mouse_y,
-  const int mouse_x,
-  const int mouse_y,
+  const double down_mouse_x,
+  const double down_mouse_y,
+  const double mouse_x,
+  const double mouse_y,
   Q_type * quat)
 {
   assert(speed_factor > 0);
@@ -86,14 +87,14 @@ IGL_INLINE void igl::trackball(
 
 template <typename Q_type>
 IGL_INLINE void igl::trackball(
-  const int w,
-  const int h,
+  const double w,
+  const double h,
   const Q_type speed_factor,
   const Q_type * down_quat,
-  const int down_mouse_x,
-  const int down_mouse_y,
-  const int mouse_x,
-  const int mouse_y,
+  const double down_mouse_x,
+  const double down_mouse_y,
+  const double mouse_x,
+  const double mouse_y,
   Q_type * quat)
 {
   double qrot[4], qres[4], qorig[4];
@@ -131,16 +132,17 @@ IGL_INLINE void igl::trackball(
 }
 
 IGL_INLINE void igl::trackball(
-  const int w,
-  const int h,
+  const double w,
+  const double h,
   const double speed_factor,
   const Eigen::Quaterniond & down_quat,
-  const int down_mouse_x,
-  const int down_mouse_y,
-  const int mouse_x,
-  const int mouse_y,
+  const double down_mouse_x,
+  const double down_mouse_y,
+  const double mouse_x,
+  const double mouse_y,
   Eigen::Quaterniond & quat)
 {
+  using namespace std;
   return trackball(
     w,
     h,
@@ -156,7 +158,7 @@ IGL_INLINE void igl::trackball(
 #ifndef IGL_HEADER_ONLY
 // Explicit template specialization
 // generated by autoexplicit.sh
-template void igl::trackball<double>(int, int, double, double const*, int, int, int, int, double*);
+template void igl::trackball<double>(double, double, double, double const*, double, double, double, double, double*);
 // generated by autoexplicit.sh
-template void igl::trackball<float>(int, int, float, float const*, int, int, int, int, float*);
+template void igl::trackball<float>(double, double, float, float const*, double, double, double, double, float*);
 #endif

+ 18 - 18
include/igl/trackball.h

@@ -26,13 +26,13 @@ namespace igl
   //   quat  the resulting rotation (as quaternion)
   template <typename Q_type>
   IGL_INLINE void trackball(
-    const int w,
-    const int h,
+    const double w,
+    const double h,
     const Q_type speed_factor,
-    const int down_mouse_x,
-    const int down_mouse_y,
-    const int mouse_x,
-    const int mouse_y,
+    const double down_mouse_x,
+    const double down_mouse_y,
+    const double mouse_x,
+    const double mouse_y,
     Q_type * quat);
 
   // Applies a trackball drag to a given rotation
@@ -50,25 +50,25 @@ namespace igl
   //   quat  the resulting rotation (as quaternion)
   template <typename Q_type>
   IGL_INLINE void trackball(
-    const int w,
-    const int h,
+    const double w,
+    const double h,
     const Q_type speed_factor,
     const Q_type * down_quat,
-    const int down_mouse_x,
-    const int down_mouse_y,
-    const int mouse_x,
-    const int mouse_y,
+    const double down_mouse_x,
+    const double down_mouse_y,
+    const double mouse_x,
+    const double mouse_y,
     Q_type * quat);
   // Eigen wrapper.
   IGL_INLINE void trackball(
-    const int w,
-    const int h,
+    const double w,
+    const double h,
     const double speed_factor,
     const Eigen::Quaterniond & down_quat,
-    const int down_mouse_x,
-    const int down_mouse_y,
-    const int mouse_x,
-    const int mouse_y,
+    const double down_mouse_x,
+    const double down_mouse_y,
+    const double mouse_x,
+    const double mouse_y,
     Eigen::Quaterniond & quat);
 }