Added more API & ICustomBody methods

API::Init
ICustomBody::SetSubscription
Gravity related calls
moved DLLMain.cpp
This commit is contained in:
Dander7BD 2013-11-26 13:27:34 +01:00
parent 2890c2a9ea
commit 29362c8c60
8 changed files with 126 additions and 13 deletions

View File

@ -152,12 +152,14 @@
<ClInclude Include="Implementation\Octree.h" /> <ClInclude Include="Implementation\Octree.h" />
<ClInclude Include="Implementation\PhysicsAPI_Impl.h" /> <ClInclude Include="Implementation\PhysicsAPI_Impl.h" />
<ClInclude Include="Implementation\SimpleRigidBody.h" /> <ClInclude Include="Implementation\SimpleRigidBody.h" />
<ClInclude Include="Implementation\SphericalRigidBody.h" />
<ClInclude Include="PhysicsAPI.h" /> <ClInclude Include="PhysicsAPI.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Implementation\DLLMain.cpp" />
<ClCompile Include="Implementation\PhysicsAPI_Impl.cpp" /> <ClCompile Include="Implementation\PhysicsAPI_Impl.cpp" />
<ClCompile Include="Implementation\SimpleRigidBody.cpp" /> <ClCompile Include="Implementation\SimpleRigidBody.cpp" />
<ClCompile Include="DLLMain.cpp" /> <ClCompile Include="Implementation\SphericalRigidBody.cpp" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

View File

@ -30,6 +30,9 @@
<ClInclude Include="Implementation\SimpleRigidBody.h"> <ClInclude Include="Implementation\SimpleRigidBody.h">
<Filter>Header Files\Implementation</Filter> <Filter>Header Files\Implementation</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Implementation\SphericalRigidBody.h">
<Filter>Header Files\Implementation</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Implementation\PhysicsAPI_Impl.cpp"> <ClCompile Include="Implementation\PhysicsAPI_Impl.cpp">
@ -38,7 +41,10 @@
<ClCompile Include="Implementation\SimpleRigidBody.cpp"> <ClCompile Include="Implementation\SimpleRigidBody.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="DLLMain.cpp"> <ClCompile Include="Implementation\DLLMain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Implementation\SphericalRigidBody.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>

View File

@ -57,6 +57,11 @@ API_Impl::API_Impl()
API_Impl::~API_Impl() {} API_Impl::~API_Impl() {}
void API_Impl::Init( unsigned int numObjects, unsigned int numGravityWells , const Float3 &worldSize )
{
//! @todo TODO: implement stub
}
void API_Impl::SetDeltaTime( float deltaTime ) void API_Impl::SetDeltaTime( float deltaTime )
{ {
updateFrameLength = deltaTime; updateFrameLength = deltaTime;
@ -155,6 +160,11 @@ void API_Impl::SetOrientation( const ICustomBody* objRef, const Float4x4 &orient
//! @todo TODO: implement stub //! @todo TODO: implement stub
} }
void API_Impl::SetSize( const ICustomBody* objRef, const Float3 &size )
{
//! @todo TODO: implement stub
}
UniquePointer<ICustomBody> API_Impl::CreateSimpleRigidBody() const UniquePointer<ICustomBody> API_Impl::CreateSimpleRigidBody() const
{ {
return new SimpleRigidBody(); return new SimpleRigidBody();

View File

@ -13,6 +13,8 @@ namespace Oyster
API_Impl(); API_Impl();
virtual ~API_Impl(); virtual ~API_Impl();
void Init( unsigned int numObjects, unsigned int numGravityWells , const ::Oyster::Math::Float3 &worldSize );
void SetDeltaTime( float deltaTime ); void SetDeltaTime( float deltaTime );
void SetGravityConstant( float g ); void SetGravityConstant( float g );
void SetAction( EventAction_Collision functionPointer ); void SetAction( EventAction_Collision functionPointer );
@ -38,6 +40,7 @@ namespace Oyster
void SetCenter( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos ); void SetCenter( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos );
void SetRotation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &rotation ); void SetRotation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &rotation );
void SetOrientation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &orientation ); void SetOrientation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &orientation );
void SetSize( const ICustomBody* objRef, const ::Oyster::Math::Float3 &size );
::Utility::DynamicMemory::UniquePointer<ICustomBody> CreateSimpleRigidBody() const; ::Utility::DynamicMemory::UniquePointer<ICustomBody> CreateSimpleRigidBody() const;
private: private:

View File

