Minor speedups for the BGE
authorCampbell Barton <ideasman42@gmail.com>
Wed, 25 Feb 2009 06:43:03 +0000 (06:43 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 25 Feb 2009 06:43:03 +0000 (06:43 +0000)
* Where possible use vec.setValue(x,y,z) to assign values to a vector instead of vec= MT_Vector3(x,y,z), for MT_Point and MT_Matrix types too.
* Comparing TexVerts was creating 10 MT_Vector types - instead compare as floats.
* Added SG_Spatial::SetWorldFromLocalTransform() since the local transform is use for world transform in some cases.
* removed some unneeded vars from UpdateChildCoordinates functions
* Py API - Mouse, Ray, Radar sensors - use PyObjectFrom(vec) rather then filling the lists in each function. Use METH_NOARGS for get*() functions.

18 files changed:
source/blender/python/api2_2x/Mathutils.c
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Converter/BL_MeshDeformer.cpp
source/gameengine/Ketsji/KX_GameObject.cpp
source/gameengine/Ketsji/KX_MouseFocusSensor.cpp
source/gameengine/Ketsji/KX_MouseFocusSensor.h
source/gameengine/Ketsji/KX_RadarSensor.cpp
source/gameengine/Ketsji/KX_RadarSensor.h
source/gameengine/Ketsji/KX_RaySensor.cpp
source/gameengine/Ketsji/KX_RaySensor.h
source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp
source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp
source/gameengine/Ketsji/KX_TrackToActuator.cpp
source/gameengine/Rasterizer/RAS_TexVert.cpp
source/gameengine/Rasterizer/RAS_TexVert.h
source/gameengine/SceneGraph/SG_BBox.cpp
source/gameengine/SceneGraph/SG_Spatial.cpp
source/gameengine/SceneGraph/SG_Spatial.h

index f0b51285376dac0fd775c014c0fd7cdff99ca9b7..b370aa0e1e830b64f2b060eb3ab263b9ab3efdab 100644 (file)
@@ -350,7 +350,7 @@ PyObject *quat_rotation(PyObject *arg1, PyObject *arg2)
 PyObject *M_Mathutils_Rand(PyObject * self, PyObject * args)
 {
        float high, low, range;
-       double rand;
+       double drand;
        //initializers
        high = 1.0;
        low = 0.0;
@@ -364,14 +364,14 @@ PyObject *M_Mathutils_Rand(PyObject * self, PyObject * args)
                        "Mathutils.Rand(): high value should be larger than low value\n"));
 
        //get the random number 0 - 1
-       rand = BLI_drand();
+       drand = BLI_drand();
 
        //set it to range
        range = high - low;
-       rand = rand * range;
-       rand = rand + low;
+       drand = drand * range;
+       drand = drand + low;
 
-       return PyFloat_FromDouble(rand);
+       return PyFloat_FromDouble(drand);
 }
 //----------------------------------VECTOR FUNCTIONS---------------------
 //----------------------------------Mathutils.Vector() ------------------
