~ubuntu-branches/ubuntu/lucid/blender/lucid

« back to all changes in this revision

Viewing changes to source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2009-08-06 22:32:19 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090806223219-8z4eej1u8levu4pz
Tags: 2.49a+dfsg-0ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/control: Build-depend on python-2.6 rather than python-2.5.
  - debian/misc/*.desktop: Add Spanish translation to .desktop 
    files.
  - debian/pyversions: 2.6.
  - debian/rules: Clean *.o of source/blender/python/api2_2x/
* New upstream release (LP: #382153).
* Refreshed patches:
  - 01_sanitize_sys.patch
  - 02_tmp_in_HOME
  - 10_use_systemwide_ftgl
  - 70_portability_platform_detection
* Removed patches merged upstream:
  - 30_fix_python_syntax_warning
  - 90_ubuntu_ffmpeg_52_changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// Adjust dynamics settins for this object
3
 
//
4
 
// $Id: KX_SCA_DynamicActuator.cpp 15444 2008-07-05 17:05:05Z lukep $
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
 
// Previously existed as:
33
 
 
34
 
// \source\gameengine\GameLogic\SCA_DynamicActuator.cpp
35
 
 
36
 
// Please look here for revision history.
37
 
 
38
 
#include "KX_SCA_DynamicActuator.h"
39
 
 
40
 
#ifdef HAVE_CONFIG_H
41
 
#include <config.h>
42
 
#endif
43
 
 
44
 
/* ------------------------------------------------------------------------- */
45
 
/* Python functions                                                          */
46
 
/* ------------------------------------------------------------------------- */
47
 
 
48
 
/* Integration hooks ------------------------------------------------------- */
49
 
 
50
 
        PyTypeObject 
51
 
 
52
 
KX_SCA_DynamicActuator::
53
 
 
54
 
Type = {
55
 
        PyObject_HEAD_INIT(&PyType_Type)
56
 
        0,
57
 
        "KX_SCA_DynamicActuator",
58
 
        sizeof(KX_SCA_DynamicActuator),
59
 
        0,
60
 
        PyDestructor,
61
 
        0,
62
 
        __getattr,
63
 
        __setattr,
64
 
        0, 
65
 
        __repr,
66
 
        0, 
67
 
        0,
68
 
        0,
69
 
        0,
70
 
        0
71
 
};
72
 
 
73
 
PyParentObject KX_SCA_DynamicActuator::Parents[] = {
74
 
        &KX_SCA_DynamicActuator::Type,
75
 
        &SCA_IActuator::Type,
76
 
        &SCA_ILogicBrick::Type,
77
 
        &CValue::Type,
78
 
        NULL
79
 
};
80
 
 
81
 
 
82
 
PyMethodDef KX_SCA_DynamicActuator::Methods[] = {
83
 
        KX_PYMETHODTABLE(KX_SCA_DynamicActuator, setOperation),
84
 
        KX_PYMETHODTABLE(KX_SCA_DynamicActuator, getOperation),
85
 
        {NULL,NULL} //Sentinel
86
 
};
87
 
 
88
 
 
89
 
 
90
 
PyObject* KX_SCA_DynamicActuator::_getattr(const STR_String& attr)
91
 
{
92
 
  _getattr_up(SCA_IActuator);
93
 
}
94
 
 
95
 
 
96
 
 
97
 
/* 1. setOperation */
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")
106
 
{
107
 
        int dyn_operation;
108
 
        
109
 
        if (!PyArg_ParseTuple(args, "i", &dyn_operation))
110
 
        {
111
 
                return NULL;    
112
 
        }
113
 
        if (dyn_operation <0 || dyn_operation>3) {
114
 
                PyErr_SetString(PyExc_IndexError, "Dynamic Actuator's setOperation() range must be between 0 and 3");
115
 
                return NULL;
116
 
        }
117
 
        m_dyn_operation= dyn_operation;
118
 
        Py_Return;
119
 
}
120
 
 
121
 
KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, getOperation,
122
 
"getOperation() -> integer\n"
123
 
"Returns the operation type of this actuator.\n"
124
 
)
125
 
{
126
 
        return PyInt_FromLong((long)m_dyn_operation);
127
 
}
128
 
 
129
 
 
130
 
/* ------------------------------------------------------------------------- */
131
 
/* Native functions                                                          */
132
 
/* ------------------------------------------------------------------------- */
133
 
 
134
 
KX_SCA_DynamicActuator::KX_SCA_DynamicActuator(SCA_IObject *gameobj,
135
 
                                                                                                           short dyn_operation,
136
 
                                                                                                           PyTypeObject* T) : 
137
 
 
138
 
        SCA_IActuator(gameobj, T),
