soc-2008-mxcurioni: merged changes to revision 15441
[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_ConstraintActuator : public SCA_IActuator
41 {
42         Py_Header;
43 protected:      
44         // Damp time (int),
45         int m_posDampTime;
46         int m_rotDampTime;
47         // min (float) 
48         float m_minimumBound;
49         // max (float)
50         float m_maximumBound;
51         // reference direction
52         MT_Vector3 m_refDirection;
53         // locrotxyz choice (pick one): only one choice allowed at a time!
54         int m_locrot;
55         // active time of actuator
56         int m_activeTime;
57         int m_currentTime;
58         // option
59         int m_option;
60         // property to check
61         char m_property[32];
62
63         /**
64          * Clamp <var> to <min>, <max>. Borders are included (in as far as
65          * float comparisons are good for equality...).
66          */
67         void Clamp(MT_Scalar &var, float min, float max);
68
69         
70  public:
71          //  m_locrot
72         enum KX_CONSTRAINTTYPE {
73                 KX_ACT_CONSTRAINT_NODEF = 0,
74                 KX_ACT_CONSTRAINT_LOCX,
75                 KX_ACT_CONSTRAINT_LOCY,
76                 KX_ACT_CONSTRAINT_LOCZ,
77                 KX_ACT_CONSTRAINT_ROTX,
78                 KX_ACT_CONSTRAINT_ROTY,
79                 KX_ACT_CONSTRAINT_ROTZ,
80                 KX_ACT_CONSTRAINT_DIRPX,
81                 KX_ACT_CONSTRAINT_DIRPY,
82                 KX_ACT_CONSTRAINT_DIRPZ,
83                 KX_ACT_CONSTRAINT_DIRMX,
84                 KX_ACT_CONSTRAINT_DIRMY,
85                 KX_ACT_CONSTRAINT_DIRMZ,
86                 KX_ACT_CONSTRAINT_ORIX,
87                 KX_ACT_CONSTRAINT_ORIY,
88                 KX_ACT_CONSTRAINT_ORIZ,
89                 KX_ACT_CONSTRAINT_MAX
90         };
91         // match ACT_CONST_... values from BIF_interface.h
92         enum KX_CONSTRAINTOPT {
93                 KX_ACT_CONSTRAINT_NORMAL = 64,
94                 KX_ACT_CONSTRAINT_MATERIAL = 128,
95                 KX_ACT_CONSTRAINT_PERMANENT = 256,
96                 KX_ACT_CONSTRAINT_DISTANCE = 512
97         };
98         bool IsValidMode(KX_CONSTRAINTTYPE m); 
99         bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data);
100
101         KX_ConstraintActuator(SCA_IObject* gameobj,
102                                                   int posDamptime,
103                                                   int rotDampTime,
104                                                   float min,
105                                                   float max,
106                                                   float refDir[3],
107                                                   int locrot,
108                                                   int time,
109                                                   int option,
110                                                   char *property,
111                                                   PyTypeObject* T=&Type);
112         virtual ~KX_ConstraintActuator();
113         virtual CValue* GetReplica() {
114                 KX_ConstraintActuator* replica = new KX_ConstraintActuator(*this);
115                 replica->ProcessReplica();
116                 // this will copy properties and so on...
117                 CValue::AddDataToReplica(replica);
118                 return replica;
119         };
120
121         virtual bool Update(double curtime, bool frame);
122
123         /* --------------------------------------------------------------------- */
124         /* Python interface ---------------------------------------------------- */
125         /* --------------------------------------------------------------------- */
126
127         virtual PyObject* _getattr(const STR_String& attr);
128
129         KX_PYMETHOD_DOC(KX_ConstraintActuator,SetDamp);
130         KX_PYMETHOD_DOC(KX_ConstraintActuator,GetDamp);
131         KX_PYMETHOD_DOC(KX_ConstraintActuator,SetRotDamp);
132         KX_PYMETHOD_DOC(KX_ConstraintActuator,GetRotDamp);
133         KX_PYMETHOD_DOC(KX_ConstraintActuator,SetDirection);
134         KX_PYMETHOD_DOC(KX_ConstraintActuator,GetDirection);
135         KX_PYMETHOD_DOC(KX_ConstraintActuator,SetOption);
136         KX_PYMETHOD_DOC(KX_ConstraintActuator,GetOption);
137         KX_PYMETHOD_DOC(KX_ConstraintActuator,SetTime);
138         KX_PYMETHOD_DOC(KX_ConstraintActuator,GetTime);
139         KX_PYMETHOD_DOC(KX_ConstraintActuator,SetProperty);
140         KX_PYMETHOD_DOC(KX_ConstraintActuator,GetProperty);
141         KX_PYMETHOD_DOC(KX_ConstraintActuator,SetMin);
142         KX_PYMETHOD_DOC(KX_ConstraintActuator,GetMin);
143         static char SetDistance_doc[];
144         static char GetDistance_doc[];
145         KX_PYMETHOD_DOC(KX_ConstraintActuator,SetMax);
146         KX_PYMETHOD_DOC(KX_ConstraintActuator,GetMax);
147         static char SetRayLength_doc[];
148         static char GetRayLength_doc[];
149         KX_PYMETHOD_DOC(KX_ConstraintActuator,SetLimit);
150         KX_PYMETHOD_DOC(KX_ConstraintActuator,GetLimit);
151 };
152
153 #endif //__KX_CONSTRAINTACTUATOR
154