index 3293d37af3a8b8bfb057095113cb9ef87412a3dd..3a0302562e611661f61cc77b451524ef8e31e536 100644 (file)
@@ -593,7 +593,7 @@ BL_Material* ConvertMaterial(
        MT_Point2 uv2[4];
        const char *uvName = "", *uv2Name = "";
 
-       uv[0]= uv[1]= uv[2]= uv[3]= MT_Point2(0.0f, 0.0f);
+       
        uv2[0]= uv2[1]= uv2[2]= uv2[3]= MT_Point2(0.0f, 0.0f);
 
        if( validface ) {
@@ -607,12 +607,12 @@ BL_Material* ConvertMaterial(
                material->tile  = tface->tile;
                material->mode  = tface->mode;
                        
-               uv[0]   = MT_Point2(tface->uv[0]);
-               uv[1]   = MT_Point2(tface->uv[1]);
-               uv[2]   = MT_Point2(tface->uv[2]);
+               uv[0].setValue(tface->uv[0]);
+               uv[1].setValue(tface->uv[1]);
+               uv[2].setValue(tface->uv[2]);
 
                if (mface->v4) 
-                       uv[3]   = MT_Point2(tface->uv[3]);
+                       uv[3].setValue(tface->uv[3]);
 
                uvName = tfaceName;
        } 
@@ -622,6 +622,8 @@ BL_Material* ConvertMaterial(
                material->mode          = default_face_mode;    
                material->transp        = TF_SOLID;
                material->tile          = 0;
+               
+               uv[0]= uv[1]= uv[2]= uv[3]= MT_Point2(0.0f, 0.0f);
        }
 
        // with ztransp enabled, enforce alpha blending mode
@@ -665,14 +667,14 @@ BL_Material* ConvertMaterial(
                                        {
                                                MT_Point2 uvSet[4];
 
-                                               uvSet[0]        = MT_Point2(layer.face->uv[0]);
-                                               uvSet[1]        = MT_Point2(layer.face->uv[1]);
-                                               uvSet[2]        = MT_Point2(layer.face->uv[2]);
+                                               uvSet[0].setValue(layer.face->uv[0]);
+                                               uvSet[1].setValue(layer.face->uv[1]);
+                                               uvSet[2].setValue(layer.face->uv[2]);
 
                                                if (mface->v4) 
-                                                       uvSet[3]        = MT_Point2(layer.face->uv[3]);
+                                                       uvSet[3].setValue(layer.face->uv[3]);
                                                else
-                                                       uvSet[3]        = MT_Point2(0.0f, 0.0f);
+                                                       uvSet[3].setValue(0.0f, 0.0f);
 
                                                if (isFirstSet)
                                                {
@@ -790,10 +792,10 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
                MT_Vector4 tan0(0,0,0,0), tan1(0,0,0,0), tan2(0,0,0,0), tan3(0,0,0,0);
 
                /* get coordinates, normals and tangents */
-               pt0 = MT_Point3(mvert[mface->v1].co);
-               pt1 = MT_Point3(mvert[mface->v2].co);
-               pt2 = MT_Point3(mvert[mface->v3].co);
-               pt3 = (mface->v4)? MT_Point3(mvert[mface->v4].co): MT_Point3(0.0, 0.0, 0.0);
+               pt0.setValue(mvert[mface->v1].co);
+               pt1.setValue(mvert[mface->v2].co);
+               pt2.setValue(mvert[mface->v3].co);
+               if (mface->v4) pt3.setValue(mvert[mface->v4].co);
 
                if(mface->flag & ME_SMOOTH) {
                        float n0[3], n1[3], n2[3], n3[3];
@@ -894,12 +896,12 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
                                        
                                        visible = !((mface->flag & ME_HIDE)||(tface->mode & TF_INVISIBLE));
                                        
-                                       uv0 = MT_Point2(tface->uv[0]);
-                                       uv1 = MT_Point2(tface->uv[1]);
-                                       uv2 = MT_Point2(tface->uv[2]);
+                                       uv0.setValue(tface->uv[0]);
+                                       uv1.setValue(tface->uv[1]);
+                                       uv2.setValue(tface->uv[2]);
        
                                        if (mface->v4)
-                                               uv3 = MT_Point2(tface->uv[3]);
+                                               uv3.setValue(tface->uv[3]);
                                } 
                                else {
                                        /* no texfaces, set COLLSION true and everything else FALSE */
@@ -960,7 +962,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
                                        polymat->m_diffuse = MT_Vector3(ma->r, ma->g, ma->b)*(ma->emit + ma->ref);
                                }
                                else {
-                                       polymat->m_specular = MT_Vector3(0.0f,0.0f,0.0f);
+                                       polymat->m_specular.setValue(0.0f,0.0f,0.0f);
                                        polymat->m_shininess = 35.0;
                                }
                        }
@@ -1911,21 +1913,14 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                        MT_Matrix3x3 angor;                     
                        if (converter->addInitFromFrame) blenderscene->r.cfra=blenderscene->r.sfra;
                        
-                       MT_Point3 pos = MT_Point3(
+                       MT_Point3 pos;
+                       pos.setValue(
                                blenderobject->loc[0]+blenderobject->dloc[0],
                                blenderobject->loc[1]+blenderobject->dloc[1],
                                blenderobject->loc[2]+blenderobject->dloc[2]
                        );
-                       MT_Vector3 eulxyz = MT_Vector3(
-                               blenderobject->rot[0],
-                               blenderobject->rot[1],
-                               blenderobject->rot[2]
-                       );
-                       MT_Vector3 scale = MT_Vector3(
-                               blenderobject->size[0],
-                               blenderobject->size[1],
-                               blenderobject->size[2]
-                       );
+                       MT_Vector3 eulxyz(blenderobject->rot);
+                       MT_Vector3 scale(blenderobject->size);
                        if (converter->addInitFromFrame){//rcruiz
                                float eulxyzPrev[3];
                                blenderscene->r.cfra=blenderscene->r.sfra-1;
@@ -2113,21 +2108,13 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                                                        if (converter->addInitFromFrame) 
                                                                blenderscene->r.cfra=blenderscene->r.sfra;
                                                        
-                                                       MT_Point3 pos = MT_Point3(
+                                                       MT_Point3 pos(
                                                                blenderobject->loc[0]+blenderobject->dloc[0],
                                                                blenderobject->loc[1]+blenderobject->dloc[1],
                                                                blenderobject->loc[2]+blenderobject->dloc[2]
                                                        );
-                                                       MT_Vector3 eulxyz = MT_Vector3(
-                                                               blenderobject->rot[0],
-                                                               blenderobject->rot[1],
-                                                               blenderobject->rot[2]
-                                                       );
-                                                       MT_Vector3 scale = MT_Vector3(
-                                                               blenderobject->size[0],
-                                                               blenderobject->size[1],
-                                                               blenderobject->size[2]
-                                                       );
+                                                       MT_Vector3 eulxyz(blenderobject->rot);
+                                                       MT_Vector3 scale(blenderobject->size);
                                                        if (converter->addInitFromFrame){//rcruiz
                                                                float eulxyzPrev[3];
                                                                blenderscene->r.cfra=blenderscene->r.sfra-1;
index fa3b8185fe2fd932c604016e5b0419db9a887f8e..80112346c728be3a178fa0062ef8cfd0ec50d111 100644 (file)
@@ -51,7 +51,6 @@
 bool BL_MeshDeformer::Apply(RAS_IPolyMaterial*)
 {
        size_t i;
-       float *co;
 
        // only apply once per frame if the mesh is actually modified
        if(m_pMeshObject->MeshModified() &&
@@ -70,8 +69,7 @@ bool BL_MeshDeformer::Apply(RAS_IPolyMaterial*)
                                //      For each vertex
                                for(i=it.startvertex; i<it.endvertex; i++) {
                                        RAS_TexVert& v = it.vertex[i];
-                                       co = m_bmesh->mvert[v.getOrigIndex()].co;
-                                       v.SetXYZ(MT_Point3(co));
+                                       v.SetXYZ(m_bmesh->mvert[v.getOrigIndex()].co);
                                }
                        }
                }
index 60512991cf4df5047e34186700d1cfe11e68716a..5e013a1c6470e097ce25736c9ec6dbf786793ddb 100644 (file)
@@ -690,9 +690,9 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis, float fac)
        switch (axis)
        {       
                case 0: //x axis
-                       ori = MT_Vector3(orimat[0][2], orimat[1][2], orimat[2][2]); //pivot axis
+                       ori.setValue(orimat[0][2], orimat[1][2], orimat[2][2]); //pivot axis
                        if (MT_abs(vect.dot(ori)) > 1.0-3.0*MT_EPSILON) //is the vector paralell to the pivot?
-                               ori = MT_Vector3(orimat[0][1], orimat[1][1], orimat[2][1]); //change the pivot!
+                               ori.setValue(orimat[0][1], orimat[1][1], orimat[2][1]); //change the pivot!
                        if (fac == 1.0) {
                                x = vect;
                        } else {
@@ -705,9 +705,9 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis, float fac)
                        z = x.cross(y);
                        break;
                case 1: //y axis
-                       ori = MT_Vector3(orimat[0][0], orimat[1][0], orimat[2][0]);
+                       ori.setValue(orimat[0][0], orimat[1][0], orimat[2][0]);
                        if (MT_abs(vect.dot(ori)) > 1.0-3.0*MT_EPSILON)
-                               ori = MT_Vector3(orimat[0][2], orimat[1][2], orimat[2][2]);
+                               ori.setValue(orimat[0][2], orimat[1][2], orimat[2][2]);
                        if (fac == 1.0) {
                                y = vect;
                        } else {
@@ -720,9 +720,9 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis, float fac)
                        x = y.cross(z);
                        break;
                case 2: //z axis
-                       ori = MT_Vector3(orimat[0][1], orimat[1][1], orimat[2][1]);
+                       ori.setValue(orimat[0][1], orimat[1][1], orimat[2][1]);
                        if (MT_abs(vect.dot(ori)) > 1.0-3.0*MT_EPSILON)
-                               ori = MT_Vector3(orimat[0][0], orimat[1][0], orimat[2][0]);
+                               ori.setValue(orimat[0][0], orimat[1][0], orimat[2][0]);
                        if (fac == 1.0) {
                                z = vect;
                        } else {
@@ -741,9 +741,9 @@ void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis, float fac)
        x.normalize(); //normalize the vectors
        y.normalize();
        z.normalize();
-       orimat = MT_Matrix3x3(  x[0],y[0],z[0],
-                                                       x[1],y[1],z[1],
-                                                       x[2],y[2],z[2]);
+       orimat.setValue(        x[0],y[0],z[0],
+                                               x[1],y[1],z[1],
+                                               x[2],y[2],z[2]);
        if (GetSGNode()->GetSGParent() != NULL)
        {
                // the object is a child, adapt its local orientation so that 
@@ -945,13 +945,11 @@ const MT_Vector3& KX_GameObject::NodeGetWorldScaling() const
 
 const MT_Point3& KX_GameObject::NodeGetWorldPosition() const
 {
-       static MT_Point3 defaultPosition = MT_Point3(0.0, 0.0, 0.0);
-
        // check on valid node in case a python controller holds a reference to a deleted object
-       if (!GetSGNode())
-               return defaultPosition;
-
-       return GetSGNode()->GetWorldPosition();
+       if (GetSGNode())
+               return GetSGNode()->GetWorldPosition();
+       else
+               return MT_Point3(0.0, 0.0, 0.0);
 }
 
 /* Suspend/ resume: for the dynamic behaviour, there is a simple
index bd15d3cffbe8fa21f29a3b4c143c4fd3d56cbe87..afe4cd1e2a48b052ef173e15d64a5b8e3e58d52f 100644 (file)
@@ -42,6 +42,7 @@
 #include "KX_Scene.h"
 #include "KX_Camera.h"
 #include "KX_MouseFocusSensor.h"
+#include "KX_PyMath.h"
 
 #include "KX_RayCast.h"
 #include "KX_IPhysicsController.h"
@@ -320,12 +321,12 @@ PyParentObject KX_MouseFocusSensor::Parents[] = {
 };
 
 PyMethodDef KX_MouseFocusSensor::Methods[] = {
-       {"getRayTarget", (PyCFunction) KX_MouseFocusSensor::sPyGetRayTarget, METH_VARARGS, (PY_METHODCHAR)GetRayTarget_doc},
-       {"getRaySource", (PyCFunction) KX_MouseFocusSensor::sPyGetRaySource, METH_VARARGS, (PY_METHODCHAR)GetRaySource_doc},
-       {"getHitObject",(PyCFunction) KX_MouseFocusSensor::sPyGetHitObject,METH_VARARGS, (PY_METHODCHAR)GetHitObject_doc},
-       {"getHitPosition",(PyCFunction) KX_MouseFocusSensor::sPyGetHitPosition,METH_VARARGS, (PY_METHODCHAR)GetHitPosition_doc},
-       {"getHitNormal",(PyCFunction) KX_MouseFocusSensor::sPyGetHitNormal,METH_VARARGS, (PY_METHODCHAR)GetHitNormal_doc},
-       {"getRayDirection",(PyCFunction) KX_MouseFocusSensor::sPyGetRayDirection,METH_VARARGS, (PY_METHODCHAR)GetRayDirection_doc},
+       {"getRayTarget", (PyCFunction) KX_MouseFocusSensor::sPyGetRayTarget, METH_NOARGS, (PY_METHODCHAR)GetRayTarget_doc},
+       {"getRaySource", (PyCFunction) KX_MouseFocusSensor::sPyGetRaySource, METH_NOARGS, (PY_METHODCHAR)GetRaySource_doc},
+       {"getHitObject",(PyCFunction) KX_MouseFocusSensor::sPyGetHitObject,METH_NOARGS, (PY_METHODCHAR)GetHitObject_doc},
+       {"getHitPosition",(PyCFunction) KX_MouseFocusSensor::sPyGetHitPosition,METH_NOARGS, (PY_METHODCHAR)GetHitPosition_doc},
+       {"getHitNormal",(PyCFunction) KX_MouseFocusSensor::sPyGetHitNormal,METH_NOARGS, (PY_METHODCHAR)GetHitNormal_doc},
+       {"getRayDirection",(PyCFunction) KX_MouseFocusSensor::sPyGetRayDirection,METH_NOARGS, (PY_METHODCHAR)GetRayDirection_doc},
 
 
        {NULL,NULL} //Sentinel
@@ -339,14 +340,11 @@ PyObject* KX_MouseFocusSensor::_getattr(const char *attr) {
 const char KX_MouseFocusSensor::GetHitObject_doc[] = 
 "getHitObject()\n"
 "\tReturns the name of the object that was hit by this ray.\n";
-PyObject* KX_MouseFocusSensor::PyGetHitObject(PyObject* self, 
-                                                                                  PyObject* args, 
-                                                                                  PyObject* kwds)
+PyObject* KX_MouseFocusSensor::PyGetHitObject(PyObject* self)
 {
        if (m_hitObject)
-       {
                return m_hitObject->AddRef();
-       }
+       
        Py_RETURN_NONE;
 }
 
@@ -354,61 +352,28 @@ PyObject* KX_MouseFocusSensor::PyGetHitObject(PyObject* self,
 const char KX_MouseFocusSensor::GetHitPosition_doc[] = 
 "getHitPosition()\n"
 "\tReturns the position (in worldcoordinates) where the object was hit by this ray.\n";
-PyObject* KX_MouseFocusSensor::PyGetHitPosition(PyObject* self, 
-                              PyObject* args, 
-                              PyObject* kwds)
+PyObject* KX_MouseFocusSensor::PyGetHitPosition(PyObject* self)
 {
-
-       MT_Point3 pos = m_hitPosition;
-
-       PyObject* resultlist = PyList_New(3);
-       int index;
-       for (index=0;index<3;index++)
-       {
-               PyList_SetItem(resultlist,index,PyFloat_FromDouble(pos[index]));
-       }
-       return resultlist;
-
+       return PyObjectFrom(m_hitPosition);
 }
 
 const char KX_MouseFocusSensor::GetRayDirection_doc[] = 
 "getRayDirection()\n"
 "\tReturns the direction from the ray (in worldcoordinates) .\n";
-PyObject* KX_MouseFocusSensor::PyGetRayDirection(PyObject* self, 
-                              PyObject* args, 
-                              PyObject* kwds)
+PyObject* KX_MouseFocusSensor::PyGetRayDirection(PyObject* self)
 {
 
        MT_Vector3 dir = m_prevTargetPoint - m_prevSourcePoint;
        dir.normalize();
-
-       PyObject* resultlist = PyList_New(3);
-       int index;
-       for (index=0;index<3;index++)
-       {
-               PyList_SetItem(resultlist,index,PyFloat_FromDouble(dir[index]));
-       }
-       return resultlist;
-
+       return PyObjectFrom(dir);
 }
 
 const char KX_MouseFocusSensor::GetHitNormal_doc[] = 
 "getHitNormal()\n"
 "\tReturns the normal (in worldcoordinates) of the object at the location where the object was hit by this ray.\n";
-PyObject* KX_MouseFocusSensor::PyGetHitNormal(PyObject* self, 
-                              PyObject* args, 
-                              PyObject* kwds)
+PyObject* KX_MouseFocusSensor::PyGetHitNormal(PyObject* self)
 {
-       MT_Vector3 pos = m_hitNormal;
-
-       PyObject* resultlist = PyList_New(3);
-       int index;
-       for (index=0;index<3;index++)
-       {
-               PyList_SetItem(resultlist,index,PyFloat_FromDouble(pos[index]));
-       }
-       return resultlist;
-
+       return PyObjectFrom(m_hitNormal);
 }
 
 
@@ -417,16 +382,8 @@ const char KX_MouseFocusSensor::GetRayTarget_doc[] =
 "getRayTarget()\n"
 "\tReturns the target of the ray that seeks the focus object,\n"
 "\tin worldcoordinates.";
-PyObject* KX_MouseFocusSensor::PyGetRayTarget(PyObject* self, 
-                                                                                         PyObject* args, 
-                                                                                         PyObject* kwds) {
-       PyObject *retVal = PyList_New(3);
-
-       PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_prevTargetPoint[0]));
-       PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_prevTargetPoint[1]));
-       PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_prevTargetPoint[2]));
-       
-       return retVal;
+PyObject* KX_MouseFocusSensor::PyGetRayTarget(PyObject* self) {
+       return PyObjectFrom(m_prevTargetPoint);
 }
 
 /*  getRayTarget                                                */
@@ -434,16 +391,8 @@ const char KX_MouseFocusSensor::GetRaySource_doc[] =
 "getRaySource()\n"
 "\tReturns the source of the ray that seeks the focus object,\n"
 "\tin worldcoordinates.";
-PyObject* KX_MouseFocusSensor::PyGetRaySource(PyObject* self, 
-                                                                                         PyObject* args, 
-                                                                                         PyObject* kwds) {
-       PyObject *retVal = PyList_New(3);
-
-       PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_prevSourcePoint[0]));
-       PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_prevSourcePoint[1]));
-       PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_prevSourcePoint[2]));
-       
-       return retVal;
+PyObject* KX_MouseFocusSensor::PyGetRaySource(PyObject* self) {
+       return PyObjectFrom(m_prevSourcePoint);
 }
 
 /* eof */
index 704198ce5a3ab9a20b1836d29657bec612e56a2d..4979783032ce1c0712a0d29dae28f946e58844c5 100644 (file)
@@ -89,13 +89,13 @@ class KX_MouseFocusSensor : public SCA_MouseSensor
        /* --------------------------------------------------------------------- */
        virtual PyObject*  _getattr(const char *attr);
 
-       KX_PYMETHOD_DOC(KX_MouseFocusSensor,GetRayTarget);
-       KX_PYMETHOD_DOC(KX_MouseFocusSensor,GetRaySource);
+       KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetRayTarget);
+       KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetRaySource);
        
-       KX_PYMETHOD_DOC(KX_MouseFocusSensor,GetHitObject);
-       KX_PYMETHOD_DOC(KX_MouseFocusSensor,GetHitPosition);
-       KX_PYMETHOD_DOC(KX_MouseFocusSensor,GetHitNormal);
-       KX_PYMETHOD_DOC(KX_MouseFocusSensor,GetRayDirection);
+       KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetHitObject);
+       KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetHitPosition);
+       KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetHitNormal);
+       KX_PYMETHOD_DOC_NOARGS(KX_MouseFocusSensor,GetRayDirection);
 
        /* --------------------------------------------------------------------- */
        SCA_IObject*    m_hitObject;
