game engine python api
[blender.git] / source / gameengine / Ketsji / KX_ConstraintActuator.cpp
1 /**
2  * Apply a constraint to a position or rotation value
3  *
4  * $Id$
5  *
6  * ***** BEGIN GPL LICENSE BLOCK *****
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23  * All rights reserved.
24  *
25  * The Original Code is: all of this file.
26  *
27  * Contributor(s): none yet.
28  *
29  * ***** END GPL LICENSE BLOCK *****
30  */
31
32 #include "SCA_IActuator.h"
33 #include "KX_ConstraintActuator.h"
34 #include "SCA_IObject.h"
35 #include "MT_Point3.h"
36 #include "MT_Matrix3x3.h"
37 #include "KX_GameObject.h"
38 #include "KX_RayCast.h"
39
40 #ifdef HAVE_CONFIG_H
41 #include <config.h>
42 #endif
43
44 /* ------------------------------------------------------------------------- */
45 /* Native functions                                                          */
46 /* ------------------------------------------------------------------------- */
47
48 KX_ConstraintActuator::KX_ConstraintActuator(SCA_IObject *gameobj, 
49                                                                                          int posDampTime,
50                                                                                          int rotDampTime,
51                                                                                          float minBound,
52                                                                                          float maxBound,
53                                                                                          float refDir[3],
54                                                                                          int locrotxyz,
55                                                                                          int time,
56                                                                                          int option,
57                                                                                          char *property,
58                                                                                          PyTypeObject* T) : 
59         m_refDirection(refDir),
60         m_currentTime(0),
61         SCA_IActuator(gameobj, T)
62 {
63         m_posDampTime = posDampTime;
64         m_rotDampTime = rotDampTime;
65         m_locrot   = locrotxyz;
66         m_option = option;
67         m_activeTime = time;
68         if (property) {
69                 strncpy(m_property, property, sizeof(m_property));
70                 m_property[sizeof(m_property)-1] = 0;
71         } else {
72                 m_property[0] = 0;
73         }
74         /* The units of bounds are determined by the type of constraint. To      */
75         /* make the constraint application easier and more transparent later on, */
76         /* I think converting the bounds to the applicable domain makes more     */
77         /* sense.                                                                */
78         switch (m_locrot) {
79         case KX_ACT_CONSTRAINT_ORIX:
80         case KX_ACT_CONSTRAINT_ORIY:
81         case KX_ACT_CONSTRAINT_ORIZ:
82                 {
83                         MT_Scalar len = m_refDirection.length();
84                         if (MT_fuzzyZero(len)) {
85                                 // missing a valid direction
86                                 std::cout << "WARNING: Constraint actuator " << GetName() << ":  There is no valid reference direction!" << std::endl;
87                                 m_locrot = KX_ACT_CONSTRAINT_NODEF;
88                         } else {
89                                 m_refDirection /= len;
90                         }
91                         m_minimumBound = cos(minBound);
92                         m_maximumBound = cos(maxBound);
93                         m_minimumSine = sin(minBound);
94                         m_maximumSine = sin(maxBound);
95                 }
96                 break;
97         default:
98                 m_minimumBound = minBound;
99                 m_maximumBound = maxBound;
100                 m_minimumSine = 0.f;
101                 m_maximumSine = 0.f;
102                 break;
103         }
104
105 } /* End of constructor */
106
107 KX_ConstraintActuator::~KX_ConstraintActuator()
108
109         // there's nothing to be done here, really....
110 } /* end of destructor */
111
112 bool KX_ConstraintActuator::RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data)
113 {
114
115         KX_GameObject* hitKXObj = client->m_gameobject;
116         
117         if (client->m_type > KX_ClientObjectInfo::ACTOR)
118         {
119                 // false hit
120                 return false;
121         }
122         bool bFound = false;
123
124         if (m_property[0] == 0)
125         {
126                 bFound = true;
127         }
128         else
129         {
130                 if (m_option & KX_ACT_CONSTRAINT_MATERIAL)
131                 {
132                         if (client->m_auxilary_info)
133                         {
134                                 bFound = !strcmp(m_property, ((char*)client->m_auxilary_info));
135                         }
136                 }
137                 else
138                 {
139                         bFound = hitKXObj->GetProperty(m_property) != NULL;
140                 }
141         }
142
143         return bFound;
144 }
145
146 bool KX_ConstraintActuator::Update(double curtime, bool frame)
147 {
148
149         bool result = false;    
150         bool bNegativeEvent = IsNegativeEvent();
151         RemoveAllEvents();
152
153         if (!bNegativeEvent) {
154                 /* Constraint clamps the values to the specified range, with a sort of    */
155                 /* low-pass filtered time response, if the damp time is unequal to 0.     */
156
157                 /* Having to retrieve location/rotation and setting it afterwards may not */
158                 /* be efficient enough... Somthing to look at later.                      */
159                 KX_GameObject  *obj = (KX_GameObject*) GetParent();
160                 MT_Point3    position = obj->NodeGetWorldPosition();
161                 MT_Point3    newposition;
162                 MT_Vector3   direction, refDirection;
163                 MT_Matrix3x3 rotation = obj->NodeGetWorldOrientation();
164                 MT_Scalar    filter, newdistance, cosangle;
165                 int axis, sign;
166
167                 if (m_posDampTime) {
168                         filter = m_posDampTime/(1.0+m_posDampTime);
169                 }
170                 switch (m_locrot) {
171                 case KX_ACT_CONSTRAINT_ORIX:
172                 case KX_ACT_CONSTRAINT_ORIY:
173                 case KX_ACT_CONSTRAINT_ORIZ:
174                         switch (m_locrot) {
175                         case KX_ACT_CONSTRAINT_ORIX:
176                                 direction[0] = rotation[0][0];
177                                 direction[1] = rotation[1][0];
178                                 direction[2] = rotation[2][0];
179                                 axis = 0;
180                                 break;
181                         case KX_ACT_CONSTRAINT_ORIY:
182                                 direction[0] = rotation[0][1];
183                                 direction[1] = rotation[1][1];
184                                 direction[2] = rotation[2][1];
185                                 axis = 1;
186                                 break;
187                         default:
188                                 direction[0] = rotation[0][2];
189                                 direction[1] = rotation[1][2];
190                                 direction[2] = rotation[2][2];
191                                 axis = 2;
192                                 break;
193                         }
194                         if ((m_maximumBound < (1.0f-FLT_EPSILON)) || (m_minimumBound < (1.0f-FLT_EPSILON))) {
195                                 // reference direction needs to be evaluated
196                                 // 1. get the cosine between current direction and target
197                                 cosangle = direction.dot(m_refDirection);
198                                 if (cosangle >= (m_maximumBound-FLT_EPSILON) && cosangle <= (m_minimumBound+FLT_EPSILON)) {
199                                         // no change to do
200                                         result = true;
201                                         goto CHECK_TIME;
202                                 }
203                                 // 2. define a new reference direction
204                                 //    compute local axis with reference direction as X and
205                                 //    Y in direction X refDirection plane
206                                 MT_Vector3 zaxis = m_refDirection.cross(direction);
207                                 if (MT_fuzzyZero2(zaxis.length2())) {
208                                         // direction and refDirection are identical,
209                                         // choose any other direction to define plane
210                                         if (direction[0] < 0.9999)
211                                                 zaxis = m_refDirection.cross(MT_Vector3(1.0,0.0,0.0));
212                                         else
213                                                 zaxis = m_refDirection.cross(MT_Vector3(0.0,1.0,0.0));
214                                 }
215                                 MT_Vector3 yaxis = zaxis.cross(m_refDirection);
216                                 yaxis.normalize();
217                                 if (cosangle > m_minimumBound) {
218                                         // angle is too close to reference direction,
219                                         // choose a new reference that is exactly at minimum angle
220                                         refDirection = m_minimumBound * m_refDirection + m_minimumSine * yaxis;
221                                 } else {
222                                         // angle is too large, choose new reference direction at maximum angle
223                                         refDirection = m_maximumBound * m_refDirection + m_maximumSine * yaxis;
224                                 }
225                         } else {
226                                 refDirection = m_refDirection;
227                         }
228                         if (m_posDampTime) {
229                                 // apply damping on the direction
230                                 direction = filter*direction + (1.0-filter)*refDirection;
231                         } else {
232                                 direction = refDirection;
233                         }
234                         obj->AlignAxisToVect(direction, axis);
235                         result = true;
236                         goto CHECK_TIME;
237                 case KX_ACT_CONSTRAINT_DIRPX:
238                 case KX_ACT_CONSTRAINT_DIRPY:
239                 case KX_ACT_CONSTRAINT_DIRPZ:
240                 case KX_ACT_CONSTRAINT_DIRNX:
241                 case KX_ACT_CONSTRAINT_DIRNY:
242                 case KX_ACT_CONSTRAINT_DIRNZ:
243                         switch (m_locrot) {
244                         case KX_ACT_CONSTRAINT_DIRPX:
245                                 direction[0] = rotation[0][0];
246                                 direction[1] = rotation[1][0];
247                                 direction[2] = rotation[2][0];
248                                 axis = 0;               // axis according to KX_GameObject::AlignAxisToVect()
249                                 sign = 1;               // X axis will be anti parrallel to normal
250                                 break;
251                         case KX_ACT_CONSTRAINT_DIRPY:
252                                 direction[0] = rotation[0][1];
253                                 direction[1] = rotation[1][1];
254                                 direction[2] = rotation[2][1];
255                                 axis = 1;
256                                 sign = 1;
257                                 break;
258                         case KX_ACT_CONSTRAINT_DIRPZ:
259                                 direction[0] = rotation[0][2];
260                                 direction[1] = rotation[1][2];
261                                 direction[2] = rotation[2][2];
262                                 axis = 2;
263                                 sign = 1;
264                                 break;
265                         case KX_ACT_CONSTRAINT_DIRNX:
266                                 direction[0] = -rotation[0][0];
267                                 direction[1] = -rotation[1][0];
268                                 direction[2] = -rotation[2][0];
269                                 axis = 0;
270                                 sign = 0;
271                                 break;
272                         case KX_ACT_CONSTRAINT_DIRNY:
273                                 direction[0] = -rotation[0][1];
274                                 direction[1] = -rotation[1][1];
275                                 direction[2] = -rotation[2][1];
276                                 axis = 1;
277                                 sign = 0;
278                                 break;
279                         case KX_ACT_CONSTRAINT_DIRNZ:
280                                 direction[0] = -rotation[0][2];
281                                 direction[1] = -rotation[1][2];
282                                 direction[2] = -rotation[2][2];
283                                 axis = 2;
284                                 sign = 0;
285                                 break;
286                         }
287                         direction.normalize();
288                         {
289                                 MT_Point3 topoint = position + (m_maximumBound) * direction;
290                                 MT_Point3 resultpoint;
291                                 MT_Vector3 resultnormal;
292                                 PHY_IPhysicsEnvironment* pe = obj->GetPhysicsEnvironment();
293                                 KX_IPhysicsController *spc = obj->GetPhysicsController();
294
295                                 if (!pe) {
296                                         std::cout << "WARNING: Constraint actuator " << GetName() << ":  There is no physics environment!" << std::endl;
297                                         goto CHECK_TIME;
298                                 }        
299                                 if (!spc) {
300                                         // the object is not physical, we probably want to avoid hitting its own parent
301                                         KX_GameObject *parent = obj->GetParent();
302                                         if (parent) {
303                                                 spc = parent->GetPhysicsController();
304                                                 parent->Release();
305                                         }
306                                 }
307                                 result = KX_RayCast::RayTest(spc, pe, position, topoint, resultpoint, resultnormal, KX_RayCast::Callback<KX_ConstraintActuator>(this));
308
309                                 if (result)     {
310                                         // compute new position & orientation
311                                         if ((m_option & (KX_ACT_CONSTRAINT_NORMAL|KX_ACT_CONSTRAINT_DISTANCE)) == 0) {
312                                                 // if none option is set, the actuator does nothing but detect ray 
313                                                 // (works like a sensor)
314                                                 goto CHECK_TIME;
315                                         }
316                                         if (m_option & KX_ACT_CONSTRAINT_NORMAL) {
317                                                 // the new orientation must be so that the axis is parallel to normal
318                                                 if (sign)
319                                                         resultnormal = -resultnormal;
320                                                 // apply damping on the direction
321                                                 if (m_rotDampTime) {
322                                                         MT_Scalar rotFilter = 1.0/(1.0+m_rotDampTime);
323                                                         resultnormal = (-m_rotDampTime*rotFilter)*direction + rotFilter*resultnormal;
324                                                 } else if (m_posDampTime) {
325                                                         resultnormal = -filter*direction + (1.0-filter)*resultnormal;
326                                                 }
327                                                 obj->AlignAxisToVect(resultnormal, axis);
328                                                 direction = -resultnormal;
329                                         }
330                                         if (m_option & KX_ACT_CONSTRAINT_DISTANCE) {
331                                                 if (m_posDampTime) {
332                                                         newdistance = filter*(position-resultpoint).length()+(1.0-filter)*m_minimumBound;
333                                                 } else {
334                                                         newdistance = m_minimumBound;
335                                                 }
336                                         } else {
337                                                 newdistance = (position-resultpoint).length();
338                                         }
339                                         newposition = resultpoint-newdistance*direction;
340                                 } else if (m_option & KX_ACT_CONSTRAINT_PERMANENT) {
341                                         // no contact but still keep running
342                                         result = true;
343                                         goto CHECK_TIME;
344                                 }
345                         }
346                         break; 
347                 case KX_ACT_CONSTRAINT_LOCX:
348                 case KX_ACT_CONSTRAINT_LOCY:
349                 case KX_ACT_CONSTRAINT_LOCZ:
350                         newposition = position;
351                         switch (m_locrot) {
352                         case KX_ACT_CONSTRAINT_LOCX:
353                                 Clamp(newposition[0], m_minimumBound, m_maximumBound);
354                                 break;
355                         case KX_ACT_CONSTRAINT_LOCY:
356                                 Clamp(newposition[1], m_minimumBound, m_maximumBound);
357                                 break;
358                         case KX_ACT_CONSTRAINT_LOCZ:
359                                 Clamp(newposition[2], m_minimumBound, m_maximumBound);
360                                 break;
361                         }
362                         result = true;
363                         if (m_posDampTime) {
364                                 newposition = filter*position + (1.0-filter)*newposition;
365                         }
366                         break;
367                 }
368                 if (result) {
369                         // set the new position but take into account parent if any
370                         obj->NodeSetWorldPosition(newposition);
371                 }
372         CHECK_TIME:
373                 if (result && m_activeTime > 0 ) {
374                         if (++m_currentTime >= m_activeTime)
375                                 result = false;
376                 }
377         }
378         if (!result) {
379                 m_currentTime = 0;
380         }
381         return result;
382 } /* end of KX_ConstraintActuator::Update(double curtime,double deltatime)   */
383
384 void KX_ConstraintActuator::Clamp(MT_Scalar &var, 
385                                                                   float min, 
386                                                                   float max) {
387         if (var < min) {
388                 var = min;
389         } else if (var > max) {
390                 var = max;
391         }
392 }
393
394
395 bool KX_ConstraintActuator::IsValidMode(KX_ConstraintActuator::KX_CONSTRAINTTYPE m) 
396 {
397         bool res = false;
398
399         if ( (m > KX_ACT_CONSTRAINT_NODEF) && (m < KX_ACT_CONSTRAINT_MAX)) {
400                 res = true;
401         }
402
403         return res;
404 }
405
406 /* ------------------------------------------------------------------------- */
407 /* Python functions                                                          */
408 /* ------------------------------------------------------------------------- */
409
410 /* Integration hooks ------------------------------------------------------- */
411 PyTypeObject KX_ConstraintActuator::Type = {
412         PyObject_HEAD_INIT(&PyType_Type)
413         0,
414         "KX_ConstraintActuator",
415         sizeof(KX_ConstraintActuator),
416         0,
417         PyDestructor,
418         0,
419         __getattr,
420         __setattr,
421         0, //&MyPyCompare,
422         __repr,
423         0, //&cvalue_as_number,
424         0,
425         0,
426         0,
427         0
428 };
429
430 PyParentObject KX_ConstraintActuator::Parents[] = {
431         &KX_ConstraintActuator::Type,
432         &SCA_IActuator::Type,
433         &SCA_ILogicBrick::Type,
434         &CValue::Type,
435         NULL
436 };
437
438 PyMethodDef KX_ConstraintActuator::Methods[] = {
439         {"setDamp", (PyCFunction) KX_ConstraintActuator::sPySetDamp, METH_VARARGS, SetDamp_doc},
440         {"getDamp", (PyCFunction) KX_ConstraintActuator::sPyGetDamp, METH_NOARGS, GetDamp_doc},
441         {"setRotDamp", (PyCFunction) KX_ConstraintActuator::sPySetRotDamp, METH_VARARGS, SetRotDamp_doc},
442         {"getRotDamp", (PyCFunction) KX_ConstraintActuator::sPyGetRotDamp, METH_NOARGS, GetRotDamp_doc},
443         {"setDirection", (PyCFunction) KX_ConstraintActuator::sPySetDirection, METH_VARARGS, SetDirection_doc},
444         {"getDirection", (PyCFunction) KX_ConstraintActuator::sPyGetDirection, METH_NOARGS, GetDirection_doc},
445         {"setOption", (PyCFunction) KX_ConstraintActuator::sPySetOption, METH_VARARGS, SetOption_doc},
446         {"getOption", (PyCFunction) KX_ConstraintActuator::sPyGetOption, METH_NOARGS, GetOption_doc},
447         {"setTime", (PyCFunction) KX_ConstraintActuator::sPySetTime, METH_VARARGS, SetTime_doc},
448         {"getTime", (PyCFunction) KX_ConstraintActuator::sPyGetTime, METH_NOARGS, GetTime_doc},
449         {"setProperty", (PyCFunction) KX_ConstraintActuator::sPySetProperty, METH_VARARGS, SetProperty_doc},
450         {"getProperty", (PyCFunction) KX_ConstraintActuator::sPyGetProperty, METH_NOARGS, GetProperty_doc},
451         {"setMin", (PyCFunction) KX_ConstraintActuator::sPySetMin, METH_VARARGS, SetMin_doc},
452         {"getMin", (PyCFunction) KX_ConstraintActuator::sPyGetMin, METH_NOARGS, GetMin_doc},
453         {"setDistance", (PyCFunction) KX_ConstraintActuator::sPySetMin, METH_VARARGS, SetDistance_doc},
454         {"getDistance", (PyCFunction) KX_ConstraintActuator::sPyGetMin, METH_NOARGS, GetDistance_doc},
455         {"setMax", (PyCFunction) KX_ConstraintActuator::sPySetMax, METH_VARARGS, SetMax_doc},
456         {"getMax", (PyCFunction) KX_ConstraintActuator::sPyGetMax, METH_NOARGS, GetMax_doc},
457         {"setRayLength", (PyCFunction) KX_ConstraintActuator::sPySetMax, METH_VARARGS, SetRayLength_doc},
458         {"getRayLength", (PyCFunction) KX_ConstraintActuator::sPyGetMax, METH_NOARGS, GetRayLength_doc},
459         {"setLimit", (PyCFunction) KX_ConstraintActuator::sPySetLimit, METH_VARARGS, SetLimit_doc},
460         {"getLimit", (PyCFunction) KX_ConstraintActuator::sPyGetLimit, METH_NOARGS, GetLimit_doc},
461         {NULL,NULL} //Sentinel
462 };
463
464 PyObject* KX_ConstraintActuator::_getattr(const STR_String& attr) {
465         _getattr_up(SCA_IActuator);
466 }
467
468 /* 2. setDamp                                                                */
469 char KX_ConstraintActuator::SetDamp_doc[] = 
470 "setDamp(duration)\n"
471 "\t- duration: integer\n"
472 "\tSets the time constant of the orientation and distance constraint.\n"
473 "\tIf the duration is negative, it is set to 0.\n";
474 PyObject* KX_ConstraintActuator::PySetDamp(PyObject* self, 
475                                                                                    PyObject* args, 
476                                                                                    PyObject* kwds) {
477         int dampArg;
478         if(!PyArg_ParseTuple(args, "i", &dampArg)) {
479                 return NULL;            
480         }
481         
482         m_posDampTime = dampArg;
483         if (m_posDampTime < 0) m_posDampTime = 0;
484
485         Py_Return;
486 }
487 /* 3. getDamp                                                                */
488 char KX_ConstraintActuator::GetDamp_doc[] = 
489 "getDamp()\n"
490 "\tReturns the damping parameter.\n";
491 PyObject* KX_ConstraintActuator::PyGetDamp(PyObject* self){
492         return PyInt_FromLong(m_posDampTime);
493 }
494
495 /* 2. setRotDamp                                                                */
496 char KX_ConstraintActuator::SetRotDamp_doc[] = 
497 "setRotDamp(duration)\n"
498 "\t- duration: integer\n"
499 "\tSets the time constant of the orientation constraint.\n"
500 "\tIf the duration is negative, it is set to 0.\n";
501 PyObject* KX_ConstraintActuator::PySetRotDamp(PyObject* self, 
502                                                                                       PyObject* args, 
503                                                                                       PyObject* kwds) {
504         int dampArg;
505         if(!PyArg_ParseTuple(args, "i", &dampArg)) {
506                 return NULL;            
507         }
508         
509         m_rotDampTime = dampArg;
510         if (m_rotDampTime < 0) m_rotDampTime = 0;
511
512         Py_Return;
513 }
514 /* 3. getRotDamp                                                                */
515 char KX_ConstraintActuator::GetRotDamp_doc[] = 
516 "getRotDamp()\n"
517 "\tReturns the damping time for application of the constraint.\n";
518 PyObject* KX_ConstraintActuator::PyGetRotDamp(PyObject* self){
519         return PyInt_FromLong(m_rotDampTime);
520 }
521
522 /* 2. setDirection                                                                */
523 char KX_ConstraintActuator::SetDirection_doc[] = 
524 "setDirection(vector)\n"
525 "\t- vector: 3-tuple\n"
526 "\tSets the reference direction in world coordinate for the orientation constraint.\n";
527 PyObject* KX_ConstraintActuator::PySetDirection(PyObject* self, 
528                                                                                         PyObject* args, 
529                                                                                         PyObject* kwds) {
530         float x, y, z;
531         MT_Scalar len;
532         MT_Vector3 dir;
533
534         if(!PyArg_ParseTuple(args, "(fff)", &x, &y, &z)) {
535                 return NULL;            
536         }
537         dir[0] = x;
538         dir[1] = y;
539         dir[2] = z;
540         len = dir.length();
541         if (MT_fuzzyZero(len)) {
542                 std::cout << "Invalid direction" << std::endl;
543                 return NULL;
544         }
545         m_refDirection = dir/len;
546
547         Py_Return;
548 }
549 /* 3. getDirection                                                                */
550 char KX_ConstraintActuator::GetDirection_doc[] = 
551 "getDirection()\n"
552 "\tReturns the reference direction of the orientation constraint as a 3-tuple.\n";
553 PyObject* KX_ConstraintActuator::PyGetDirection(PyObject* self){
554         PyObject *retVal = PyList_New(3);
555
556         PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_refDirection[0]));
557         PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_refDirection[1]));
558         PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_refDirection[2]));
559         return retVal;
560 }
561
562 /* 2. setOption                                                                */
563 char KX_ConstraintActuator::SetOption_doc[] = 
564 "setOption(option)\n"
565 "\t- option: integer\n"
566 "\tSets several options of the distance  constraint.\n"
567 "\tBinary combination of the following values:\n"
568 "\t\t 64 : Activate alignment to surface\n"
569 "\t\t128 : Detect material rather than property\n"
570 "\t\t256 : No deactivation if ray does not hit target\n"
571 "\t\t512 : Activate distance control\n";
572 PyObject* KX_ConstraintActuator::PySetOption(PyObject* self, 
573                                                                                      PyObject* args, 
574                                                                                      PyObject* kwds) {
575         int option;
576         if(!PyArg_ParseTuple(args, "i", &option)) {
577                 return NULL;            
578         }
579         
580         m_option = option;
581
582         Py_Return;
583 }
584 /* 3. getOption                                                              */
585 char KX_ConstraintActuator::GetOption_doc[] = 
586 "getOption()\n"
587 "\tReturns the option parameter.\n";
588 PyObject* KX_ConstraintActuator::PyGetOption(PyObject* self){
589         return PyInt_FromLong(m_option);
590 }
591
592 /* 2. setTime                                                                */
593 char KX_ConstraintActuator::SetTime_doc[] = 
594 "setTime(duration)\n"
595 "\t- duration: integer\n"
596 "\tSets the activation time of the actuator.\n"
597 "\tThe actuator disables itself after this many frame.\n"
598 "\tIf set to 0 or negative, the actuator is not limited in time.\n";
599 PyObject* KX_ConstraintActuator::PySetTime(PyObject* self, 
600                                                                                    PyObject* args, 
601                                                                                    PyObject* kwds) {
602         int t;
603         if(!PyArg_ParseTuple(args, "i", &t)) {
604                 return NULL;            
605         }
606         
607         if (t < 0)
608                 t = 0;
609         m_activeTime = t;
610
611         Py_Return;
612 }
613 /* 3. getTime                                                                */
614 char KX_ConstraintActuator::GetTime_doc[] = 
615 "getTime()\n"
616 "\tReturns the time parameter.\n";
617 PyObject* KX_ConstraintActuator::PyGetTime(PyObject* self){
618         return PyInt_FromLong(m_activeTime);
619 }
620
621 /* 2. setProperty                                                                */
622 char KX_ConstraintActuator::SetProperty_doc[] = 
623 "setProperty(property)\n"
624 "\t- property: string\n"
625 "\tSets the name of the property or material for the ray detection of the distance constraint.\n"
626 "\tIf empty, the ray will detect any collisioning object.\n";
627 PyObject* KX_ConstraintActuator::PySetProperty(PyObject* self, 
628                                                                                        PyObject* args, 
629                                                                                        PyObject* kwds) {
630         char *property;
631         if (!PyArg_ParseTuple(args, "s", &property)) {
632                 return NULL;
633         }
634         if (property == NULL) {
635                 m_property[0] = 0;
636         } else {
637                 strncpy(m_property, property, sizeof(m_property));
638                 m_property[sizeof(m_property)-1] = 0;
639         }
640
641         Py_Return;
642 }
643 /* 3. getProperty                                                                */
644 char KX_ConstraintActuator::GetProperty_doc[] = 
645 "getProperty()\n"
646 "\tReturns the property parameter.\n";
647 PyObject* KX_ConstraintActuator::PyGetProperty(PyObject* self){
648         return PyString_FromString(m_property);
649 }
650
651 /* 4. setDistance                                                                 */
652 char KX_ConstraintActuator::SetDistance_doc[] = 
653 "setDistance(distance)\n"
654 "\t- distance: float\n"
655 "\tSets the target distance in distance constraint\n";
656 /* 4. setMin                                                                 */
657 char KX_ConstraintActuator::SetMin_doc[] = 
658 "setMin(lower_bound)\n"
659 "\t- lower_bound: float\n"
660 "\tSets the lower value of the interval to which the value\n"
661 "\tis clipped.\n";
662 PyObject* KX_ConstraintActuator::PySetMin(PyObject* self, 
663                                                                                   PyObject* args, 
664                                                                                   PyObject* kwds) {
665         float minArg;
666         if(!PyArg_ParseTuple(args, "f", &minArg)) {
667                 return NULL;            
668         }
669
670         switch (m_locrot) {
671         default:
672                 m_minimumBound = minArg;
673                 break;
674         case KX_ACT_CONSTRAINT_ROTX:
675         case KX_ACT_CONSTRAINT_ROTY:
676         case KX_ACT_CONSTRAINT_ROTZ:
677                 m_minimumBound = MT_radians(minArg);
678                 break;
679         }
680
681         Py_Return;
682 }
683 /* 5. getDistance                                                                 */
684 char KX_ConstraintActuator::GetDistance_doc[] = 
685 "getDistance()\n"
686 "\tReturns the distance parameter \n";
687 /* 5. getMin                                                                 */
688 char KX_ConstraintActuator::GetMin_doc[] = 
689 "getMin()\n"
690 "\tReturns the lower value of the interval to which the value\n"
691 "\tis clipped.\n";
692 PyObject* KX_ConstraintActuator::PyGetMin(PyObject* self) {
693         return PyFloat_FromDouble(m_minimumBound);
694 }
695
696 /* 6. setRayLength                                                                 */
697 char KX_ConstraintActuator::SetRayLength_doc[] = 
698 "setRayLength(length)\n"
699 "\t- length: float\n"
700 "\tSets the maximum ray length of the distance constraint\n";
701 /* 6. setMax                                                                 */
702 char KX_ConstraintActuator::SetMax_doc[] = 
703 "setMax(upper_bound)\n"
704 "\t- upper_bound: float\n"
705 "\tSets the upper value of the interval to which the value\n"
706 "\tis clipped.\n";
707 PyObject* KX_ConstraintActuator::PySetMax(PyObject* self, 
708                                                                                   PyObject* args, 
709                                                                                   PyObject* kwds){
710         float maxArg;
711         if(!PyArg_ParseTuple(args, "f", &maxArg)) {
712                 return NULL;            
713         }
714
715         switch (m_locrot) {
716         default:
717                 m_maximumBound = maxArg;
718                 break;
719         case KX_ACT_CONSTRAINT_ROTX:
720         case KX_ACT_CONSTRAINT_ROTY:
721         case KX_ACT_CONSTRAINT_ROTZ:
722                 m_maximumBound = MT_radians(maxArg);
723                 break;
724         }
725
726         Py_Return;
727 }
728 /* 7. getRayLength                                                                 */
729 char KX_ConstraintActuator::GetRayLength_doc[] = 
730 "getRayLength()\n"
731 "\tReturns the length of the ray\n";
732 /* 7. getMax                                                                 */
733 char KX_ConstraintActuator::GetMax_doc[] = 
734 "getMax()\n"
735 "\tReturns the upper value of the interval to which the value\n"
736 "\tis clipped.\n";
737 PyObject* KX_ConstraintActuator::PyGetMax(PyObject* self) {
738         return PyFloat_FromDouble(m_maximumBound);
739 }
740
741
742 /* This setter/getter probably for the constraint type                       */
743 /* 8. setLimit                                                               */
744 char KX_ConstraintActuator::SetLimit_doc[] = 
745 "setLimit(type)\n"
746 "\t- type: integer\n"
747 "\t  1  : LocX\n"
748 "\t  2  : LocY\n"
749 "\t  3  : LocZ\n"
750 "\t  7  : Distance along +X axis\n"
751 "\t  8  : Distance along +Y axis\n"
752 "\t  9  : Distance along +Z axis\n"
753 "\t  10 : Distance along -X axis\n"
754 "\t  11 : Distance along -Y axis\n"
755 "\t  12 : Distance along -Z axis\n"
756 "\t  13 : Align X axis\n"
757 "\t  14 : Align Y axis\n"
758 "\t  15 : Align Z axis\n"
759 "\tSets the type of constraint.\n";
760 PyObject* KX_ConstraintActuator::PySetLimit(PyObject* self, 
761                                                                                         PyObject* args, 
762                                                                                         PyObject* kwds) {
763         int locrotArg;
764         if(!PyArg_ParseTuple(args, "i", &locrotArg)) {
765                 return NULL;            
766         }
767         
768         if (IsValidMode((KX_CONSTRAINTTYPE)locrotArg)) m_locrot = locrotArg;
769
770         Py_Return;
771 }
772 /* 9. getLimit                                                               */
773 char KX_ConstraintActuator::GetLimit_doc[] = 
774 "getLimit()\n"
775 "\tReturns the type of constraint.\n";
776 PyObject* KX_ConstraintActuator::PyGetLimit(PyObject* self) {
777         return PyInt_FromLong(m_locrot);
778 }
779
780 /* eof */