00001
00006
00007 #include "SCA_IActuator.h"
00008 #include "KX_ConstraintActuator.h"
00009 #include "SCA_IObject.h"
00010 #include "MT_Point3.h"
00011 #include "MT_Matrix3x3.h"
00012 #include "KX_GameObject.h"
00013
00014
00015
00016
00017 KX_ConstraintActuator::KX_ConstraintActuator(SCA_IObject *gameobj,
00018 int dampTime,
00019 float minBound,
00020 float maxBound,
00021 int locrotxyz,
00022 PyTypeObject* T)
00023 : SCA_IActuator(gameobj, T)
00024 {
00025 m_dampTime = dampTime;
00026 m_locrot = locrotxyz;
00027
00028
00029
00030
00031 switch (m_locrot) {
00032 case KX_ACT_CONSTRAINT_LOCX:
00033 case KX_ACT_CONSTRAINT_LOCY:
00034 case KX_ACT_CONSTRAINT_LOCZ:
00035 m_minimumBound = minBound;
00036 m_maximumBound = maxBound;
00037 break;
00038 case KX_ACT_CONSTRAINT_ROTX:
00039 case KX_ACT_CONSTRAINT_ROTY:
00040 case KX_ACT_CONSTRAINT_ROTZ:
00041
00042 m_minimumBound = MT_radians(minBound);
00043 m_maximumBound = MT_radians(maxBound);
00044 break;
00045 default:
00046 ;
00047 }
00048
00049 }
00050
00051 KX_ConstraintActuator::~KX_ConstraintActuator()
00052 {
00053
00054 }
00055
00056 bool KX_ConstraintActuator::Update(double curtime,double deltatime)
00057 {
00058 return false;
00059
00060 bool result = false;
00061 bool bNegativeEvent = IsNegativeEvent();
00062
00063 if (bNegativeEvent)
00064 return false;
00065
00066
00067
00068
00069
00070
00071 KX_GameObject *parent = (KX_GameObject*) GetParent();
00072 MT_Point3 position = parent->NodeGetWorldPosition();
00073 MT_Matrix3x3 rotation = parent->NodeGetWorldOrientation();
00074
00075 MT_Scalar *var;
00076 MT_Scalar angle;
00077
00078 switch (m_locrot) {
00079 case KX_ACT_CONSTRAINT_LOCX:
00080 var = &(position[0]);
00081 break;
00082 case KX_ACT_CONSTRAINT_LOCY:
00083 var = &(position[1]);
00084 break;
00085 case KX_ACT_CONSTRAINT_LOCZ:
00086 var = &(position[2]);
00087 break;
00088 case KX_ACT_CONSTRAINT_ROTX:
00089
00090
00091 var = ∠
00092 break;
00093 case KX_ACT_CONSTRAINT_ROTY:
00094 var = ∠
00095 break;
00096 case KX_ACT_CONSTRAINT_ROTZ:
00097 var = ∠
00098 break;
00099 default:
00100 ;
00101 }
00102
00103
00104 if (var) Clamp(*var, m_minimumBound, m_maximumBound);
00105
00106 switch (m_locrot) {
00107 case KX_ACT_CONSTRAINT_LOCX:
00108 case KX_ACT_CONSTRAINT_LOCY:
00109 case KX_ACT_CONSTRAINT_LOCZ:
00110 parent->NodeSetLocalPosition(position);
00111 break;
00112 case KX_ACT_CONSTRAINT_ROTX:
00113 parent->NodeSetLocalOrientation(rotation);
00114 break;
00115 case KX_ACT_CONSTRAINT_ROTY:
00116 parent->NodeSetLocalOrientation(rotation);
00117 break;
00118 case KX_ACT_CONSTRAINT_ROTZ:
00119 parent->NodeSetLocalOrientation(rotation);
00120 break;
00121 default:
00122 ;
00123 }
00124
00125 return false;
00126 }
00127
00128 void KX_ConstraintActuator::Clamp(MT_Scalar &var,
00129 float min,
00130 float max) {
00131 if (var < min) {
00132 var = min;
00133 } else if (var > max) {
00134 var = max;
00135 }
00136 }
00137
00138
00139 bool KX_ConstraintActuator::IsValidMode(KX_ConstraintActuator::KX_CONSTRAINTTYPE m)
00140 {
00141 bool res = false;
00142
00143 if ( (m > KX_ACT_CONSTRAINT_NODEF) && (m < KX_ACT_CONSTRAINT_MAX)) {
00144 res = true;
00145 }
00146
00147 return res;
00148 }
00149
00150
00151
00152
00153
00154
00155 PyTypeObject KX_ConstraintActuator::Type = {
00156 PyObject_HEAD_INIT(&PyType_Type)
00157 0,
00158 "KX_ConstraintActuator",
00159 sizeof(KX_ConstraintActuator),
00160 0,
00161 PyDestructor,
00162 0,
00163 __getattr,
00164 __setattr,
00165 0,
00166 __repr,
00167 0,
00168 0,
00169 0,
00170 0,
00171 0
00172 };
00173
00174 PyParentObject KX_ConstraintActuator::Parents[] = {
00175 &KX_ConstraintActuator::Type,
00176 &SCA_IActuator::Type,
00177 &SCA_ILogicBrick::Type,
00178 &CValue::Type,
00179 NULL
00180 };
00181
00182 PyMethodDef KX_ConstraintActuator::Methods[] = {
00183 {"setDamp", (PyCFunction) KX_ConstraintActuator::sPySetDamp, METH_VARARGS, SetDamp_doc},
00184 {"getDamp", (PyCFunction) KX_ConstraintActuator::sPyGetDamp, METH_VARARGS, GetDamp_doc},
00185 {"setMin", (PyCFunction) KX_ConstraintActuator::sPySetMin, METH_VARARGS, SetMin_doc},
00186 {"getMin", (PyCFunction) KX_ConstraintActuator::sPyGetMin, METH_VARARGS, GetMin_doc},
00187 {"setMax", (PyCFunction) KX_ConstraintActuator::sPySetMax, METH_VARARGS, SetMax_doc},
00188 {"getMax", (PyCFunction) KX_ConstraintActuator::sPyGetMax, METH_VARARGS, GetMax_doc},
00189 {"setLimit", (PyCFunction) KX_ConstraintActuator::sPySetLimit, METH_VARARGS, SetLimit_doc},
00190 {"getLimit", (PyCFunction) KX_ConstraintActuator::sPyGetLimit, METH_VARARGS, GetLimit_doc},
00191 {NULL,NULL}
00192 };
00193
00194 PyObject* KX_ConstraintActuator::_getattr(char* attr) {
00195 _getattr_up(SCA_IActuator);
00196 }
00197
00198
00199 char KX_ConstraintActuator::SetDamp_doc[] =
00200 "setDamp(duration)\n"
00201 "\t- duration: integer\n"
00202 "\tSets the time with which the constraint application is delayed.\n"
00203 "\tIf the duration is negative, it is set to 0.\n";
00204 PyObject* KX_ConstraintActuator::PySetDamp(PyObject* self,
00205 PyObject* args,
00206 PyObject* kwds) {
00207 int dampArg;
00208 if(!PyArg_ParseTuple(args, "i", &dampArg)) {
00209 return NULL;
00210 }
00211
00212 m_dampTime = dampArg;
00213 if (m_dampTime < 0) m_dampTime = 0;
00214
00215 Py_Return;
00216 }
00217
00218 char KX_ConstraintActuator::GetDamp_doc[] =
00219 "GetDamp()\n"
00220 "\tReturns the damping time for application of the constraint.\n";
00221 PyObject* KX_ConstraintActuator::PyGetDamp(PyObject* self,
00222 PyObject* args,
00223 PyObject* kwds){
00224 return PyInt_FromLong(m_dampTime);
00225 }
00226
00227
00228 char KX_ConstraintActuator::SetMin_doc[] =
00229 "setMin(lower_bound)\n"
00230 "\t- lower_bound: float\n"
00231 "\tSets the lower value of the interval to which the value\n"
00232 "\tis clipped.\n";
00233 PyObject* KX_ConstraintActuator::PySetMin(PyObject* self,
00234 PyObject* args,
00235 PyObject* kwds) {
00236 float minArg;
00237 if(!PyArg_ParseTuple(args, "f", &minArg)) {
00238 return NULL;
00239 }
00240
00241 switch (m_locrot) {
00242 case KX_ACT_CONSTRAINT_LOCX:
00243 case KX_ACT_CONSTRAINT_LOCY:
00244 case KX_ACT_CONSTRAINT_LOCZ:
00245 m_minimumBound = minArg;
00246 break;
00247 case KX_ACT_CONSTRAINT_ROTX:
00248 case KX_ACT_CONSTRAINT_ROTY:
00249 case KX_ACT_CONSTRAINT_ROTZ:
00250 m_minimumBound = MT_radians(minArg);
00251 break;
00252 default:
00253 ;
00254 }
00255
00256 Py_Return;
00257 }
00258
00259 char KX_ConstraintActuator::GetMin_doc[] =
00260 "getMin()\n"
00261 "\tReturns the lower value of the interval to which the value\n"
00262 "\tis clipped.\n";
00263 PyObject* KX_ConstraintActuator::PyGetMin(PyObject* self,
00264 PyObject* args,
00265 PyObject* kwds) {
00266 return PyFloat_FromDouble(m_minimumBound);
00267 }
00268
00269
00270 char KX_ConstraintActuator::SetMax_doc[] =
00271 "setMax(upper_bound)\n"
00272 "\t- upper_bound: float\n"
00273 "\tSets the upper value of the interval to which the value\n"
00274 "\tis clipped.\n";
00275 PyObject* KX_ConstraintActuator::PySetMax(PyObject* self,
00276 PyObject* args,
00277 PyObject* kwds){
00278 float maxArg;
00279 if(!PyArg_ParseTuple(args, "f", &maxArg)) {
00280 return NULL;
00281 }
00282
00283 switch (m_locrot) {
00284 case KX_ACT_CONSTRAINT_LOCX:
00285 case KX_ACT_CONSTRAINT_LOCY:
00286 case KX_ACT_CONSTRAINT_LOCZ:
00287 m_maximumBound = maxArg;
00288 break;
00289 case KX_ACT_CONSTRAINT_ROTX:
00290 case KX_ACT_CONSTRAINT_ROTY:
00291 case KX_ACT_CONSTRAINT_ROTZ:
00292 m_maximumBound = MT_radians(maxArg);
00293 break;
00294 default:
00295 ;
00296 }
00297
00298 Py_Return;
00299 }
00300
00301 char KX_ConstraintActuator::GetMax_doc[] =
00302 "getMax()\n"
00303 "\tReturns the upper value of the interval to which the value\n"
00304 "\tis clipped.\n";
00305 PyObject* KX_ConstraintActuator::PyGetMax(PyObject* self,
00306 PyObject* args,
00307 PyObject* kwds) {
00308 return PyFloat_FromDouble(m_maximumBound);
00309 }
00310
00311
00312
00313
00314 char KX_ConstraintActuator::SetLimit_doc[] =
00315 "setLimit(type)\n"
00316 "\t- type: KX_CONSTRAINTACT_LOCX, KX_CONSTRAINTACT_LOCY,\n"
00317 "\t KX_CONSTRAINTACT_LOCZ, KX_CONSTRAINTACT_ROTX,\n"
00318 "\t KX_CONSTRAINTACT_ROTY, or KX_CONSTRAINTACT_ROTZ.\n"
00319 "\tSets the type of constraint.\n";
00320 PyObject* KX_ConstraintActuator::PySetLimit(PyObject* self,
00321 PyObject* args,
00322 PyObject* kwds) {
00323 int locrotArg;
00324 if(!PyArg_ParseTuple(args, "i", &locrotArg)) {
00325 return NULL;
00326 }
00327
00328 if (IsValidMode((KX_CONSTRAINTTYPE)locrotArg)) m_locrot = locrotArg;
00329
00330 Py_Return;
00331 }
00332
00333 char KX_ConstraintActuator::GetLimit_doc[] =
00334 "getLimit(type)\n"
00335 "\tReturns the type of constraint.\n";
00336 PyObject* KX_ConstraintActuator::PyGetLimit(PyObject* self,
00337 PyObject* args,
00338 PyObject* kwds) {
00339 return PyInt_FromLong(m_locrot);
00340 }
00341
00342