svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r22205:22290
[blender.git] / source / gameengine / Ketsji / KX_ConstraintActuator.h
1 /**
2  * KX_ConstraintActuator.h
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 #ifndef __KX_CONSTRAINTACTUATOR
33 #define __KX_CONSTRAINTACTUATOR
34
35 #include "SCA_IActuator.h"
36 #include "MT_Scalar.h"
37 #include "MT_Vector3.h"
38 #include "KX_ClientObjectInfo.h"
39
40 class KX_RayCast;
41 class KX_GameObject;
42
43 class KX_ConstraintActuator : public SCA_IActuator
44 {
45         Py_Header;
46 protected:      
47         // Damp time (int),
48         int m_posDampTime;
49         int m_rotDampTime;
50         // min (float) 
51         float m_minimumBound;
52         // max (float)
53         float m_maximumBound;
54         // sinus of minimum angle
55         float m_minimumSine;
56         // sinus of maximum angle
57         float m_maximumSine;
58         // reference direction
59         float m_refDirection[3];
60         MT_Vector3 m_refDirVector;      // same as m_refDirection
61         // locrotxyz choice (pick one): only one choice allowed at a time!
62         int m_locrot;
63         // active time of actuator
64         int m_activeTime;
65         int m_currentTime;
66         // option
67         int m_option;
68         // property to check
69         STR_String m_property;
70         // hit object
71         KX_GameObject* m_hitObject;
72
73         /**
74          * Clamp <var> to <min>, <max>. Borders are included (in as far as
75          * float comparisons are good for equality...).
76          */
77         void Clamp(MT_Scalar &var, float min, float max);
78
79         
80  public:
81          //  m_locrot
82         enum KX_CONSTRAINTTYPE {
83                 KX_ACT_CONSTRAINT_NODEF = 0,
84                 KX_ACT_CONSTRAINT_LOCX,
85                 KX_ACT_CONSTRAINT_LOCY,
86                 KX_ACT_CONSTRAINT_LOCZ,
87                 KX_ACT_CONSTRAINT_ROTX,
88                 KX_ACT_CONSTRAINT_ROTY,
89                 KX_ACT_CONSTRAINT_ROTZ,
90                 KX_ACT_CONSTRAINT_DIRPX,
91                 KX_ACT_CONSTRAINT_DIRPY,
92                 KX_ACT_CONSTRAINT_DIRPZ,
93                 KX_ACT_CONSTRAINT_DIRNX,
94                 KX_ACT_CONSTRAINT_DIRNY,
95                 KX_ACT_CONSTRAINT_DIRNZ,
96                 KX_ACT_CONSTRAINT_ORIX,
97                 KX_ACT_CONSTRAINT_ORIY,
98                 KX_ACT_CONSTRAINT_ORIZ,
99                 KX_ACT_CONSTRAINT_FHPX,
100                 KX_ACT_CONSTRAINT_FHPY,
101                 KX_ACT_CONSTRAINT_FHPZ,
102                 KX_ACT_CONSTRAINT_FHNX,
103                 KX_ACT_CONSTRAINT_FHNY,
104                 KX_ACT_CONSTRAINT_FHNZ,
105                 KX_ACT_CONSTRAINT_MAX
106         };
107         // match ACT_CONST_... values from BIF_interface.h
108         enum KX_CONSTRAINTOPT {
109                 KX_ACT_CONSTRAINT_NORMAL = 64,
110                 KX_ACT_CONSTRAINT_MATERIAL = 128,
111                 KX_ACT_CONSTRAINT_PERMANENT = 256,
112                 KX_ACT_CONSTRAINT_DISTANCE = 512,
113                 KX_ACT_CONSTRAINT_LOCAL = 1024,
114                 KX_ACT_CONSTRAINT_DOROTFH = 2048
115         };
116         bool IsValidMode(KX_CONSTRAINTTYPE m); 
117         bool RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void * const data);
118         bool NeedRayCast(KX_ClientObjectInfo*);
119
120         KX_ConstraintActuator(SCA_IObject* gameobj,
121                                                   int posDamptime,
122                                                   int rotDampTime,
123                                                   float min,
124                                                   float max,
125                                                   float refDir[3],
126                                                   int locrot,
127                                                   int time,
128                                                   int option,
129                                                   char *property);
130         virtual ~KX_ConstraintActuator();
131         virtual CValue* GetReplica() {
132                 KX_ConstraintActuator* replica = new KX_ConstraintActuator(*this);
133                 replica->ProcessReplica();
134                 return replica;
135         };
136
137         virtual bool Update(double curtime, bool frame);
138
139         /* --------------------------------------------------------------------- */
140         /* Python interface ---------------------------------------------------- */
141         /* --------------------------------------------------------------------- */
142
143         static int pyattr_check_direction(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
144         static int pyattr_check_min(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
145
146         KX_PYMETHOD_DOC_VARARGS(KX_ConstraintActuator,SetDamp);
147         KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetDamp);
148         KX_PYMETHOD_DOC_VARARGS(KX_ConstraintActuator,SetRotDamp);
149         KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetRotDamp);
150         KX_PYMETHOD_DOC_VARARGS(KX_ConstraintActuator,SetDirection);
151         KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetDirection);
152         KX_PYMETHOD_DOC_VARARGS(KX_ConstraintActuator,SetOption);
153         KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetOption);
154         KX_PYMETHOD_DOC_VARARGS(KX_ConstraintActuator,SetTime);
155         KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetTime);
156         KX_PYMETHOD_DOC_VARARGS(KX_ConstraintActuator,SetProperty);
157         KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetProperty);
158         KX_PYMETHOD_DOC_VARARGS(KX_ConstraintActuator,SetMin);
159         KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetMin);
160         static const char SetDistance_doc[];
161         static const char GetDistance_doc[];
162         KX_PYMETHOD_DOC_VARARGS(KX_ConstraintActuator,SetMax);
163         KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetMax);
164         static const char SetRayLength_doc[];
165         static const char GetRayLength_doc[];
166         KX_PYMETHOD_DOC_VARARGS(KX_ConstraintActuator,SetLimit);
167         KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetLimit);
168 };
169
170 #endif //__KX_CONSTRAINTACTUATOR
171