diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-06-26 00:47:41 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-06-26 00:47:41 +0400 |
commit | 4b914c7f75faa65a7d2a991b7904c18051d13a13 (patch) | |
tree | 35ff731a37f612e491f21ee1b036f3d1679e9a69 /source/gameengine/Ketsji/KX_PyMath.cpp | |
parent | 47ca543b32e74b67e5f8eb6265cc08f93018b002 (diff) |
Made Mathutils use radians rather then degrees. defining USE_MATHUTILS_DEG for testing existing scripts.
Added conversion for BGE Quaternion WXYZ (Blender/C) -> XYZW (Moto C++).
BGE Python API now uses WXYZ following mathutils (break script warning).
Diffstat (limited to 'source/gameengine/Ketsji/KX_PyMath.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_PyMath.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/source/gameengine/Ketsji/KX_PyMath.cpp b/source/gameengine/Ketsji/KX_PyMath.cpp index ee9fed5d30a..76cfb0e572d 100644 --- a/source/gameengine/Ketsji/KX_PyMath.cpp +++ b/source/gameengine/Ketsji/KX_PyMath.cpp @@ -53,7 +53,7 @@ bool PyOrientationTo(PyObject* pyval, MT_Matrix3x3 &rot, const char *error_prefi if (size == 4) { MT_Quaternion qrot; - if (PyVecTo(pyval, qrot)) + if (PyQuatTo(pyval, qrot)) { rot.setRotation(qrot); return true; @@ -79,6 +79,21 @@ bool PyOrientationTo(PyObject* pyval, MT_Matrix3x3 &rot, const char *error_prefi return false; } +bool PyQuatTo(PyObject* pyval, MT_Quaternion &qrot) +{ + if(!PyVecTo(pyval, qrot)) + return false; + + /* annoying!, Blender/Mathutils have the W axis first! */ + MT_Scalar w= qrot[0]; /* from python, this is actually the W */ + qrot[0]= qrot[1]; + qrot[1]= qrot[2]; + qrot[2]= qrot[3]; + qrot[3]= w; + + return true; +} + PyObject* PyObjectFrom(const MT_Matrix4x4 &mat) { #ifdef USE_MATHUTILS @@ -126,6 +141,15 @@ PyObject* PyObjectFrom(const MT_Matrix3x3 &mat) #endif } +#ifdef USE_MATHUTILS +PyObject* PyObjectFrom(const MT_Quaternion &qrot) +{ + /* NOTE, were re-ordering here for Mathutils compat */ + float fvec[4]= {qrot[3], qrot[0], qrot[1], qrot[2]}; + return newQuaternionObject(fvec, Py_WRAP); +} +#endif + PyObject* PyObjectFrom(const MT_Tuple4 &vec) { #ifdef USE_MATHUTILS |