Added more data for bodies and added cylinder
This commit is contained in:
parent
05aa3cc9e9
commit
c18eb668aa
|
@ -47,7 +47,7 @@ API_Impl::~API_Impl()
|
|||
}
|
||||
|
||||
// Bullet physics
|
||||
ICustomBody* API_Impl::AddCollisionSphere(float radius, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass)
|
||||
ICustomBody* API_Impl::AddCollisionSphere(float radius, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction)
|
||||
{
|
||||
SimpleRigidBody* body = new SimpleRigidBody;
|
||||
|
||||
|
@ -73,7 +73,8 @@ ICustomBody* API_Impl::AddCollisionSphere(float radius, ::Oyster::Math::Float4 r
|
|||
|
||||
return body;
|
||||
}
|
||||
ICustomBody* API_Impl::AddCollisionBox(Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass)
|
||||
|
||||
ICustomBody* API_Impl::AddCollisionBox(Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction)
|
||||
{
|
||||
SimpleRigidBody* body = new SimpleRigidBody;
|
||||
|
||||
|
@ -100,6 +101,33 @@ ICustomBody* API_Impl::AddCollisionBox(Float3 halfSize, ::Oyster::Math::Float4 r
|
|||
return body;
|
||||
}
|
||||
|
||||
ICustomBody* API_Impl::AddCollisionCylinder(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction)
|
||||
{
|
||||
SimpleRigidBody* body = new SimpleRigidBody;
|
||||
|
||||
// Add collision shape
|
||||
btCollisionShape* collisionShape = new btCylinderShape(btVector3(halfSize.x, halfSize.y, halfSize.z));
|
||||
body->SetCollisionShape(collisionShape);
|
||||
|
||||
// Add motion state
|
||||
btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w),btVector3(position.x, position.y, position.z)));
|
||||
body->SetMotionState(motionState);
|
||||
|
||||
// Add rigid body
|
||||
btVector3 fallInertia(0, 0, 0);
|
||||
collisionShape->calculateLocalInertia(mass, fallInertia);
|
||||
btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(mass, motionState, collisionShape, fallInertia);
|
||||
btRigidBody* rigidBody = new btRigidBody(rigidBodyCI);
|
||||
rigidBody->setUserPointer(body);
|
||||
body->SetRigidBody(rigidBody);
|
||||
|
||||
// Add rigid body to world
|
||||
this->dynamicsWorld->addRigidBody(rigidBody);
|
||||
this->customBodies.push_back(body);
|
||||
|
||||
return body;
|
||||
}
|
||||
|
||||
void API_Impl::UpdateWorld()
|
||||
{
|
||||
this->dynamicsWorld->stepSimulation(1.0f/60.0f, 1.0f, 1.0f/60.0f);
|
||||
|
|
|
@ -22,8 +22,9 @@ namespace Oyster
|
|||
void ReleaseFromLimbo( const ICustomBody* objRef );
|
||||
|
||||
// Bullet physics
|
||||
ICustomBody* AddCollisionSphere(float radius, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass);
|
||||
ICustomBody* AddCollisionBox(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass);
|
||||
ICustomBody* AddCollisionSphere(float radius, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction);
|
||||
ICustomBody* AddCollisionBox(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction);
|
||||
ICustomBody* AddCollisionCylinder(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction);
|
||||
|
||||
void UpdateWorld();
|
||||
|
||||
|
|
|
@ -64,6 +64,27 @@ void SimpleRigidBody::SetSubscription(EventAction_Move function)
|
|||
this->onMovement = function;
|
||||
}
|
||||
|
||||
void SimpleRigidBody::SetLinearVelocity(Float3 velocity)
|
||||
{
|
||||
this->rigidBody->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z));
|
||||
}
|
||||
|
||||
void SimpleRigidBody::SetRotation(Float4 quaternion)
|
||||
{
|
||||
btTransform trans;
|
||||
this->motionState->getWorldTransform(trans);
|
||||
trans.setRotation(btQuaternion(quaternion.x, quaternion.y, quaternion.z, quaternion.w));
|
||||
this->motionState->setWorldTransform(trans);
|
||||
}
|
||||
|
||||
void SimpleRigidBody::SetRotation(Float3 eulerAngles)
|
||||
{
|
||||
btTransform trans;
|
||||
this->motionState->getWorldTransform(trans);
|
||||
trans.setRotation(btQuaternion(eulerAngles.x, eulerAngles.y, eulerAngles.z));
|
||||
this->motionState->setWorldTransform(trans);
|
||||
}
|
||||
|
||||
void SimpleRigidBody::CallSubscription_AfterCollisionResponse(ICustomBody* bodyA, ICustomBody* bodyB, Oyster::Math::Float kineticEnergyLoss)
|
||||
{
|
||||
if(this->onMovement)
|
||||
|
|
|
@ -21,6 +21,10 @@ namespace Oyster
|
|||
void SetSubscription(EventAction_AfterCollisionResponse function);
|
||||
void SetSubscription(EventAction_Move function);
|
||||
|
||||
void SetLinearVelocity(Math::Float3 velocity);
|
||||
void SetRotation(Math::Float4 quaternion);
|
||||
void SetRotation(Math::Float3 eulerAngles);
|
||||
|
||||
void CallSubscription_AfterCollisionResponse(ICustomBody* bodyA, ICustomBody* bodyB, Math::Float kineticEnergyLoss);
|
||||
void CallSubscription_Move();
|
||||
|
||||
|
|
|
@ -80,9 +80,9 @@ namespace Oyster
|
|||
|
||||
|
||||
// Bullet physics
|
||||
virtual ICustomBody* AddCollisionSphere(float radius, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass) = 0;
|
||||
|
||||
virtual ICustomBody* AddCollisionBox(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass) = 0;
|
||||
virtual ICustomBody* AddCollisionSphere(float radius, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction) = 0;
|
||||
virtual ICustomBody* AddCollisionBox(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction) = 0;
|
||||
virtual ICustomBody* AddCollisionCylinder(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction) = 0;
|
||||
|
||||
virtual void UpdateWorld() = 0;
|
||||
|
||||
|
@ -144,6 +144,9 @@ namespace Oyster
|
|||
virtual void SetSubscription(EventAction_AfterCollisionResponse function) = 0;
|
||||
virtual void SetSubscription(EventAction_Move function) = 0;
|
||||
|
||||
virtual void SetLinearVelocity(::Oyster::Math::Float3 velocity) = 0;
|
||||
virtual void SetRotation(::Oyster::Math::Float4 quaternion) = 0;
|
||||
virtual void SetRotation(::Oyster::Math::Float3 eulerAngles) = 0;
|
||||
|
||||
/********************************************************
|
||||
* @return the void pointer set by SetCustomTag.
|
||||
|
|
|
@ -30,8 +30,13 @@ namespace Oyster
|
|||
::Oyster::Math::Float4x4 GetOrientation() const;
|
||||
::Oyster::Math::Float4x4 GetView() const;
|
||||
::Oyster::Math::Float4x4 GetView( const ::Oyster::Math::Float3 &offset ) const;
|
||||
void CustomBodyState::ApplyFriction( const ::Oyster::Math::Float3 &j);
|
||||
|
||||
::Oyster::Math::Float GetMass() const;
|
||||
::Oyster::Math::Float GetStaticFriction() const;
|
||||
::Oyster::Math::Float GetDynamicFriction() const;
|
||||
::Oyster::Math::Float GetRestitution() const;
|
||||
|
||||
|
||||
// Variables for state
|
||||
::Oyster::Math::Float mass, restitutionCoeff, staticFrictionCoeff, dynamicFrictionCoeff;
|
||||
::Oyster::Math::Float3 reach, centerPos;
|
||||
|
|
Loading…
Reference in New Issue