2
// Adjust dynamics settins for this object
4
// $Id: KX_SCA_DynamicActuator.cpp 15444 2008-07-05 17:05:05Z lukep $
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
// Previously existed as:
34
// \source\gameengine\GameLogic\SCA_DynamicActuator.cpp
36
// Please look here for revision history.
38
#include "KX_SCA_DynamicActuator.h"
44
/* ------------------------------------------------------------------------- */
45
/* Python functions */
46
/* ------------------------------------------------------------------------- */
48
/* Integration hooks ------------------------------------------------------- */
52
KX_SCA_DynamicActuator::
55
PyObject_HEAD_INIT(&PyType_Type)
57
"KX_SCA_DynamicActuator",
58
sizeof(KX_SCA_DynamicActuator),
73
PyParentObject KX_SCA_DynamicActuator::Parents[] = {
74
&KX_SCA_DynamicActuator::Type,
76
&SCA_ILogicBrick::Type,
82
PyMethodDef KX_SCA_DynamicActuator::Methods[] = {
83
KX_PYMETHODTABLE(KX_SCA_DynamicActuator, setOperation),
84
KX_PYMETHODTABLE(KX_SCA_DynamicActuator, getOperation),
85
{NULL,NULL} //Sentinel
90
PyObject* KX_SCA_DynamicActuator::_getattr(const STR_String& attr)
92
_getattr_up(SCA_IActuator);
98
KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, setOperation,
99
"setOperation(operation?)\n"
100
"\t - operation? : type of dynamic operation\n"
101
"\t 0 = restore dynamics\n"
102
"\t 1 = disable dynamics\n"
103
"\t 2 = enable rigid body\n"
104
"\t 3 = disable rigid body\n"
105
"Change the dynamic status of the parent object.\n")
109
if (!PyArg_ParseTuple(args, "i", &dyn_operation))
113
if (dyn_operation <0 || dyn_operation>3) {
114
PyErr_SetString(PyExc_IndexError, "Dynamic Actuator's setOperation() range must be between 0 and 3");
117
m_dyn_operation= dyn_operation;
121
KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, getOperation,
122
"getOperation() -> integer\n"
123
"Returns the operation type of this actuator.\n"
126
return PyInt_FromLong((long)m_dyn_operation);
130
/* ------------------------------------------------------------------------- */
131
/* Native functions */
132
/* ------------------------------------------------------------------------- */
134
KX_SCA_DynamicActuator::KX_SCA_DynamicActuator(SCA_IObject *gameobj,
138
SCA_IActuator(gameobj, T),
139
m_dyn_operation(dyn_operation)
141
} /* End of constructor */
144
KX_SCA_DynamicActuator::~KX_SCA_DynamicActuator()
146
// there's nothing to be done here, really....
147
} /* end of destructor */
151
bool KX_SCA_DynamicActuator::Update()
153
// bool result = false; /*unused*/
154
KX_GameObject *obj = (KX_GameObject*) GetParent();
155
bool bNegativeEvent = IsNegativeEvent();
156
KX_IPhysicsController* controller;
160
return false; // do nothing on negative events
163
return false; // object not accessible, shouldnt happen
164
controller = obj->GetPhysicsController();
166
return false; // no physic object
168
switch (m_dyn_operation)
171
obj->RestoreDynamics();
174
obj->SuspendDynamics();
177
controller->setRigidBody(true);
180
controller->setRigidBody(false);
189
CValue* KX_SCA_DynamicActuator::GetReplica()
191
KX_SCA_DynamicActuator* replica =
192
new KX_SCA_DynamicActuator(*this);
197
replica->ProcessReplica();
199
// this will copy properties and so on...
200
CValue::AddDataToReplica(replica);
2
// Adjust dynamics settins for this object
4
// $Id: KX_SCA_DynamicActuator.cpp 20210 2009-05-15 03:26:53Z campbellbarton $
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
// Previously existed as:
34
// \source\gameengine\GameLogic\SCA_DynamicActuator.cpp
36
// Please look here for revision history.
38
#include "KX_SCA_DynamicActuator.h"
45
/* ------------------------------------------------------------------------- */
46
/* Python functions */
47
/* ------------------------------------------------------------------------- */
49
/* Integration hooks ------------------------------------------------------- */
53
KX_SCA_DynamicActuator::Type = {
54
#if (PY_VERSION_HEX >= 0x02060000)
55
PyVarObject_HEAD_INIT(NULL, 0)
57
/* python 2.5 and below */
58
PyObject_HEAD_INIT( NULL ) /* required py macro */
61
"KX_SCA_DynamicActuator",
62
sizeof(PyObjectPlus_Proxy),
77
PyParentObject KX_SCA_DynamicActuator::Parents[] = {
78
&KX_SCA_DynamicActuator::Type,
80
&SCA_ILogicBrick::Type,
86
PyMethodDef KX_SCA_DynamicActuator::Methods[] = {
88
KX_PYMETHODTABLE(KX_SCA_DynamicActuator, setOperation),
89
KX_PYMETHODTABLE(KX_SCA_DynamicActuator, getOperation),
90
{NULL,NULL} //Sentinel
93
PyAttributeDef KX_SCA_DynamicActuator::Attributes[] = {
94
KX_PYATTRIBUTE_SHORT_RW("mode",0,4,false,KX_SCA_DynamicActuator,m_dyn_operation),
95
KX_PYATTRIBUTE_FLOAT_RW("mass",0.0,MAXFLOAT,KX_SCA_DynamicActuator,m_setmass),
100
PyObject* KX_SCA_DynamicActuator::py_getattro(PyObject *attr)
102
py_getattro_up(SCA_IActuator);
105
PyObject* KX_SCA_DynamicActuator::py_getattro_dict() {
106
py_getattro_dict_up(SCA_IActuator);
109
int KX_SCA_DynamicActuator::py_setattro(PyObject *attr, PyObject* value)
111
py_setattro_up(SCA_IActuator);
115
/* 1. setOperation */
116
KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, setOperation,
117
"setOperation(operation?)\n"
118
"\t - operation? : type of dynamic operation\n"
119
"\t 0 = restore dynamics\n"
120
"\t 1 = disable dynamics\n"
121
"\t 2 = enable rigid body\n"
122
"\t 3 = disable rigid body\n"
123
"Change the dynamic status of the parent object.\n")
125
ShowDeprecationWarning("setOperation()", "the mode property");
128
if (!PyArg_ParseTuple(args, "i:setOperation", &dyn_operation))
132
if (dyn_operation <0 || dyn_operation>3) {
133
PyErr_SetString(PyExc_IndexError, "Dynamic Actuator's setOperation() range must be between 0 and 3");
136
m_dyn_operation= dyn_operation;
140
KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, getOperation,
141
"getOperation() -> integer\n"
142
"Returns the operation type of this actuator.\n"
145
ShowDeprecationWarning("getOperation()", "the mode property");
146
return PyInt_FromLong((long)m_dyn_operation);
150
/* ------------------------------------------------------------------------- */
151
/* Native functions */
152
/* ------------------------------------------------------------------------- */
154
KX_SCA_DynamicActuator::KX_SCA_DynamicActuator(SCA_IObject *gameobj,
159
SCA_IActuator(gameobj, T),
160
m_dyn_operation(dyn_operation),
163
} /* End of constructor */
166
KX_SCA_DynamicActuator::~KX_SCA_DynamicActuator()
168
// there's nothing to be done here, really....
169
} /* end of destructor */
173
bool KX_SCA_DynamicActuator::Update()
175
// bool result = false; /*unused*/
176
KX_GameObject *obj = (KX_GameObject*) GetParent();
177
bool bNegativeEvent = IsNegativeEvent();
178
KX_IPhysicsController* controller;
182
return false; // do nothing on negative events
185
return false; // object not accessible, shouldnt happen
186
controller = obj->GetPhysicsController();
188
return false; // no physic object
190
switch (m_dyn_operation)
193
obj->RestoreDynamics();
196
obj->SuspendDynamics();
199
controller->setRigidBody(true);
202
controller->setRigidBody(false);
205
controller->SetMass(m_setmass);
214
CValue* KX_SCA_DynamicActuator::GetReplica()
216
KX_SCA_DynamicActuator* replica =
217
new KX_SCA_DynamicActuator(*this);
222
replica->ProcessReplica();