static PyObject* gPyGetCharacter(PyObject* self, PyObject* args, PyObject* kwds) { PyObject* pyob; KX_GameObject *ob; if (!PyArg_ParseTuple(args,"O", &pyob)) return NULL; if (!ConvertPythonToGameObject(pyob, &ob, false, "bge.constraints.getCharacter(value)")) return NULL; if (PHY_GetActiveEnvironment()) { PHY_ICharacter* character= PHY_GetActiveEnvironment()->getCharacterController(ob); if (character) { KX_CharacterWrapper* pyWrapper = new KX_CharacterWrapper(character); return pyWrapper->NewProxy(true); } } Py_RETURN_NONE; }
PyObject *KX_VehicleWrapper::PyAddWheel(PyObject *args) { PyObject *pylistPos,*pylistDir,*pylistAxleDir; PyObject *wheelGameObject; float suspensionRestLength,wheelRadius; int hasSteering; if (PyArg_ParseTuple(args,"OOOOffi:addWheel",&wheelGameObject,&pylistPos,&pylistDir,&pylistAxleDir,&suspensionRestLength,&wheelRadius,&hasSteering)) { KX_GameObject *gameOb; if (!ConvertPythonToGameObject(wheelGameObject, &gameOb, false, "vehicle.addWheel(...): KX_VehicleWrapper (first argument)")) return NULL; if (gameOb->GetSGNode()) { MT_Vector3 attachPos,attachDir,attachAxle; if(!PyVecTo(pylistPos,attachPos)) { PyErr_SetString(PyExc_AttributeError, "addWheel(...) Unable to add wheel. attachPos must be a vector with 3 elements."); return NULL; } if(!PyVecTo(pylistDir,attachDir)) { PyErr_SetString(PyExc_AttributeError, "addWheel(...) Unable to add wheel. downDir must be a vector with 3 elements."); return NULL; } if(!PyVecTo(pylistAxleDir,attachAxle)) { PyErr_SetString(PyExc_AttributeError, "addWheel(...) Unable to add wheel. axleDir must be a vector with 3 elements."); return NULL; } //someone reverse some conventions inside Bullet (axle winding) attachAxle = -attachAxle; if(wheelRadius<=0) { PyErr_SetString(PyExc_AttributeError, "addWheel(...) Unable to add wheel. wheelRadius must be positive."); return NULL; } PHY_IMotionState *motionState = new KX_MotionState(gameOb->GetSGNode()); m_vehicle->AddWheel(motionState,attachPos,attachDir,attachAxle,suspensionRestLength,wheelRadius,hasSteering); } } else { return NULL; } Py_RETURN_NONE; }
int KX_CameraActuator::pyattr_set_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { KX_CameraActuator* self = static_cast<KX_CameraActuator*>(self_v); KX_GameObject *gameobj; if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_CameraActuator")) return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error if (self->m_ob) self->m_ob->UnregisterActuator(self); if ((self->m_ob = (SCA_IObject*)gameobj)) self->m_ob->RegisterActuator(self); return PY_SET_ATTR_SUCCESS; }
PyObject* KX_VehicleWrapper::PyAddWheel(PyObject* args) { PyObject* pylistPos,*pylistDir,*pylistAxleDir; PyObject* wheelGameObject; float suspensionRestLength,wheelRadius; int hasSteering; if (PyArg_ParseTuple(args,"OOOOffi:addWheel",&wheelGameObject,&pylistPos,&pylistDir,&pylistAxleDir,&suspensionRestLength,&wheelRadius,&hasSteering)) { KX_GameObject *gameOb; if (!ConvertPythonToGameObject(wheelGameObject, &gameOb, false, "vehicle.addWheel(...): KX_VehicleWrapper (first argument)")) return NULL; if (gameOb->GetSGNode()) { PHY_IMotionState* motionState = new KX_MotionState(gameOb->GetSGNode()); /* TODO - no error checking here! - bad juju */ MT_Vector3 attachPos,attachDir,attachAxle; PyVecTo(pylistPos,attachPos); PyVecTo(pylistDir,attachDir); PyVecTo(pylistAxleDir,attachAxle); PHY__Vector3 aPos,aDir,aAxle; aPos[0] = attachPos[0]; aPos[1] = attachPos[1]; aPos[2] = attachPos[2]; aDir[0] = attachDir[0]; aDir[1] = attachDir[1]; aDir[2] = attachDir[2]; aAxle[0] = -attachAxle[0];//someone reverse some conventions inside Bullet (axle winding) aAxle[1] = -attachAxle[1]; aAxle[2] = -attachAxle[2]; printf("attempt for addWheel: suspensionRestLength%f wheelRadius %f, hasSteering:%d\n",suspensionRestLength,wheelRadius,hasSteering); m_vehicle->AddWheel(motionState,aPos,aDir,aAxle,suspensionRestLength,wheelRadius,hasSteering); } } else { return NULL; } Py_RETURN_NONE; }
int KX_ParentActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { KX_ParentActuator* actuator = static_cast<KX_ParentActuator*>(self); KX_GameObject *gameobj; if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_ParentActuator")) return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error if (actuator->m_ob != NULL) actuator->m_ob->UnregisterActuator(actuator); actuator->m_ob = (SCA_IObject*) gameobj; if (actuator->m_ob) actuator->m_ob->RegisterActuator(actuator); return PY_SET_ATTR_SUCCESS; }
int KX_SteeringActuator::pyattr_set_target(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { KX_SteeringActuator* actuator = static_cast<KX_SteeringActuator*>(self); KX_GameObject *gameobj; if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: KX_SteeringActuator")) return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error if (actuator->m_target != NULL) actuator->m_target->UnregisterActuator(actuator); actuator->m_target = (KX_GameObject*) gameobj; if (actuator->m_target) actuator->m_target->RegisterActuator(actuator); return PY_SET_ATTR_SUCCESS; }
int BL_ArmatureActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { BL_ArmatureActuator* actuator = static_cast<BL_ArmatureActuator*>(self); KX_GameObject* &target = (attrdef->m_name == "target") ? actuator->m_gametarget : actuator->m_gamesubtarget; KX_GameObject *gameobj; if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: BL_ArmatureActuator")) return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error if (target != NULL) target->UnregisterActuator(actuator); target = gameobj; if (target) target->RegisterActuator(actuator); return PY_SET_ATTR_SUCCESS; }
int KX_SteeringActuator::pyattr_set_navmesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { KX_SteeringActuator* actuator = static_cast<KX_SteeringActuator*>(self); KX_GameObject *gameobj; if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: KX_SteeringActuator")) return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error if (dynamic_cast<KX_NavMeshObject *>(gameobj) == NULL) { PyErr_Format(PyExc_TypeError, "KX_NavMeshObject is expected"); return PY_SET_ATTR_FAIL; } if (actuator->m_navmesh != NULL) actuator->m_navmesh->UnregisterActuator(actuator); actuator->m_navmesh = static_cast<KX_NavMeshObject*>(gameobj); if (actuator->m_navmesh) actuator->m_navmesh->RegisterActuator(actuator); return PY_SET_ATTR_SUCCESS; }
int BL_ArmatureConstraint::py_attr_setattr(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { BL_ArmatureConstraint* self= static_cast<BL_ArmatureConstraint*>(self_v); bConstraint* constraint = self->m_constraint; bKinematicConstraint* ikconstraint = (constraint && constraint->type == CONSTRAINT_TYPE_KINEMATIC) ? (bKinematicConstraint*)constraint->data : NULL; int attr_order = attrdef-Attributes; int ival; double dval; char* sval; KX_GameObject *oval; if (!constraint) { PyErr_SetString(PyExc_AttributeError, "constraint is NULL"); return PY_SET_ATTR_FAIL; } switch (attr_order) { case BCA_ENFORCE: dval = PyFloat_AsDouble(value); if (dval < 0.0f || dval > 1.0f) { /* also accounts for non float */ PyErr_SetString(PyExc_AttributeError, "constraint.enforce = float: BL_ArmatureConstraint, expected a float between 0 and 1"); return PY_SET_ATTR_FAIL; } constraint->enforce = dval; return PY_SET_ATTR_SUCCESS; case BCA_HEADTAIL: dval = PyFloat_AsDouble(value); if (dval < 0.0f || dval > 1.0f) { /* also accounts for non float */ PyErr_SetString(PyExc_AttributeError, "constraint.headtail = float: BL_ArmatureConstraint, expected a float between 0 and 1"); return PY_SET_ATTR_FAIL; } constraint->headtail = dval; return PY_SET_ATTR_SUCCESS; case BCA_TARGET: if (!ConvertPythonToGameObject(value, &oval, true, "constraint.target = value: BL_ArmatureConstraint")) return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error self->SetTarget(oval); return PY_SET_ATTR_SUCCESS; case BCA_SUBTARGET: if (!ConvertPythonToGameObject(value, &oval, true, "constraint.subtarget = value: BL_ArmatureConstraint")) return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error self->SetSubtarget(oval); return PY_SET_ATTR_SUCCESS; case BCA_ACTIVE: ival = PyObject_IsTrue( value ); if (ival == -1) { PyErr_SetString(PyExc_AttributeError, "constraint.active = bool: BL_ArmatureConstraint, expected True or False"); return PY_SET_ATTR_FAIL; } self->m_constraint->flag = (self->m_constraint->flag & ~CONSTRAINT_OFF) | ((ival)?0:CONSTRAINT_OFF); return PY_SET_ATTR_SUCCESS; case BCA_IKWEIGHT: case BCA_IKDIST: case BCA_IKMODE: if (!ikconstraint) { PyErr_SetString(PyExc_AttributeError, "constraint is not of IK type"); return PY_SET_ATTR_FAIL; } switch (attr_order) { case BCA_IKWEIGHT: dval = PyFloat_AsDouble(value); if (dval < 0.0f || dval > 1.0f) { /* also accounts for non float */ PyErr_SetString(PyExc_AttributeError, "constraint.weight = float: BL_ArmatureConstraint, expected a float between 0 and 1"); return PY_SET_ATTR_FAIL; } ikconstraint->weight = dval; return PY_SET_ATTR_SUCCESS; case BCA_IKDIST: dval = PyFloat_AsDouble(value); if (dval < 0.0f) { /* also accounts for non float */ PyErr_SetString(PyExc_AttributeError, "constraint.ik_dist = float: BL_ArmatureConstraint, expected a positive float"); return PY_SET_ATTR_FAIL; } ikconstraint->dist = dval; return PY_SET_ATTR_SUCCESS; case BCA_IKMODE: ival = PyLong_AsLong(value); if (ival < 0) { PyErr_SetString(PyExc_AttributeError, "constraint.ik_mode = integer: BL_ArmatureConstraint, expected a positive integer"); return PY_SET_ATTR_FAIL; } ikconstraint->mode = ival; return PY_SET_ATTR_SUCCESS; } // should not come here break; } PyErr_SetString(PyExc_AttributeError, "constraint unknown attribute"); return PY_SET_ATTR_FAIL; }