diff options
author | Erwin Coumans <blender@erwincoumans.com> | 2005-11-11 08:02:14 +0300 |
---|---|---|
committer | Erwin Coumans <blender@erwincoumans.com> | 2005-11-11 08:02:14 +0300 |
commit | fbee75fef3b584138874b1b973a533773e082f7c (patch) | |
tree | 31f73bbc6f92fc56e2692ee675222ee876928114 /source/gameengine/Ketsji | |
parent | 07b826409a990d3750a4790f791319dacf923b28 (diff) |
fixed raysensor, hooked up a few more bullet method: force, torque etc, + 'local'. cosmetic change in physics-engine menu.
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r-- | source/gameengine/Ketsji/KX_RaySensor.cpp | 145 |
1 files changed, 50 insertions, 95 deletions
diff --git a/source/gameengine/Ketsji/KX_RaySensor.cpp b/source/gameengine/Ketsji/KX_RaySensor.cpp index 01d49cef777..b7d6ccab15b 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.cpp +++ b/source/gameengine/Ketsji/KX_RaySensor.cpp @@ -40,7 +40,7 @@ #include "KX_ClientObjectInfo.h" #include "KX_GameObject.h" #include "KX_Scene.h" - +#include "KX_RayCast.h" #include "PHY_IPhysicsEnvironment.h" #include "KX_IPhysicsController.h" #include "PHY_IPhysicsController.h" @@ -103,6 +103,50 @@ bool KX_RaySensor::IsPositiveTrigger() return result; } +bool KX_RaySensor::RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data) +{ + + KX_GameObject* hitKXObj = client->m_gameobject; + + if (client->m_type > KX_ClientObjectInfo::ACTOR) + { + // false hit + return false; + } + 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 = hit_point; + m_hitNormal = hit_normal; + + } + + return true; + +} + bool KX_RaySensor::Evaluate(CValue* event) @@ -188,101 +232,12 @@ bool KX_RaySensor::Evaluate(CValue* event) if (parent) parent->Release(); - do { - PHY_IPhysicsController* physCtrl = 0; -// frompoint, -// topoint, -// resultpoint, -// resultnormal); - - if (physCtrl) - { - - KX_ClientObjectInfo* info = static_cast<KX_ClientObjectInfo*>(physCtrl->getNewClientInfo()); - bool bFound = false; - - if (!info) - { - std::cout<< "WARNING: Ray sensor ";// << GetName() << " cannot sense SM_Object " << hitObj << " - no client info.\n" << std::endl; - ready = true; - break; - } - - SCA_IObject *hitgameobj = info->m_gameobject; - - if (hitgameobj == obj || info->m_type > KX_ClientObjectInfo::ACTOR) - { -#ifdef NOPE - /* - // false hit - KX_IPhysicsController *hitspc = (static_cast<KX_GameObject*> (hitgameobj))->GetPhysicsController(); - - if (hitspc) - { - /* We add 0.01 of fudge, so that if the margin && radius == 0., we don't endless loop. */ - MT_Scalar marg = 0.01;// + hitspc->getmargin(); - - if (hitspc->GetSumoObject()->getShapeProps()) - { - marg += 2*hitspc->GetSumoObject()->getShapeProps()->m_radius; - } - - /* Calculate the other side of this object */ - MT_Point3 hitObjPos; - hitspc->GetWorldPosition(hitObjPos); - MT_Vector3 hitvector = hitObjPos - resultpoint; - if (hitvector.dot(hitvector) > MT_EPSILON) - { - hitvector.normalize(); - marg *= 2.*todir.dot(hitvector); - } - frompoint = resultpoint + marg * todir; - } else { - ready = true; - } -#endif - ready = true; - } - else - { - ready = true; - if (m_propertyname.Length() == 0) - { - bFound = true; - } - else - { - if (m_bFindMaterial) - { - if (info->m_auxilary_info) - { - bFound = (m_propertyname== ((char*)info->m_auxilary_info)); - } - } - else - { - bFound = hitgameobj->GetProperty(m_propertyname) != NULL; - } - } - - if (bFound) - { - m_rayHit = true; - m_hitObject = hitgameobj; - m_hitPosition = resultpoint; - m_hitNormal = resultnormal; - - } - } - } - else - { - ready = true; - } - } - while (!ready); - + + PHY_IPhysicsEnvironment* physics_environment = this->m_scene->GetPhysicsEnvironment(); + + result = KX_RayCast::RayTest(spc, physics_environment, frompoint, topoint, resultpoint, resultnormal, KX_RayCast::Callback<KX_RaySensor>(this)); + /* now pass this result to some controller */ if (m_rayHit) |