139
 
        m_dyn_operation(dyn_operation)
140
 
{
141
 
} /* End of constructor */
142
 
 
143
 
 
144
 
KX_SCA_DynamicActuator::~KX_SCA_DynamicActuator()
145
 
146
 
        // there's nothing to be done here, really....
147
 
} /* end of destructor */
148
 
 
149
 
 
150
 
 
151
 
bool KX_SCA_DynamicActuator::Update()
152
 
{
153
 
        // bool result = false; /*unused*/
154
 
        KX_GameObject *obj = (KX_GameObject*) GetParent();
155
 
        bool bNegativeEvent = IsNegativeEvent();
156
 
        KX_IPhysicsController* controller;
157
 
        RemoveAllEvents();
158
 
 
159
 
        if (bNegativeEvent)
160
 
                return false; // do nothing on negative events
161
 
        
162
 
        if (!obj)
163
 
                return false; // object not accessible, shouldnt happen
164
 
        controller = obj->GetPhysicsController();
165
 
        if (!controller)
166
 
                return false;   // no physic object
167
 
 
168
 
        switch (m_dyn_operation)
169
 
        {
170
 
                case 0:                 
171
 
                        obj->RestoreDynamics(); 
172
 
                        break;
173
 
                case 1:
174
 
                        obj->SuspendDynamics();
175
 
                        break;
176
 
                case 2:
177
 
                        controller->setRigidBody(true); 
178
 
                        break;
179
 
                case 3:
180
 
                        controller->setRigidBody(false);
181
 
                        break;
182
 
        }
183
 
 
184
 
        return false;
185
 
}
186
 
 
187
 
 
188
 
 
189
 
CValue* KX_SCA_DynamicActuator::GetReplica()
190
 
{
191
 
        KX_SCA_DynamicActuator* replica = 
192
 
                new KX_SCA_DynamicActuator(*this);
193
 
 
194
 
        if (replica == NULL)
195
 
                return NULL;
196
 
 
197
 
        replica->ProcessReplica();
198
 
 
199
 
        // this will copy properties and so on...
200
 
        CValue::AddDataToReplica(replica);
201
 
 
202
 
        return replica;
203
 
};
204
 
 
205
 
 
206
 
/* eof */
 
1
//
 
2
// Adjust dynamics settins for this object
 
3
//
 
4
// $Id: KX_SCA_DynamicActuator.cpp 20210 2009-05-15 03:26:53Z campbellbarton $
 
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
// Previously existed as:
 
33
 
 
34
// \source\gameengine\GameLogic\SCA_DynamicActuator.cpp
 
35
 
 
36
// Please look here for revision history.
 
37
 
 
38
#include "KX_SCA_DynamicActuator.h"
 
39
#include "blendef.h"
 
40
 
 
41
#ifdef HAVE_CONFIG_H
 
42
#include <config.h>
 
43
#endif
 
44
 
 
45
/* ------------------------------------------------------------------------- */
 
46
/* Python functions                                                          */
 
47
/* ------------------------------------------------------------------------- */
 
48
 
 
49
/* Integration hooks ------------------------------------------------------- */
 
50
 
 
51
        PyTypeObject 
 
52
 
 
53
KX_SCA_DynamicActuator::Type = {
 
54
#if (PY_VERSION_HEX >= 0x02060000)
 
55
        PyVarObject_HEAD_INIT(NULL, 0)
 
56
#else
 
57
        /* python 2.5 and below */
 
58
        PyObject_HEAD_INIT( NULL )  /* required py macro */
 
59
        0,                          /* ob_size */
 
60
#endif
 
61
        "KX_SCA_DynamicActuator",
 
62
        sizeof(PyObjectPlus_Proxy),
 
63
        0,
 
64
        py_base_dealloc,
 
65
        0,
 
66
        0,
 
67
        0,
 
68
        0,
 
69
        py_base_repr,
 
70
        0,0,0,0,0,0,
 
71
        py_base_getattro,
 
72
        py_base_setattro,
 
73
        0,0,0,0,0,0,0,0,0,
 
74
        Methods
 
75
};
 
76
 
 
77
PyParentObject KX_SCA_DynamicActuator::Parents[] = {
 
78
        &KX_SCA_DynamicActuator::Type,
 
79
        &SCA_IActuator::Type,
 
80
        &SCA_ILogicBrick::Type,
 
81
        &CValue::Type,
 
82
        NULL
 
83
};
 
84
 
 
85
 
 
86
PyMethodDef KX_SCA_DynamicActuator::Methods[] = {
 
87
        // ---> deprecated
 
88
        KX_PYMETHODTABLE(KX_SCA_DynamicActuator, setOperation),
 
89
        KX_PYMETHODTABLE(KX_SCA_DynamicActuator, getOperation),
 
90
        {NULL,NULL} //Sentinel
 
91
};
 
