2013-12-06 09:46:30 +01:00
|
|
|
#ifndef PHYSICS_API_H
|
2013-11-20 11:09:27 +01:00
|
|
|
#define PHYSICS_API_H
|
|
|
|
|
2013-11-21 15:19:32 +01:00
|
|
|
#include "OysterCollision3D.h"
|
2013-11-20 11:09:27 +01:00
|
|
|
#include "OysterMath.h"
|
|
|
|
|
2013-11-25 12:21:44 +01:00
|
|
|
#if defined PHYSICS_DLL_EXPORT
|
|
|
|
#define PHYSICS_DLL_USAGE __declspec(dllexport)
|
2013-11-25 11:47:42 +01:00
|
|
|
#else
|
2013-11-25 12:21:44 +01:00
|
|
|
#define PHYSICS_DLL_USAGE __declspec(dllimport)
|
2013-11-25 11:47:42 +01:00
|
|
|
#endif
|
|
|
|
|
2013-11-20 11:09:27 +01:00
|
|
|
namespace Oyster
|
|
|
|
{
|
|
|
|
namespace Physics
|
|
|
|
{
|
|
|
|
class API;
|
2013-11-21 17:22:13 +01:00
|
|
|
class ICustomBody;
|
2013-11-20 11:09:27 +01:00
|
|
|
|
2013-12-06 09:46:30 +01:00
|
|
|
namespace Struct
|
|
|
|
{
|
|
|
|
struct SimpleBodyDescription;
|
|
|
|
struct SphericalBodyDescription;
|
|
|
|
struct CustomBodyState;
|
2014-01-15 10:44:31 +01:00
|
|
|
struct Gravity;
|
2013-12-06 09:46:30 +01:00
|
|
|
}
|
|
|
|
|
2013-11-21 15:19:32 +01:00
|
|
|
enum UpdateState
|
|
|
|
{
|
2013-11-28 10:26:29 +01:00
|
|
|
UpdateState_resting,
|
|
|
|
UpdateState_altered
|
2013-11-21 15:19:32 +01:00
|
|
|
};
|
|
|
|
|
2013-11-20 11:09:27 +01:00
|
|
|
namespace Constant
|
|
|
|
{
|
2013-11-25 08:57:47 +01:00
|
|
|
const float gravity_constant = (const float)6.67284e-11; //!< The _big_G_! ( N(m/kg)^2 ) Used in real gravityforcefields.
|
2014-01-31 13:41:06 +01:00
|
|
|
const float epsilon = (const float)1.0e-3;
|
2013-11-20 11:09:27 +01:00
|
|
|
}
|
|
|
|
|
2013-11-25 12:21:44 +01:00
|
|
|
class PHYSICS_DLL_USAGE API
|
2013-11-20 11:09:27 +01:00
|
|
|
{
|
|
|
|
public:
|
2013-12-06 09:46:30 +01:00
|
|
|
typedef Struct::SimpleBodyDescription SimpleBodyDescription;
|
|
|
|
typedef Struct::SphericalBodyDescription SphericalBodyDescription;
|
2014-01-15 10:44:31 +01:00
|
|
|
typedef Struct::Gravity Gravity;
|
2013-11-28 11:58:46 +01:00
|
|
|
|
2013-11-25 16:57:38 +01:00
|
|
|
typedef void (*EventAction_Destruction)( ::Utility::DynamicMemory::UniquePointer<ICustomBody> proto );
|
2013-11-20 11:09:27 +01:00
|
|
|
|
2013-11-25 08:57:47 +01:00
|
|
|
/** Gets the Physics instance. */
|
2013-11-25 12:21:44 +01:00
|
|
|
static API & Instance();
|
2013-11-20 11:09:27 +01:00
|
|
|
|
2013-11-26 13:27:34 +01:00
|
|
|
/********************************************************
|
|
|
|
* Clears all content and reset Engine assetts such as buffers.
|
|
|
|
* @param numObjects: The predicted max number of active objects.
|
|
|
|
* @param numGravityWells: The predicted max number of active gravity wells.
|
|
|
|
* @param worldSize: The size of acceptable physics space.
|
|
|
|
********************************************************/
|
2014-02-09 21:24:09 +01:00
|
|
|
virtual void Init() = 0;
|
2013-11-20 11:09:27 +01:00
|
|
|
|
2013-11-25 08:57:47 +01:00
|
|
|
/********************************************************
|
|
|
|
* An object in limbo state will be ignored during the physics frame Update.
|
2013-11-25 10:54:27 +01:00
|
|
|
* @param objRef: A pointer to the ICustomBody representing a physical object.
|
2013-11-25 08:57:47 +01:00
|
|
|
* @return true if object is in limbo state.
|
|
|
|
********************************************************/
|
2013-11-25 10:54:27 +01:00
|
|
|
virtual bool IsInLimbo( const ICustomBody* objRef ) = 0;
|
2013-11-25 08:57:47 +01:00
|
|
|
|
|
|
|
/********************************************************
|
|
|
|
* An object in limbo state will be ignored during the physics frame Update.
|
|
|
|
* This will put an object in Limbo state.
|
2013-11-25 10:54:27 +01:00
|
|
|
* @param objRef: A pointer to the ICustomBody representing a physical object.
|
2013-11-25 08:57:47 +01:00
|
|
|
********************************************************/
|
2013-11-25 10:54:27 +01:00
|
|
|
virtual void MoveToLimbo( const ICustomBody* objRef ) = 0;
|
2013-11-25 08:57:47 +01:00
|
|
|
|
|
|
|
/********************************************************
|
|
|
|
* An object in limbo state will be ignored during the physics frame Update.
|
|
|
|
* This will clear the accumulated force/torque and remove the Limbo state.
|
2013-11-25 10:54:27 +01:00
|
|
|
* @param objRef: A pointer to the ICustomBody representing a physical object.
|
2013-11-25 08:57:47 +01:00
|
|
|
********************************************************/
|
2013-11-25 10:54:27 +01:00
|
|
|
virtual void ReleaseFromLimbo( const ICustomBody* objRef ) = 0;
|
2013-11-20 11:09:27 +01:00
|
|
|
|
2014-02-11 13:36:14 +01:00
|
|
|
virtual void SetGravityPoint(::Oyster::Math::Float3 gravityPoint) = 0;
|
|
|
|
virtual void SetGravity(float gravity) = 0;
|
2013-11-25 08:57:47 +01:00
|
|
|
|
2014-02-09 21:24:09 +01:00
|
|
|
// Bullet physics
|
2014-02-10 14:18:45 +01:00
|
|
|
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;
|
2014-02-09 21:24:09 +01:00
|
|
|
|
2014-02-11 09:15:21 +01:00
|
|
|
virtual void SetTimeStep(float timeStep) = 0;
|
|
|
|
|
2014-02-09 21:24:09 +01:00
|
|
|
virtual void UpdateWorld() = 0;
|
2013-11-21 17:22:13 +01:00
|
|
|
|
2014-01-15 10:44:31 +01:00
|
|
|
|
|
|
|
|
2014-01-22 12:36:12 +01:00
|
|
|
/********************************************************
|
|
|
|
* Applies an effect to objects that collide with the set volume.
|
|
|
|
* @param collideable: An ICollideable that defines the volume of the effect.
|
2014-01-28 10:18:26 +01:00
|
|
|
* @param args: The arguments needed for the hitAction function.
|
|
|
|
* @param hitAction: A function that contains the effect. Parameterlist contains the custom body
|
|
|
|
the collideable hits, and the arguments sent to the function.
|
2014-01-22 12:36:12 +01:00
|
|
|
********************************************************/
|
2014-01-28 10:18:26 +01:00
|
|
|
virtual void ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void* args, void(hitAction)(ICustomBody*, void*) ) = 0;
|
2014-01-21 14:10:31 +01:00
|
|
|
|
2013-11-21 17:22:13 +01:00
|
|
|
protected:
|
|
|
|
virtual ~API() {}
|
2013-11-20 11:09:27 +01:00
|
|
|
};
|
2013-12-19 11:46:11 +01:00
|
|
|
|
|
|
|
|
2013-11-25 13:46:05 +01:00
|
|
|
//! The root interface for all physical representations processable by the engine.
|
2013-11-25 12:21:44 +01:00
|
|
|
class PHYSICS_DLL_USAGE ICustomBody
|
2013-11-20 11:09:27 +01:00
|
|
|
{
|
2013-12-19 11:46:11 +01:00
|
|
|
|
2013-11-20 11:09:27 +01:00
|
|
|
public:
|
2013-11-28 10:26:29 +01:00
|
|
|
enum SubscriptMessage
|
|
|
|
{
|
|
|
|
SubscriptMessage_none,
|
2014-01-22 13:50:54 +01:00
|
|
|
SubscriptMessage_kineticLoss,
|
2014-02-05 11:46:04 +01:00
|
|
|
SubscriptMessage_ignore_collision_response,
|
|
|
|
SubscriptMessage_player_collision_response
|
2013-11-28 10:26:29 +01:00
|
|
|
};
|
|
|
|
|
2014-02-09 21:24:09 +01:00
|
|
|
|
2014-01-29 11:22:04 +01:00
|
|
|
typedef SubscriptMessage (*EventAction_BeforeCollisionResponse)( const ICustomBody *proto, const ICustomBody *deuter );
|
|
|
|
typedef void (*EventAction_AfterCollisionResponse)( const ICustomBody *proto, const ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss );
|
2014-01-17 16:07:25 +01:00
|
|
|
typedef void (*EventAction_Move)( const ICustomBody *object );
|
2013-12-06 09:46:30 +01:00
|
|
|
typedef Struct::CustomBodyState State;
|
2013-11-28 10:26:29 +01:00
|
|
|
|
2013-11-21 17:22:13 +01:00
|
|
|
virtual ~ICustomBody() {};
|
2013-11-21 15:19:32 +01:00
|
|
|
|
2014-02-10 14:50:40 +01:00
|
|
|
virtual State GetState() const = 0;
|
|
|
|
virtual State & GetState( State &targetMem ) const = 0;
|
|
|
|
virtual void SetState( const State &state ) = 0;
|
2013-12-06 09:46:30 +01:00
|
|
|
|
2014-02-09 21:24:09 +01:00
|
|
|
virtual void SetSubscription(EventAction_AfterCollisionResponse function) = 0;
|
2014-02-10 13:55:01 +01:00
|
|
|
virtual void SetSubscription(EventAction_Move function) = 0;
|
|
|
|
|
2014-02-10 14:18:45 +01:00
|
|
|
virtual void SetLinearVelocity(::Oyster::Math::Float3 velocity) = 0;
|
2014-02-10 14:39:45 +01:00
|
|
|
virtual void SetPosition(::Oyster::Math::Float3 position) = 0;
|
2014-02-10 14:18:45 +01:00
|
|
|
virtual void SetRotation(::Oyster::Math::Float4 quaternion) = 0;
|
2014-02-10 14:39:45 +01:00
|
|
|
virtual void SetRotation(::Oyster::Math::Quaternion quaternion) = 0;
|
2014-02-10 14:18:45 +01:00
|
|
|
virtual void SetRotation(::Oyster::Math::Float3 eulerAngles) = 0;
|
2014-02-11 09:15:21 +01:00
|
|
|
virtual void SetAngularFactor(::Oyster::Math::Float factor) = 0;
|
|
|
|
|
2014-02-11 13:09:46 +01:00
|
|
|
virtual void SetGravity(::Oyster::Math::Float3 gravity) = 0;
|
|
|
|
|
2014-02-11 09:15:21 +01:00
|
|
|
virtual void SetUpAndRight(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 right) = 0;
|
|
|
|
virtual void SetUpAndForward(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 forward) = 0;
|
2013-11-26 13:27:34 +01:00
|
|
|
|
2014-02-11 13:53:44 +01:00
|
|
|
virtual ::Oyster::Math::Float4x4 GetRotation() const = 0;
|
|
|
|
virtual ::Oyster::Math::Float4 GetRotationAsAngularAxis() = 0;
|
|
|
|
virtual ::Oyster::Math::Float4x4 GetOrientation() const = 0;
|
|
|
|
virtual ::Oyster::Math::Float4x4 GetView() const = 0;
|
|
|
|
virtual ::Oyster::Math::Float4x4 GetView(const ::Oyster::Math::Float3 &offset) const = 0;
|
2014-02-10 14:39:45 +01:00
|
|
|
|
2014-01-20 13:44:12 +01:00
|
|
|
/********************************************************
|
|
|
|
* @return the void pointer set by SetCustomTag.
|
|
|
|
* nullptr if none is set.
|
|
|
|
********************************************************/
|
2014-02-09 21:24:09 +01:00
|
|
|
virtual void* GetCustomTag() const = 0;
|
2013-11-26 13:27:34 +01:00
|
|
|
|
2014-01-20 13:44:12 +01:00
|
|
|
/********************************************************
|
|
|
|
* Not used by the engine itself. Just a quality of life feature
|
|
|
|
* for developers who want to tag something to the objects.
|
|
|
|
* @param ref: Anything castable to a void pointer, the engine won't care.
|
|
|
|
********************************************************/
|
|
|
|
virtual void SetCustomTag( void *ref ) = 0;
|
2013-11-20 11:09:27 +01:00
|
|
|
};
|
2013-11-21 17:22:13 +01:00
|
|
|
}
|
2013-11-20 11:09:27 +01:00
|
|
|
}
|
2013-12-06 09:46:30 +01:00
|
|
|
|
|
|
|
#include "PhysicsStructs.h"
|
2013-12-16 08:58:15 +01:00
|
|
|
#include "PhysicsFormula.h"
|
2013-12-06 09:46:30 +01:00
|
|
|
|
2013-11-20 11:09:27 +01:00
|
|
|
#endif
|