fixed raysensor, hooked up a few more bullet method: force, torque etc, + 'local'. cosmetic change in physics-engine menu.

This commit is contained in:
Erwin Coumans 2005-11-11 05:02:14 +00:00
parent 07b826409a
commit fbee75fef3
3 changed files with 108 additions and 98 deletions

@ -1885,7 +1885,11 @@ static void world_panel_mistaph(World *wrld)
#if GAMEBLENDER == 1
uiDefButI(block, MENU, 1,
#ifdef USE_ODE
"Physics %t|None %x0|Sumo %x2|Ode %x4 |Bullet %x5",
#else
"Physics %t|None %x0|Sumo %x2|Bullet %x5",
#endif
10,180,140,19, &wrld->physicsEngine, 0, 0, 0, 0,
"Physics Engine");

@ -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,100 +232,11 @@ bool KX_RaySensor::Evaluate(CValue* event)
if (parent)
parent->Release();
do {
PHY_IPhysicsController* physCtrl = 0;
// frompoint,
// topoint,
// resultpoint,
// resultnormal);
if (physCtrl)
{
PHY_IPhysicsEnvironment* physics_environment = this->m_scene->GetPhysicsEnvironment();
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);
result = KX_RayCast::RayTest(spc, physics_environment, frompoint, topoint, resultpoint, resultnormal, KX_RayCast::Callback<KX_RaySensor>(this));
/* now pass this result to some controller */

@ -114,8 +114,15 @@ void CcdPhysicsController::PostProcessReplica(class PHY_IMotionState* motionsta
// kinematic methods
void CcdPhysicsController::RelativeTranslate(float dlocX,float dlocY,float dlocZ,bool local)
{
SimdVector3 dloc(dlocX,dlocY,dlocZ);
SimdTransform xform = m_body->getCenterOfMassTransform();
xform.setOrigin(xform.getOrigin() + SimdVector3(dlocX,dlocY,dlocZ));
if (local)
{
dloc = xform.getBasis()*dloc;
}
xform.setOrigin(xform.getOrigin() + dloc);
this->m_body->setCenterOfMassTransform(xform);
}
@ -152,7 +159,11 @@ void CcdPhysicsController::GetWorldOrientation(SimdMatrix3x3& mat)
void CcdPhysicsController::getOrientation(float &quatImag0,float &quatImag1,float &quatImag2,float &quatReal)
{
SimdQuaternion q = m_body->getCenterOfMassTransform().getRotation();
quatImag0 = q[0];
quatImag1 = q[1];
quatImag2 = q[2];
quatReal = q[3];
}
void CcdPhysicsController::setOrientation(float quatImag0,float quatImag1,float quatImag2,float quatReal)
{
@ -184,26 +195,55 @@ void CcdPhysicsController::getPosition(PHY__Vector3& pos) const
void CcdPhysicsController::setScaling(float scaleX,float scaleY,float scaleZ)
{
if (m_body && m_body->GetCollisionShape())
{
SimdVector3 scaling(scaleX,scaleY,scaleZ);
m_body->GetCollisionShape()->setLocalScaling(scaling);
}
}
// physics methods
void CcdPhysicsController::ApplyTorque(float torqueX,float torqueY,float torqueZ,bool local)
{
SimdVector3 torque(torqueX,torqueY,torqueZ);
SimdTransform xform = m_body->getCenterOfMassTransform();
if (local)
{
torque = xform.getBasis()*torque;
}
m_body->applyTorque(torque);
}
void CcdPhysicsController::ApplyForce(float forceX,float forceY,float forceZ,bool local)
{
SimdVector3 force(forceX,forceX,forceX);
SimdTransform xform = m_body->getCenterOfMassTransform();
if (local)
{
force = xform.getBasis()*force;
}
m_body->applyCentralForce(force);
}
void CcdPhysicsController::SetAngularVelocity(float ang_velX,float ang_velY,float ang_velZ,bool local)
{
SimdVector3 angvel(ang_velX,ang_velY,ang_velZ);
SimdTransform xform = m_body->getCenterOfMassTransform();
if (local)
{
angvel = xform.getBasis()*angvel;
}
m_body->setAngularVelocity(angvel);
}
void CcdPhysicsController::SetLinearVelocity(float lin_velX,float lin_velY,float lin_velZ,bool local)
{
SimdVector3 linVel(lin_velX,lin_velY,lin_velZ);
SimdTransform xform = m_body->getCenterOfMassTransform();
if (local)
{
linVel = xform.getBasis()*linVel;
}
m_body->setLinearVelocity(linVel);
}
void CcdPhysicsController::applyImpulse(float attachX,float attachY,float attachZ, float impulseX,float impulseY,float impulseZ)
@ -223,9 +263,20 @@ void CcdPhysicsController::SetActive(bool active)
// reading out information from physics
void CcdPhysicsController::GetLinearVelocity(float& linvX,float& linvY,float& linvZ)
{
const SimdVector3& linvel = this->m_body->getLinearVelocity();
linvX = linvel.x();
linvY = linvel.y();
linvZ = linvel.z();
}
void CcdPhysicsController::GetVelocity(const float posX,const float posY,const float posZ,float& linvX,float& linvY,float& linvZ)
{
SimdVector3 pos(posX,posY,posZ);
SimdVector3 rel_pos = pos-m_body->getCenterOfMassPosition();
SimdVector3 linvel = m_body->getVelocityInLocalPoint(rel_pos);
linvX = linvel.x();
linvY = linvel.y();
linvZ = linvel.z();
}
void CcdPhysicsController::getReactionForce(float& forceX,float& forceY,float& forceZ)
{