index 1321b862463fb73f7d52b6ebbecc6a86fa3896c6..2ba1126a633d6b197df6bb6b03220985d473b43e 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "KX_RadarSensor.h"
 #include "KX_GameObject.h"
+#include "KX_PyMath.h"
 #include "PHY_IPhysicsController.h"
 
 #ifdef HAVE_CONFIG_H
@@ -221,11 +222,11 @@ PyParentObject KX_RadarSensor::Parents[] = {
 
 PyMethodDef KX_RadarSensor::Methods[] = {
        {"getConeOrigin", (PyCFunction) KX_RadarSensor::sPyGetConeOrigin, 
-        METH_VARARGS, (PY_METHODCHAR)GetConeOrigin_doc},
+        METH_NOARGS, (PY_METHODCHAR)GetConeOrigin_doc},
        {"getConeTarget", (PyCFunction) KX_RadarSensor::sPyGetConeTarget, 
-        METH_VARARGS, (PY_METHODCHAR)GetConeTarget_doc},
+        METH_NOARGS, (PY_METHODCHAR)GetConeTarget_doc},
        {"getConeHeight", (PyCFunction) KX_RadarSensor::sPyGetConeHeight, 
-        METH_VARARGS, (PY_METHODCHAR)GetConeHeight_doc},
+        METH_NOARGS, (PY_METHODCHAR)GetConeHeight_doc},
        {NULL,NULL,NULL,NULL} //Sentinel
 };
 
