[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19631] trunk/blender/source/gameengine: BGE API cleanup: ConstraintActuator.

Benoit Bolsee benoit.bolsee at online.be
Fri Apr 10 01:10:12 CEST 2009


Revision: 19631
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19631
Author:   ben2610
Date:     2009-04-10 01:10:12 +0200 (Fri, 10 Apr 2009)

Log Message:
-----------
BGE API cleanup: ConstraintActuator.

Modified Paths:
--------------
    trunk/blender/source/gameengine/Ketsji/KX_ConstraintActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_ConstraintActuator.h
    trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
    trunk/blender/source/gameengine/PyDoc/KX_ConstraintActuator.py
    trunk/blender/source/gameengine/PyDoc/KX_StateActuator.py

Modified: trunk/blender/source/gameengine/Ketsji/KX_ConstraintActuator.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_ConstraintActuator.cpp	2009-04-09 22:15:26 UTC (rev 19630)
+++ trunk/blender/source/gameengine/Ketsji/KX_ConstraintActuator.cpp	2009-04-09 23:10:12 UTC (rev 19631)
@@ -36,6 +36,7 @@
 #include "MT_Matrix3x3.h"
 #include "KX_GameObject.h"
 #include "KX_RayCast.h"
+#include "blendef.h"
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -57,19 +58,21 @@
 											 char *property,
 											 PyTypeObject* T) : 
 	SCA_IActuator(gameobj, T),
