Commit: d54e71c8bf1b0ea5651f9b44282f367c5d4e0906
Author: Porteries Tristan
Date:   Sat Oct 31 10:24:38 2015 +0100
Branches: temp_bge_moto
https://developer.blender.org/rBd54e71c8bf1b0ea5651f9b44282f367c5d4e0906

BGE: Moto: use templates to avoid duplicated code to convert in double or float 
arrays.

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

M       intern/moto/include/MT_CmMatrix4x4.h
M       intern/moto/include/MT_Matrix3x3.h
M       intern/moto/include/MT_Matrix4x4.h
M       intern/moto/include/MT_Point2.h
M       intern/moto/include/MT_Point3.h
M       intern/moto/include/MT_Quaternion.h
M       intern/moto/include/MT_Transform.h
M       intern/moto/include/MT_Tuple2.h
M       intern/moto/include/MT_Tuple3.h
M       intern/moto/include/MT_Tuple4.h
M       intern/moto/include/MT_Vector2.h
M       intern/moto/include/MT_Vector3.h
M       intern/moto/include/MT_Vector4.h
M       intern/moto/intern/MT_CmMatrix4x4.cpp
M       intern/moto/intern/MT_Transform.cpp

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

diff --git a/intern/moto/include/MT_CmMatrix4x4.h 
b/intern/moto/include/MT_CmMatrix4x4.h
index 2b710c6..962451c 100644
--- a/intern/moto/include/MT_CmMatrix4x4.h
+++ b/intern/moto/include/MT_CmMatrix4x4.h
@@ -54,16 +54,17 @@ class MT_CmMatrix4x4
 
 public :
 