@@ -238,41 +239,23 @@ const char KX_RadarSensor::GetConeOrigin_doc[] =
 "getConeOrigin()\n"
 "\tReturns the origin of the cone with which to test. The origin\n"
 "\tis in the middle of the cone.";
-PyObject* KX_RadarSensor::PyGetConeOrigin(PyObject* self, 
-                                                                                 PyObject* args, 
-                                                                                 PyObject* kwds) {
-       PyObject *retVal = PyList_New(3);
-       
-       PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_cone_origin[0]));
-       PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_cone_origin[1]));
-       PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_cone_origin[2]));
-       
-       return retVal;
+PyObject* KX_RadarSensor::PyGetConeOrigin(PyObject* self) {
+       return PyObjectFrom(m_cone_origin);
 }
 
 /* getConeOrigin */
 const char KX_RadarSensor::GetConeTarget_doc[] = 
 "getConeTarget()\n"
 "\tReturns the center of the bottom face of the cone with which to test.\n";
-PyObject* KX_RadarSensor::PyGetConeTarget(PyObject* self, 
-                                                                                 PyObject* args, 
-                                                                                 PyObject* kwds) {
-       PyObject *retVal = PyList_New(3);
-       
-       PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_cone_target[0]));
-       PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_cone_target[1]));
-       PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_cone_target[2]));
-       
-       return retVal;
+PyObject* KX_RadarSensor::PyGetConeTarget(PyObject* self) {
+       return PyObjectFrom(m_cone_target);
 }
 
 /* getConeOrigin */
 const char KX_RadarSensor::GetConeHeight_doc[] = 
 "getConeHeight()\n"
 "\tReturns the height of the cone with which to test.\n";