-	m_refDirection(refDir),
+	m_refDirVector(refDir),
 	m_currentTime(0)
 {
+	m_refDirection[0] = refDir[0];
+	m_refDirection[1] = refDir[1];
+	m_refDirection[2] = refDir[2];
 	m_posDampTime = posDampTime;
 	m_rotDampTime = rotDampTime;
 	m_locrot   = locrotxyz;
 	m_option = option;
 	m_activeTime = time;
 	if (property) {
-		strncpy(m_property, property, sizeof(m_property));
-		m_property[sizeof(m_property)-1] = 0;
+		m_property = property;
 	} else {
-		m_property[0] = 0;
+		m_property = "";
 	}
 	/* The units of bounds are determined by the type of constraint. To      */
 	/* make the constraint application easier and more transparent later on, */
@@ -80,13 +83,16 @@
 	case KX_ACT_CONSTRAINT_ORIY:
 	case KX_ACT_CONSTRAINT_ORIZ:
 		{
-			MT_Scalar len = m_refDirection.length();
+			MT_Scalar len = m_refDirVector.length();
 			if (MT_fuzzyZero(len)) {
 				// missing a valid direction
 				std::cout << "WARNING: Constraint actuator " << GetName() << ":  There is no valid reference direction!" << std::endl;
 				m_locrot = KX_ACT_CONSTRAINT_NODEF;
 			} else {
-				m_refDirection /= len;
+				m_refDirection[0] /= len;
+				m_refDirection[1] /= len;
+				m_refDirection[2] /= len;
+				m_refDirVector /= len;
 			}
 			m_minimumBound = cos(minBound);
 			m_maximumBound = cos(maxBound);
@@ -116,7 +122,7 @@
 	
 	bool bFound = false;
 
-	if (m_property[0] == 0)
+	if (m_property.IsEmpty())
 	{
 		bFound = true;
 	}
@@ -126,7 +132,7 @@
 		{
 			if (client->m_auxilary_info)
 			{
-				bFound = !strcmp(m_property, ((char*)client->m_auxilary_info));
+				bFound = !strcmp(m_property.Ptr(), ((char*)client->m_auxilary_info));
 			}
 		}
 		else
@@ -209,7 +215,7 @@
 			if ((m_maximumBound < (1.0f-FLT_EPSILON)) || (m_minimumBound < (1.0f-FLT_EPSILON))) {
 				// reference direction needs to be evaluated
 				// 1. get the cosine between current direction and target
-				cosangle = direction.dot(m_refDirection);
+				cosangle = direction.dot(m_refDirVector);
 				if (cosangle >= (m_maximumBound-FLT_EPSILON) && cosangle <= (m_minimumBound+FLT_EPSILON)) {
 					// no change to do
 					result = true;
@@ -218,27 +224,27 @@
 				// 2. define a new reference direction
 				//    compute local axis with reference direction as X and
 				//    Y in direction X refDirection plane
-				MT_Vector3 zaxis = m_refDirection.cross(direction);
+				MT_Vector3 zaxis = m_refDirVector.cross(direction);
 				if (MT_fuzzyZero2(zaxis.length2())) {
 					// direction and refDirection are identical,
 					// choose any other direction to define plane
 					if (direction[0] < 0.9999)
-						zaxis = m_refDirection.cross(MT_Vector3(1.0,0.0,0.0));
+						zaxis = m_refDirVector.cross(MT_Vector3(1.0,0.0,0.0));
 					else
-						zaxis = m_refDirection.cross(MT_Vector3(0.0,1.0,0.0));
+						zaxis = m_refDirVector.cross(MT_Vector3(0.0,1.0,0.0));
 				}
-				MT_Vector3 yaxis = zaxis.cross(m_refDirection);
+				MT_Vector3 yaxis = zaxis.cross(m_refDirVector);
 				yaxis.normalize();
 				if (cosangle > m_minimumBound) {
 					// angle is too close to reference direction,
 					// choose a new reference that is exactly at minimum angle
-					refDirection = m_minimumBound * m_refDirection + m_minimumSine * yaxis;
+					refDirection = m_minimumBound * m_refDirVector + m_minimumSine * yaxis;
 				} else {
 					// angle is too large, choose new reference direction at maximum angle
-					refDirection = m_maximumBound * m_refDirection + m_maximumSine * yaxis;
+					refDirection = m_maximumBound * m_refDirVector + m_maximumSine * yaxis;
 				}
 			} else {
-				refDirection = m_refDirection;
+				refDirection = m_refDirVector;
 			}
 			// apply damping on the direction
 			direction = filter*direction + (1.0-filter)*refDirection;
@@ -470,7 +476,7 @@
 					// Fh force is stored in m_maximum
 					MT_Scalar springForce = springExtent * m_maximumBound;
 					// damping is stored in m_refDirection [0] = damping, [1] = rot damping
-					MT_Scalar springDamp = relativeVelocityRay * m_refDirection[0];
+					MT_Scalar springDamp = relativeVelocityRay * m_refDirVector[0];
 					MT_Vector3 newVelocity = spc->GetLinearVelocity()-(springForce+springDamp)*direction;
 					if (m_option & KX_ACT_CONSTRAINT_NORMAL)
 					{
@@ -483,7 +489,7 @@
 						MT_Vector3 angVelocity = spc->GetAngularVelocity();
 						// remove component that is parallel to normal
 						angVelocity -= angVelocity.dot(newnormal)*newnormal;
-						MT_Vector3 angDamp = angVelocity * ((m_refDirection[1]>MT_EPSILON)?m_refDirection[1]:m_refDirection[0]);
+						MT_Vector3 angDamp = angVelocity * ((m_refDirVector[1]>MT_EPSILON)?m_refDirVector[1]:m_refDirVector[0]);
 						spc->SetAngularVelocity(spc->GetAngularVelocity()+(angSpring-angDamp), false);
 					}
 				} else if (m_option & KX_ACT_CONSTRAINT_PERMANENT) {
@@ -587,6 +593,7 @@
 };
 
 PyMethodDef KX_ConstraintActuator::Methods[] = {
+	// Deprecated -->
 	{"setDamp", (PyCFunction) KX_ConstraintActuator::sPySetDamp, METH_VARARGS, (PY_METHODCHAR)SetDamp_doc},
 	{"getDamp", (PyCFunction) KX_ConstraintActuator::sPyGetDamp, METH_NOARGS, (PY_METHODCHAR)GetDamp_doc},
 	{"setRotDamp", (PyCFunction) KX_ConstraintActuator::sPySetRotDamp, METH_VARARGS, (PY_METHODCHAR)SetRotDamp_doc},
@@ -609,17 +616,49 @@
 	{"getRayLength", (PyCFunction) KX_ConstraintActuator::sPyGetMax, METH_NOARGS, (PY_METHODCHAR)GetRayLength_doc},
 	{"setLimit", (PyCFunction) KX_ConstraintActuator::sPySetLimit, METH_VARARGS, (PY_METHODCHAR)SetLimit_doc},
 	{"getLimit", (PyCFunction) KX_ConstraintActuator::sPyGetLimit, METH_NOARGS, (PY_METHODCHAR)GetLimit_doc},
+	// <--
 	{NULL,NULL} //Sentinel
 };
 
 PyAttributeDef KX_ConstraintActuator::Attributes[] = {
+	KX_PYATTRIBUTE_INT_RW("damp",0,100,true,KX_ConstraintActuator,m_posDampTime),
+	KX_PYATTRIBUTE_INT_RW("rotDamp",0,100,true,KX_ConstraintActuator,m_rotDampTime),
+	KX_PYATTRIBUTE_FLOAT_ARRAY_RW_CHECK("direction",-MAXFLOAT,MAXFLOAT,KX_ConstraintActuator,m_refDirection,3,pyattr_check_direction),
+	KX_PYATTRIBUTE_INT_RW("option",0,0xFFFF,false,KX_ConstraintActuator,m_option),
+	KX_PYATTRIBUTE_INT_RW("time",0,1000,true,KX_ConstraintActuator,m_activeTime),
+	KX_PYATTRIBUTE_STRING_RW("property",0,32,true,KX_ConstraintActuator,m_property),
+	KX_PYATTRIBUTE_FLOAT_RW("min",-MAXFLOAT,MAXFLOAT,KX_ConstraintActuator,m_minimumBound),
+	KX_PYATTRIBUTE_FLOAT_RW("distance",-MAXFLOAT,MAXFLOAT,KX_ConstraintActuator,m_minimumBound),
+	KX_PYATTRIBUTE_FLOAT_RW("max",-MAXFLOAT,MAXFLOAT,KX_ConstraintActuator,m_maximumBound),
+	KX_PYATTRIBUTE_FLOAT_RW("rayLength",0,2000.f,KX_ConstraintActuator,m_maximumBound),
+	KX_PYATTRIBUTE_INT_RW("limit",KX_ConstraintActuator::KX_ACT_CONSTRAINT_NODEF+1,KX_ConstraintActuator::KX_ACT_CONSTRAINT_MAX-1,false,KX_ConstraintActuator,m_locrot),
 	{ NULL }	//Sentinel
 };
 
-PyObject* KX_ConstraintActuator::py_getattro(PyObject *attr) {
+PyObject* KX_ConstraintActuator::py_getattro(PyObject *attr) 
+{
 	py_getattro_up(SCA_IActuator);
 }
 
+int KX_ConstraintActuator::py_setattro(PyObject *attr, PyObject* value)
+{
+	py_setattro_up(SCA_IActuator);
+}
+
+
+int KX_ConstraintActuator::pyattr_check_direction(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
+{
+	KX_ConstraintActuator* act = static_cast<KX_ConstraintActuator*>(self);
+	MT_Vector3 dir(act->m_refDirection);
+	MT_Scalar len = dir.length();
+	if (MT_fuzzyZero(len)) {
+		PyErr_SetString(PyExc_ValueError, "Invalid direction");
+		return 1;
+	}
+	act->m_refDirVector = dir/len;
+	return 0;	
+}
+
 /* 2. setDamp                                                                */
 const char KX_ConstraintActuator::SetDamp_doc[] = 
 "setDamp(duration)\n"
@@ -629,6 +668,7 @@
 PyObject* KX_ConstraintActuator::PySetDamp(PyObject* self, 
 										   PyObject* args, 
 										   PyObject* kwds) {
+	ShowDeprecationWarning("setDamp()", "the damp property");
 	int dampArg;
 	if(!PyArg_ParseTuple(args, "i", &dampArg)) {
 		return NULL;		
@@ -644,6 +684,7 @@
 "getDamp()\n"
 "\tReturns the damping parameter.\n";
 PyObject* KX_ConstraintActuator::PyGetDamp(PyObject* self){
+	ShowDeprecationWarning("getDamp()", "the damp property");
 	return PyInt_FromLong(m_posDampTime);
 }
 
@@ -656,6 +697,7 @@
 PyObject* KX_ConstraintActuator::PySetRotDamp(PyObject* self, 
 										      PyObject* args, 
 										      PyObject* kwds) {
+	ShowDeprecationWarning("setRotDamp()", "the rotDamp property");
 	int dampArg;
 	if(!PyArg_ParseTuple(args, "i", &dampArg)) {
 		return NULL;		
@@ -671,6 +713,7 @@
 "getRotDamp()\n"
 "\tReturns the damping time for application of the constraint.\n";
 PyObject* KX_ConstraintActuator::PyGetRotDamp(PyObject* self){
+	ShowDeprecationWarning("getRotDamp()", "the rotDamp property");
 	return PyInt_FromLong(m_rotDampTime);
 }
 
@@ -682,6 +725,7 @@
 PyObject* KX_ConstraintActuator::PySetDirection(PyObject* self, 
 										        PyObject* args, 
 										        PyObject* kwds) {
+	ShowDeprecationWarning("setDirection()", "the direction property");
 	float x, y, z;
 	MT_Scalar len;
 	MT_Vector3 dir;
@@ -697,7 +741,10 @@
 		std::cout << "Invalid direction" << std::endl;
 		return NULL;
 	}
-	m_refDirection = dir/len;
+	m_refDirVector = dir/len;
+	m_refDirection[0] = x/len;
+	m_refDirection[1] = y/len;
+	m_refDirection[2] = z/len;
 
 	Py_RETURN_NONE;
 }
@@ -706,6 +753,7 @@
 "getDirection()\n"
 "\tReturns the reference direction of the orientation constraint as a 3-tuple.\n";
 PyObject* KX_ConstraintActuator::PyGetDirection(PyObject* self){
+	ShowDeprecationWarning("getDirection()", "the direction property");
 	PyObject *retVal = PyList_New(3);
 
 	PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_refDirection[0]));
@@ -727,6 +775,7 @@
 PyObject* KX_ConstraintActuator::PySetOption(PyObject* self, 
 										     PyObject* args, 
 										     PyObject* kwds) {
+	ShowDeprecationWarning("setOption()", "the option property");
 	int option;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list