-       MT_CmMatrix4x4(
-               const float value[4][4]
-       );
-
-       MT_CmMatrix4x4(
-       );
-
+       template <typename T>
+       MT_CmMatrix4x4(const T value[4][4])
+       {
+               for (int i=0;i<4;i++)
+               {
+                       for (int j=0;j<4;j++)
+                               m_V[i][j] = (double)value[i][j];
+               }
+       }
 
        MT_CmMatrix4x4(
-               const double value[16]
        );
 
        MT_CmMatrix4x4(
@@ -94,11 +95,11 @@ public :
        getPointer(
        ) const;
 
-               void
-       setElem(
-               int pos,
-               double newvalue
-       );
+       template <typename T>
+       void setElem(int pos, T newvalue)
+       {
+               m_Vflat[pos] = (double)newvalue;
+       }
 
                MT_Vector3
        GetRight(
diff --git a/intern/moto/include/MT_Matrix3x3.h 
b/intern/moto/include/MT_Matrix3x3.h
index 17dd533..eac629e 100644
--- a/intern/moto/include/MT_Matrix3x3.h
+++ b/intern/moto/include/MT_Matrix3x3.h
@@ -55,8 +55,8 @@
 class MT_Matrix3x3 {
 public:
     MT_Matrix3x3() {}
-    MT_Matrix3x3(const float *m) { setValue(m); }
-    MT_Matrix3x3(const double *m) { setValue(m); }
+    template <typename T>
+    MT_Matrix3x3(const T *m) { setValue(m); }
     MT_Matrix3x3(const MT_Quaternion& q) { setRotation(q); }
     
        MT_Matrix3x3(const MT_Quaternion& q, const MT_Vector3& s) { 
@@ -97,28 +97,18 @@ public:
                m_el[i][2] = v[2];
        }
     
-    void setValue(const float *m) {
+    template <typename T>
+    void setValue(const T *m) {
         m_el[0][0] = *m++; m_el[1][0] = *m++; m_el[2][0] = *m++; m++;
         m_el[0][1] = *m++; m_el[1][1] = *m++; m_el[2][1] = *m++; m++;
         m_el[0][2] = *m++; m_el[1][2] = *m++; m_el[2][2] = *m;
     }
 
-    void setValue(const double *m) {
-        m_el[0][0] = *m++; m_el[1][0] = *m++; m_el[2][0] = *m++; m++;
-        m_el[0][1] = *m++; m_el[1][1] = *m++; m_el[2][1] = *m++; m++;
-        m_el[0][2] = *m++; m_el[1][2] = *m++; m_el[2][2] = *m;
-    }
-
-    void setValue3x3(const float *m) {
-        m_el[0][0] = *m++; m_el[1][0] = *m++; m_el[2][0] = *m++;
-        m_el[0][1] = *m++; m_el[1][1] = *m++; m_el[2][1] = *m++;
-        m_el[0][2] = *m++; m_el[1][2] = *m++; m_el[2][2] = *m;
-    }
-
-    void setValue3x3(const double *m) {
-        m_el[0][0] = *m++; m_el[1][0] = *m++; m_el[2][0] = *m++;
-        m_el[0][1] = *m++; m_el[1][1] = *m++; m_el[2][1] = *m++;
-        m_el[0][2] = *m++; m_el[1][2] = *m++; m_el[2][2] = *m;
+    template <typename T>
+    void setValue3x3(const T *m) {
+        m_el[0][0] = (MT_Scalar)*m++; m_el[1][0] = (MT_Scalar)*m++; m_el[2][0] 
= (MT_Scalar)*m++;
+        m_el[0][1] = (MT_Scalar)*m++; m_el[1][1] = (MT_Scalar)*m++; m_el[2][1] 
= (MT_Scalar)*m++;
+        m_el[0][2] = (MT_Scalar)*m++; m_el[1][2] = (MT_Scalar)*m++; m_el[2][2] 
= (MT_Scalar)*m;
     }
 
     void setValue(MT_Scalar xx, MT_Scalar xy, MT_Scalar xz, 
@@ -205,28 +195,18 @@ public:
                  MT_Scalar(0.0), MT_Scalar(0.0), MT_Scalar(1.0)); 
     }
     
-    void getValue(float *m) const {
-        *m++ = (float) m_el[0][0]; *m++ = (float) m_el[1][0]; *m++ = (float) 
m_el[2][0]; *m++ = (float) 0.0;
-        *m++ = (float) m_el[0][1]; *m++ = (float) m_el[1][1]; *m++ = (float) 
m_el[2][1]; *m++ = (float) 0.0;
-        *m++ = (float) m_el[0][2]; *m++ = (float) m_el[1][2]; *m++ = (float) 
m_el[2][2]; *m   = (float) 0.0;
-    }
-
-    void getValue(double *m) const {
-        *m++ = m_el[0][0]; *m++ = m_el[1][0]; *m++ = m_el[2][0]; *m++ = 0.0;
-        *m++ = m_el[0][1]; *m++ = m_el[1][1]; *m++ = m_el[2][1]; *m++ = 0.0;
-        *m++ = m_el[0][2]; *m++ = m_el[1][2]; *m++ = m_el[2][2]; *m   = 0.0;
-    }
-
-    void getValue3x3(float *m) const {
-        *m++ = (float) m_el[0][0]; *m++ = (float) m_el[1][0]; *m++ = (float) 
m_el[2][0];
-        *m++ = (float) m_el[0][1]; *m++ = (float) m_el[1][1]; *m++ = (float) 
m_el[2][1];
-        *m++ = (float) m_el[0][2]; *m++ = (float) m_el[1][2]; *m++ = (float) 
m_el[2][2];
+    template <typename T>
+    void getValue(T *m) const {
+        *m++ = (T)m_el[0][0]; *m++ = (T)m_el[1][0]; *m++ = (T)m_el[2][0]; *m++ 
= (T)0;
+        *m++ = (T)m_el[0][1]; *m++ = (T)m_el[1][1]; *m++ = (T)m_el[2][1]; *m++ 
= (T)0;
+        *m++ = (T)m_el[0][2]; *m++ = (T)m_el[1][2]; *m++ = (T)m_el[2][2]; *m   
= (T)0;
     }
 
-    void getValue3x3(double *m) const {
-        *m++ = m_el[0][0]; *m++ = m_el[1][0]; *m++ = m_el[2][0];
-        *m++ = m_el[0][1]; *m++ = m_el[1][1]; *m++ = m_el[2][1];
-        *m++ = m_el[0][2]; *m++ = m_el[1][2]; *m++ = m_el[2][2];
+    template <typename T>
+    void getValue3x3(T *m) const {
+        *m++ = (T)m_el[0][0]; *m++ = (T)m_el[1][0]; *m++ = (T)m_el[2][0];
+        *m++ = (T)m_el[0][1]; *m++ = (T)m_el[1][1]; *m++ = (T)m_el[2][1];
+        *m++ = (T)m_el[0][2]; *m++ = (T)m_el[1][2]; *m++ = (T)m_el[2][2];
     }
 
     MT_Quaternion getRotation() const;
diff --git a/intern/moto/include/MT_Matrix4x4.h 
b/intern/moto/include/MT_Matrix4x4.h
index de2ea99..c9d7b6f 100644
--- a/intern/moto/include/MT_Matrix4x4.h
+++ b/intern/moto/include/MT_Matrix4x4.h
@@ -55,11 +55,8 @@ public:
        /**
         * Initialize all fields with the values pointed at by m. A
         * contigous block of 16 values is read.  */
-    MT_Matrix4x4(const float *m) { setValue(m); }
-       /**
-        * Initialize all fields with the values pointed at by m. A
-        * contigous block of 16 values is read.  */
-    MT_Matrix4x4(const double *m) { setValue(m); }
+       template <typename T>
+    MT_Matrix4x4(const T *m) { setValue(m); }
     
        /**
         * Initialise with these 16 explicit values.
@@ -101,23 +98,14 @@ public:
 
     /**
         * Set the matrix to the values pointer at by m. A contiguous
-        * block of 16 values is copied.  */
-    void setValue(const float *m) {
-        m_el[0][0] = *m++; m_el[1][0] = *m++; m_el[2][0] = *m++; m_el[3][0] = 
*m++;
-        m_el[0][1] = *m++; m_el[1][1] = *m++; m_el[2][1] = *m++; m_el[3][1] = 
*m++;
-        m_el[0][2] = *m++; m_el[1][2] = *m++; m_el[2][2] = *m++; m_el[3][2] = 
*m++;
-        m_el[0][3] = *m++; m_el[1][3] = *m++; m_el[2][3] = *m++; m_el[3][3] = 
*m;
-    }
-
-    /**
-        * Set the matrix to the values pointer at by m. A contiguous
-        * block of 16 values is copied.
+        * block of 16 values is copied.  
         */
-    void setValue(const double *m) {
-        m_el[0][0] = *m++; m_el[1][0] = *m++; m_el[2][0] = *m++; m_el[3][0] = 
*m++;
-        m_el[0][1] = *m++; m_el[1][1] = *m++; m_el[2][1] = *m++; m_el[3][1] = 
*m++;
-        m_el[0][2] = *m++; m_el[1][2] = *m++; m_el[2][2] = *m++; m_el[3][2] = 
*m++;
-        m_el[0][3] = *m++; m_el[1][3] = *m++; m_el[2][3] = *m++; m_el[3][3] = 
*m;
+    template <typename T>
+    void setValue(const T *m) {
+        m_el[0][0] = (MT_Scalar)*m++; m_el[1][0] = (MT_Scalar)*m++; m_el[2][0] 
= (MT_Scalar)*m++; m_el[3][0] = (MT_Scalar)*m++;
+        m_el[0][1] = (MT_Scalar)*m++; m_el[1][1] = (MT_Scalar)*m++; m_el[2][1] 
= (MT_Scalar)*m++; m_el[3][1] = (MT_Scalar)*m++;
+        m_el[0][2] = (MT_Scalar)*m++; m_el[1][2] = (MT_Scalar)*m++; m_el[2][2] 
= (MT_Scalar)*m++; m_el[3][2] = (MT_Scalar)*m++;
+        m_el[0][3] = (MT_Scalar)*m++; m_el[1][3] = (MT_Scalar)*m++; m_el[2][3] 
= (MT_Scalar)*m++; m_el[3][3] = (MT_Scalar)*m;
     }
 
     /**
@@ -166,28 +154,20 @@ public:
        /**
         * Read the element from row i, column j.
         */
-       float getElement(int i, int j) {
-               return (float) m_el[i][j];
+       template <typename T>
+       T getElement(int i, int j) {
+               return (T)m_el[i][j];
        }
        
     /**
         * Copy the contents to a contiguous block of 16 floats.
         */
-    void getValue(float *m) const {
-        *m++ = (float) m_el[0][0]; *m++ = (float) m_el[1][0]; *m++ = (float) 
m_el[2][0]; *m++ = (float) m_el[3][0];
-        *m++ = (float) m_el[0][1]; *m++ = (float) m_el[1][1]; *m++ = (float) 
m_el[2][1]; *m++ = (float) m_el[3][1];
-        *m++ = (float) m_el[0][2]; *m++ = (float) m_el[1][2]; *m++ = (float) 
m_el[2][2]; *m++ = (float) m_el[3][2];
-        *m++ = (float) m_el[0][3]; *m++ = (float) m_el[1][3]; *m++ = (float) 
m_el[2][3]; *m = (float) m_el[3][3];
-    }
-
-    /**
-        * Copy the contents to a contiguous block of 16 doubles.
-        */
-    void getValue(double *m) const {
-        *m++ = m_el[0][0]; *m++ = m_el[1][0]; *m++ = m_el[2][0]; *m++ = 
m_el[3][0];
-        *m++ = m_el[0][1]; *m++ = m_el[1][1]; *m++ = m_el[2][1]; *m++ = 
m_el[3][1];
-        *m++ = m_el[0][2]; *m++ = m_el[1][2]; *m++ = m_el[2][2]; *m++ = 
m_el[3][2];
-        *m++ = m_el[0][3]; *m++ = m_el[1][3]; *m++ = m_el[2][3]; *m = 
m_el[3][3];
+    template <typename T>
+    void getValue(T *m) const {
+        *m++ = (T)m_el[0][0]; *m++ = (T)m_el[1][0]; *m++ = (T)m_el[2][0]; *m++ 
= (T)m_el[3][0];
+        *m++ = (T)m_el[0][1]; *m++ = (T)m_el[1][1]; *m++ = (T)m_el[2][1]; *m++ 
= (T)m_el[3][1];
+        *m++ = (T)m_el[0][2]; *m++ = (T)m_el[1][2]; *m++ = (T)m_el[2][2]; *m++ 
= (T)m_el[3][2];
+        *m++ = (T)m_el[0][3]; *m++ = (T)m_el[1][3]; *m++ = (T)m_el[2][3]; *m = 
  (T)m_el[3][3];
     }
 
        /** 
diff --git a/intern/moto/include/MT_Point2.h b/intern/moto/include/MT_Point2.h
index 587379b..53eba1d 100644
--- a/intern/moto/include/MT_Point2.h
+++ b/intern/moto/include/MT_Point2.h
@@ -52,8 +52,8 @@
 class MT_Point2 : public MT_Vector2 {
 public:
     MT_Point2() {}
-    MT_Point2(const float *v2) : MT_Vector2(v2) {} 
-    MT_Point2(const double *v2) : MT_Vector2(v2) {}
+    template <typename T>
+    MT_Point2(const T *v2) : MT_Vector2(v2) {} 
     MT_Point2(MT_Scalar x2, MT_Scalar y2) : MT_Vector2(x2, y2) {}
 
     MT_Point2& operator+=(const MT_Vector2& v);
diff --git a/intern/moto/include/MT_Point3.h b/intern/moto/include/MT_Point3.h
index f19b2e2..8b0431c 100644
--- a/intern/moto/include/MT_Point3.h
+++ b/intern/moto/include/MT_Point3.h
@@ -52,8 +52,8 @@
 class MT_Point3 : public MT_Vector3 {
 public:
     MT_Point3() {}
-    MT_Point3(const float *v) : MT_Vector3(v) {} 
-    MT_Point3(const double *v) : MT_Vector3(v) {}
+    template <typename T>
+    MT_Point3(const T *v) : MT_Vector3(v) {} 
     MT_Point3(MT_Scalar xx, MT_Scalar yy, MT_Scalar zz) : MT_Vector3(xx, yy, 
zz) {}
 
     MT_Point3& operator+=(const MT_Vector3& v);
diff --git a/intern/moto/include/MT_Quaternion.h 
b/intern/moto/include/MT_Quaternion.h
index 4

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to