/* this function is used to pre-filter the object before casting the ray on them. * This is useful for "X-Ray" option when we want to see "through" unwanted object. */ bool KX_MouseFocusSensor::NeedRayCast(KX_ClientObjectInfo* client) { KX_GameObject *hitKXObj = client->m_gameobject; if (client->m_type > KX_ClientObjectInfo::ACTOR) { // Unknown type of object, skip it. // Should not occur as the sensor objects are filtered in RayTest() printf("Invalid client type %d found ray casting\n", client->m_type); return false; } if (m_bXRay && m_propertyname.Length() != 0) { if (m_bFindMaterial) { bool found = false; for (unsigned int i = 0; i < hitKXObj->GetMeshCount(); ++i) { RAS_MeshObject *meshObj = hitKXObj->GetMesh(i); for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) { found = strcmp(m_propertyname.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0; if (found) break; } } if (!found) return false; } else { if (hitKXObj->GetProperty(m_propertyname) == NULL) return false; } } return true; }
// this function is called at broad phase stage to check if the two controller // need to interact at all. It is used for Near/Radar sensor that don't need to // check collision with object not included in filter bool KX_NearSensor::BroadPhaseFilterCollision(void*obj1,void*obj2) { KX_GameObject* parent = static_cast<KX_GameObject*>(GetParent()); // need the mapping from PHY_IPhysicsController to gameobjects now assert(obj1==m_physCtrl && obj2); KX_ClientObjectInfo *client_info = static_cast<KX_ClientObjectInfo*>((static_cast<PHY_IPhysicsController*>(obj2))->GetNewClientInfo()); KX_GameObject* gameobj = ( client_info ? client_info->m_gameobject : NULL); if (gameobj && (gameobj != parent)) { // only take valid colliders if (client_info->m_type == KX_ClientObjectInfo::ACTOR) { if ((m_touchedpropname.size() == 0) || (gameobj->GetProperty(m_touchedpropname))) { return true; } } } return false; }
bool KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_CollData* colldata) { // KX_TouchEventManager* toucheventmgr = (KX_TouchEventManager*)m_eventmgr; KX_GameObject* parent = (KX_GameObject*)GetParent(); // need the mapping from PHY_IPhysicsController to gameobjects now KX_ClientObjectInfo *client_info = static_cast<KX_ClientObjectInfo*> (object1 == m_physCtrl? ((PHY_IPhysicsController*)object2)->GetNewClientInfo(): ((PHY_IPhysicsController*)object1)->GetNewClientInfo()); KX_GameObject* gameobj = ( client_info ? client_info->m_gameobject : NULL); // add the same check as in SCA_ISensor::Activate(), // we don't want to record collision when the sensor is not active. if (m_links && !m_suspended && gameobj && (gameobj != parent) && client_info->isActor()) { bool found = m_touchedpropname.IsEmpty(); bool hitMaterial = false; if (!found) { if (m_bFindMaterial) { for (unsigned int i = 0; i < gameobj->GetMeshCount(); ++i) { RAS_MeshObject *meshObj = gameobj->GetMesh(i); for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) { found = strcmp(m_touchedpropname.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0; if (found) { hitMaterial = true; break; } } } } else { found = (gameobj->GetProperty(m_touchedpropname) != NULL); } } if (found) { if (!m_colliders->SearchValue(gameobj)) { m_colliders->Add(gameobj->AddRef()); if (m_bTouchPulse) m_bColliderHash += (uint_ptr)(static_cast<void *>(&gameobj)); } m_bTriggered = true; m_hitObject = gameobj; m_hitMaterial = hitMaterial; //printf("KX_TouchSensor::HandleCollision\n"); } } return false; // was DT_CONTINUE but this was defined in sumo as false. }
PyObject *BL_ArmatureActuator::pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) { BL_ArmatureActuator* actuator = static_cast<BL_ArmatureActuator*>(self); KX_GameObject *target = (attrdef->m_name == "target") ? actuator->m_gametarget : actuator->m_gamesubtarget; if (!target) Py_RETURN_NONE; else return target->GetProxy(); }
const char* KX_BulletPhysicsController::getName() { if (m_pObject) { KX_GameObject* gameobj = (KX_GameObject*) m_pObject->GetSGClientObject(); return gameobj->GetName(); } return 0; }
void KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo) { //TODO this entire function is deprecated, written for 2.4x //the functionality should be rewritten, currently it does nothing KX_SceneList *scenes = m_ketsjiEngine->CurrentScenes(); int numScenes = scenes->size(); int i; for (i = 0; i < numScenes; i++) { KX_Scene *scene = scenes->at(i); CListValue *parentList = scene->GetRootParentList(); int numObjects = parentList->GetCount(); int g; for (g = 0; g < numObjects; g++) { KX_GameObject *gameObj = (KX_GameObject *)parentList->GetValue(g); if (gameObj->IsRecordAnimation()) { Object *blenderObject = gameObj->GetBlenderObject(); if (blenderObject) { #if 0 //erase existing ipo's Ipo* ipo = blenderObject->ipo;//findIpoForName(blenderObject->id.name+2); if (ipo) { //clear the curve data if (clearIpo) {//rcruiz IpoCurve *icu1; int numCurves = 0; for ( icu1 = (IpoCurve*)ipo->curve.first; icu1; ) { IpoCurve* tmpicu = icu1; /*int i; BezTriple *bezt; for ( bezt = tmpicu->bezt, i = 0; i < tmpicu->totvert; i++, bezt++) { printf("(%f,%f,%f),(%f,%f,%f),(%f,%f,%f)\n",bezt->vec[0][0],bezt->vec[0][1],bezt->vec[0][2],bezt->vec[1][0],bezt->vec[1][1],bezt->vec[1][2],bezt->vec[2][0],bezt->vec[2][1],bezt->vec[2][2]); }*/ icu1 = icu1->next; numCurves++; BLI_remlink( &( blenderObject->ipo->curve ), tmpicu ); if ( tmpicu->bezt ) MEM_freeN( tmpicu->bezt ); MEM_freeN( tmpicu ); localDel_ipoCurve( tmpicu ); } } } else { ipo = NULL; // XXX add_ipo(blenderObject->id.name+2, ID_OB); blenderObject->ipo = ipo; } #endif } } } } }
void BL_ActionActuator::DecLink() { SCA_IActuator::DecLink(); /* In this case no controllers use this action actuator, and it should stop its action. */ if (m_links == 0) { KX_GameObject *obj = (KX_GameObject *)GetParent(); obj->StopAction(m_layer); } }
KX_ObjectActuator:: KX_ObjectActuator( SCA_IObject* gameobj, KX_GameObject* refobj, const MT_Vector3& force, const MT_Vector3& torque, const MT_Vector3& dloc, const MT_Vector3& drot, const MT_Vector3& linV, const MT_Vector3& angV, const short damping, const KX_LocalFlags& flag ) : SCA_IActuator(gameobj, KX_ACT_OBJECT), m_force(force), m_torque(torque), m_dloc(dloc), m_drot(drot), m_linear_velocity(linV), m_angular_velocity(angV), m_linear_length2(0.0f), m_current_linear_factor(0.0f), m_current_angular_factor(0.0f), m_damping(damping), m_previous_error(0.0f,0.0f,0.0f), m_error_accumulator(0.0f,0.0f,0.0f), m_bitLocalFlag (flag), m_reference(refobj), m_active_combined_velocity (false), m_linear_damping_active(false), m_angular_damping_active(false), m_jumping(false) { if (m_bitLocalFlag.ServoControl) { // in servo motion, the force is local if the target velocity is local m_bitLocalFlag.Force = m_bitLocalFlag.LinearVelocity; m_pid = m_torque; } if (m_bitLocalFlag.CharacterMotion) { KX_GameObject *parent = static_cast<KX_GameObject *>(GetParent()); PHY_ICharacter *character = parent->GetScene()->GetPhysicsEnvironment()->GetCharacterController(parent); if (!character) { printf("Character motion enabled on non-character object (%s), falling back to simple motion.\n", parent->GetName().Ptr()); m_bitLocalFlag.CharacterMotion = false; } } if (m_reference) m_reference->RegisterActuator(this); UpdateFuzzyFlags(); }
PyObject* KX_PythonComponent::pyattr_get_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_PythonComponent *self = static_cast<KX_PythonComponent *>(self_v); KX_GameObject *gameobj = self->GetGameObject(); if (gameobj) { return gameobj->GetProxy(); } else { 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; }
KX_SteeringActuator::KX_SteeringActuator(SCA_IObject *gameobj, int mode, KX_GameObject *target, KX_GameObject *navmesh, float distance, float velocity, float acceleration, float turnspeed, bool isSelfTerminated, int pathUpdatePeriod, KX_ObstacleSimulation* simulation, short facingmode, bool normalup, bool enableVisualization, bool lockzvel) : SCA_IActuator(gameobj, KX_ACT_STEERING), m_target(target), m_mode(mode), m_distance(distance), m_velocity(velocity), m_acceleration(acceleration), m_turnspeed(turnspeed), m_simulation(simulation), m_updateTime(0), m_obstacle(NULL), m_isActive(false), m_isSelfTerminated(isSelfTerminated), m_enableVisualization(enableVisualization), m_facingMode(facingmode), m_normalUp(normalup), m_pathLen(0), m_pathUpdatePeriod(pathUpdatePeriod), m_lockzvel(lockzvel), m_wayPointIdx(-1), m_steerVec(MT_Vector3(0, 0, 0)) { m_navmesh = static_cast<KX_NavMeshObject*>(navmesh); if (m_navmesh) m_navmesh->RegisterActuator(this); if (m_target) m_target->RegisterActuator(this); if (m_simulation) m_obstacle = m_simulation->GetObstacle((KX_GameObject*)gameobj); KX_GameObject* parent = ((KX_GameObject*)gameobj)->GetParent(); if (m_facingMode>0 && parent) { m_parentlocalmat = parent->GetSGNode()->GetLocalOrientation(); } else m_parentlocalmat.setIdentity(); }
void KX_CollisionSensor::ReParent(SCA_IObject *parent) { KX_GameObject *gameobj = static_cast<KX_GameObject *>(parent); PHY_IPhysicsController *sphy = ((KX_GameObject *)parent)->GetPhysicsController(); if (sphy) { m_physCtrl = sphy; } KX_ClientObjectInfo *client_info = gameobj->getClientInfo(); client_info->m_sensors.push_back(this); SCA_ISensor::ReParent(parent); }
bool KX_MouseFocusSensor::RayHit(KX_ClientObjectInfo *client_info, KX_RayCast *result, void * const data) { KX_GameObject* hitKXObj = client_info->m_gameobject; /* Is this me? In the ray test, there are a lot of extra checks * for aliasing artifacts from self-hits. That doesn't happen * here, so a simple test suffices. Or does the camera also get * self-hits? (No, and the raysensor shouldn't do it either, since * self-hits are excluded by setting the correct ignore-object.) * Hitspots now become valid. */ KX_GameObject* thisObj = (KX_GameObject*) GetParent(); bool bFound = false; if ((m_focusmode == 2) || hitKXObj == thisObj) { if (m_propertyname.Length() == 0) { bFound = true; } else { if (m_bFindMaterial) { for (unsigned int i = 0; i < hitKXObj->GetMeshCount(); ++i) { RAS_MeshObject *meshObj = hitKXObj->GetMesh(i); for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) { bFound = strcmp(m_propertyname.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0; if (bFound) break; } } } else { bFound = hitKXObj->GetProperty(m_propertyname) != NULL; } } if (bFound) { m_hitObject = hitKXObj; m_hitPosition = result->m_hitPoint; m_hitNormal = result->m_hitNormal; m_hitUV = result->m_hitUV; return true; } } return true; // object must be visible to trigger //return false; // occluded objects can trigger }
void KX_TouchSensor::ReParent(SCA_IObject* parent) { KX_GameObject *gameobj = static_cast<KX_GameObject *>(parent); PHY_IPhysicsController *sphy = ((KX_GameObject*)parent)->GetPhysicsController(); if (sphy) m_physCtrl = sphy; // m_solidHandle = m_sumoObj->getObjectHandle(); KX_ClientObjectInfo *client_info = gameobj->getClientInfo(); //client_info->m_gameobject = gameobj; //client_info->m_auxilary_info = NULL; client_info->m_sensors.push_back(this); SCA_ISensor::ReParent(parent); }
KX_BulletPhysicsController::~KX_BulletPhysicsController () { // The game object has a direct link to if (m_pObject) { // If we cheat in SetObject, we must also cheat here otherwise the // object will still things it has a physical controller // Note that it requires that m_pObject is reset in case the object is deleted // before the controller (usual case, see KX_Scene::RemoveNodeDestructObjec) // The non usual case is when the object is not deleted because its reference is hanging // in a AddObject actuator but the node is deleted. This case is covered here. KX_GameObject* gameobj = (KX_GameObject*) m_pObject->GetSGClientObject(); gameobj->SetPhysicsController(NULL,false); } }
void KX_BlenderMaterial::setObjectMatrixData(int i, RAS_IRasterizer *ras) { KX_GameObject *obj = (KX_GameObject*) mScene->GetObjectList()->FindValue(mMaterial->mapping[i].objconame); if (!obj) return; glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR ); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR ); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR ); GLenum plane = GL_EYE_PLANE; // figure plane gen float proj[4] = {0.f,0.f,0.f,0.f}; GetProjPlane(mMaterial, i, 0, proj); glTexGenfv(GL_S, plane, proj); GetProjPlane(mMaterial, i, 1, proj); glTexGenfv(GL_T, plane, proj); GetProjPlane(mMaterial, i, 2, proj); glTexGenfv(GL_R, plane, proj); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_R); const MT_Matrix4x4& mvmat = ras->GetViewMatrix(); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glScalef( mMaterial->mapping[i].scale[0], mMaterial->mapping[i].scale[1], mMaterial->mapping[i].scale[2] ); MT_Point3 pos = obj->NodeGetWorldPosition(); MT_Vector4 matmul = MT_Vector4(pos[0], pos[1], pos[2], 1.f); MT_Vector4 t = mvmat*matmul; glTranslatef( (float)(-t[0]), (float)(-t[1]), (float)(-t[2]) ); glMatrixMode(GL_MODELVIEW); }
bool KX_VisibilityActuator::Update() { bool bNegativeEvent = IsNegativeEvent(); RemoveAllEvents(); if (bNegativeEvent) return false; KX_GameObject *obj = (KX_GameObject*) GetParent(); obj->SetVisible(m_visible, m_recursive); obj->SetOccluder(m_occlusion, m_recursive); obj->UpdateBuckets(m_recursive); return false; }
void KX_NearSensor::SynchronizeTransform() { // The near and radar sensors are using a different physical object which is // not linked to the parent object, must synchronize it. if (m_physCtrl) { PHY_IMotionState* motionState = m_physCtrl->GetMotionState(); KX_GameObject* parent = ((KX_GameObject*)GetParent()); const MT_Vector3& pos = parent->NodeGetWorldPosition(); float ori[12]; parent->NodeGetWorldOrientation().getValue(ori); motionState->SetWorldPosition(pos[0], pos[1], pos[2]); motionState->SetWorldOrientation(ori); m_physCtrl->WriteMotionStateToDynamics(true); } }
void KX_BlenderSceneConverter::TestHandlesPhysicsObjectToAnimationIpo() { KX_SceneList *scenes = m_ketsjiEngine->CurrentScenes(); int numScenes = scenes->size(); int i; for (i = 0; i < numScenes; i++) { KX_Scene *scene = scenes->at(i); //PHY_IPhysicsEnvironment* physEnv = scene->GetPhysicsEnvironment(); CListValue *parentList = scene->GetRootParentList(); int numObjects = parentList->GetCount(); int g; for (g = 0; g < numObjects; g++) { KX_GameObject *gameObj = (KX_GameObject *)parentList->GetValue(g); if (gameObj->IsRecordAnimation()) { Object *blenderObject = gameObj->GetBlenderObject(); if (blenderObject && blenderObject->adt) { bAction *act = verify_adt_action(&blenderObject->id, false); FCurve *fcu; if (!act) { continue; } /* for now, not much choice but to run this on all curves... */ for (fcu = (FCurve *)act->curves.first; fcu; fcu = fcu->next) { /* Note: calling `sort_time_fcurve()` here is not needed, since * all keys have been added in 'right' order. */ calchandles_fcurve(fcu); } #if 0 // XXX animato Ipo* ipo = blenderObject->ipo; //create the curves, if not existing //testhandles_ipocurve checks for NULL testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"LocX")); testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"LocY")); testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"LocZ")); testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"RotX")); testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"RotY")); testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"RotZ")); #endif } } } } }
void KX_BlenderSceneConverter::TestHandlesPhysicsObjectToAnimationIpo() { KX_SceneList* scenes = m_ketsjiEngine->CurrentScenes(); int numScenes = scenes->size(); int i; for (i=0;i<numScenes;i++) { KX_Scene* scene = scenes->at(i); //PHY_IPhysicsEnvironment* physEnv = scene->GetPhysicsEnvironment(); CListValue* parentList = scene->GetRootParentList(); int numObjects = parentList->GetCount(); int g; for (g=0;g<numObjects;g++) { KX_GameObject* gameObj = (KX_GameObject*)parentList->GetValue(g); if (gameObj->IsDynamic()) { //KX_IPhysicsController* physCtrl = gameObj->GetPhysicsController(); Object* blenderObject = gameObj->GetBlenderObject(); if (blenderObject && blenderObject->ipo) { // XXX animato #if 0 Ipo* ipo = blenderObject->ipo; //create the curves, if not existing //testhandles_ipocurve checks for NULL testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"LocX")); testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"LocY")); testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"LocZ")); testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"RotX")); testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"RotY")); testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"RotZ")); #endif } } } } }
SG_Controller* KX_BulletPhysicsController::GetReplica(class SG_Node* destnode) { PHY_IMotionState* motionstate = new KX_MotionState(destnode); KX_BulletPhysicsController* physicsreplica = new KX_BulletPhysicsController(*this); //parentcontroller is here be able to avoid collisions between parent/child PHY_IPhysicsController* parentctrl = NULL; KX_BulletPhysicsController* parentKxCtrl = NULL; CcdPhysicsController* ccdParent = NULL; if (destnode != destnode->GetRootSGParent()) { KX_GameObject* clientgameobj = (KX_GameObject*) destnode->GetRootSGParent()->GetSGClientObject(); if (clientgameobj) { parentctrl = (KX_BulletPhysicsController*)clientgameobj->GetPhysicsController(); } else { // it could be a false node, try the children NodeList::const_iterator childit; for ( childit = destnode->GetSGChildren().begin(); childit!= destnode->GetSGChildren().end(); ++childit ) { KX_GameObject *clientgameobj_child = static_cast<KX_GameObject*>( (*childit)->GetSGClientObject()); if (clientgameobj_child) { parentKxCtrl = (KX_BulletPhysicsController*)clientgameobj_child->GetPhysicsController(); parentctrl = parentKxCtrl; ccdParent = parentKxCtrl; } } } } physicsreplica->setParentCtrl(ccdParent); physicsreplica->PostProcessReplica(motionstate,parentctrl); physicsreplica->m_userdata = (PHY_IPhysicsController*)physicsreplica; physicsreplica->m_bulletChildShape = NULL; return physicsreplica; }
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; }
void KX_BulletPhysicsController::SetObject (SG_IObject* object) { SG_Controller::SetObject(object); // cheating here... //should not be necessary, is it for duplicates ? KX_GameObject* gameobj = (KX_GameObject*) object->GetSGClientObject(); gameobj->SetPhysicsController(this,gameobj->IsDynamic()); CcdPhysicsController::setNewClientInfo(gameobj->getClientInfo()); if (m_bSensor) { // use a different callback function for sensor object, // bullet will not synchronize, we must do it explicitly SG_Callbacks& callbacks = gameobj->GetSGNode()->GetCallBackFunctions(); callbacks.m_updatefunc = KX_GameObject::SynchronizeTransformFunc; } }
bool KX_RaySensor::RayHit(KX_ClientObjectInfo *client, KX_RayCast *result, void * const data) { KX_GameObject* hitKXObj = client->m_gameobject; bool bFound = false; if (m_propertyname.Length() == 0) { bFound = true; } else { if (m_bFindMaterial) { if (client->m_auxilary_info) { bFound = (m_propertyname== ((char*)client->m_auxilary_info)); } } else { bFound = hitKXObj->GetProperty(m_propertyname) != NULL; } } if (bFound) { m_rayHit = true; m_hitObject = hitKXObj; m_hitPosition[0] = result->m_hitPoint[0]; m_hitPosition[1] = result->m_hitPoint[1]; m_hitPosition[2] = result->m_hitPoint[2]; m_hitNormal[0] = result->m_hitNormal[0]; m_hitNormal[1] = result->m_hitNormal[1]; m_hitNormal[2] = result->m_hitNormal[2]; m_hitMaterial = (client->m_auxilary_info ? (char*)client->m_auxilary_info : ""); } // no multi-hit search yet return true; }
// get pointer to material RAS_IPolyMaterial * getMaterial (PyObject *obj, short matID) { // if object is available if (obj != NULL) { // get pointer to texture image KX_GameObject * gameObj = gameObjectType.checkType(obj); if (gameObj != NULL && gameObj->GetMeshCount() > 0) { // get material from mesh RAS_MeshObject * mesh = gameObj->GetMesh(0); RAS_MeshMaterial *meshMat = mesh->GetMeshMaterial(matID); if (meshMat != NULL && meshMat->m_bucket != NULL) // return pointer to polygon or blender material return meshMat->m_bucket->GetPolyMaterial(); } } // otherwise material was not found return NULL; }
bool KX_SCA_DynamicActuator::Update() { // bool result = false; /*unused*/ KX_GameObject *obj = (KX_GameObject*) GetParent(); bool bNegativeEvent = IsNegativeEvent(); PHY_IPhysicsController* controller; RemoveAllEvents(); if (bNegativeEvent) return false; // do nothing on negative events if (!obj) return false; // object not accessible, shouldnt happen controller = obj->GetPhysicsController(); if (!controller) return false; // no physic object switch (m_dyn_operation) { case 0: // Child objects must be static, so we block changing to dynamic if (!obj->GetParent()) controller->RestoreDynamics(); break; case 1: controller->SuspendDynamics(); break; case 2: controller->SetRigidBody(true); break; case 3: controller->SetRigidBody(false); break; case 4: controller->SetMass(m_setmass); break; } return false; }
bool KX_ParentActuator::Update() { bool bNegativeEvent = IsNegativeEvent(); RemoveAllEvents(); if (bNegativeEvent) return false; // do nothing on negative events KX_GameObject *obj = (KX_GameObject*) GetParent(); KX_Scene *scene = KX_GetActiveScene(); switch (m_mode) { case KX_PARENT_SET: if (m_ob) obj->SetParent(scene, (KX_GameObject*)m_ob, m_addToCompound, m_ghost); break; case KX_PARENT_REMOVE: obj->RemoveParent(scene); break; }; return false; }
bool KX_NearSensor::NewHandleCollision(void *obj1, void *obj2, const PHY_CollData *coll_data) { // KX_CollisionEventManager* toucheventmgr = static_cast<KX_CollisionEventManager*>(m_eventmgr); // KX_GameObject* parent = static_cast<KX_GameObject*>(GetParent()); // need the mapping from PHY_IPhysicsController to gameobjects now KX_ClientObjectInfo *client_info = static_cast<KX_ClientObjectInfo*> (obj1 == m_physCtrl? ((PHY_IPhysicsController*)obj2)->GetNewClientInfo() : ((PHY_IPhysicsController*)obj1)->GetNewClientInfo()); KX_GameObject* gameobj = ( client_info ? client_info->m_gameobject : NULL); // Add the same check as in SCA_ISensor::Activate(), // we don't want to record collision when the sensor is not active. if (m_links && !m_suspended && gameobj /* done in BroadPhaseFilterCollision() && (gameobj != parent)*/) { if (!m_colliders->SearchValue(gameobj)) m_colliders->Add(gameobj->AddRef()); // only take valid colliders // These checks are done already in BroadPhaseFilterCollision() //if (client_info->m_type == KX_ClientObjectInfo::ACTOR) //{ // if ((m_touchedpropname.size() == 0) || // (gameobj->GetProperty(m_touchedpropname))) // { m_bTriggered = true; m_hitObject = gameobj; // } //} } return false; // was DT_CONTINUE; but this was defined in Sumo as false }
bool KX_StateActuator::Update() { bool bNegativeEvent = IsNegativeEvent(); unsigned int objMask; // execution of state actuator means that we are in the execution phase, reset this pointer // because all the active actuator of this object will be removed for sure. m_gameobj->m_firstState = NULL; RemoveAllEvents(); if (bNegativeEvent) return false; KX_GameObject *obj = (KX_GameObject*) GetParent(); objMask = obj->GetState(); switch (m_operation) { case OP_CPY: objMask = m_mask; break; case OP_SET: objMask |= m_mask; break; case OP_CLR: objMask &= ~m_mask; break; case OP_NEG: objMask ^= m_mask; break; default: // unsupported operation, no nothing return false; } obj->SetState(objMask); return false; }
bool KX_TrackToActuator::Update(double curtime, bool frame) { bool result = false; bool bNegativeEvent = IsNegativeEvent(); RemoveAllEvents(); if (bNegativeEvent) { // do nothing on negative events } else if (m_object) { KX_GameObject* curobj = (KX_GameObject*) GetParent(); MT_Vector3 dir = curobj->NodeGetWorldPosition() - ((KX_GameObject*)m_object)->NodeGetWorldPosition(); MT_Matrix3x3 mat; MT_Matrix3x3 oldmat; mat = vectomat(dir, m_trackflag, m_upflag, m_allow3D); oldmat = curobj->NodeGetWorldOrientation(); /* erwin should rewrite this! */ mat = matrix3x3_interpol(oldmat, mat, m_time); /* check if the model is parented and calculate the child transform */ if (m_parentobj) { MT_Point3 localpos; localpos = curobj->GetSGNode()->GetLocalPosition(); // Get the inverse of the parent matrix MT_Matrix3x3 parentmatinv; parentmatinv = m_parentobj->NodeGetWorldOrientation().inverse(); // transform the local coordinate system into the parents system mat = parentmatinv * mat; // append the initial parent local rotation matrix mat = m_parentlocalmat * mat; // set the models tranformation properties curobj->NodeSetLocalOrientation(mat); curobj->NodeSetLocalPosition(localpos); //curobj->UpdateTransform(); } else { curobj->NodeSetLocalOrientation(mat); } result = true; } return result; }