2 * Do translation/rotation actions
6 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
22 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23 * All rights reserved.
25 * The Original Code is: all of this file.
27 * Contributor(s): none yet.
29 * ***** END GPL LICENSE BLOCK *****
32 #ifndef __KX_OBJECTACTUATOR
33 #define __KX_OBJECTACTUATOR
35 #include "SCA_IActuator.h"
36 #include "MT_Vector3.h"
39 void KX_ObjectActuator_Mathutils_Callback_Init(void);
45 // Stores the flags for each CValue derived class
47 struct KX_LocalFlags {
53 LinearVelocity(false),
54 AngularVelocity(false),
59 ZeroLinearVelocity(false),
60 ZeroAngularVelocity(false)
76 bool ZeroLinearVelocity;
77 bool ZeroAngularVelocity;
80 class KX_ObjectActuator : public SCA_IActuator
88 MT_Vector3 m_linear_velocity;
89 MT_Vector3 m_angular_velocity;
91 MT_Scalar m_linear_length2;
92 MT_Scalar m_angular_length2;
94 MT_Scalar m_current_linear_factor;
95 MT_Scalar m_current_angular_factor;
97 // used in servo control
98 MT_Vector3 m_previous_error;
99 MT_Vector3 m_error_accumulator;
100 KX_LocalFlags m_bitLocalFlag;
101 KX_GameObject* m_reference;
102 // A hack bool -- oh no sorry everyone
103 // This bool is used to check if we have informed
104 // the physics object that we are no longer
105 // setting linear velocity.
107 bool m_active_combined_velocity;
108 bool m_linear_damping_active;
109 bool m_angular_damping_active;
112 enum KX_OBJECT_ACT_VEC_TYPE {
113 KX_OBJECT_ACT_NODEF = 0,
115 KX_OBJECT_ACT_TORQUE,
118 KX_OBJECT_ACT_LINEAR_VELOCITY,
119 KX_OBJECT_ACT_ANGULAR_VELOCITY,
124 * Check whether this is a valid vector mode
126 bool isValid(KX_OBJECT_ACT_VEC_TYPE type);
129 SCA_IObject* gameobj,
130 KX_GameObject* refobj,
131 const MT_Vector3& force,
132 const MT_Vector3& torque,
133 const MT_Vector3& dloc,
134 const MT_Vector3& drot,
135 const MT_Vector3& linV,
136 const MT_Vector3& angV,
138 const KX_LocalFlags& flag,
139 PyTypeObject* T=&Type
141 ~KX_ObjectActuator();
142 CValue* GetReplica();
143 void ProcessReplica();
144 bool UnlinkObject(SCA_IObject* clientobj);
145 void Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map);
147 void SetForceLoc(const double force[3]) { /*m_force=force;*/ }
148 void UpdateFuzzyFlags()
150 m_bitLocalFlag.ZeroForce = MT_fuzzyZero(m_force);
151 m_bitLocalFlag.ZeroTorque = MT_fuzzyZero(m_torque);
152 m_bitLocalFlag.ZeroDLoc = MT_fuzzyZero(m_dloc);
153 m_bitLocalFlag.ZeroDRot = MT_fuzzyZero(m_drot);
154 m_bitLocalFlag.ZeroLinearVelocity = MT_fuzzyZero(m_linear_velocity);
155 m_linear_length2 = (m_bitLocalFlag.ZeroLinearVelocity) ? 0.0 : m_linear_velocity.length2();
156 m_bitLocalFlag.ZeroAngularVelocity = MT_fuzzyZero(m_angular_velocity);
157 m_angular_length2 = (m_bitLocalFlag.ZeroAngularVelocity) ? 0.0 : m_angular_velocity.length2();
159 virtual bool Update();
163 /* --------------------------------------------------------------------- */
164 /* Python interface ---------------------------------------------------- */
165 /* --------------------------------------------------------------------- */
167 virtual PyObject* py_getattro(PyObject *attr);
168 virtual PyObject* py_getattro_dict();
169 virtual int py_setattro(PyObject *attr, PyObject *value);
171 KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetForce);
172 KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetForce);
173 KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetTorque);
174 KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetTorque);
175 KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetDLoc);
176 KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetDLoc);
177 KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetDRot);
178 KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetDRot);
179 KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetLinearVelocity);
180 KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetLinearVelocity);
181 KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetAngularVelocity);
182 KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetAngularVelocity);
183 KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetDamping);
184 KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetDamping);
185 KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetForceLimitX);
186 KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetForceLimitX);
187 KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetForceLimitY);
188 KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetForceLimitY);
189 KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetForceLimitZ);
190 KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetForceLimitZ);
191 KX_PYMETHOD_NOARGS(KX_ObjectActuator,GetPID);
192 KX_PYMETHOD_VARARGS(KX_ObjectActuator,SetPID);
195 static PyObject* pyattr_get_forceLimitX(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
196 static int pyattr_set_forceLimitX(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
197 static PyObject* pyattr_get_forceLimitY(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
198 static int pyattr_set_forceLimitY(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
199 static PyObject* pyattr_get_forceLimitZ(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
200 static int pyattr_set_forceLimitZ(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
201 static PyObject* pyattr_get_reference(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
202 static int pyattr_set_reference(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
205 static PyObject* pyattr_get_linV(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
206 static int pyattr_set_linV(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
207 static PyObject* pyattr_get_angV(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
208 static int pyattr_set_angV(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
211 // This lets the attribute macros use UpdateFuzzyFlags()
212 static int PyUpdateFuzzyFlags(void *self, const PyAttributeDef *attrdef)
214 KX_ObjectActuator* act = reinterpret_cast<KX_ObjectActuator*>(self);
215 act->UpdateFuzzyFlags();
219 // This is the keep the PID values in check after they are assigned with Python
220 static int PyCheckPid(void *self, const PyAttributeDef *attrdef)
222 KX_ObjectActuator* act = reinterpret_cast<KX_ObjectActuator*>(self);
225 if (act->m_pid[0] < 0) {
227 } else if (act->m_pid[0] > 200) {
232 if (act->m_pid[1] < 0) {
234 } else if (act->m_pid[1] > 3) {
239 if (act->m_pid[2] < -100) {
240 act->m_pid[2] = -100;
241 } else if (act->m_pid[2] > 100) {
249 #endif //__KX_OBJECTACTUATOR