Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/Ketsji/KX_NearSensor.cpp
| Context not available. | |||||
| #include "KX_NearSensor.h" | #include "KX_NearSensor.h" | ||||
| #include "SCA_LogicManager.h" | #include "SCA_LogicManager.h" | ||||
| #include "KX_GameObject.h" | #include "KX_GameObject.h" | ||||
| #include "KX_TouchEventManager.h" | #include "KX_CollisionEventManager.h" | ||||
| #include "KX_Scene.h" // needed to create a replica | #include "KX_Scene.h" // needed to create a replica | ||||
| #include "PHY_IPhysicsEnvironment.h" | #include "PHY_IPhysicsEnvironment.h" | ||||
| #include "PHY_IPhysicsController.h" | #include "PHY_IPhysicsController.h" | ||||
| Context not available. | |||||
| float margin, | float margin, | ||||
| float resetmargin, | float resetmargin, | ||||
| bool bFindMaterial, | bool bFindMaterial, | ||||
| const STR_String& touchedpropname, | const std::string& touchedpropname, | ||||
| PHY_IPhysicsController* ctrl) | PHY_IPhysicsController* ctrl) | ||||
| :KX_TouchSensor(eventmgr, | :KX_CollisionSensor(eventmgr, | ||||
| gameobj, | gameobj, | ||||
| bFindMaterial, | bFindMaterial, | ||||
| false, | false, | ||||
| Context not available. | |||||
| { | { | ||||
| PHY_IMotionState* motionState = m_physCtrl->GetMotionState(); | PHY_IMotionState* motionState = m_physCtrl->GetMotionState(); | ||||
| KX_GameObject* parent = ((KX_GameObject*)GetParent()); | KX_GameObject* parent = ((KX_GameObject*)GetParent()); | ||||
| const MT_Point3& pos = parent->NodeGetWorldPosition(); | const MT_Vector3& pos = parent->NodeGetWorldPosition(); | ||||
| float ori[12]; | float ori[12]; | ||||
| parent->NodeGetWorldOrientation().getValue(ori); | parent->NodeGetWorldOrientation().getValue(ori); | ||||
| motionState->SetWorldPosition(pos[0], pos[1], pos[2]); | motionState->SetWorldPosition(pos[0], pos[1], pos[2]); | ||||
| Context not available. | |||||
| void KX_NearSensor::ProcessReplica() | void KX_NearSensor::ProcessReplica() | ||||
| { | { | ||||
| KX_TouchSensor::ProcessReplica(); | KX_CollisionSensor::ProcessReplica(); | ||||
| m_client_info = new KX_ClientObjectInfo(m_client_info->m_gameobject, KX_ClientObjectInfo::SENSOR); | m_client_info = new KX_ClientObjectInfo(m_client_info->m_gameobject, KX_ClientObjectInfo::SENSOR); | ||||
| Context not available. | |||||
| m_physCtrl = m_physCtrl->GetReplicaForSensors(); | m_physCtrl = m_physCtrl->GetReplicaForSensors(); | ||||
| if (m_physCtrl) | if (m_physCtrl) | ||||
| { | { | ||||
| //static_cast<KX_TouchEventManager*>(m_eventmgr)->GetPhysicsEnvironment()->addSensor(replica->m_physCtrl); | //static_cast<KX_CollisionEventManager*>(m_eventmgr)->GetPhysicsEnvironment()->addSensor(replica->m_physCtrl); | ||||
| m_physCtrl->SetMargin(m_Margin); | m_physCtrl->SetMargin(m_Margin); | ||||
| m_physCtrl->SetNewClientInfo(m_client_info); | m_physCtrl->SetNewClientInfo(m_client_info); | ||||
| } | } | ||||
| Context not available. | |||||
| KX_NearSensor::~KX_NearSensor() | KX_NearSensor::~KX_NearSensor() | ||||
| { | { | ||||
| // for nearsensor, the sensor is the 'owner' of sumoobj | // for nearsensor, the sensor is the 'owner' of sumoobj | ||||
| // for touchsensor, it's the parent | // for collisionsensor, it's the parent | ||||
| if (m_physCtrl) | if (m_physCtrl) | ||||
| { | { | ||||
| //static_cast<KX_TouchEventManager*>(m_eventmgr)->GetPhysicsEnvironment()->removeSensor(m_physCtrl); | //static_cast<KX_CollisionEventManager*>(m_eventmgr)->GetPhysicsEnvironment()->removeSensor(m_physCtrl); | ||||
| delete m_physCtrl; | delete m_physCtrl; | ||||
| m_physCtrl = NULL; | m_physCtrl = NULL; | ||||
| } | } | ||||
| Context not available. | |||||
| // only take valid colliders | // only take valid colliders | ||||
| if (client_info->m_type == KX_ClientObjectInfo::ACTOR) | if (client_info->m_type == KX_ClientObjectInfo::ACTOR) | ||||
| { | { | ||||
| if ((m_touchedpropname.Length() == 0) || | if ((m_touchedpropname.size() == 0) || | ||||
| (gameobj->GetProperty(m_touchedpropname))) | (gameobj->GetProperty(m_touchedpropname))) | ||||
| { | { | ||||
| return true; | return true; | ||||
| Context not available. | |||||
| bool KX_NearSensor::NewHandleCollision(void *obj1, void *obj2, const PHY_CollData *coll_data) | bool KX_NearSensor::NewHandleCollision(void *obj1, void *obj2, const PHY_CollData *coll_data) | ||||
| { | { | ||||
| // KX_TouchEventManager* toucheventmgr = static_cast<KX_TouchEventManager*>(m_eventmgr); | // KX_CollisionEventManager* toucheventmgr = static_cast<KX_CollisionEventManager*>(m_eventmgr); | ||||
| // KX_GameObject* parent = static_cast<KX_GameObject*>(GetParent()); | // KX_GameObject* parent = static_cast<KX_GameObject*>(GetParent()); | ||||
| // need the mapping from PHY_IPhysicsController to gameobjects now | // need the mapping from PHY_IPhysicsController to gameobjects now | ||||
| Context not available. | |||||
| // These checks are done already in BroadPhaseFilterCollision() | // These checks are done already in BroadPhaseFilterCollision() | ||||
| //if (client_info->m_type == KX_ClientObjectInfo::ACTOR) | //if (client_info->m_type == KX_ClientObjectInfo::ACTOR) | ||||
| //{ | //{ | ||||
| // if ((m_touchedpropname.Length() == 0) || | // if ((m_touchedpropname.size() == 0) || | ||||
| // (gameobj->GetProperty(m_touchedpropname))) | // (gameobj->GetProperty(m_touchedpropname))) | ||||
| // { | // { | ||||
| m_bTriggered = true; | m_bTriggered = true; | ||||
| Context not available. | |||||
| Methods, | Methods, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| &KX_TouchSensor::Type, | &KX_CollisionSensor::Type, | ||||
| 0,0,0,0,0,0, | 0,0,0,0,0,0, | ||||
| py_base_new | py_base_new | ||||
| }; | }; | ||||
| Context not available. | |||||
| PyAttributeDef KX_NearSensor::Attributes[] = { | PyAttributeDef KX_NearSensor::Attributes[] = { | ||||
| KX_PYATTRIBUTE_FLOAT_RW_CHECK("distance", 0, 10000, KX_NearSensor, m_Margin, CheckResetDistance), | KX_PYATTRIBUTE_FLOAT_RW_CHECK("distance", 0, 10000, KX_NearSensor, m_Margin, CheckResetDistance), | ||||
| KX_PYATTRIBUTE_FLOAT_RW_CHECK("resetDistance", 0, 10000, KX_NearSensor, m_ResetMargin, CheckResetDistance), | KX_PYATTRIBUTE_FLOAT_RW_CHECK("resetDistance", 0, 10000, KX_NearSensor, m_ResetMargin, CheckResetDistance), | ||||
| {NULL} //Sentinel | KX_PYATTRIBUTE_NULL //Sentinel | ||||
| }; | }; | ||||
| #endif // WITH_PYTHON | #endif // WITH_PYTHON | ||||
| Context not available. | |||||