Merge of trunk into blender 2.5:
[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         MT_Vector3 m_refDirection;
60         // locrotxyz choice (pick one): only one choice allowed at a time!
61         int m_locrot;
62         // active time of actuator
63         int m_activeTime;
64         int m_currentTime;
65         // option
66         int m_option;
67         // property to check
68         char m_property[32];
69         // hit object
70         KX_GameObject* m_hitObject;
71
72         /**
73          * Clamp <var> to <min>, <max>. Borders are included (in as far as
74          * float comparisons are good for equality...).
75          */
76         void Clamp(MT_Scalar &var, float min, float max);
77
78         
79  public:
80          //  m_locrot
81         enum KX_CONSTRAINTTYPE {
82                 KX_ACT_CONSTRAINT_NODEF = 0,
83                 KX_ACT_CONSTRAINT_LOCX,
84                 KX_ACT_CONSTRAINT_LOCY,
85                 KX_ACT_CONSTRAINT_LOCZ,
86                 KX_ACT_CONSTRAINT_ROTX,
87                 KX_ACT_CONSTRAINT_ROTY,
88                 KX_ACT_CONSTRAINT_ROTZ,
89                 KX_ACT_CONSTRAINT_DIRPX,
90                 KX_ACT_CONSTRAINT_DIRPY,
91                 KX_ACT_CONSTRAINT_DIRPZ,
92                 KX_ACT_CONSTRAINT_DIRNX,
93                 KX_ACT_CONSTRAINT_DIRNY,
94                 KX_ACT_CONSTRAINT_DIRNZ,
95                 KX_ACT_CONSTRAINT_ORIX,
96                 KX_ACT_CONSTRAINT_ORIY,
97                 KX_ACT_CONSTRAINT_ORIZ,
98                 KX_ACT_CONSTRAINT_FHPX,
99                 KX_ACT_CONSTRAINT_FHPY,
100                 KX_ACT_CONSTRAINT_FHPZ,
101                 KX_ACT_CONSTRAINT_FHNX,
102                 KX_ACT_CONSTRAINT_FHNY,
103                 KX_ACT_CONSTRAINT_FHNZ,
104                 KX_ACT_CONSTRAINT_MAX
105         };
106         // match ACT_CONST_... values from BIF_interface.h
107         enum KX_CONSTRAINTOPT {
108                 KX_ACT_CONSTRAINT_NORMAL = 64,
109                 KX_ACT_CONSTRAINT_MATERIAL = 128,
110                 KX_ACT_CONSTRAINT_PERMANENT = 256,
111                 KX_ACT_CONSTRAINT_DISTANCE = 512,
112                 KX_ACT_CONSTRAINT_LOCAL = 1024,
113                 KX_ACT_CONSTRAINT_DOROTFH = 2048
114         };
115         bool IsValidMode(KX_CONSTRAINTTYPE m); 
116         bool RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void * const data);
117         bool NeedRayCast(KX_ClientObjectInfo*);
118
119         KX_ConstraintActuator(SCA_IObject* gameobj,
120                                                   int posDamptime,
121                                                   int rotDampTime,
122                                                   float min,
123                                                   float max,
124                                                   float refDir[3],
125                                                   int locrot,
126                                                   int time,
127                                                   int option,
128                                                   char *property,
129                                                   PyTypeObject* T=&Type);
130         virtual ~KX_ConstraintActuator();
131         virtual CValue* GetReplica() {
132                 KX_ConstraintActuator* replica = new KX_ConstraintActuator(*this);
133                 replica->ProcessReplica();
134                 // this will copy properties and so on...
135                 CValue::AddDataToReplica(replica);
136                 return replica;
137         };
138
139         virtual bool Update(double curtime, bool frame);
140
141         /* --------------------------------------------------------------------- */
142         /* Python interface ---------------------------------------------------- */
143         /* --------------------------------------------------------------------- */
144
145         virtual PyObject* _getattr(const STR_String& attr);
146
147         KX_PYMETHOD_DOC(KX_ConstraintActuator,SetDamp);
148         KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetDamp);
149         KX_PYMETHOD_DOC(KX_ConstraintActuator,SetRotDamp);
150         KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetRotDamp);
151         KX_PYMETHOD_DOC(KX_ConstraintActuator,SetDirection);
152         KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetDirection);
153         KX_PYMETHOD_DOC(KX_ConstraintActuator,SetOption);
154         KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetOption);
155         KX_PYMETHOD_DOC(KX_ConstraintActuator,SetTime);
156         KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetTime);
157         KX_PYMETHOD_DOC(KX_ConstraintActuator,SetProperty);
158         KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetProperty);
159         KX_PYMETHOD_DOC(KX_ConstraintActuator,SetMin);
160         KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetMin);
161         static const char SetDistance_doc[];
162         static const char GetDistance_doc[];
163         KX_PYMETHOD_DOC(KX_ConstraintActuator,SetMax);
164         KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetMax);
165         static const char SetRayLength_doc[];
166         static const char GetRayLength_doc[];
167         KX_PYMETHOD_DOC(KX_ConstraintActuator,SetLimit);
168         KX_PYMETHOD_DOC_NOARGS(KX_ConstraintActuator,GetLimit);
169 };
170
171 #endif //__KX_CONSTRAINTACTUATOR
172