-PyObject* KX_RadarSensor::PyGetConeHeight(PyObject* self, 
-                                                                                 PyObject* args, 
-                                                                                 PyObject* kwds) {
+PyObject* KX_RadarSensor::PyGetConeHeight(PyObject* self) {
        return PyFloat_FromDouble(m_coneheight);
 }
 
index f8f807251459966ed701fac9f93a58ad7540322a..e4c6d73f22dabbebf63a8612df47b53b8cde2602 100644 (file)
@@ -83,9 +83,9 @@ public:
        
        virtual PyObject* _getattr(const char *attr);
 
-       KX_PYMETHOD_DOC(KX_RadarSensor,GetConeOrigin);
-       KX_PYMETHOD_DOC(KX_RadarSensor,GetConeTarget);
-       KX_PYMETHOD_DOC(KX_RadarSensor,GetConeHeight);
+       KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeOrigin);
+       KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeTarget);
+       KX_PYMETHOD_DOC_NOARGS(KX_RadarSensor,GetConeHeight);
 
 };
 
index b8ebce2881474dd91fd44e3e2e8ebe17f8bbfe65..c7cb53f64ed679ff0067ab25c76fd276d3d0d00c 100644 (file)
@@ -38,6 +38,7 @@
 #include "KX_GameObject.h"
 #include "KX_Scene.h"
 #include "KX_RayCast.h"
+#include "KX_PyMath.h"
 #include "PHY_IPhysicsEnvironment.h"
 #include "KX_IPhysicsController.h"
 #include "PHY_IPhysicsController.h"
@@ -179,8 +180,8 @@ bool KX_RaySensor::Evaluate(CValue* event)
        bool reset = m_reset && m_level;
        m_rayHit = false; 
        m_hitObject = NULL;
-       m_hitPosition = MT_Vector3(0,0,0);
-       m_hitNormal = MT_Vector3(1,0,0);
+       m_hitPosition.setValue(0,0,0);
+       m_hitNormal.setValue(1,0,0);
        
        KX_GameObject* obj = (KX_GameObject*)GetParent();
        MT_Point3 frompoint = obj->NodeGetWorldPosition();
