Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/GameLogic/SCA_RaySensor.cpp
- This file was moved from source/gameengine/Ketsji/KX_RaySensor.cpp.
| Show All 22 Lines | |||||
| * | * | ||||
| * The Original Code is: all of this file. | * The Original Code is: all of this file. | ||||
| * | * | ||||
| * Contributor(s): none yet. | * Contributor(s): none yet. | ||||
| * | * | ||||
| * ***** END GPL LICENSE BLOCK ***** | * ***** END GPL LICENSE BLOCK ***** | ||||
| */ | */ | ||||
| /** \file gameengine/Ketsji/KX_RaySensor.cpp | /** \file gameengine/GameLogic/SCA_RaySensor.cpp | ||||
| * \ingroup ketsji | * \ingroup gamelogic | ||||
| */ | */ | ||||
| #include "KX_RaySensor.h" | #include "SCA_RaySensor.h" | ||||
| #include "SCA_EventManager.h" | #include "SCA_EventManager.h" | ||||
| #include "SCA_RandomEventManager.h" | #include "SCA_RandomEventManager.h" | ||||
| #include "SCA_LogicManager.h" | #include "SCA_LogicManager.h" | ||||
| #include "SCA_IObject.h" | #include "SCA_IObject.h" | ||||
| #include "KX_ClientObjectInfo.h" | #include "KX_ClientObjectInfo.h" | ||||
| #include "KX_GameObject.h" | #include "KX_GameObject.h" | ||||
| #include "KX_Scene.h" | #include "KX_Scene.h" | ||||
| #include "KX_RayCast.h" | #include "KX_RayCast.h" | ||||
| #include "KX_PyMath.h" | #include "KX_PyMath.h" | ||||
| #include "PHY_IPhysicsEnvironment.h" | #include "PHY_IPhysicsEnvironment.h" | ||||
| #include "PHY_IPhysicsController.h" | #include "PHY_IPhysicsController.h" | ||||
| #include "DNA_sensor_types.h" | #include "DNA_sensor_types.h" | ||||
| #include <stdio.h> | #include <stdio.h> | ||||
| KX_RaySensor::KX_RaySensor(class SCA_EventManager* eventmgr, | SCA_RaySensor::SCA_RaySensor(class SCA_EventManager* eventmgr, | ||||
| SCA_IObject* gameobj, | SCA_IObject* gameobj, | ||||
| const STR_String& propname, | const STR_String& propname, | ||||
| bool bFindMaterial, | bool bFindMaterial, | ||||
| bool bXRay, | bool bXRay, | ||||
| double distance, | double distance, | ||||
| int axis, | int axis, | ||||
| KX_Scene* ketsjiScene) | KX_Scene* ketsjiScene) | ||||
| : SCA_ISensor(gameobj,eventmgr), | : SCA_ISensor(gameobj,eventmgr), | ||||
| m_propertyname(propname), | m_propertyname(propname), | ||||
| m_bFindMaterial(bFindMaterial), | m_bFindMaterial(bFindMaterial), | ||||
| m_bXRay(bXRay), | m_bXRay(bXRay), | ||||
| m_distance(distance), | m_distance(distance), | ||||
| m_scene(ketsjiScene), | m_scene(ketsjiScene), | ||||
| m_axis(axis), | m_axis(axis), | ||||
| m_hitMaterial("") | m_hitMaterial("") | ||||
| { | { | ||||
| Init(); | Init(); | ||||
| } | } | ||||
| void KX_RaySensor::Init() | void SCA_RaySensor::Init() | ||||
| { | { | ||||
| m_bTriggered = (m_invert)?true:false; | m_bTriggered = (m_invert)?true:false; | ||||
| m_rayHit = false; | m_rayHit = false; | ||||
| m_hitObject = NULL; | m_hitObject = NULL; | ||||
| m_reset = true; | m_reset = true; | ||||
| } | } | ||||
| KX_RaySensor::~KX_RaySensor() | SCA_RaySensor::~SCA_RaySensor() | ||||
| { | { | ||||
| /* Nothing to be done here. */ | /* Nothing to be done here. */ | ||||
| } | } | ||||
| CValue* KX_RaySensor::GetReplica() | CValue* SCA_RaySensor::GetReplica() | ||||
| { | { | ||||
| KX_RaySensor* replica = new KX_RaySensor(*this); | SCA_RaySensor* replica = new SCA_RaySensor(*this); | ||||
| replica->ProcessReplica(); | replica->ProcessReplica(); | ||||
| replica->Init(); | replica->Init(); | ||||
| return replica; | return replica; | ||||
| } | } | ||||
| bool KX_RaySensor::IsPositiveTrigger() | bool SCA_RaySensor::IsPositiveTrigger() | ||||
| { | { | ||||
| bool result = m_rayHit; | bool result = m_rayHit; | ||||
| if (m_invert) | if (m_invert) | ||||
| result = !result; | result = !result; | ||||
| return result; | return result; | ||||
| } | } | ||||
| bool KX_RaySensor::RayHit(KX_ClientObjectInfo *client, KX_RayCast *result, void * const data) | bool SCA_RaySensor::RayHit(KX_ClientObjectInfo *client, KX_RayCast *result, void * const data) | ||||
| { | { | ||||
| KX_GameObject* hitKXObj = client->m_gameobject; | KX_GameObject* hitKXObj = client->m_gameobject; | ||||
| bool bFound = false; | bool bFound = false; | ||||
| if (m_propertyname.Length() == 0) | if (m_propertyname.Length() == 0) | ||||
| { | { | ||||
| bFound = true; | bFound = true; | ||||
| Show All 29 Lines | bool SCA_RaySensor::RayHit(KX_ClientObjectInfo *client, KX_RayCast *result, void * const data) | ||||
| } | } | ||||
| // no multi-hit search yet | // no multi-hit search yet | ||||
| return true; | return true; | ||||
| } | } | ||||
| /* this function is used to pre-filter the object before casting the ray on them. | /* 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. | * This is useful for "X-Ray" option when we want to see "through" unwanted object. | ||||
| */ | */ | ||||
| bool KX_RaySensor::NeedRayCast(KX_ClientObjectInfo *client) | bool SCA_RaySensor::NeedRayCast(KX_ClientObjectInfo *client) | ||||
| { | { | ||||
| if (client->m_type > KX_ClientObjectInfo::ACTOR) | if (client->m_type > KX_ClientObjectInfo::ACTOR) | ||||
| { | { | ||||
| // Unknown type of object, skip it. | // Unknown type of object, skip it. | ||||
| // Should not occur as the sensor objects are filtered in RayTest() | // Should not occur as the sensor objects are filtered in RayTest() | ||||
| printf("Invalid client type %d found ray casting\n", client->m_type); | printf("Invalid client type %d found ray casting\n", client->m_type); | ||||
| return false; | return false; | ||||
| } | } | ||||
| Show All 10 Lines | if (m_bXRay && m_propertyname.Length() != 0) | ||||
| { | { | ||||
| if (client->m_gameobject->GetProperty(m_propertyname) == NULL) | if (client->m_gameobject->GetProperty(m_propertyname) == NULL) | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| bool KX_RaySensor::Evaluate() | bool SCA_RaySensor::Evaluate() | ||||
| { | { | ||||
| bool result = false; | bool result = false; | ||||
| bool reset = m_reset && m_level; | bool reset = m_reset && m_level; | ||||
| m_rayHit = false; | m_rayHit = false; | ||||
| m_hitObject = NULL; | m_hitObject = NULL; | ||||
| m_hitPosition[0] = 0; | m_hitPosition[0] = 0; | ||||
| m_hitPosition[1] = 0; | m_hitPosition[1] = 0; | ||||
| m_hitPosition[2] = 0; | m_hitPosition[2] = 0; | ||||
| ▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | bool SCA_RaySensor::Evaluate() | ||||
| KX_GameObject *parent = obj->GetParent(); | KX_GameObject *parent = obj->GetParent(); | ||||
| if (!spc && parent) | if (!spc && parent) | ||||
| spc = parent->GetPhysicsController(); | spc = parent->GetPhysicsController(); | ||||
| PHY_IPhysicsEnvironment* physics_environment = this->m_scene->GetPhysicsEnvironment(); | PHY_IPhysicsEnvironment* physics_environment = this->m_scene->GetPhysicsEnvironment(); | ||||
| KX_RayCast::Callback<KX_RaySensor> callback(this, spc); | KX_RayCast::Callback<SCA_RaySensor> callback(this, spc); | ||||
| KX_RayCast::RayTest(physics_environment, frompoint, topoint, callback); | KX_RayCast::RayTest(physics_environment, frompoint, topoint, callback); | ||||
| /* now pass this result to some controller */ | /* now pass this result to some controller */ | ||||
| if (m_rayHit) | if (m_rayHit) | ||||
| { | { | ||||
| if (!m_bTriggered) | if (!m_bTriggered) | ||||
| { | { | ||||
| Show All 31 Lines | |||||
| #ifdef WITH_PYTHON | #ifdef WITH_PYTHON | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Python functions */ | /* Python functions */ | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Integration hooks ------------------------------------------------------- */ | /* Integration hooks ------------------------------------------------------- */ | ||||
| PyTypeObject KX_RaySensor::Type = { | PyTypeObject SCA_RaySensor::Type = { | ||||
| PyVarObject_HEAD_INIT(NULL, 0) | PyVarObject_HEAD_INIT(NULL, 0) | ||||
| "KX_RaySensor", | "SCA_RaySensor", | ||||
| sizeof(PyObjectPlus_Proxy), | sizeof(PyObjectPlus_Proxy), | ||||
| 0, | 0, | ||||
| py_base_dealloc, | py_base_dealloc, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| py_base_repr, | py_base_repr, | ||||
| 0,0,0,0,0,0,0,0,0, | 0,0,0,0,0,0,0,0,0, | ||||
| Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | ||||
| 0,0,0,0,0,0,0, | 0,0,0,0,0,0,0, | ||||
| Methods, | Methods, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| &SCA_ISensor::Type, | &SCA_ISensor::Type, | ||||
| 0,0,0,0,0,0, | 0,0,0,0,0,0, | ||||
| py_base_new | py_base_new | ||||
| }; | }; | ||||
| PyMethodDef KX_RaySensor::Methods[] = { | PyMethodDef SCA_RaySensor::Methods[] = { | ||||
| {NULL,NULL} //Sentinel | {NULL,NULL} //Sentinel | ||||
| }; | }; | ||||
| PyAttributeDef KX_RaySensor::Attributes[] = { | PyAttributeDef SCA_RaySensor::Attributes[] = { | ||||
| KX_PYATTRIBUTE_BOOL_RW("useMaterial", KX_RaySensor, m_bFindMaterial), | KX_PYATTRIBUTE_BOOL_RW("useMaterial", SCA_RaySensor, m_bFindMaterial), | ||||
| KX_PYATTRIBUTE_BOOL_RW("useXRay", KX_RaySensor, m_bXRay), | KX_PYATTRIBUTE_BOOL_RW("useXRay", SCA_RaySensor, m_bXRay), | ||||
| KX_PYATTRIBUTE_FLOAT_RW("range", 0, 10000, KX_RaySensor, m_distance), | KX_PYATTRIBUTE_FLOAT_RW("range", 0, 10000, SCA_RaySensor, m_distance), | ||||
| KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, KX_RaySensor, m_propertyname), | KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, SCA_RaySensor, m_propertyname), | ||||
| KX_PYATTRIBUTE_INT_RW("axis", 0, 5, true, KX_RaySensor, m_axis), | KX_PYATTRIBUTE_INT_RW("axis", 0, 5, true, SCA_RaySensor, m_axis), | ||||
| KX_PYATTRIBUTE_FLOAT_ARRAY_RO("hitPosition", KX_RaySensor, m_hitPosition, 3), | KX_PYATTRIBUTE_FLOAT_ARRAY_RO("hitPosition", SCA_RaySensor, m_hitPosition, 3), | ||||
| KX_PYATTRIBUTE_FLOAT_ARRAY_RO("rayDirection", KX_RaySensor, m_rayDirection, 3), | KX_PYATTRIBUTE_FLOAT_ARRAY_RO("rayDirection", SCA_RaySensor, m_rayDirection, 3), | ||||
| KX_PYATTRIBUTE_FLOAT_ARRAY_RO("hitNormal", KX_RaySensor, m_hitNormal, 3), | KX_PYATTRIBUTE_FLOAT_ARRAY_RO("hitNormal", SCA_RaySensor, m_hitNormal, 3), | ||||
| KX_PYATTRIBUTE_STRING_RO("hitMaterial", KX_RaySensor, m_hitMaterial), | KX_PYATTRIBUTE_STRING_RO("hitMaterial", SCA_RaySensor, m_hitMaterial), | ||||
| KX_PYATTRIBUTE_RO_FUNCTION("hitObject", KX_RaySensor, pyattr_get_hitobject), | KX_PYATTRIBUTE_RO_FUNCTION("hitObject", SCA_RaySensor, pyattr_get_hitobject), | ||||
| { NULL } //Sentinel | { NULL } //Sentinel | ||||
| }; | }; | ||||
| PyObject *KX_RaySensor::pyattr_get_hitobject(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | PyObject *SCA_RaySensor::pyattr_get_hitobject(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| KX_RaySensor* self = static_cast<KX_RaySensor*>(self_v); | SCA_RaySensor* self = static_cast<SCA_RaySensor*>(self_v); | ||||
| if (self->m_hitObject) | if (self->m_hitObject) | ||||
| return self->m_hitObject->GetProxy(); | return self->m_hitObject->GetProxy(); | ||||
| Py_RETURN_NONE; | Py_RETURN_NONE; | ||||
| } | } | ||||
| #endif // WITH_PYTHON | #endif // WITH_PYTHON | ||||