92
 
 
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),
 
96
        { NULL }        //Sentinel
 
97
};
 
98
 
 
99
 
 
100
PyObject* KX_SCA_DynamicActuator::py_getattro(PyObject *attr)
 
101
{
 
102
        py_getattro_up(SCA_IActuator);
 
103
}
 
104
 
 
105
PyObject* KX_SCA_DynamicActuator::py_getattro_dict() {
 
106
        py_getattro_dict_up(SCA_IActuator);
 
107
}
 
108
 
 
109
int KX_SCA_DynamicActuator::py_setattro(PyObject *attr, PyObject* value)
 
110
{
 
111
        py_setattro_up(SCA_IActuator);
 
112
}
 
113
 
 
114
 
 
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")
 
124
{
 
125
        ShowDeprecationWarning("setOperation()", "the mode property");
 
126
        int dyn_operation;
 
127
        
 
128
        if (!PyArg_ParseTuple(args, "i:setOperation", &dyn_operation))
 
129
        {
 
130
                return NULL;    
 
131
        }
 
132
        if (dyn_operation <0 || dyn_operation>3) {
 
133
                PyErr_SetString(PyExc_IndexError, "Dynamic Actuator's setOperation() range must be between 0 and 3");
 
134
                return NULL;
 
135
        }
 
136
        m_dyn_operation= dyn_operation;
 
137
        Py_RETURN_NONE;
 
138
}
 
139
 
 
140
KX_PYMETHODDEF_DOC(KX_SCA_DynamicActuator, getOperation,
 
141
"getOperation() -> integer\n"
 
142
"Returns the operation type of this actuator.\n"
 
143
)
 
144
{
 
145
        ShowDeprecationWarning("getOperation()", "the mode property");
 
146
        return PyInt_FromLong((long)m_dyn_operation);
 
147
}
 
148
 
 
149
 
 
150
/* ------------------------------------------------------------------------- */
 
151
/* Native functions                                                          */
 
152
/* ------------------------------------------------------------------------- */
 
153
 
 
154
KX_SCA_DynamicActuator::KX_SCA_DynamicActuator(SCA_IObject *gameobj,
 
155
                                                                                                           short dyn_operation,
 
156
                                                                                                           float setmass,
 
157
                                                                                                           PyTypeObject* T) : 
 
158
 
 
159
        SCA_IActuator(gameobj, T),
 
160
        m_dyn_operation(dyn_operation),
 
161
        m_setmass(setmass)
 
162
{
 
163
} /* End of constructor */
 
164
 
 
165
 
 
166
KX_SCA_DynamicActuator::~KX_SCA_DynamicActuator()
 
167
 
168
        // there's nothing to be done here, really....
 
169
} /* end of destructor */
 
170
 
 
171
 
 
172
 
 
173
bool KX_SCA_DynamicActuator::Update()
 
174
{
 
175
        // bool result = false; /*unused*/
 
176
        KX_GameObject *obj = (KX_GameObject*) GetParent();
 
177
        bool bNegativeEvent = IsNegativeEvent();
 
178
        KX_IPhysicsController* controller;
 
179
        RemoveAllEvents();
 
180
 
 
181
        if (bNegativeEvent)
 
182
                return false; // do nothing on negative events
 
183
        
 
184
        if (!obj)
 
185
                return false; // object not accessible, shouldnt happen
 
186
        controller = obj->GetPhysicsController();
 
187
        if (!controller)
 
188
                return false;   // no physic object
 
189
 
 
190
        switch (m_dyn_operation)
 
191
        {
 
192
                case 0:                 
 
193
                        obj->RestoreDynamics(); 
 
194
                        break;
 
195
                case 1:
 
196
                        obj->SuspendDynamics();
 
197
                        break;
 
198
                case 2:
 
199
                        controller->setRigidBody(true); 
 
200
                        break;
 
201
                case 3:
 
202
                        controller->setRigidBody(false);
 
203
                        break;
 
204
                case 4:
 
205
                        controller->SetMass(m_setmass);
 
206
                        break;
 
207
        }
 
208
 
 
209
        return false;
 
210
}
 
211
 
 
212
 
 
213
 
 
214
CValue* KX_SCA_DynamicActuator::GetReplica()
 
215
{
 
216
        KX_SCA_DynamicActuator* replica = 
 
217
                new KX_SCA_DynamicActuator(*this);
 
218
 
 
219
        if (replica == NULL)
 
220
                return NULL;
 
221
 
 
222
        replica->ProcessReplica();
 
223
        return replica;
 
224
};
 
225
 
 
226
 
 
227
/* eof */