@@ -335,19 +336,17 @@ PyParentObject KX_RaySensor::Parents[] = {
 };
 
 PyMethodDef KX_RaySensor::Methods[] = {
-       {"getHitObject",(PyCFunction) KX_RaySensor::sPyGetHitObject,METH_VARARGS, (PY_METHODCHAR)GetHitObject_doc},
-       {"getHitPosition",(PyCFunction) KX_RaySensor::sPyGetHitPosition,METH_VARARGS, (PY_METHODCHAR)GetHitPosition_doc},
-       {"getHitNormal",(PyCFunction) KX_RaySensor::sPyGetHitNormal,METH_VARARGS, (PY_METHODCHAR)GetHitNormal_doc},
-       {"getRayDirection",(PyCFunction) KX_RaySensor::sPyGetRayDirection,METH_VARARGS, (PY_METHODCHAR)GetRayDirection_doc},
+       {"getHitObject",(PyCFunction) KX_RaySensor::sPyGetHitObject,METH_NOARGS, (PY_METHODCHAR)GetHitObject_doc},
+       {"getHitPosition",(PyCFunction) KX_RaySensor::sPyGetHitPosition,METH_NOARGS, (PY_METHODCHAR)GetHitPosition_doc},
+       {"getHitNormal",(PyCFunction) KX_RaySensor::sPyGetHitNormal,METH_NOARGS, (PY_METHODCHAR)GetHitNormal_doc},
+       {"getRayDirection",(PyCFunction) KX_RaySensor::sPyGetRayDirection,METH_NOARGS, (PY_METHODCHAR)GetRayDirection_doc},
        {NULL,NULL} //Sentinel
 };
 
 const char KX_RaySensor::GetHitObject_doc[] = 
 "getHitObject()\n"
 "\tReturns the name of the object that was hit by this ray.\n";