@ -7,7 +7,11 @@ using namespace ::Oyster::Collision3D;
using namespace ::Utility::DynamicMemory; using namespace ::Utility::DynamicMemory;
using namespace ::Utility::Value; using namespace ::Utility::Value;
SimpleRigidBody::SimpleRigidBody() : previous(), current() {} SimpleRigidBody::SimpleRigidBody()
: previous(), current(),
gravityNormal(0.0f),
subscribeCollision(true),
ignoreGravity(false) {}
SimpleRigidBody::~SimpleRigidBody() {} SimpleRigidBody::~SimpleRigidBody() {}
@ -18,7 +22,12 @@ UniquePointer<ICustomBody> SimpleRigidBody::Clone() const
bool SimpleRigidBody::IsSubscribingCollisions() const bool SimpleRigidBody::IsSubscribingCollisions() const
{ // Assumption { // Assumption
return true; return this->subscribeCollision;
}
bool SimpleRigidBody::IsAffectedByGravity() const
{
return !this->ignoreGravity;
} }
bool SimpleRigidBody::Intersects( const ICustomBody &object, Float timeStepLength, Float &deltaWhen, Float3 &worldPointOfContact ) const bool SimpleRigidBody::Intersects( const ICustomBody &object, Float timeStepLength, Float &deltaWhen, Float3 &worldPointOfContact ) const
@ -51,6 +60,11 @@ Float3 & SimpleRigidBody::GetNormalAt( const Float3 &worldPos, Float3 &targetMem
return targetMem = (worldPos - this->current.box.center).GetNormalized(); return targetMem = (worldPos - this->current.box.center).GetNormalized();
} }
Float3 & SimpleRigidBody::GetGravityNormal( Float3 &targetMem ) const
{
return targetMem = this->gravityNormal;
}
Float3 & SimpleRigidBody::GetCenter( Float3 &targetMem ) const Float3 & SimpleRigidBody::GetCenter( Float3 &targetMem ) const
{ {
return targetMem = this->current.box.center; return targetMem = this->current.box.center;
@ -81,6 +95,22 @@ UpdateState SimpleRigidBody::Update( Float timeStepLength )
return this->current == this->previous ? resting : altered; return this->current == this->previous ? resting : altered;
} }
void SimpleRigidBody::SetGravity( bool ignore)
{
this->ignoreGravity = ignore;
this->gravityNormal = Float3::null;
}
void SimpleRigidBody::SetGravityNormal( const Float3 &normalizedVector )
{
this->gravityNormal = normalizedVector;
}
void SimpleRigidBody::SetSubscription( bool subscribeCollision )
{
this->subscribeCollision = subscribeCollision;
}
void SimpleRigidBody::SetMomentOfInertiaTensor_KeepVelocity( const Float4x4 &localI ) void SimpleRigidBody::SetMomentOfInertiaTensor_KeepVelocity( const Float4x4 &localI )
{ {
this->current.SetMomentOfInertia_KeepVelocity( localI ); this->current.SetMomentOfInertia_KeepVelocity( localI );
@ -115,3 +145,8 @@ void SimpleRigidBody::SetOrientation( const Float4x4 &orientation )
{ {
this->current.SetOrientation( orientation ); this->current.SetOrientation( orientation );
} }
void SimpleRigidBody::SetSize( const Float3 &size )
{
this->current.SetSize( size );
}

View File

@ -15,11 +15,13 @@ namespace Oyster { namespace Physics
::Utility::DynamicMemory::UniquePointer<ICustomBody> Clone() const; ::Utility::DynamicMemory::UniquePointer<ICustomBody> Clone() const;
bool IsSubscribingCollisions() const; bool IsSubscribingCollisions() const;
bool IsAffectedByGravity() const;
bool Intersects( const ICustomBody &object, ::Oyster::Math::Float timeStepLength, ::Oyster::Math::Float &deltaWhen, ::Oyster::Math::Float3 &worldPointOfContact ) const; bool Intersects( const ICustomBody &object, ::Oyster::Math::Float timeStepLength, ::Oyster::Math::Float &deltaWhen, ::Oyster::Math::Float3 &worldPointOfContact ) const;
bool Intersects( const ::Oyster::Collision3D::ICollideable &shape ) const; bool Intersects( const ::Oyster::Collision3D::ICollideable &shape ) const;
::Oyster::Collision3D::Sphere & GetBoundingSphere( ::Oyster::Collision3D::Sphere &targetMem = ::Oyster::Collision3D::Sphere() ) const; ::Oyster::Collision3D::Sphere & GetBoundingSphere( ::Oyster::Collision3D::Sphere &targetMem = ::Oyster::Collision3D::Sphere() ) const;
::Oyster::Math::Float3 & GetNormalAt( const ::Oyster::Math::Float3 &worldPos, ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const; ::Oyster::Math::Float3 & GetNormalAt( const ::Oyster::Math::Float3 &worldPos, ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const;
::Oyster::Math::Float3 & GetGravityNormal( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const;
::Oyster::Math::Float3 & GetCenter( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const; ::Oyster::Math::Float3 & GetCenter( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const;
::Oyster::Math::Float4x4 & GetRotation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const; ::Oyster::Math::Float4x4 & GetRotation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
::Oyster::Math::Float4x4 & GetOrientation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const; ::Oyster::Math::Float4x4 & GetOrientation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
@ -27,6 +29,9 @@ namespace Oyster { namespace Physics
UpdateState Update( ::Oyster::Math::Float timeStepLength ); UpdateState Update( ::Oyster::Math::Float timeStepLength );
void SetGravity( bool ignore);
void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector );
void SetSubscription( bool subscribeCollision );
void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI ); void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI );
void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI ); void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI );
void SetMass_KeepVelocity( ::Oyster::Math::Float m ); void SetMass_KeepVelocity( ::Oyster::Math::Float m );
@ -34,9 +39,12 @@ namespace Oyster { namespace Physics
void SetCenter( const ::Oyster::Math::Float3 &worldPos ); void SetCenter( const ::Oyster::Math::Float3 &worldPos );
void SetRotation( const ::Oyster::Math::Float4x4 &rotation ); void SetRotation( const ::Oyster::Math::Float4x4 &rotation );
void SetOrientation( const ::Oyster::Math::Float4x4 &orientation ); void SetOrientation( const ::Oyster::Math::Float4x4 &orientation );
void SetSize( const ::Oyster::Math::Float3 &size );
private: private:
::Oyster::Physics3D::RigidBody previous, current; ::Oyster::Physics3D::RigidBody previous, current;
::Oyster::Math::Float3 gravityNormal;
bool subscribeCollision, ignoreGravity;
}; };
} } } }

