2013-11-21 17:22:13 +01:00
|
|
|
#include "SimpleRigidBody.h"
|
2013-11-25 16:35:56 +01:00
|
|
|
#include "PhysicsAPI_Impl.h"
|
2013-11-21 17:22:13 +01:00
|
|
|
|
|
|
|
using namespace ::Oyster::Physics;
|
2013-11-28 11:58:46 +01:00
|
|
|
using namespace ::Oyster::Physics3D;
|
2013-11-25 16:35:56 +01:00
|
|
|
using namespace ::Oyster::Math3D;
|
2013-11-21 17:22:13 +01:00
|
|
|
using namespace ::Oyster::Collision3D;
|
|
|
|
using namespace ::Utility::DynamicMemory;
|
2013-11-25 16:35:56 +01:00
|
|
|
using namespace ::Utility::Value;
|
2013-11-21 17:22:13 +01:00
|
|
|
|
2013-11-26 13:27:34 +01:00
|
|
|
SimpleRigidBody::SimpleRigidBody()
|
2013-11-28 11:58:46 +01:00
|
|
|
{
|
2014-02-09 21:24:09 +01:00
|
|
|
this->collisionShape = NULL;
|
|
|
|
this->motionState = NULL;
|
|
|
|
this->rigidBody = NULL;
|
|
|
|
|
|
|
|
this->state.centerPos = Float3(0.0f, 0.0f, 0.0f);
|
|
|
|
this->state.quaternion = Quaternion(Float3(0.0f, 0.0f, 0.0f), 1.0f);
|
|
|
|
this->state.dynamicFrictionCoeff = 0.0f;
|
|
|
|
this->state.staticFrictionCoeff = 0.0f;
|
|
|
|
this->state.mass = 0.0f;
|
|
|
|
this->state.restitutionCoeff = 0.0f;
|
|
|
|
this->state.reach = Float3(0.0f, 0.0f, 0.0f);
|
2014-02-03 15:48:42 +01:00
|
|
|
|
2014-02-21 12:21:10 +01:00
|
|
|
this->collisionFlags = 0;
|
|
|
|
|
2014-02-10 13:55:01 +01:00
|
|
|
this->afterCollision = NULL;
|
|
|
|
this->onMovement = NULL;
|
2013-12-19 21:39:20 +01:00
|
|
|
|
2014-01-20 13:44:12 +01:00
|
|
|
this->customTag = nullptr;
|
2013-11-28 11:58:46 +01:00
|
|
|
}
|
2013-11-21 17:22:13 +01:00
|
|
|
|
2014-02-09 21:24:09 +01:00
|
|
|
SimpleRigidBody::~SimpleRigidBody()
|
2013-11-21 17:22:13 +01:00
|
|
|
{
|
2014-02-09 21:24:09 +01:00
|
|
|
delete this->motionState;
|
|
|
|
this->motionState = NULL;
|
|
|
|
delete this->collisionShape;
|
|
|
|
this->collisionShape = NULL;
|
|
|
|
delete this->rigidBody;
|
|
|
|
this->rigidBody = NULL;
|
2013-11-21 17:22:13 +01:00
|
|
|
}
|
|
|
|
|
2014-02-10 14:50:40 +01:00
|
|
|
SimpleRigidBody::State SimpleRigidBody::GetState() const
|
|
|
|
{
|
|
|
|
return this->state;
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleRigidBody::State& SimpleRigidBody::GetState( SimpleRigidBody::State &targetMem ) const
|
|
|
|
{
|
|
|
|
targetMem = this->state;
|
|
|
|
return targetMem;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleRigidBody::SetState( const SimpleRigidBody::State &state )
|
|
|
|
{
|
|
|
|
btTransform trans;
|
2014-02-10 15:46:55 +01:00
|
|
|
btVector3 position(state.centerPos.x, state.centerPos.y, state.centerPos.z);
|
|
|
|
btQuaternion quaternion(state.quaternion.imaginary.x, state.quaternion.imaginary.y, state.quaternion.imaginary.z, state.quaternion.real);
|
2014-02-10 14:50:40 +01:00
|
|
|
this->motionState->getWorldTransform(trans);
|
2014-02-10 15:46:55 +01:00
|
|
|
trans.setRotation(quaternion);
|
|
|
|
trans.setOrigin(position);
|
2014-02-10 14:50:40 +01:00
|
|
|
this->motionState->setWorldTransform(trans);
|
|
|
|
this->rigidBody->setFriction(state.staticFrictionCoeff);
|
|
|
|
this->rigidBody->setRestitution(state.restitutionCoeff);
|
|
|
|
btVector3 fallInertia(0, 0, 0);
|
|
|
|
collisionShape->calculateLocalInertia(state.mass, fallInertia);
|
|
|
|
this->rigidBody->setMassProps(state.mass, fallInertia);
|
|
|
|
|
|
|
|
this->state = state;
|
|
|
|
}
|
|
|
|
|
2014-02-12 08:50:10 +01:00
|
|
|
void SimpleRigidBody::ApplyImpulse(Float3 impulse)
|
|
|
|
{
|
2014-02-17 06:44:29 +01:00
|
|
|
this->rigidBody->applyCentralImpulse(btVector3(impulse.x, impulse.y, impulse.z));
|
2014-02-12 08:50:10 +01:00
|
|
|
}
|
|
|
|
|
2014-02-09 21:24:09 +01:00
|
|
|
void SimpleRigidBody::SetCollisionShape(btCollisionShape* shape)
|
2013-12-06 09:46:30 +01:00
|
|
|
{
|
2014-02-09 21:24:09 +01:00
|
|
|
this->collisionShape = shape;
|
2013-12-06 09:46:30 +01:00
|
|
|
}
|
|
|
|
|
2014-02-09 21:24:09 +01:00
|
|
|
void SimpleRigidBody::SetMotionState(btDefaultMotionState* motionState)
|
2013-12-06 09:46:30 +01:00
|
|
|
{
|
2014-02-09 21:24:09 +01:00
|
|
|
this->motionState = motionState;
|
2013-12-06 09:46:30 +01:00
|
|
|
}
|
|
|
|
|
2014-02-09 21:24:09 +01:00
|
|
|
void SimpleRigidBody::SetRigidBody(btRigidBody* rigidBody)
|
2013-12-19 10:53:55 +01:00
|
|
|
{
|
2014-02-09 21:24:09 +01:00
|
|
|
this->rigidBody = rigidBody;
|
2014-02-21 12:21:10 +01:00
|
|
|
this->collisionFlags = rigidBody->getCollisionFlags();
|
2013-11-21 17:22:13 +01:00
|
|
|
}
|
|
|
|
|
2014-02-09 21:24:09 +01:00
|
|
|
void SimpleRigidBody::SetSubscription(EventAction_AfterCollisionResponse function)
|
2013-11-21 17:22:13 +01:00
|
|
|
{
|
2014-02-09 21:24:09 +01:00
|
|
|
this->afterCollision = function;
|
2013-12-18 08:57:27 +01:00
|
|
|
}
|
|
|
|
|
2014-02-10 13:55:01 +01:00
|
|
|
void SimpleRigidBody::SetSubscription(EventAction_Move function)
|
|
|
|
{
|
|
|
|
this->onMovement = function;
|
|
|
|
}
|
|
|
|
|
2014-02-10 14:18:45 +01:00
|
|
|
void SimpleRigidBody::SetLinearVelocity(Float3 velocity)
|
|
|
|
{
|
|
|
|
this->rigidBody->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z));
|
|
|
|
}
|
|
|
|
|
2014-02-10 14:39:45 +01:00
|
|
|
void SimpleRigidBody::SetPosition(::Oyster::Math::Float3 position)
|
|
|
|
{
|
|
|
|
btTransform trans;
|
2014-02-12 13:55:43 +01:00
|
|
|
trans = this->rigidBody->getWorldTransform();
|
2014-02-10 14:39:45 +01:00
|
|
|
trans.setOrigin(btVector3(position.x, position.y, position.z));
|
2014-02-12 13:55:43 +01:00
|
|
|
this->rigidBody->setWorldTransform(trans);
|
2014-02-10 14:39:45 +01:00
|
|
|
this->state.centerPos = position;
|
|
|
|
}
|
|
|
|
|
2014-02-10 14:18:45 +01:00
|
|
|
void SimpleRigidBody::SetRotation(Float4 quaternion)
|
|
|
|
{
|
|
|
|
btTransform trans;
|
2014-02-12 13:55:43 +01:00
|
|
|
trans = this->rigidBody->getWorldTransform();
|
2014-02-10 14:18:45 +01:00
|
|
|
trans.setRotation(btQuaternion(quaternion.x, quaternion.y, quaternion.z, quaternion.w));
|
2014-02-12 13:55:43 +01:00
|
|
|
this->rigidBody->setWorldTransform(trans);
|
2014-02-10 14:39:45 +01:00
|
|
|
this->state.quaternion = Quaternion(quaternion.xyz, quaternion.w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleRigidBody::SetRotation(::Oyster::Math::Quaternion quaternion)
|
|
|
|
{
|
|
|
|
btTransform trans;
|
2014-02-12 13:55:43 +01:00
|
|
|
trans = this->rigidBody->getWorldTransform();
|
2014-02-10 14:39:45 +01:00
|
|
|
trans.setRotation(btQuaternion(quaternion.imaginary.x, quaternion.imaginary.y, quaternion.imaginary.z, quaternion.real));
|
2014-02-12 13:55:43 +01:00
|
|
|
this->rigidBody->setWorldTransform(trans);
|
2014-02-10 14:39:45 +01:00
|
|
|
this->state.quaternion = quaternion;
|
2014-02-10 14:18:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleRigidBody::SetRotation(Float3 eulerAngles)
|
|
|
|
{
|
|
|
|
btTransform trans;
|
2014-02-12 13:55:43 +01:00
|
|
|
trans = this->rigidBody->getWorldTransform();
|
2014-02-10 14:18:45 +01:00
|
|
|
trans.setRotation(btQuaternion(eulerAngles.x, eulerAngles.y, eulerAngles.z));
|
2014-02-12 13:55:43 +01:00
|
|
|
this->rigidBody->setWorldTransform(trans);
|
2014-02-10 14:39:45 +01:00
|
|
|
this->state.quaternion = Quaternion(Float3(trans.getRotation().x(), trans.getRotation().y(), trans.getRotation().z()), trans.getRotation().w());
|
|
|
|
}
|
|
|
|
|
2014-02-13 19:49:33 +01:00
|
|
|
void SimpleRigidBody::SetRotation(::Oyster::Math::Float4x4 rotation)
|
|
|
|
{
|
|
|
|
btTransform trans;
|
|
|
|
btMatrix3x3 newRotation;
|
|
|
|
btVector3 rightVector(rotation.v[0].x, rotation.v[0].y, rotation.v[0].z);
|
|
|
|
btVector3 upVector(rotation.v[1].x, rotation.v[1].y, rotation.v[1].z);
|
|
|
|
btVector3 forwardVector(rotation.v[2].x, rotation.v[2].y, rotation.v[2].z);
|
|
|
|
|
|
|
|
|
|
|
|
newRotation[0] = rightVector;
|
|
|
|
newRotation[1] = upVector;
|
|
|
|
newRotation[2] = forwardVector;
|
|
|
|
|
|
|
|
trans = this->rigidBody->getWorldTransform();
|
|
|
|
trans.setBasis(newRotation);
|
|
|
|
this->rigidBody->setWorldTransform(trans);
|
|
|
|
|
|
|
|
btQuaternion quaternion;
|
|
|
|
quaternion = trans.getRotation();
|
|
|
|
this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleRigidBody::SetRotationAsAngularAxis(::Oyster::Math::Float4 angularAxis)
|
|
|
|
{
|
|
|
|
if(angularAxis.xyz.GetMagnitude() == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-20 15:13:52 +01:00
|
|
|
float s = sin(angularAxis.w/2);
|
|
|
|
float x = angularAxis.x * s;
|
|
|
|
float y = angularAxis.y * s;
|
|
|
|
float z = angularAxis.z * s;
|
|
|
|
float w = cos(angularAxis.w/2);
|
|
|
|
|
2014-02-13 19:49:33 +01:00
|
|
|
btTransform trans;
|
|
|
|
btVector3 vector(angularAxis.x, angularAxis.y, angularAxis.z);
|
2014-02-20 15:13:52 +01:00
|
|
|
btQuaternion quaternion(x,y,z,w);
|
2014-02-13 19:49:33 +01:00
|
|
|
|
|
|
|
trans = this->rigidBody->getWorldTransform();
|
|
|
|
trans.setRotation(quaternion);
|
|
|
|
this->rigidBody->setWorldTransform(trans);
|
|
|
|
|
|
|
|
this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w());
|
|
|
|
}
|
|
|
|
|
2014-02-11 09:15:21 +01:00
|
|
|
void SimpleRigidBody::SetAngularFactor(Float factor)
|
|
|
|
{
|
|
|
|
this->rigidBody->setAngularFactor(factor);
|
|
|
|
}
|
|
|
|
|
2014-02-14 08:29:49 +01:00
|
|
|
void SimpleRigidBody::SetMass(Float mass)
|
|
|
|
{
|
|
|
|
btVector3 fallInertia(0, 0, 0);
|
|
|
|
collisionShape->calculateLocalInertia(mass, fallInertia);
|
|
|
|
this->rigidBody->setMassProps(mass, fallInertia);
|
|
|
|
this->state.mass = mass;
|
|
|
|
}
|
|
|
|
|
2014-02-11 13:09:46 +01:00
|
|
|
void SimpleRigidBody::SetGravity(Float3 gravity)
|
|
|
|
{
|
|
|
|
this->rigidBody->setGravity(btVector3(gravity.x, gravity.y, gravity.z));
|
|
|
|
this->gravity = gravity;
|
|
|
|
}
|
|
|
|
|
2014-02-11 09:15:21 +01:00
|
|
|
void SimpleRigidBody::SetUpAndRight(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 right)
|
|
|
|
{
|
2014-02-11 10:49:37 +01:00
|
|
|
btTransform trans;
|
2014-02-11 09:15:21 +01:00
|
|
|
btMatrix3x3 rotation;
|
|
|
|
btVector3 upVector(up.x, up.y, up.z);
|
|
|
|
btVector3 rightVector(right.x, right.y, right.z);
|
|
|
|
rotation[1] = upVector.normalized();
|
|
|
|
rotation[0] = rightVector.normalized();
|
2014-02-11 10:49:37 +01:00
|
|
|
rotation[2] = rightVector.cross(upVector).normalized();
|
2014-02-11 09:15:21 +01:00
|
|
|
|
2014-02-11 11:45:16 +01:00
|
|
|
trans = this->rigidBody->getWorldTransform();
|
2014-02-11 10:49:37 +01:00
|
|
|
trans.setBasis(rotation);
|
2014-02-11 11:45:16 +01:00
|
|
|
this->rigidBody->setWorldTransform(trans);
|
2014-02-11 10:49:37 +01:00
|
|
|
|
|
|
|
btQuaternion quaternion;
|
|
|
|
quaternion = trans.getRotation();
|
|
|
|
this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w());
|
2014-02-11 09:15:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleRigidBody::SetUpAndForward(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 forward)
|
|
|
|
{
|
2014-02-11 10:49:37 +01:00
|
|
|
btTransform trans;
|
2014-02-11 09:15:21 +01:00
|
|
|
btMatrix3x3 rotation;
|
|
|
|
btVector3 upVector(up.x, up.y, up.z);
|
|
|
|
btVector3 forwardVector(forward.x, forward.y, forward.z);
|
|
|
|
rotation[1] = upVector.normalized();
|
2014-02-11 10:49:37 +01:00
|
|
|
rotation[2] = forwardVector.normalized();
|
2014-02-13 19:49:33 +01:00
|
|
|
rotation[0] = upVector.cross(forwardVector).normalized();
|
2014-02-11 11:45:16 +01:00
|
|
|
trans = this->rigidBody->getWorldTransform();
|
2014-02-11 10:49:37 +01:00
|
|
|
trans.setBasis(rotation);
|
2014-02-11 11:45:16 +01:00
|
|
|
this->rigidBody->setWorldTransform(trans);
|
2014-02-11 10:49:37 +01:00
|
|
|
|
|
|
|
btQuaternion quaternion;
|
|
|
|
quaternion = trans.getRotation();
|
|
|
|
this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w());
|
2014-02-11 09:15:21 +01:00
|
|
|
}
|
|
|
|
|
2014-02-13 19:49:33 +01:00
|
|
|
void SimpleRigidBody::SetUp(::Oyster::Math::Float3 up)
|
|
|
|
{
|
|
|
|
Float3 vector = Float3(0, 1, 0).Cross(up);
|
|
|
|
|
|
|
|
if(vector == Float3::null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Float sine = vector.GetLength();
|
|
|
|
Float cosine = acos(Float3(0, 1, 0).Dot(up));
|
|
|
|
|
|
|
|
btQuaternion quaternion(btVector3(vector.x, vector.y, vector.z),cosine);
|
|
|
|
|
|
|
|
btTransform trans;
|
|
|
|
trans = this->rigidBody->getWorldTransform();
|
|
|
|
trans.setRotation(quaternion);
|
|
|
|
this->rigidBody->setWorldTransform(trans);
|
|
|
|
this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w());
|
|
|
|
}
|
|
|
|
|
2014-02-10 14:39:45 +01:00
|
|
|
Float4x4 SimpleRigidBody::GetRotation() const
|
|
|
|
{
|
|
|
|
return this->state.GetRotation();
|
|
|
|
}
|
2014-02-11 13:53:44 +01:00
|
|
|
Float4 SimpleRigidBody::GetRotationAsAngularAxis()
|
|
|
|
{
|
|
|
|
Float4 axis = Float4::null;
|
2014-02-20 15:13:52 +01:00
|
|
|
btTransform trans;
|
2014-02-11 13:53:44 +01:00
|
|
|
|
2014-02-20 15:13:52 +01:00
|
|
|
trans = this->rigidBody->getWorldTransform();
|
|
|
|
axis.xyz = trans.getRotation().getAxis();
|
|
|
|
axis.w = trans.getRotation().getAngle();
|
2014-02-11 13:53:44 +01:00
|
|
|
|
|
|
|
return axis;
|
|
|
|
}
|
2014-02-10 14:39:45 +01:00
|
|
|
|
|
|
|
Float4x4 SimpleRigidBody::GetOrientation() const
|
|
|
|
{
|
|
|
|
return this->state.GetOrientation();
|
|
|
|
}
|
|
|
|
|
|
|
|
Float4x4 SimpleRigidBody::GetView() const
|
|
|
|
{
|
|
|
|
return this->state.GetView();
|
|
|
|
}
|
|
|
|
|
|
|
|
Float4x4 SimpleRigidBody::GetView( const ::Oyster::Math::Float3 &offset ) const
|
|
|
|
{
|
|
|
|
return this->state.GetView(offset);
|
2014-02-10 14:18:45 +01:00
|
|
|
}
|
|
|
|
|
2014-02-13 19:49:33 +01:00
|
|
|
Float3 SimpleRigidBody::GetGravity() const
|
|
|
|
{
|
2014-02-18 10:12:21 +01:00
|
|
|
btVector3 gravity = this->rigidBody->getGravity();
|
|
|
|
return Float3(gravity.x(), gravity.y(), gravity.z());
|
2014-02-13 19:49:33 +01:00
|
|
|
}
|
|
|
|
Float3 SimpleRigidBody::GetLinearVelocity() const
|
|
|
|
{
|
2014-02-18 10:12:21 +01:00
|
|
|
btVector3 linearVelocity = this->rigidBody->getLinearVelocity();
|
|
|
|
return Float3(linearVelocity.x(), linearVelocity.y(), linearVelocity.z());
|
2014-02-13 19:49:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-10 13:55:01 +01:00
|
|
|
void SimpleRigidBody::CallSubscription_AfterCollisionResponse(ICustomBody* bodyA, ICustomBody* bodyB, Oyster::Math::Float kineticEnergyLoss)
|
2013-12-18 08:57:27 +01:00
|
|
|
{
|
2014-02-10 15:46:55 +01:00
|
|
|
if(this->afterCollision)
|
2014-02-10 13:55:01 +01:00
|
|
|
this->afterCollision(bodyA, bodyB, kineticEnergyLoss);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleRigidBody::CallSubscription_Move()
|
|
|
|
{
|
|
|
|
if(this->onMovement)
|
|
|
|
this->onMovement(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
btCollisionShape* SimpleRigidBody::GetCollisionShape() const
|
|
|
|
{
|
|
|
|
return this->collisionShape;
|
2013-11-21 17:22:13 +01:00
|
|
|
}
|
|
|
|
|
2014-02-09 21:24:09 +01:00
|
|
|
btDefaultMotionState* SimpleRigidBody::GetMotionState() const
|
2014-02-03 15:48:42 +01:00
|
|
|
{
|
2014-02-09 21:24:09 +01:00
|
|
|
return this->motionState;
|
2014-02-03 15:48:42 +01:00
|
|
|
}
|
|
|
|
|
2014-02-10 13:55:01 +01:00
|
|
|
btRigidBody* SimpleRigidBody::GetRigidBody() const
|
|
|
|
{
|
|
|
|
return this->rigidBody;
|
|
|
|
}
|
|
|
|
|
2014-01-20 13:44:12 +01:00
|
|
|
void * SimpleRigidBody::GetCustomTag() const
|
|
|
|
{
|
|
|
|
return this->customTag;
|
|
|
|
}
|
|
|
|
|
2013-11-26 13:27:34 +01:00
|
|
|
|
2014-01-20 13:44:12 +01:00
|
|
|
void SimpleRigidBody::SetCustomTag( void *ref )
|
|
|
|
{
|
|
|
|
this->customTag = ref;
|
2014-02-14 11:52:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SimpleRigidBody::PreStep (const btCollisionWorld* collisionWorld)
|
|
|
|
{
|
|
|
|
btTransform xform;
|
2014-02-17 06:44:29 +01:00
|
|
|
xform = this->rigidBody->getWorldTransform ();
|
2014-02-20 15:13:52 +01:00
|
|
|
Float3 normalDown = -this->state.centerPos.GetNormalized();
|
|
|
|
btVector3 down(normalDown.x, normalDown.y, normalDown.z);
|
2014-02-14 11:52:44 +01:00
|
|
|
btVector3 forward = xform.getBasis()[2];
|
|
|
|
down.normalize ();
|
|
|
|
forward.normalize();
|
|
|
|
|
|
|
|
this->raySource[0] = xform.getOrigin();
|
|
|
|
this->raySource[1] = xform.getOrigin();
|
|
|
|
|
2014-02-20 15:13:52 +01:00
|
|
|
if(this->state.reach.y < 1.0f)
|
|
|
|
|
|
|
|
|
2014-02-17 06:44:29 +01:00
|
|
|
Float angle = acos(Float3(0, 1, 0).Dot(this->state.centerPos.GetNormalized()));
|
2014-02-20 15:13:52 +01:00
|
|
|
//down.setZ(-down.z());
|
2014-02-17 06:44:29 +01:00
|
|
|
btVector3 targetPlus = down * this->state.reach.y * btScalar(1.1);
|
|
|
|
|
2014-02-20 15:13:52 +01:00
|
|
|
if(this->state.mass == 40)
|
|
|
|
{
|
|
|
|
const char* breakpoint = "STOP";
|
|
|
|
}
|
2014-02-17 06:44:29 +01:00
|
|
|
|
|
|
|
this->rayTarget[0] = this->raySource[0] + targetPlus;
|
2014-02-14 11:52:44 +01:00
|
|
|
this->rayTarget[1] = this->raySource[1] + forward * this->state.reach.y * btScalar(1.1);
|
|
|
|
|
|
|
|
class ClosestNotMe : public btCollisionWorld::ClosestRayResultCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ClosestNotMe (btRigidBody* me) : btCollisionWorld::ClosestRayResultCallback(btVector3(0.0, 0.0, 0.0), btVector3(0.0, 0.0, 0.0))
|
|
|
|
{
|
|
|
|
m_me = me;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult,bool normalInWorldSpace)
|
|
|
|
{
|
|
|
|
if (rayResult.m_collisionObject == m_me)
|
|
|
|
return 1.0;
|
|
|
|
return ClosestRayResultCallback::addSingleResult (rayResult, normalInWorldSpace);
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
btRigidBody* m_me;
|
|
|
|
};
|
|
|
|
|
|
|
|
ClosestNotMe rayCallback(this->rigidBody);
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
rayCallback.m_closestHitFraction = 1.0;
|
|
|
|
if((this->raySource[i] - this->rayTarget[i]).length() != 0)
|
|
|
|
collisionWorld->rayTest (this->raySource[i], this->rayTarget[i], rayCallback);
|
|
|
|
if (rayCallback.hasHit())
|
|
|
|
{
|
|
|
|
this->rayLambda[i] = rayCallback.m_closestHitFraction;
|
2014-02-17 06:44:29 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-14 11:52:44 +01:00
|
|
|
this->rayLambda[i] = 1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-17 06:44:29 +01:00
|
|
|
float SimpleRigidBody::GetLambda() const
|
2014-02-14 11:52:44 +01:00
|
|
|
{
|
|
|
|
return this->rayLambda[0];
|
2014-02-20 15:45:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleRigidBody::MoveToLimbo()
|
|
|
|
{
|
|
|
|
this->rigidBody->setCollisionFlags(this->rigidBody->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleRigidBody::ReleaseFromLimbo()
|
|
|
|
{
|
2014-02-21 12:21:10 +01:00
|
|
|
this->rigidBody->setCollisionFlags(this->collisionFlags);
|
2014-02-21 09:54:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void SimpleRigidBody::SetPreviousVelocity(::Oyster::Math::Float3 velocity)
|
|
|
|
{
|
|
|
|
this->state.previousVelocity = velocity;
|
2014-02-13 19:49:33 +01:00
|
|
|
}
|