-PyObject* KX_RaySensor::PyGetHitObject(PyObject* self, 
-                                                                                  PyObject* args, 
-                                                                                  PyObject* kwds)
+PyObject* KX_RaySensor::PyGetHitObject(PyObject* self)
 {
        if (m_hitObject)
        {
@@ -360,60 +359,25 @@ PyObject* KX_RaySensor::PyGetHitObject(PyObject* self,
 const char KX_RaySensor::GetHitPosition_doc[] = 
 "getHitPosition()\n"
 "\tReturns the position (in worldcoordinates) where the object was hit by this ray.\n";
-PyObject* KX_RaySensor::PyGetHitPosition(PyObject* self, 
-                              PyObject* args, 
-                              PyObject* kwds)
+PyObject* KX_RaySensor::PyGetHitPosition(PyObject* self)
 {
-
-       MT_Point3 pos = m_hitPosition;
-
-       PyObject* resultlist = PyList_New(3);
-       int index;
-       for (index=0;index<3;index++)
-       {
-               PyList_SetItem(resultlist,index,PyFloat_FromDouble(pos[index]));
-       }
-       return resultlist;
-
+       return PyObjectFrom(m_hitPosition);
 }
 
 const char KX_RaySensor::GetRayDirection_doc[] = 
 "getRayDirection()\n"
 "\tReturns the direction from the ray (in worldcoordinates) .\n";
-PyObject* KX_RaySensor::PyGetRayDirection(PyObject* self, 
-                              PyObject* args, 
-                              PyObject* kwds)
+PyObject* KX_RaySensor::PyGetRayDirection(PyObject* self)
 {
-
-       MT_Vector3 dir = m_rayDirection;
-
-       PyObject* resultlist = PyList_New(3);
-       int index;
-       for (index=0;index<3;index++)
-       {
-               PyList_SetItem(resultlist,index,PyFloat_FromDouble(dir[index]));
-       }
-       return resultlist;
-
+       return PyObjectFrom(m_rayDirection);
 }
 
 const char KX_RaySensor::GetHitNormal_doc[] = 
 "getHitNormal()\n"
 "\tReturns the normal (in worldcoordinates) of the object at the location where the object was hit by this ray.\n";
-PyObject* KX_RaySensor::PyGetHitNormal(PyObject* self, 
-                              PyObject* args, 
-                              PyObject* kwds)
+PyObject* KX_RaySensor::PyGetHitNormal(PyObject* self)
 {
-       MT_Vector3 pos = m_hitNormal;
-
-       PyObject* resultlist = PyList_New(3);
-       int index;
-       for (index=0;index<3;index++)
-       {
-               PyList_SetItem(resultlist,index,PyFloat_FromDouble(pos[index]));
-       }
-       return resultlist;
-
+       return PyObjectFrom(m_hitNormal);
 }
 
 
index 2baec12f74e3e8a751a7cb8043a469077ec8c9f2..09d8bc1369a2d505c0c69e67a545dd8dcfcd0f2e 100644 (file)
@@ -74,10 +74,10 @@ public:
        bool RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void * const data);
        bool NeedRayCast(KX_ClientObjectInfo* client);
        
-       KX_PYMETHOD_DOC(KX_RaySensor,GetHitObject);
-       KX_PYMETHOD_DOC(KX_RaySensor,GetHitPosition);
-       KX_PYMETHOD_DOC(KX_RaySensor,GetHitNormal);
-       KX_PYMETHOD_DOC(KX_RaySensor,GetRayDirection);
+       KX_PYMETHOD_DOC_NOARGS(KX_RaySensor,GetHitObject);
+       KX_PYMETHOD_DOC_NOARGS(KX_RaySensor,GetHitPosition);
+       KX_PYMETHOD_DOC_NOARGS(KX_RaySensor,GetHitNormal);
+       KX_PYMETHOD_DOC_NOARGS(KX_RaySensor,GetRayDirection);
 
        virtual PyObject* _getattr(const char *attr);
        
index d651373869a3887cda377880371257dee6d4f139..151270cbd68fd2e662f9a6564b34a2fafd4f4191 100644 (file)
@@ -97,11 +97,11 @@ UpdateChildCoordinates(
                                child_transform = parent_matrix * child_transform;
                                
                                // Recompute the child transform components from the transform.
-                               child_w_scale =  MT_Vector3
+                               child_w_scale.setValue
                                        MT_Vector3(child_transform[0][0], child_transform[0][1], child_transform[0][2]).length(),
                                        MT_Vector3(child_transform[1][0], child_transform[1][1], child_transform[1][2]).length(),
                                        MT_Vector3(child_transform[2][0], child_transform[2][1], child_transform[2][2]).length());
-                               child_w_rotation = MT_Matrix3x3(child_transform[0][0], child_transform[0][1], child_transform[0][2], 
+                               child_w_rotation.setValue(child_transform[0][0], child_transform[0][1], child_transform[0][2], 
                                        child_transform[1][0], child_transform[1][1], child_transform[1][2], 
                                        child_transform[2][0], child_transform[2][1], child_transform[2][2]);
                                child_w_rotation.scale(1.0/child_w_scale[0], 1.0/child_w_scale[1], 1.0/child_w_scale[2]);
@@ -113,16 +113,15 @@ UpdateChildCoordinates(
                }
        } 
        
-       if (!valid_parent_transform)
+       if (valid_parent_transform)
        {
-               child_w_scale = child_scale;
-               child_w_pos = child_pos;
-               child_w_rotation = child_rotation;
+               child->SetWorldScale(child_w_scale);
+               child->SetWorldPosition(child_w_pos);
+               child->SetWorldOrientation(child_w_rotation);
+       }
+       else {
+               child->SetWorldFromLocalTransform();
        }
-
-       child->SetWorldScale(child_w_scale);
-       child->SetWorldPosition(child_w_pos);
-       child->SetWorldOrientation(child_w_rotation);
        
        return valid_parent_transform;
 }
index 0c8e7e287716b5bc4746e5b83b115781bdf2ab5b..0729ec8a9025badf3d9f6a3202533ce41ad70865 100644 (file)
@@ -55,43 +55,21 @@ UpdateChildCoordinates(
 ){
        MT_assert(child != NULL);
 
-       // This way of accessing child coordinates is a bit cumbersome
-       // be nice to have non constant reference access to these values.
-
-       const MT_Vector3 & child_scale = child->GetLocalScale();
-       const MT_Point3 & child_pos = child->GetLocalPosition();
-       const MT_Matrix3x3 & child_rotation = child->GetLocalOrientation();
-
-       // the childs world locations which we will update.     
-       
-       MT_Vector3 child_w_scale;
-       MT_Point3 child_w_pos;
-       MT_Matrix3x3 child_w_rotation;
-               
-       if (parent) {
-
+       if (parent==NULL) { /* Simple case */
+               child->SetWorldFromLocalTransform();
+               return false;
+       }
+       else {
+               // the childs world locations which we will update.     
                const MT_Vector3 & p_world_scale = parent->GetWorldScaling();
                const MT_Point3 & p_world_pos = parent->GetWorldPosition();
                const MT_Matrix3x3 & p_world_rotation = parent->GetWorldOrientation();
 
-               child_w_scale = p_world_scale * child_scale;
-               child_w_rotation = p_world_rotation * child_rotation;
-
-               child_w_pos = p_world_pos + p_world_scale * 
-                       (p_world_rotation * child_pos);
-               
-       } else {
-
-               child_w_scale = child_scale;
-               child_w_pos = child_pos;
-               child_w_rotation = child_rotation;
+               child->SetWorldScale(p_world_scale * child->GetLocalScale());
+               child->SetWorldOrientation(p_world_rotation * child->GetLocalOrientation());
+               child->SetWorldPosition(p_world_pos + p_world_scale * (p_world_rotation * child->GetLocalPosition()));
+               return true;
        }
-
-       child->SetWorldScale(child_w_scale);
-       child->SetWorldPosition(child_w_pos);
-       child->SetWorldOrientation(child_w_rotation);
-       
-       return parent != NULL;
 }
 
        SG_ParentRelation *
@@ -138,40 +116,14 @@ UpdateChildCoordinates(
 ){
 
        MT_assert(child != NULL);
-
-       const MT_Vector3 & child_scale = child->GetLocalScale();
-       const MT_Point3 & child_pos = child->GetLocalPosition();
-       const MT_Matrix3x3 & child_rotation = child->GetLocalOrientation();
-
-       // the childs world locations which we will update.     
+       child->SetWorldScale(child->GetLocalScale());
        
-       MT_Vector3 child_w_scale;
-       MT_Point3 child_w_pos;
-       MT_Matrix3x3 child_w_rotation;
-               
-       if (parent) {
-
-               // This is a vertex parent so we do not inherit orientation 
-               // information.
-
-               // const MT_Vector3 & p_world_scale = parent->GetWorldScaling(); /*unused*/
-               const MT_Point3 & p_world_pos = parent->GetWorldPosition();
-               // const MT_Matrix3x3 & p_world_rotation = parent->GetWorldOrientation(); /*unused*/
-
-               child_w_scale = child_scale;
-               child_w_rotation = child_rotation;
-               child_w_pos = p_world_pos + child_pos;
-       } else {
-
-               child_w_scale = child_scale;
-               child_w_pos = child_pos;
-               child_w_rotation = child_rotation;
-       }
-
-       child->SetWorldScale(child_w_scale);
-       child->SetWorldPosition(child_w_pos);
-       child->SetWorldOrientation(child_w_rotation);
+       if (parent)
+               child->SetWorldPosition(child->GetLocalPosition()+parent->GetWorldPosition());
+       else
+               child->SetWorldPosition(child->GetLocalPosition());
        
+       child->SetWorldOrientation(child->GetLocalOrientation());
        return parent != NULL;
 }
 
index 89dfc8e57add4eaa74bf8cb379fda4f3fc9c37e0..9d4fa14ad8ebb679879343a52114facab174023f 100644 (file)
@@ -258,18 +258,18 @@ bool KX_TrackToActuator::Update(double curtime, bool frame)
                {
                case 0:
                        {
-                               up = MT_Vector3(1.0,0,0);
+                               up.setValue(1.0,0,0);
                                break;
                        } 
                case 1:
                        {
-                               up = MT_Vector3(0,1.0,0);
+                               up.setValue(0,1.0,0);
                                break;
                        }
                case 2:
                default:
                        {
-                               up = MT_Vector3(0,0,1.0);
+                               up.setValue(0,0,1.0);
                        }
                }
 #endif 
index b92965ed1ccbe78f436b562e8179714df205e0a2..210addfb927de0dbedf9f8278accbea0e2a35da5 100644 (file)
@@ -59,10 +59,10 @@ const MT_Point3& RAS_TexVert::xyz()
 void RAS_TexVert::SetRGBA(const MT_Vector4& rgba)
 {
        unsigned char *colp = (unsigned char*) &m_rgba;
-       colp[0] = (unsigned char) (rgba[0]*255.0);
-       colp[1] = (unsigned char) (rgba[1]*255.0);
-       colp[2] = (unsigned char) (rgba[2]*255.0);
-       colp[3] = (unsigned char) (rgba[3]*255.0);
+       colp[0] = (unsigned char) (rgba[0]*255.0f);
+       colp[1] = (unsigned char) (rgba[1]*255.0f);
+       colp[2] = (unsigned char) (rgba[2]*255.0f);
+       colp[3] = (unsigned char) (rgba[3]*255.0f);
 }
 
 
@@ -71,7 +71,10 @@ void RAS_TexVert::SetXYZ(const MT_Point3& xyz)
        xyz.getValue(m_localxyz);
 }
 
-
+void RAS_TexVert::SetXYZ(const float *xyz)
+{
+       m_localxyz[0]= xyz[0]; m_localxyz[1]= xyz[1]; m_localxyz[2]= xyz[2];
+}
 
 void RAS_TexVert::SetUV(const MT_Point2& uv)
 {
@@ -111,15 +114,18 @@ void RAS_TexVert::SetTangent(const MT_Vector3& tangent)
 }
 
 // compare two vertices, and return TRUE if both are almost identical (they can be shared)
+#define _VEC_EQUAL3(_v1, _v2) (_v1[0]==_v2[0] && _v1[1]==_v2[1] && _v1[2]==_v2[2])
+#define _VEC_EQUAL2(_v1, _v2) (_v1[0]==_v2[0] && _v1[1]==_v2[1])
 bool RAS_TexVert::closeTo(const RAS_TexVert* other)
 {
        return (m_flag == other->m_flag &&
                m_rgba == other->m_rgba &&
-               MT_fuzzyEqual(MT_Vector3(m_normal), MT_Vector3(other->m_normal)) &&
-               MT_fuzzyEqual(MT_Vector3(m_tangent), MT_Vector3(other->m_tangent)) &&
-               MT_fuzzyEqual(MT_Vector2(m_uv1), MT_Vector2(other->m_uv1)) &&
-               MT_fuzzyEqual(MT_Vector2(m_uv2), MT_Vector2(other->m_uv2)) && // p --
-               MT_fuzzyEqual(MT_Vector3(m_localxyz), MT_Vector3(other->m_localxyz))) ;
+               _VEC_EQUAL3(m_normal, other->m_normal) &&
+               _VEC_EQUAL3(m_tangent, other->m_tangent) &&
+               _VEC_EQUAL2(m_uv1, other->m_uv1) &&
+               _VEC_EQUAL2(m_uv2, other->m_uv2) // p --
+               /* we know the verts must be shared so dont need to check this */
+               /*&& FAST_MT_fuzzyEqual3(m_localxyz, other->m_localxyz)*/) ;
 }
 
 short RAS_TexVert::getFlag() const
