soc-2008-mxcurioni: merged changes to revision 23516
[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 #include "KX_PythonInit.h" // KX_GetActiveScene
40
41 #ifdef HAVE_CONFIG_H
42 #include <config.h>
43 #endif
44
45 /* ------------------------------------------------------------------------- */
46 /* Native functions                                                          */
47 /* ------------------------------------------------------------------------- */
48
49 KX_ConstraintActuator::KX_ConstraintActuator(SCA_IObject *gameobj, 
50                                                                                          int posDampTime,
51                                                                                          int rotDampTime,
52                                                                                          float minBound,
53                                                                                          float maxBound,
54                                                                                          float refDir[3],
55                                                                                          int locrotxyz,
56                                                                                          int time,
57                                                                                          int option,
58                                                                                          char *property) :
59         SCA_IActuator(gameobj, KX_ACT_CONSTRAINT),
60         m_refDirVector(refDir),
61         m_currentTime(0)
62 {
63         m_refDirection[0] = refDir[0];
64         m_refDirection[1] = refDir[1];
65         m_refDirection[2] = refDir[2];
66         m_posDampTime = posDampTime;
67         m_rotDampTime = rotDampTime;
68         m_locrot   = locrotxyz;
69         m_option = option;
70         m_activeTime = time;
71         if (property) {
72                 m_property = property;
73         } else {
74                 m_property = "";
75         }
76         /* The units of bounds are determined by the type of constraint. To      */
77         /* make the constraint application easier and more transparent later on, */
78         /* I think converting the bounds to the applicable domain makes more     */
79         /* sense.                                                                */
80         switch (m_locrot) {
81         case KX_ACT_CONSTRAINT_ORIX:
82         case KX_ACT_CONSTRAINT_ORIY:
83         case KX_ACT_CONSTRAINT_ORIZ:
84                 {
85                         MT_Scalar len = m_refDirVector.length();
86                         if (MT_fuzzyZero(len)) {
87                                 // missing a valid direction
88                                 std::cout << "WARNING: Constraint actuator " << GetName() << ":  There is no valid reference direction!" << std::endl;
89                                 m_locrot = KX_ACT_CONSTRAINT_NODEF;
90                         } else {
91                                 m_refDirection[0] /= len;
92                                 m_refDirection[1] /= len;
93                                 m_refDirection[2] /= len;
94                                 m_refDirVector /= len;
95                         }
96                         m_minimumBound = cos(minBound);
97                         m_maximumBound = cos(maxBound);
98                         m_minimumSine = sin(minBound);
99                         m_maximumSine = sin(maxBound);
100                 }
101                 break;
102         default:
103                 m_minimumBound = minBound;
104                 m_maximumBound = maxBound;
105                 m_minimumSine = 0.f;
106                 m_maximumSine = 0.f;
107                 break;
108         }
109
110 } /* End of constructor */
111
112 KX_ConstraintActuator::~KX_ConstraintActuator()
113
114         // there's nothing to be done here, really....
115 } /* end of destructor */
116
117 bool KX_ConstraintActuator::RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void * const data)
118 {
119
120         m_hitObject = client->m_gameobject;
121         
122         bool bFound = false;
123
124         if (m_property.IsEmpty())
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.Ptr(), ((char*)client->m_auxilary_info));
135                         }
136                 }
137                 else
138                 {
139                         bFound = m_hitObject->GetProperty(m_property) != NULL;
140                 }
141         }
142         // update the hit status
143         result->m_hitFound = bFound;
144         // stop looking
145         return true;
146 }
147
148 /* this function is used to pre-filter the object before casting the ray on them.
149    This is useful for "X-Ray" option when we want to see "through" unwanted object.
150  */
151 bool KX_ConstraintActuator::NeedRayCast(KX_ClientObjectInfo* client)
152 {
153         if (client->m_type > KX_ClientObjectInfo::ACTOR)
154         {
155                 // Unknown type of object, skip it.
156                 // Should not occur as the sensor objects are filtered in RayTest()
157                 printf("Invalid client type %d found in ray casting\n", client->m_type);
158                 return false;
159         }
160         // no X-Ray function yet
161         return true;
162 }
163
164 bool KX_ConstraintActuator::Update(double curtime, bool frame)
165 {
166
167         bool result = false;    
168         bool bNegativeEvent = IsNegativeEvent();
169         RemoveAllEvents();
170
171         if (!bNegativeEvent) {
172                 /* Constraint clamps the values to the specified range, with a sort of    */
173                 /* low-pass filtered time response, if the damp time is unequal to 0.     */
174
175                 /* Having to retrieve location/rotation and setting it afterwards may not */
176                 /* be efficient enough... Somthing to look at later.                      */
177                 KX_GameObject  *obj = (KX_GameObject*) GetParent();
178                 MT_Point3    position = obj->NodeGetWorldPosition();
179                 MT_Point3    newposition;
180                 MT_Vector3   normal, direction, refDirection;
181                 MT_Matrix3x3 rotation = obj->NodeGetWorldOrientation();
182                 MT_Scalar    filter, newdistance, cosangle;
183                 int axis, sign;
184
185                 if (m_posDampTime) {
186                         filter = m_posDampTime/(1.0+m_posDampTime);
187                 } else {
188                         filter = 0.0;
189                 }
190                 switch (m_locrot) {
191                 case KX_ACT_CONSTRAINT_ORIX:
192                 case KX_ACT_CONSTRAINT_ORIY:
193                 case KX_ACT_CONSTRAINT_ORIZ:
194                         switch (m_locrot) {
195                         case KX_ACT_CONSTRAINT_ORIX:
196                                 direction[0] = rotation[0][0];
197                                 direction[1] = rotation[1][0];
198                                 direction[2] = rotation[2][0];
199                                 axis = 0;
200                                 break;
201                         case KX_ACT_CONSTRAINT_ORIY:
202                                 direction[0] = rotation[0][1];
203                                 direction[1] = rotation[1][1];
204                                 direction[2] = rotation[2][1];
205                                 axis = 1;
206                                 break;
207                         default:
208                                 direction[0] = rotation[0][2];
209                                 direction[1] = rotation[1][2];
210                                 direction[2] = rotation[2][2];
211                                 axis = 2;
212                                 break;
213                         }
214                         if ((m_maximumBound < (1.0f-FLT_EPSILON)) || (m_minimumBound < (1.0f-FLT_EPSILON))) {
215                                 // reference direction needs to be evaluated
216                                 // 1. get the cosine between current direction and target
217                                 cosangle = direction.dot(m_refDirVector);
218                                 if (cosangle >= (m_maximumBound-FLT_EPSILON) && cosangle <= (m_minimumBound+FLT_EPSILON)) {
219                                         // no change to do
220                                         result = true;
221                                         goto CHECK_TIME;
222                                 }
223                                 // 2. define a new reference direction
224                                 //    compute local axis with reference direction as X and
225                                 //    Y in direction X refDirection plane
226                                 MT_Vector3 zaxis = m_refDirVector.cross(direction);
227                                 if (MT_fuzzyZero2(zaxis.length2())) {
228                                         // direction and refDirection are identical,
229                                         // choose any other direction to define plane
230                                         if (direction[0] < 0.9999)
231                                                 zaxis = m_refDirVector.cross(MT_Vector3(1.0,0.0,0.0));
232                                         else
233                                                 zaxis = m_refDirVector.cross(MT_Vector3(0.0,1.0,0.0));
234                                 }
235                                 MT_Vector3 yaxis = zaxis.cross(m_refDirVector);
236                                 yaxis.normalize();
237                                 if (cosangle > m_minimumBound) {
238                                         // angle is too close to reference direction,
239                                         // choose a new reference that is exactly at minimum angle
240                                         refDirection = m_minimumBound * m_refDirVector + m_minimumSine * yaxis;
241                                 } else {
242                                         // angle is too large, choose new reference direction at maximum angle
243                                         refDirection = m_maximumBound * m_refDirVector + m_maximumSine * yaxis;
244                                 }
245                         } else {
246                                 refDirection = m_refDirVector;
247                         }
248                         // apply damping on the direction
249                         direction = filter*direction + (1.0-filter)*refDirection;
250                         obj->AlignAxisToVect(direction, axis);
251                         result = true;
252                         goto CHECK_TIME;
253                 case KX_ACT_CONSTRAINT_DIRPX:
254                 case KX_ACT_CONSTRAINT_DIRPY:
255                 case KX_ACT_CONSTRAINT_DIRPZ:
256                 case KX_ACT_CONSTRAINT_DIRNX:
257                 case KX_ACT_CONSTRAINT_DIRNY:
258                 case KX_ACT_CONSTRAINT_DIRNZ:
259                         switch (m_locrot) {
260                         case KX_ACT_CONSTRAINT_DIRPX:
261                                 normal[0] = rotation[0][0];
262                                 normal[1] = rotation[1][0];
263                                 normal[2] = rotation[2][0];
264                                 axis = 0;               // axis according to KX_GameObject::AlignAxisToVect()
265                                 sign = 0;               // X axis will be parrallel to direction of ray
266                                 break;
267                         case KX_ACT_CONSTRAINT_DIRPY:
268                                 normal[0] = rotation[0][1];
269                                 normal[1] = rotation[1][1];
270                                 normal[2] = rotation[2][1];
271                                 axis = 1;
272                                 sign = 0;
273                                 break;
274                         case KX_ACT_CONSTRAINT_DIRPZ:
275                                 normal[0] = rotation[0][2];
276                                 normal[1] = rotation[1][2];
277                                 normal[2] = rotation[2][2];
278                                 axis = 2;
279                                 sign = 0;
280                                 break;
281                         case KX_ACT_CONSTRAINT_DIRNX:
282                                 normal[0] = -rotation[0][0];
283                                 normal[1] = -rotation[1][0];
284                                 normal[2] = -rotation[2][0];
285                                 axis = 0;
286                                 sign = 1;
287                                 break;
288                         case KX_ACT_CONSTRAINT_DIRNY:
289                                 normal[0] = -rotation[0][1];
290                                 normal[1] = -rotation[1][1];
291                                 normal[2] = -rotation[2][1];
292                                 axis = 1;
293                                 sign = 1;
294                                 break;
295                         case KX_ACT_CONSTRAINT_DIRNZ:
296                                 normal[0] = -rotation[0][2];
297                                 normal[1] = -rotation[1][2];
298                                 normal[2] = -rotation[2][2];
299                                 axis = 2;
300                                 sign = 1;
301                                 break;
302                         }
303                         normal.normalize();
304                         if (m_option & KX_ACT_CONSTRAINT_LOCAL) {
305                                 // direction of the ray is along the local axis
306                                 direction = normal;
307                         } else {
308                                 switch (m_locrot) {
309                                 case KX_ACT_CONSTRAINT_DIRPX:
310                                         direction = MT_Vector3(1.0,0.0,0.0);
311                                         break;
312                                 case KX_ACT_CONSTRAINT_DIRPY:
313                                         direction = MT_Vector3(0.0,1.0,0.0);
314                                         break;
315                                 case KX_ACT_CONSTRAINT_DIRPZ:
316                                         direction = MT_Vector3(0.0,0.0,1.0);
317                                         break;
318                                 case KX_ACT_CONSTRAINT_DIRNX:
319                                         direction = MT_Vector3(-1.0,0.0,0.0);
320                                         break;
321                                 case KX_ACT_CONSTRAINT_DIRNY:
322                                         direction = MT_Vector3(0.0,-1.0,0.0);
323                                         break;
324                                 case KX_ACT_CONSTRAINT_DIRNZ:
325                                         direction = MT_Vector3(0.0,0.0,-1.0);
326                                         break;
327                                 }
328                         }
329                         {
330                                 MT_Point3 topoint = position + (m_maximumBound) * direction;
331                                 PHY_IPhysicsEnvironment* pe = KX_GetActiveScene()->GetPhysicsEnvironment();
332                                 KX_IPhysicsController *spc = obj->GetPhysicsController();
333
334                                 if (!pe) {
335                                         std::cout << "WARNING: Constraint actuator " << GetName() << ":  There is no physics environment!" << std::endl;
336                                         goto CHECK_TIME;
337                                 }        
338                                 if (!spc) {
339                                         // the object is not physical, we probably want to avoid hitting its own parent
340                                         KX_GameObject *parent = obj->GetParent();
341                                         if (parent) {
342                                                 spc = parent->GetPhysicsController();
343                                                 parent->Release();
344                                         }
345                                 }
346                                 KX_RayCast::Callback<KX_ConstraintActuator> callback(this,spc);
347                                 result = KX_RayCast::RayTest(pe, position, topoint, callback);
348                                 if (result)     {
349                                         MT_Vector3 newnormal = callback.m_hitNormal;
350                                         // compute new position & orientation
351                                         if ((m_option & (KX_ACT_CONSTRAINT_NORMAL|KX_ACT_CONSTRAINT_DISTANCE)) == 0) {
352                                                 // if none option is set, the actuator does nothing but detect ray 
353                                                 // (works like a sensor)
354                                                 goto CHECK_TIME;
355                                         }
356                                         if (m_option & KX_ACT_CONSTRAINT_NORMAL) {
357                                                 MT_Scalar rotFilter;
358                                                 // apply damping on the direction
359                                                 if (m_rotDampTime) {
360                                                         rotFilter = m_rotDampTime/(1.0+m_rotDampTime);
361                                                 } else {
362                                                         rotFilter = filter;
363                                                 }
364                                                 newnormal = rotFilter*normal - (1.0-rotFilter)*newnormal;
365                                                 obj->AlignAxisToVect((sign)?-newnormal:newnormal, axis);
366                                                 if (m_option & KX_ACT_CONSTRAINT_LOCAL) {
367                                                         direction = newnormal;
368                                                         direction.normalize();
369                                                 }
370                                         }
371                                         if (m_option & KX_ACT_CONSTRAINT_DISTANCE) {
372                                                 if (m_posDampTime) {
373                                                         newdistance = filter*(position-callback.m_hitPoint).length()+(1.0-filter)*m_minimumBound;
374                                                 } else {
375                                                         newdistance = m_minimumBound;
376                                                 }
377                                                 // logically we should cancel the speed along the ray direction as we set the
378                                                 // position along that axis
379                                                 spc = obj->GetPhysicsController();
380                                                 if (spc && spc->IsDyna()) {
381                                                         MT_Vector3 linV = spc->GetLinearVelocity();
382                                                         // cancel the projection along the ray direction
383                                                         MT_Scalar fallspeed = linV.dot(direction);
384                                                         if (!MT_fuzzyZero(fallspeed))
385                                                                 spc->SetLinearVelocity(linV-fallspeed*direction,false);
386                                                 }
387                                         } else {
388                                                 newdistance = (position-callback.m_hitPoint).length();
389                                         }
390                                         newposition = callback.m_hitPoint-newdistance*direction;
391                                 } else if (m_option & KX_ACT_CONSTRAINT_PERMANENT) {
392                                         // no contact but still keep running
393                                         result = true;
394                                         goto CHECK_TIME;
395                                 }
396                         }
397                         break; 
398                 case KX_ACT_CONSTRAINT_FHPX:
399                 case KX_ACT_CONSTRAINT_FHPY:
400                 case KX_ACT_CONSTRAINT_FHPZ:
401                 case KX_ACT_CONSTRAINT_FHNX:
402                 case KX_ACT_CONSTRAINT_FHNY:
403                 case KX_ACT_CONSTRAINT_FHNZ:
404                         switch (m_locrot) {
405                         case KX_ACT_CONSTRAINT_FHPX:
406                                 normal[0] = -rotation[0][0];
407                                 normal[1] = -rotation[1][0];
408                                 normal[2] = -rotation[2][0];
409                                 direction = MT_Vector3(1.0,0.0,0.0);
410                                 break;
411                         case KX_ACT_CONSTRAINT_FHPY:
412                                 normal[0] = -rotation[0][1];
413                                 normal[1] = -rotation[1][1];
414                                 normal[2] = -rotation[2][1];
415                                 direction = MT_Vector3(0.0,1.0,0.0);
416                                 break;
417                         case KX_ACT_CONSTRAINT_FHPZ:
418                                 normal[0] = -rotation[0][2];
419                                 normal[1] = -rotation[1][2];
420                                 normal[2] = -rotation[2][2];
421                                 direction = MT_Vector3(0.0,0.0,1.0);
422                                 break;
423                         case KX_ACT_CONSTRAINT_FHNX:
424                                 normal[0] = rotation[0][0];
425                                 normal[1] = rotation[1][0];
426                                 normal[2] = rotation[2][0];
427                                 direction = MT_Vector3(-1.0,0.0,0.0);
428                                 break;
429                         case KX_ACT_CONSTRAINT_FHNY:
430                                 normal[0] = rotation[0][1];
431                                 normal[1] = rotation[1][1];
432                                 normal[2] = rotation[2][1];
433                                 direction = MT_Vector3(0.0,-1.0,0.0);
434                                 break;
435                         case KX_ACT_CONSTRAINT_FHNZ:
436                                 normal[0] = rotation[0][2];
437                                 normal[1] = rotation[1][2];
438                                 normal[2] = rotation[2][2];
439                                 direction = MT_Vector3(0.0,0.0,-1.0);
440                                 break;
441                         }
442                         normal.normalize();
443                         {
444                                 PHY_IPhysicsEnvironment* pe = KX_GetActiveScene()->GetPhysicsEnvironment();
445                                 KX_IPhysicsController *spc = obj->GetPhysicsController();
446
447                                 if (!pe) {
448                                         std::cout << "WARNING: Constraint actuator " << GetName() << ":  There is no physics environment!" << std::endl;
449                                         goto CHECK_TIME;
450                                 }        
451                                 if (!spc || !spc->IsDyna()) {
452                                         // the object is not dynamic, it won't support setting speed
453                                         goto CHECK_TIME;
454                                 }
455                                 m_hitObject = NULL;
456                                 // distance of Fh area is stored in m_minimum
457                                 MT_Point3 topoint = position + (m_minimumBound+spc->GetRadius()) * direction;
458                                 KX_RayCast::Callback<KX_ConstraintActuator> callback(this,spc);
459                                 result = KX_RayCast::RayTest(pe, position, topoint, callback);
460                                 // we expect a hit object
461                                 if (!m_hitObject)
462                                         result = false;
463                                 if (result)     
464                                 {
465                                         MT_Vector3 newnormal = callback.m_hitNormal;
466                                         // compute new position & orientation
467                                         MT_Scalar distance = (callback.m_hitPoint-position).length()-spc->GetRadius(); 
468                                         // estimate the velocity of the hit point
469                                         MT_Point3 relativeHitPoint;
470                                         relativeHitPoint = (callback.m_hitPoint-m_hitObject->NodeGetWorldPosition());
471                                         MT_Vector3 velocityHitPoint = m_hitObject->GetVelocity(relativeHitPoint);
472                                         MT_Vector3 relativeVelocity = spc->GetLinearVelocity() - velocityHitPoint;
473                                         MT_Scalar relativeVelocityRay = direction.dot(relativeVelocity);
474                                         MT_Scalar springExtent = 1.0 - distance/m_minimumBound;
475                                         // Fh force is stored in m_maximum
476                                         MT_Scalar springForce = springExtent * m_maximumBound;
477                                         // damping is stored in m_refDirection [0] = damping, [1] = rot damping
478                                         MT_Scalar springDamp = relativeVelocityRay * m_refDirVector[0];
479                                         MT_Vector3 newVelocity = spc->GetLinearVelocity()-(springForce+springDamp)*direction;
480                                         if (m_option & KX_ACT_CONSTRAINT_NORMAL)
481                                         {
482                                                 newVelocity+=(springForce+springDamp)*(newnormal-newnormal.dot(direction)*direction);
483                                         }
484                                         spc->SetLinearVelocity(newVelocity, false);
485                                         if (m_option & KX_ACT_CONSTRAINT_DOROTFH)
486                                         {
487                                                 MT_Vector3 angSpring = (normal.cross(newnormal))*m_maximumBound;
488                                                 MT_Vector3 angVelocity = spc->GetAngularVelocity();
489                                                 // remove component that is parallel to normal
490                                                 angVelocity -= angVelocity.dot(newnormal)*newnormal;
491                                                 MT_Vector3 angDamp = angVelocity * ((m_refDirVector[1]>MT_EPSILON)?m_refDirVector[1]:m_refDirVector[0]);
492                                                 spc->SetAngularVelocity(spc->GetAngularVelocity()+(angSpring-angDamp), false);
493                                         }
494                                 } else if (m_option & KX_ACT_CONSTRAINT_PERMANENT) {
495                                         // no contact but still keep running
496                                         result = true;
497                                 }
498                                 // don't set the position with this constraint
499                                 goto CHECK_TIME;
500                         }
501                         break; 
502                 case KX_ACT_CONSTRAINT_LOCX:
503                 case KX_ACT_CONSTRAINT_LOCY:
504                 case KX_ACT_CONSTRAINT_LOCZ:
505                         newposition = position = obj->GetSGNode()->GetLocalPosition();
506                         switch (m_locrot) {
507                         case KX_ACT_CONSTRAINT_LOCX:
508                                 Clamp(newposition[0], m_minimumBound, m_maximumBound);
509                                 break;
510                         case KX_ACT_CONSTRAINT_LOCY:
511                                 Clamp(newposition[1], m_minimumBound, m_maximumBound);
512                                 break;
513                         case KX_ACT_CONSTRAINT_LOCZ:
514                                 Clamp(newposition[2], m_minimumBound, m_maximumBound);
515                                 break;
516                         }
517                         result = true;
518                         if (m_posDampTime) {
519                                 newposition = filter*position + (1.0-filter)*newposition;
520                         }
521                         obj->NodeSetLocalPosition(newposition);
522                         goto CHECK_TIME;
523                 }
524                 if (result) {
525                         // set the new position but take into account parent if any
526                         obj->NodeSetWorldPosition(newposition);
527                 }
528         CHECK_TIME:
529                 if (result && m_activeTime > 0 ) {
530                         if (++m_currentTime >= m_activeTime)
531                                 result = false;
532                 }
533         }
534         if (!result) {
535                 m_currentTime = 0;
536         }
537         return result;
538 } /* end of KX_ConstraintActuator::Update(double curtime,double deltatime)   */
539
540 void KX_ConstraintActuator::Clamp(MT_Scalar &var, 
541                                                                   float min, 
542                                                                   float max) {
543         if (var < min) {
544                 var = min;
545         } else if (var > max) {
546                 var = max;
547         }
548 }
549
550
551 bool KX_ConstraintActuator::IsValidMode(KX_ConstraintActuator::KX_CONSTRAINTTYPE m) 
552 {
553         bool res = false;
554
555         if ( (m > KX_ACT_CONSTRAINT_NODEF) && (m < KX_ACT_CONSTRAINT_MAX)) {
556                 res = true;
557         }
558
559         return res;
560 }
561
562 /* ------------------------------------------------------------------------- */
563 /* Python functions                                                          */
564 /* ------------------------------------------------------------------------- */
565
566 /* Integration hooks ------------------------------------------------------- */
567 PyTypeObject KX_ConstraintActuator::Type = {
568         PyVarObject_HEAD_INIT(NULL, 0)
569         "KX_ConstraintActuator",
570         sizeof(PyObjectPlus_Proxy),
571         0,
572         py_base_dealloc,
573         0,
574         0,
575         0,
576         0,
577         py_base_repr,
578         0,0,0,0,0,0,0,0,0,
579         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
580         0,0,0,0,0,0,0,
581         Methods,
582         0,
583         0,
584         &SCA_IActuator::Type,
585         0,0,0,0,0,0,
586         py_base_new
587 };
588
589 PyMethodDef KX_ConstraintActuator::Methods[] = {
590         {NULL,NULL} //Sentinel
591 };
592
593 PyAttributeDef KX_ConstraintActuator::Attributes[] = {
594         KX_PYATTRIBUTE_INT_RW("damp",0,100,true,KX_ConstraintActuator,m_posDampTime),
595         KX_PYATTRIBUTE_INT_RW("rotDamp",0,100,true,KX_ConstraintActuator,m_rotDampTime),
596         KX_PYATTRIBUTE_FLOAT_ARRAY_RW_CHECK("direction",-FLT_MAX,FLT_MAX,KX_ConstraintActuator,m_refDirection,3,pyattr_check_direction),
597         KX_PYATTRIBUTE_INT_RW("option",0,0xFFFF,false,KX_ConstraintActuator,m_option),
598         KX_PYATTRIBUTE_INT_RW("time",0,1000,true,KX_ConstraintActuator,m_activeTime),
599         KX_PYATTRIBUTE_STRING_RW("propName",0,32,true,KX_ConstraintActuator,m_property),
600         KX_PYATTRIBUTE_FLOAT_RW("min",-FLT_MAX,FLT_MAX,KX_ConstraintActuator,m_minimumBound),
601         KX_PYATTRIBUTE_FLOAT_RW("distance",-FLT_MAX,FLT_MAX,KX_ConstraintActuator,m_minimumBound),
602         KX_PYATTRIBUTE_FLOAT_RW("max",-FLT_MAX,FLT_MAX,KX_ConstraintActuator,m_maximumBound),
603         KX_PYATTRIBUTE_FLOAT_RW("rayLength",0,2000.f,KX_ConstraintActuator,m_maximumBound),
604         KX_PYATTRIBUTE_INT_RW("limit",KX_ConstraintActuator::KX_ACT_CONSTRAINT_NODEF+1,KX_ConstraintActuator::KX_ACT_CONSTRAINT_MAX-1,false,KX_ConstraintActuator,m_locrot),
605         { NULL }        //Sentinel
606 };
607
608 int KX_ConstraintActuator::pyattr_check_direction(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
609 {
610         KX_ConstraintActuator* act = static_cast<KX_ConstraintActuator*>(self);
611         MT_Vector3 dir(act->m_refDirection);
612         MT_Scalar len = dir.length();
613         if (MT_fuzzyZero(len)) {
614                 PyErr_SetString(PyExc_ValueError, "actuator.direction = vec: KX_ConstraintActuator, invalid direction");
615                 return 1;
616         }
617         act->m_refDirVector = dir/len;
618         return 0;       
619 }
620
621 /* eof */