View File

@ -51,6 +51,14 @@ namespace Oyster
/** Gets the Physics instance. */ /** Gets the Physics instance. */
static API & Instance(); static API & Instance();
/********************************************************
* 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.
********************************************************/
virtual void Init( unsigned int numObjects, unsigned int numGravityWells , const ::Oyster::Math::Float3 &worldSize ) = 0;
/******************************************************** /********************************************************
* Sets the time length of each physics update frame. * Sets the time length of each physics update frame.
********************************************************/ ********************************************************/
@ -196,6 +204,13 @@ namespace Oyster
********************************************************/ ********************************************************/
virtual void SetOrientation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &orientation ) = 0; virtual void SetOrientation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &orientation ) = 0;
/********************************************************
* Resizes the boundingBox.
* @param objRef: A pointer to the ICustomBody representing a physical object.
* @param size: New size of this [m]
********************************************************/
virtual void SetSize( const ICustomBody* objRef, const ::Oyster::Math::Float3 &size ) = 0;
/******************************************************** /********************************************************
* Creates a new dynamically allocated object that can be used as a component for more complex ICustomBodies. * Creates a new dynamically allocated object that can be used as a component for more complex ICustomBodies.
* @return A pointer along with the responsibility to delete. * @return A pointer along with the responsibility to delete.
@ -223,6 +238,11 @@ namespace Oyster
********************************************************/ ********************************************************/
virtual bool IsSubscribingCollisions() const = 0; virtual bool IsSubscribingCollisions() const = 0;
/********************************************************
* @return true if Engine should apply gravity on this object.
********************************************************/
virtual bool IsAffectedByGravity() const = 0;
/******************************************************** /********************************************************
* Performs a detailed Intersect test and returns if, when and where. * Performs a detailed Intersect test and returns if, when and where.
* @param object: What this is intersect testing against. * @param object: What this is intersect testing against.
@ -254,6 +274,13 @@ namespace Oyster
********************************************************/ ********************************************************/
virtual ::Oyster::Math::Float3 & GetNormalAt( const ::Oyster::Math::Float3 &worldPos, ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const = 0; virtual ::Oyster::Math::Float3 & GetNormalAt( const ::Oyster::Math::Float3 &worldPos, ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const = 0;
/********************************************************
* The gravity normal will have same direction as the total gravity force pulling on this and have the magnitude of 1.0f.
* @param targetMem: Provided memory that written into and then returned.
* @return a normalized vector in worldSpace. Exception: Null vector if no gravity been applied.
********************************************************/
virtual ::Oyster::Math::Float3 & GetGravityNormal( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const = 0;
/******************************************************** /********************************************************
* The world position of this center of gravity. * The world position of this center of gravity.
* @param targetMem: Provided memory that written into and then returned. * @param targetMem: Provided memory that written into and then returned.
@ -280,52 +307,74 @@ namespace Oyster
virtual ::Oyster::Math::Float4x4 & GetView( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const = 0; virtual ::Oyster::Math::Float4x4 & GetView( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const = 0;
/******************************************************** /********************************************************
* To be only called by Engine * To not be called if is in Engine
* Is called during API::Update * Is called during API::Update
********************************************************/ ********************************************************/
virtual UpdateState Update( ::Oyster::Math::Float timeStepLength ) = 0; virtual UpdateState Update( ::Oyster::Math::Float timeStepLength ) = 0;
/******************************************************** /********************************************************
* To be only called by Engine * @param ignore: True if Engine should not apply Gravity.
********************************************************/
virtual void SetGravity( bool ignore) = 0;
/********************************************************
* Used by Engine
* @param normalizedVector: Should have same direction as the pullinggravity.
********************************************************/
virtual void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector ) = 0;
/********************************************************
* @param subscribeCollision: If is true, engine will call EventAction_Collision when this collides.
********************************************************/
virtual void SetSubscription( bool subscribeCollision ) = 0;
/********************************************************
* To not be called if is in Engine
* Use API::SetMomentOfInertiaTensor_KeepVelocity(...) instead * Use API::SetMomentOfInertiaTensor_KeepVelocity(...) instead
********************************************************/ ********************************************************/
virtual void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI ) = 0; virtual void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI ) = 0;
/******************************************************** /********************************************************
* To be only called by Engine * To not be called if is in Engine
* Use API::SetMomentOfInertiaTensor_KeepMomentum(...) * Use API::SetMomentOfInertiaTensor_KeepMomentum(...)
********************************************************/ ********************************************************/
virtual void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI ) = 0; virtual void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI ) = 0;
/******************************************************** /********************************************************
* To be only called by Engine * To not be called if is in Engine
* Use API::SetMass_KeepVelocity(...) * Use API::SetMass_KeepVelocity(...)
********************************************************/ ********************************************************/
virtual void SetMass_KeepVelocity( ::Oyster::Math::Float m ) = 0; virtual void SetMass_KeepVelocity( ::Oyster::Math::Float m ) = 0;
/******************************************************** /********************************************************
* To be only called by Engine * To not be called if is in Engine
* Use API::SetMass_KeepMomentum(...) * Use API::SetMass_KeepMomentum(...)
********************************************************/ ********************************************************/
virtual void SetMass_KeepMomentum( ::Oyster::Math::Float m ) = 0; virtual void SetMass_KeepMomentum( ::Oyster::Math::Float m ) = 0;
/******************************************************** /********************************************************
* To be only called by Engine * To not be called if is in Engine
* Use API::SetCenter(...) * Use API::SetCenter(...)
********************************************************/ ********************************************************/
virtual void SetCenter( const ::Oyster::Math::Float3 &worldPos ) = 0; virtual void SetCenter( const ::Oyster::Math::Float3 &worldPos ) = 0;
/******************************************************** /********************************************************
* To be only called by Engine * To not be called if is in Engine
* Use API::SetRotation(...) * Use API::SetRotation(...)
********************************************************/ ********************************************************/
virtual void SetRotation( const ::Oyster::Math::Float4x4 &rotation ) = 0; virtual void SetRotation( const ::Oyster::Math::Float4x4 &rotation ) = 0;
/******************************************************** /********************************************************
* To be only called by Engine * To not be called if is in Engine
* Use API::SetOrientation(...) * Use API::SetOrientation(...)
********************************************************/ ********************************************************/
virtual void SetOrientation( const ::Oyster::Math::Float4x4 &orientation ) = 0; virtual void SetOrientation( const ::Oyster::Math::Float4x4 &orientation ) = 0;
/********************************************************
* To not be called if is in Engine
* Use API::SetSize(...)
********************************************************/
virtual void SetSize( const ::Oyster::Math::Float3 &size ) = 0;
}; };
} }
} }