index 157a6ce3d51b73ff74b9ae590ecf5cb4b022e5a3..811867f35790248a09d4158541c62720d78c33d0 100644 (file)
@@ -115,6 +115,7 @@ public:
        }
 
        void                            SetXYZ(const MT_Point3& xyz);
+       void                            SetXYZ(const float *xyz);
        void                            SetUV(const MT_Point2& uv);
        void                            SetUV2(const MT_Point2& uv);
 
index 4bd2805978e63d7558a5cbeb9f24e68ecf12f890..a44262d04f756efbda6ff5e348e4c9a26becb1e2 100644 (file)
@@ -34,8 +34,8 @@
  #include "SG_Node.h"
  
 SG_BBox::SG_BBox() :
-       m_min(MT_Point3(0., 0., 0.)),
-       m_max(MT_Point3(0., 0., 0.))
+       m_min(0., 0., 0.),
+       m_max(0., 0., 0.)
 {
 }
 
index 5ba116e59db0aeecec23c77d8f39c58078ba2364..99aeb3e72eeb6ff7585d92926ee945f3a1b0f915 100644 (file)
@@ -44,13 +44,13 @@ SG_Spatial(
 ): 
 
        SG_IObject(clientobj,clientinfo,callbacks),
-       m_localPosition(MT_Point3(0.0,0.0,0.0)),
-       m_localRotation(MT_Matrix3x3(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0)),
-       m_localScaling(MT_Vector3(1.f,1.f,1.f)),
+       m_localPosition(0.0,0.0,0.0),
+       m_localRotation(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0),
+       m_localScaling(1.f,1.f,1.f),
        
-       m_worldPosition(MT_Point3(0.0,0.0,0.0)),
-       m_worldRotation(MT_Matrix3x3(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0)),
-       m_worldScaling(MT_Vector3(1.f,1.f,1.f)),
+       m_worldPosition(0.0,0.0,0.0),
+       m_worldRotation(1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0),
+       m_worldScaling(1.f,1.f,1.f),
 
        m_parent_relation (NULL),
        
@@ -297,6 +297,13 @@ GetWorldScaling(
        return m_worldScaling;
 }
 
+void SG_Spatial::SetWorldFromLocalTransform()
+{
+       m_worldPosition= m_localPosition;
+       m_worldScaling= m_localScaling;
+       m_worldRotation= m_localRotation;
+}
+
 SG_BBox& SG_Spatial::BBox()
 {
        return m_bbox;
index 28848b0f933653b89fd83bbfe6cb04859771d9eb..6ccec2aa9c107a50004b951e3d608ded7b0cb5f8 100644 (file)
@@ -176,6 +176,8 @@ public:
        GetWorldScaling(
        ) const ;
 
+       void SetWorldFromLocalTransform();
+
        MT_Transform GetWorldTransform() const;
 
        bool    ComputeWorldTransforms(         const SG_Spatial *parent);