[Bf-committers] SVN commit: /data/svn/bf-blender [20370] trunk/blender/source/gameengine/ Ketsji: fix generic 6dof constraint support -> convert 3 values into euler angles and convert those into a full constraint frame

blender at erwincoumans.com blender at erwincoumans.com
Sun May 24 07:30:49 CEST 2009


Sure, please go ahead and change it as you like,
Thanks,
Erwin 

 

Campbell Barton writes: 

> The "if (len == 3)" in PySetLimit isnt needed, PyArg_ParseTuple will
> check the length. 
> 
> Also, returning NULL without setting an error will give a
> "SystemError, return without exception set"., These used to happen all
> the time before 2.48 and it makes it very confusing to find out where
> python errors are. 
> 
> In 2.49 now we have all the PyArg_ParseTuple's include the function
> name which is then included in the error.
> -  PyArg_ParseTuple(args,"iff:setLimit",&dof,&minLimit,&maxLimit) 
> 
> On Sun, May 24, 2009 at 10:42 AM, Erwin Coumans
> <blender at erwincoumans.com> wrote:
>> Revision: 20370
>>          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20370
>> Author:   erwin
>> Date:     2009-05-24 02:42:40 +0200 (Sun, 24 May 2009) 
>>
>> Log Message:
>> -----------
>> fix generic 6dof constraint support -> convert 3 values into euler angles and convert those into a full constraint frame
>> (same values as Rigid Body constraint Generic 6DOF values), and add 'setLimit' support for generic 6DOF constraint. todo: enableMotor 
>>
>> Modified Paths:
>> --------------
>>    trunk/blender/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp
>>    trunk/blender/source/gameengine/Ketsji/KX_ConstraintWrapper.h
>>    trunk/blender/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp 
>>
>> Modified: trunk/blender/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp
>> ===================================================================
>> --- trunk/blender/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp     2009-05-23 22:35:47 UTC (rev 20369)
>> +++ trunk/blender/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp     2009-05-24 00:42:40 UTC (rev 20370)
>> @@ -54,6 +54,31 @@
>>        return PyInt_FromLong(m_constraintId);
>>  } 
>>
>> +PyObject* KX_ConstraintWrapper::PySetLimit(PyObject* args, PyObject* kwds)
>> +{
>> +       int len = PyTuple_Size(args);
>> +       int success = 1;
>> +
>> +       if (len == 3)
>> +       {
>> +               int dof;
>> +               float minLimit,maxLimit;
>> +               success = PyArg_ParseTuple(args,"iff",&dof,&minLimit,&maxLimit);
>> +               if (success)
>> +               {
>> +                       m_physenv->setConstraintParam(m_constraintId,dof,minLimit,maxLimit);
>> +                       Py_RETURN_NONE;
>> +               }
>> +       }
>> +       return NULL;
>> +}
>> +
>> +PyObject* KX_ConstraintWrapper::PyEnableMotor(PyObject* args, PyObject* kwds)
>> +{
>> +       ///will add it soon
>> +       return PyInt_FromLong(0);
>> +}
>> +
>>  //python specific stuff
>>  PyTypeObject KX_ConstraintWrapper::Type = {
>>  #if (PY_VERSION_HEX >= 0x02060000)
>> @@ -100,8 +125,13 @@
>>  }; 
>>
>>
>> +
>> +
>> +
>>  PyMethodDef KX_ConstraintWrapper::Methods[] = {
>>        {"getConstraintId",(PyCFunction) KX_ConstraintWrapper::sPyGetConstraintId, METH_VARARGS},
>> +       {"setLimit",(PyCFunction) KX_ConstraintWrapper::sPySetLimit, METH_VARARGS},
>> +       {"enableMotor",(PyCFunction) KX_ConstraintWrapper::sPyEnableMotor, METH_VARARGS},
>>        {NULL,NULL} //Sentinel
>>  }; 
>>
>>
>> Modified: trunk/blender/source/gameengine/Ketsji/KX_ConstraintWrapper.h
>> ===================================================================
>> --- trunk/blender/source/gameengine/Ketsji/KX_ConstraintWrapper.h       2009-05-23 22:35:47 UTC (rev 20369)
>> +++ trunk/blender/source/gameengine/Ketsji/KX_ConstraintWrapper.h       2009-05-24 00:42:40 UTC (rev 20370)
>> @@ -45,6 +45,8 @@ 
>>
>>        KX_PYMETHOD(KX_ConstraintWrapper,TestMethod);
>>        KX_PYMETHOD(KX_ConstraintWrapper,GetConstraintId);
>> +       KX_PYMETHOD(KX_ConstraintWrapper,SetLimit);
>> +       KX_PYMETHOD(KX_ConstraintWrapper,EnableMotor); 
>>
>>  private:
>>        int                                     m_constraintId; 
>>
>> Modified: trunk/blender/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp
>> ===================================================================
>> --- trunk/blender/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp   2009-05-23 22:35:47 UTC (rev 20369)
>> +++ trunk/blender/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp   2009-05-24 00:42:40 UTC (rev 20370)
>> @@ -33,6 +33,7 @@
>>  #include "KX_PhysicsObjectWrapper.h"
>>  #include "PHY_IPhysicsController.h"
>>  #include "PHY_IVehicle.h"
>> +#include "MT_Matrix3x3.h" 
>>
>>  #include "PyObjectPlus.h" 
>>
>> @@ -435,7 +436,31 @@
>>                        PHY_IPhysicsController* physctrl2 = (PHY_IPhysicsController*) physicsid2;
>>                        if (physctrl) //TODO:check for existance of this pointer!
>>                        {
>> -                               int constraintid = PHY_GetActiveEnvironment()->createConstraint(physctrl,physctrl2,(enum PHY_ConstraintType)constrainttype,pivotX,pivotY,pivotZ,axisX,axisY,axisZ,0);
>> +                               PHY_ConstraintType ct = (PHY_ConstraintType) constrainttype;
>> +                               int constraintid =0;
>> +
>> +                               if (ct == PHY_GENERIC_6DOF_CONSTRAINT)
>> +                               {
>> +                                       //convert from euler angle into axis
>> +                                       float radsPerDeg = 6.283185307179586232f / 360.f;
>> +
>> +                                       //we need to pass a full constraint frame, not just axis
>> +                                       //localConstraintFrameBasis
>> +                                       MT_Matrix3x3 localCFrame(MT_Vector3(radsPerDeg*axisX,radsPerDeg*axisY,radsPerDeg*axisZ));
>> +                                       MT_Vector3 axis0 = localCFrame.getColumn(0);
>> +                                       MT_Vector3 axis1 = localCFrame.getColumn(1);
>> +                                       MT_Vector3 axis2 = localCFrame.getColumn(2);
>> +
>> +                                       constraintid = PHY_GetActiveEnvironment()->createConstraint(physctrl,physctrl2,(enum PHY_ConstraintType)constrainttype,
>> +                                               pivotX,pivotY,pivotZ,
>> +                                               (float)axis0.x(),(float)axis0.y(),(float)axis0.z(),
>> +                                               (float)axis1.x(),(float)axis1.y(),(float)axis1.z(),
>> +                                               (float)axis2.x(),(float)axis2.y(),(float)axis2.z(),0);//dat->flag); //flag?
>> +
>> +                               } else
>> +                               {
>> +                                       constraintid = PHY_GetActiveEnvironment()->createConstraint(physctrl,physctrl2,(enum PHY_ConstraintType)constrainttype,pivotX,pivotY,pivotZ,axisX,axisY,axisZ,0);
>> +                               } 
>>
>>                                KX_ConstraintWrapper* wrap = new KX_ConstraintWrapper((enum PHY_ConstraintType)constrainttype,constraintid,PHY_GetActiveEnvironment()); 
>>
>> 
>>
>> _______________________________________________
>> Bf-blender-cvs mailing list
>> Bf-blender-cvs at blender.org
>> http://lists.blender.org/mailman/listinfo/bf-blender-cvs 
>>
>  
> 
> 
> -- 
> - Campbell
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers
 



More information about the Bf-committers mailing list