BGE patch: Add PyDoc for new logic bricks, set exception message on Py error, remove...
[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                 PyErr_SetString(PyExc_TypeError, "Invalid arguments");
480                 return NULL;            
481         }
482         
483         m_posDampTime = dampArg;
484         if (m_posDampTime < 0) m_posDampTime = 0;
485
486         Py_Return;
487 }
488 /* 3. getDamp                                                                */
489 char KX_ConstraintActuator::GetDamp_doc[] = 
490 "getDamp()\n"
491 "\tReturns the damping parameter.\n";
492 PyObject* KX_ConstraintActuator::PyGetDamp(PyObject* self){
493         return PyInt_FromLong(m_posDampTime);
494 }
495
496 /* 2. setRotDamp                                                                */
497 char KX_ConstraintActuator::SetRotDamp_doc[] = 
498 "setRotDamp(duration)\n"
499 "\t- duration: integer\n"
500 "\tSets the time constant of the orientation constraint.\n"
501 "\tIf the duration is negative, it is set to 0.\n";
502 PyObject* KX_ConstraintActuator::PySetRotDamp(PyObject* self, 
503                                                                                       PyObject* args, 
504                                                                                       PyObject* kwds) {
505         int dampArg;
506         if(!PyArg_ParseTuple(args, "i", &dampArg)) {
507                 PyErr_SetString(PyExc_TypeError, "Invalid arguments");
508                 return NULL;            
509         }
510         
511         m_rotDampTime = dampArg;
512         if (m_rotDampTime < 0) m_rotDampTime = 0;
513
514         Py_Return;
515 }
516 /* 3. getRotDamp                                                                */
517 char KX_ConstraintActuator::GetRotDamp_doc[] = 
518 "getRotDamp()\n"
519 "\tReturns the damping time for application of the constraint.\n";
520 PyObject* KX_ConstraintActuator::PyGetRotDamp(PyObject* self){
521         return PyInt_FromLong(m_rotDampTime);
522 }
523
524 /* 2. setDirection                                                                */
525 char KX_ConstraintActuator::SetDirection_doc[] = 
526 "setDirection(vector)\n"
527 "\t- vector: 3-tuple\n"
528 "\tSets the reference direction in world coordinate for the orientation constraint.\n";
529 PyObject* KX_ConstraintActuator::PySetDirection(PyObject* self, 
530                                                                                         PyObject* args, 
531                                                                                         PyObject* kwds) {
532         float x, y, z;
533         MT_Scalar len;
534         MT_Vector3 dir;
535
536         if(!PyArg_ParseTuple(args, "(fff)", &x, &y, &z)) {
537                 PyErr_SetString(PyExc_TypeError, "Invalid arguments");
538                 return NULL;            
539         }
540         dir[0] = x;
541         dir[1] = y;
542         dir[2] = z;
543         len = dir.length();
544         if (MT_fuzzyZero(len)) {
545                 std::cout << "Invalid direction" << std::endl;
546                 return NULL;
547         }
548         m_refDirection = dir/len;
549
550         Py_Return;
551 }
552 /* 3. getDirection                                                                */
553 char KX_ConstraintActuator::GetDirection_doc[] = 
554 "getDirection()\n"
555 "\tReturns the reference direction of the orientation constraint as a 3-tuple.\n";
556 PyObject* KX_ConstraintActuator::PyGetDirection(PyObject* self){
557         PyObject *retVal = PyList_New(3);
558
559         PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_refDirection[0]));
560         PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_refDirection[1]));
561         PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_refDirection[2]));
562         return retVal;
563 }
564
565 /* 2. setOption                                                                */
566 char KX_ConstraintActuator::SetOption_doc[] = 
567 "setOption(option)\n"
568 "\t- option: integer\n"
569 "\tSets several options of the distance  constraint.\n"
570 "\tBinary combination of the following values:\n"
571 "\t\t 64 : Activate alignment to surface\n"
572 "\t\t128 : Detect material rather than property\n"
573 "\t\t256 : No deactivation if ray does not hit target\n"
574 "\t\t512 : Activate distance control\n";
575 PyObject* KX_ConstraintActuator::PySetOption(PyObject* self, 
576                                                                                      PyObject* args, 
577                                                                                      PyObject* kwds) {
578         int option;
579         if(!PyArg_ParseTuple(args, "i", &option)) {
580                 PyErr_SetString(PyExc_TypeError, "Invalid arguments");
581                 return NULL;            
582         }
583         
584         m_option = option;
585
586         Py_Return;
587 }
588 /* 3. getOption                                                              */
589 char KX_ConstraintActuator::GetOption_doc[] = 
590 "getOption()\n"
591 "\tReturns the option parameter.\n";
592 PyObject* KX_ConstraintActuator::PyGetOption(PyObject* self){
593         return PyInt_FromLong(m_option);
594 }
595
596 /* 2. setTime                                                                */
597 char KX_ConstraintActuator::SetTime_doc[] = 
598 "setTime(duration)\n"
599 "\t- duration: integer\n"
600 "\tSets the activation time of the actuator.\n"
601 "\tThe actuator disables itself after this many frame.\n"
602 "\tIf set to 0 or negative, the actuator is not limited in time.\n";
603 PyObject* KX_ConstraintActuator::PySetTime(PyObject* self, 
604                                                                                    PyObject* args, 
605                                                                                    PyObject* kwds) {
606         int t;
607         if(!PyArg_ParseTuple(args, "i", &t)) {
608                 PyErr_SetString(PyExc_TypeError, "Invalid arguments");
609                 return NULL;            
610         }
611         
612         if (t < 0)
613                 t = 0;
614         m_activeTime = t;
615
616         Py_Return;
617 }
618 /* 3. getTime                                                                */
619 char KX_ConstraintActuator::GetTime_doc[] = 
620 "getTime()\n"
621 "\tReturns the time parameter.\n";
622 PyObject* KX_ConstraintActuator::PyGetTime(PyObject* self){
623         return PyInt_FromLong(m_activeTime);
624 }
625
626 /* 2. setProperty                                                                */
627 char KX_ConstraintActuator::SetProperty_doc[] = 
628 "setProperty(property)\n"
629 "\t- property: string\n"
630 "\tSets the name of the property or material for the ray detection of the distance constraint.\n"
631 "\tIf empty, the ray will detect any collisioning object.\n";
632 PyObject* KX_ConstraintActuator::PySetProperty(PyObject* self, 
633                                                                                        PyObject* args, 
634                                                                                        PyObject* kwds) {
635         char *property;
636         if (!PyArg_ParseTuple(args, "s", &property)) {
637                 PyErr_SetString(PyExc_TypeError, "Invalid arguments");
638                 return NULL;
639         }
640         if (property == NULL) {
641                 m_property[0] = 0;
642         } else {
643                 strncpy(m_property, property, sizeof(m_property));
644                 m_property[sizeof(m_property)-1] = 0;
645         }
646
647         Py_Return;
648 }
649 /* 3. getProperty                                                                */
650 char KX_ConstraintActuator::GetProperty_doc[] = 
651 "getProperty()\n"
652 "\tReturns the property parameter.\n";
653 PyObject* KX_ConstraintActuator::PyGetProperty(PyObject* self){
654         return PyString_FromString(m_property);
655 }
656
657 /* 4. setDistance                                                                 */
658 char KX_ConstraintActuator::SetDistance_doc[] = 
659 "setDistance(distance)\n"
660 "\t- distance: float\n"
661 "\tSets the target distance in distance constraint\n";
662 /* 4. setMin                                                                 */
663 char KX_ConstraintActuator::SetMin_doc[] = 
664 "setMin(lower_bound)\n"
665 "\t- lower_bound: float\n"
666 "\tSets the lower value of the interval to which the value\n"
667 "\tis clipped.\n";
668 PyObject* KX_ConstraintActuator::PySetMin(PyObject* self, 
669                                                                                   PyObject* args, 
670                                                                                   PyObject* kwds) {
671         float minArg;
672         if(!PyArg_ParseTuple(args, "f", &minArg)) {
673                 PyErr_SetString(PyExc_TypeError, "Invalid arguments");
674                 return NULL;            
675         }
676
677         switch (m_locrot) {
678         default:
679                 m_minimumBound = minArg;
680                 break;
681         case KX_ACT_CONSTRAINT_ROTX:
682         case KX_ACT_CONSTRAINT_ROTY:
683         case KX_ACT_CONSTRAINT_ROTZ:
684                 m_minimumBound = MT_radians(minArg);
685                 break;
686         }
687
688         Py_Return;
689 }
690 /* 5. getDistance                                                                 */
691 char KX_ConstraintActuator::GetDistance_doc[] = 
692 "getDistance()\n"
693 "\tReturns the distance parameter \n";
694 /* 5. getMin                                                                 */
695 char KX_ConstraintActuator::GetMin_doc[] = 
696 "getMin()\n"
697 "\tReturns the lower value of the interval to which the value\n"
698 "\tis clipped.\n";
699 PyObject* KX_ConstraintActuator::PyGetMin(PyObject* self) {
700         return PyFloat_FromDouble(m_minimumBound);
701 }
702
703 /* 6. setRayLength                                                                 */
704 char KX_ConstraintActuator::SetRayLength_doc[] = 
705 "setRayLength(length)\n"
706 "\t- length: float\n"
707 "\tSets the maximum ray length of the distance constraint\n";
708 /* 6. setMax                                                                 */
709 char KX_ConstraintActuator::SetMax_doc[] = 
710 "setMax(upper_bound)\n"
711 "\t- upper_bound: float\n"
712 "\tSets the upper value of the interval to which the value\n"
713 "\tis clipped.\n";
714 PyObject* KX_ConstraintActuator::PySetMax(PyObject* self, 
715                                                                                   PyObject* args, 
716                                                                                   PyObject* kwds){
717         float maxArg;
718         if(!PyArg_ParseTuple(args, "f", &maxArg)) {
719                 PyErr_SetString(PyExc_TypeError, "Invalid arguments");
720                 return NULL;            
721         }
722
723         switch (m_locrot) {
724         default:
725                 m_maximumBound = maxArg;
726                 break;
727         case KX_ACT_CONSTRAINT_ROTX:
728         case KX_ACT_CONSTRAINT_ROTY:
729         case KX_ACT_CONSTRAINT_ROTZ:
730                 m_maximumBound = MT_radians(maxArg);
731                 break;
732         }
733
734         Py_Return;
735 }
736 /* 7. getRayLength                                                                 */
737 char KX_ConstraintActuator::GetRayLength_doc[] = 
738 "getRayLength()\n"
739 "\tReturns the length of the ray\n";
740 /* 7. getMax                                                                 */
741 char KX_ConstraintActuator::GetMax_doc[] = 
742 "getMax()\n"
743 "\tReturns the upper value of the interval to which the value\n"
744 "\tis clipped.\n";
745 PyObject* KX_ConstraintActuator::PyGetMax(PyObject* self) {
746         return PyFloat_FromDouble(m_maximumBound);
747 }
748
749
750 /* This setter/getter probably for the constraint type                       */
751 /* 8. setLimit                                                               */
752 char KX_ConstraintActuator::SetLimit_doc[] = 
753 "setLimit(type)\n"
754 "\t- type: integer\n"
755 "\t  1  : LocX\n"
756 "\t  2  : LocY\n"
757 "\t  3  : LocZ\n"
758 "\t  7  : Distance along +X axis\n"
759 "\t  8  : Distance along +Y axis\n"
760 "\t  9  : Distance along +Z axis\n"
761 "\t  10 : Distance along -X axis\n"
762 "\t  11 : Distance along -Y axis\n"
763 "\t  12 : Distance along -Z axis\n"
764 "\t  13 : Align X axis\n"
765 "\t  14 : Align Y axis\n"
766 "\t  15 : Align Z axis\n"
767 "\tSets the type of constraint.\n";
768 PyObject* KX_ConstraintActuator::PySetLimit(PyObject* self, 
769                                                                                         PyObject* args, 
770                                                                                         PyObject* kwds) {
771         int locrotArg;
772         if(!PyArg_ParseTuple(args, "i", &locrotArg)) {
773                 PyErr_SetString(PyExc_TypeError, "Invalid arguments");
774                 return NULL;            
775         }
776         
777         if (IsValidMode((KX_CONSTRAINTTYPE)locrotArg)) m_locrot = locrotArg;
778
779         Py_Return;
780 }
781 /* 9. getLimit                                                               */
782 char KX_ConstraintActuator::GetLimit_doc[] = 
783 "getLimit()\n"
784 "\tReturns the type of constraint.\n";
785 PyObject* KX_ConstraintActuator::PyGetLimit(PyObject* self) {
786         return PyInt_FromLong(m_locrot);
787 }
788
789 /* eof */