From 834de9ba8423f9b3142d33007ffa5b3c67132fc8 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 28 Nov 2013 17:59:12 +0100 Subject: [PATCH 01/18] Bunch of implementations --- Code/GamePhysics/GamePhysics.vcxproj.filters | 2 +- Code/GamePhysics/Implementation/Octree.cpp | 60 ++++++++- Code/GamePhysics/Implementation/Octree.h | 10 +- .../Implementation/PhysicsAPI_Impl.cpp | 123 +++++++++++++----- .../Implementation/PhysicsAPI_Impl.h | 4 +- Code/GamePhysics/PhysicsAPI.h | 2 +- 6 files changed, 158 insertions(+), 43 deletions(-) diff --git a/Code/GamePhysics/GamePhysics.vcxproj.filters b/Code/GamePhysics/GamePhysics.vcxproj.filters index 72b83568..694a8ec7 100644 --- a/Code/GamePhysics/GamePhysics.vcxproj.filters +++ b/Code/GamePhysics/GamePhysics.vcxproj.filters @@ -51,7 +51,7 @@ Source Files - Header Files\Implementation + Source Files \ No newline at end of file diff --git a/Code/GamePhysics/Implementation/Octree.cpp b/Code/GamePhysics/Implementation/Octree.cpp index 6a6416b8..baa431da 100644 --- a/Code/GamePhysics/Implementation/Octree.cpp +++ b/Code/GamePhysics/Implementation/Octree.cpp @@ -2,6 +2,9 @@ using namespace Oyster; using namespace Physics; +using namespace ::Utility::DynamicMemory; + +const unsigned int Octree::invalid_ref = ::Utility::Value::numeric_limits::max(); Octree::Octree(unsigned int bufferSize, unsigned char numLayers, Math::Float3 worldSize) { @@ -26,7 +29,7 @@ Octree& Octree::operator=(const Octree& orig) return *this; } -void Octree::AddObject(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef) +void Octree::AddObject(UniquePointer< ICustomBody > customBodyRef) { Data data; //Data* tempPtr = this->worldNode.dataPtr; @@ -54,15 +57,15 @@ void Octree::AddObject(Utility::DynamicMemory::UniquePointer< ICustomBody > cust }*/ } -void Octree::MoveToUpdateQueue(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef) +void Octree::MoveToUpdateQueue(UniquePointer< ICustomBody > customBodyRef) { /*this->leafData[this->mapReferences[customBodyRef]].queueRef = this->updateQueue.size(); this->updateQueue.push_back(&this->leafData[this->mapReferences[customBodyRef]]);*/ } -void Octree::DestroyObject(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef) +void Octree::DestroyObject(UniquePointer< ICustomBody > customBodyRef) { - std::map::iterator it = this->mapReferences.find(customBodyRef); + std::map::iterator it = this->mapReferences.find(customBodyRef); this->mapReferences.erase(it); @@ -116,4 +119,53 @@ void Octree::Visit(ICustomBody* customBodyRef, VistorAction hitAction ) ICustomBody* Octree::GetCustomBody(const unsigned int tempRef) { return this->leafData[tempRef].customBodyRef; +} + +UniquePointer Octree::Extract( const ICustomBody* objRef ) +{ // Dan Andersson + auto iter = this->mapReferences.find( objRef ); + if( iter != this->mapReferences.end() ) + { + return this->Extract( iter->second ); + } + else + { + return NULL; + } +} + +UniquePointer Octree::Extract( unsigned int tempRef ) +{ + if( tempRef != Octree::invalid_ref ) + { + //! @todo TODO: implement stub + return NULL; + } + else + { + return NULL; + } +} + +unsigned int Octree::GetTemporaryReferenceOf( const ICustomBody* objRef ) const +{ // Dan Andersson + auto iter = this->mapReferences.find( objRef ); + if( iter != this->mapReferences.end() ) + { + return iter->second; + } + else + { + return Octree::invalid_ref; + } +} + +void Octree::SetAsAltered( unsigned int tempRef ) +{ + //! @todo TODO: implement stub +} + +void Octree::EvaluatePosition( unsigned int tempRef ) +{ + //! @todo TODO: implement stub } \ No newline at end of file diff --git a/Code/GamePhysics/Implementation/Octree.h b/Code/GamePhysics/Implementation/Octree.h index 8d111329..5ef3b0a8 100644 --- a/Code/GamePhysics/Implementation/Octree.h +++ b/Code/GamePhysics/Implementation/Octree.h @@ -15,6 +15,8 @@ namespace Oyster class Octree { public: + static const unsigned int invalid_ref; + typedef void(*VistorAction)(Octree&, unsigned int, unsigned int); struct Data @@ -52,11 +54,17 @@ namespace Oyster ICustomBody* GetCustomBody(const unsigned int tempRef); + ::Utility::DynamicMemory::UniquePointer Extract( const ICustomBody* objRef ); + ::Utility::DynamicMemory::UniquePointer Extract( unsigned int tempRef ); // Dan vill ha + unsigned int GetTemporaryReferenceOf( const ICustomBody* objRef ) const; // Dan vill ha + void SetAsAltered( unsigned int tempRef ); // Dan vill ha + void EvaluatePosition( unsigned int tempRef ); // Dan vill ha + private: std::vector < Data > leafData; std::vector < Data* > updateQueue; - std::map< ICustomBody*, unsigned int > mapReferences; + std::map< const ICustomBody*, unsigned int > mapReferences; OctreeNode worldNode; }; diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 6c9b212a..0374704f 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -42,21 +42,24 @@ API & API::Instance() } API_Impl::API_Impl() - : gravityConstant( Constant::gravity_constant ), - updateFrameLength( 1.0f / 120.0f ), - destructionAction( Default::EventAction_Destruction ) -{} +{ + this->gravityConstant = Constant::gravity_constant; + this->updateFrameLength = 1.0f / 120.0f; + this->destructionAction = Default::EventAction_Destruction; + this->worldScene = Octree(); +} API_Impl::~API_Impl() {} void API_Impl::Init( unsigned int numObjects, unsigned int numGravityWells , const Float3 &worldSize ) { - //! @todo TODO: implement stub + unsigned char numLayers = 4; //!< @todo TODO: calc numLayers from worldSize + this->worldScene = Octree( numObjects, numLayers, worldSize ); } -void API_Impl::SetDeltaTime( float deltaTime ) +void API_Impl::SetFrameTimeLength( float deltaTime ) { - updateFrameLength = deltaTime; + this->updateFrameLength = deltaTime; } void API_Impl::SetGravityConstant( float g ) @@ -98,68 +101,117 @@ void API_Impl::ReleaseFromLimbo( const ICustomBody* objRef ) void API_Impl::AddObject( ::Utility::DynamicMemory::UniquePointer handle ) { - /** @todo TODO: Fix this function.*/ + this->worldScene.AddObject( handle ); } -::Utility::DynamicMemory::UniquePointer API_Impl::ExtractObject( const ICustomBody* objRef ) +UniquePointer API_Impl::ExtractObject( const ICustomBody* objRef ) { - //! @todo TODO: implement stub - return NULL; + return this->worldScene.Extract( objRef ); } void API_Impl::DestroyObject( const ICustomBody* objRef ) { - /** @todo TODO: Fix this function.*/ + UniquePointer object = this->worldScene.Extract( objRef ); + if( object != NULL ) + { + this->destructionAction( object ); + } } void API_Impl::ApplyForceAt( const ICustomBody* objRef, const Float3 &worldPos, const Float3 &worldF ) { - //! @todo TODO: implement stub + unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef ); + if( tempRef != this->worldScene.invalid_ref ) + { + //this->worldScene.GetCustomBody( tempRef )->Apply //!< @todo TODO: need function + this->worldScene.SetAsAltered( tempRef ); + } } void API_Impl::ApplyCollisionResponse( const ICustomBody* objRefA, const ICustomBody* objRefB, Float &deltaWhen, Float3 &worldPointOfContact ) { - //! @todo TODO: implement stub + unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRefA ); + if( tempRef != this->worldScene.invalid_ref ) + { + //! @todo TODO: implement stub + this->worldScene.SetAsAltered( tempRef ); + } } void API_Impl::SetMomentOfInertiaTensor_KeepVelocity( const ICustomBody* objRef, const Float4x4 &localI ) -{ - //! @todo TODO: implement stub +{ // deprecated + unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef ); + if( tempRef != this->worldScene.invalid_ref ) + { + this->worldScene.GetCustomBody( tempRef )->SetMomentOfInertiaTensor_KeepVelocity( localI ); + } } void API_Impl::SetMomentOfInertiaTensor_KeepMomentum( const ICustomBody* objRef, const Float4x4 &localI ) -{ - //! @todo TODO: implement stub +{ // deprecated + unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef ); + if( tempRef != this->worldScene.invalid_ref ) + { + this->worldScene.GetCustomBody( tempRef )->SetMomentOfInertiaTensor_KeepMomentum( localI ); + } } void API_Impl::SetMass_KeepVelocity( const ICustomBody* objRef, Float m ) -{ - //! @todo TODO: implement stub +{ // deprecated + unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef ); + if( tempRef != this->worldScene.invalid_ref ) + { + this->worldScene.GetCustomBody( tempRef )->SetMass_KeepVelocity( m ); + } } void API_Impl::SetMass_KeepMomentum( const ICustomBody* objRef, Float m ) -{ - //! @todo TODO: implement stub +{ // deprecated + unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef ); + if( tempRef != this->worldScene.invalid_ref ) + { + this->worldScene.GetCustomBody( tempRef )->SetMass_KeepMomentum( m ); + } } void API_Impl::SetCenter( const ICustomBody* objRef, const Float3 &worldPos ) { - //! @todo TODO: implement stub + unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef ); + if( tempRef != this->worldScene.invalid_ref ) + { + //this->worldScene.GetCustomBody( tempRef )->Set //!< @todo TODO: need function + this->worldScene.EvaluatePosition( tempRef ); + } } void API_Impl::SetRotation( const ICustomBody* objRef, const Float4x4 &rotation ) { - //! @todo TODO: implement stub + unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef ); + if( tempRef != this->worldScene.invalid_ref ) + { + this->worldScene.GetCustomBody( tempRef )->SetRotation( rotation ); + this->worldScene.EvaluatePosition( tempRef ); + } } void API_Impl::SetOrientation( const ICustomBody* objRef, const Float4x4 &orientation ) { - //! @todo TODO: implement stub + unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef ); + if( tempRef != this->worldScene.invalid_ref ) + { + this->worldScene.GetCustomBody( tempRef )->SetOrientation( orientation ); + this->worldScene.EvaluatePosition( tempRef ); + } } void API_Impl::SetSize( const ICustomBody* objRef, const Float3 &size ) { - //! @todo TODO: implement stub + unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef ); + if( tempRef != this->worldScene.invalid_ref ) + { + this->worldScene.GetCustomBody( tempRef )->SetSize( size ); + this->worldScene.EvaluatePosition( tempRef ); + } } UniquePointer API_Impl::CreateRigidBody( const API::SimpleBodyDescription &desc ) const @@ -172,15 +224,16 @@ UniquePointer API_Impl::CreateRigidBody( const API::SphericalBodyDe return new SphericalRigidBody( desc ); } -namespace Oyster { namespace Physics { namespace Default +namespace Oyster { namespace Physics { + namespace Default + { + void EventAction_Destruction( ::Utility::DynamicMemory::UniquePointer<::Oyster::Physics::ICustomBody> proto ) + { /* Do nothing except allowing the proto uniquePointer destroy itself. */ } - void EventAction_Destruction( ::Utility::DynamicMemory::UniquePointer<::Oyster::Physics::ICustomBody> proto ) - { /* Do nothing except allowing the proto uniquePointer destroy itself. */ } - - ::Oyster::Physics::ICustomBody::SubscriptMessage EventAction_Collision( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter ) - { /* Do nothing except returning business as usual. */ - return ::Oyster::Physics::ICustomBody::SubscriptMessage_none; + ::Oyster::Physics::ICustomBody::SubscriptMessage EventAction_Collision( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter ) + { /* Do nothing except returning business as usual. */ + return ::Oyster::Physics::ICustomBody::SubscriptMessage_none; + } } - -} } } \ No newline at end of file +} } \ No newline at end of file diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h index 7d6858f0..5de9c05a 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h @@ -2,6 +2,7 @@ #define PHYSICS_API_IMPL_H #include "../PhysicsAPI.h" +#include "Octree.h" namespace Oyster { @@ -15,7 +16,7 @@ namespace Oyster void Init( unsigned int numObjects, unsigned int numGravityWells , const ::Oyster::Math::Float3 &worldSize ); - void SetDeltaTime( float deltaTime ); + void SetFrameTimeLength( float deltaTime ); void SetGravityConstant( float g ); void SetSubscription( EventAction_Destruction functionPointer ); @@ -47,6 +48,7 @@ namespace Oyster private: ::Oyster::Math::Float gravityConstant, updateFrameLength; EventAction_Destruction destructionAction; + Octree worldScene; }; namespace Default diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index 6cba993c..5d44b695 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -64,7 +64,7 @@ namespace Oyster /******************************************************** * Sets the time length of each physics update frame. ********************************************************/ - virtual void SetDeltaTime( float seconds ) = 0; + virtual void SetFrameTimeLength( float seconds ) = 0; /******************************************************** * Sets the Gravityconstant in the physics that will be From 14b1f20b87a21e4a3386b79f69e603f124310766 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 28 Nov 2013 18:05:19 +0100 Subject: [PATCH 02/18] minor compilation error fix Forgot that UniquePointer had a special operator for checking if it is not NULL >.< --- Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 0374704f..ed8f8eed 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -112,7 +112,7 @@ UniquePointer API_Impl::ExtractObject( const ICustomBody* objRef ) void API_Impl::DestroyObject( const ICustomBody* objRef ) { UniquePointer object = this->worldScene.Extract( objRef ); - if( object != NULL ) + if( object ) { this->destructionAction( object ); } From 255a0b0070ed94ec38a8097b97f76085791febed Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Fri, 29 Nov 2013 09:03:37 +0100 Subject: [PATCH 03/18] Added overloads for visitor and sample functions They now have an overload for accepting ICollideable --- Code/GamePhysics/Implementation/Octree.cpp | 34 ++++++++++++++++++---- Code/GamePhysics/Implementation/Octree.h | 4 ++- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Code/GamePhysics/Implementation/Octree.cpp b/Code/GamePhysics/Implementation/Octree.cpp index baa431da..70d2842a 100644 --- a/Code/GamePhysics/Implementation/Octree.cpp +++ b/Code/GamePhysics/Implementation/Octree.cpp @@ -72,15 +72,13 @@ void Octree::DestroyObject(UniquePointer< ICustomBody > customBodyRef) this->leafData.erase(this->leafData.begin() + this->leafData[this->mapReferences[customBodyRef]].queueRef); } -std::vector Octree::Sample(ICustomBody* customBodyRef) +std::vector& Octree::Sample(ICustomBody* customBodyRef, std::vector& updateList) { - std::vector list; - auto object = this->mapReferences.find(customBodyRef); if(object == this->mapReferences.end()) { - return list; + return updateList; } unsigned int tempRef = object->second; @@ -89,11 +87,24 @@ std::vector Octree::Sample(ICustomBody* customBodyRef) { if(tempRef != i) if(this->leafData[tempRef].container.Intersects(this->leafData[i].container)) { - list.push_back(this->leafData[i].customBodyRef); + updateList.push_back(this->leafData[i].customBodyRef); } } - return list; + return updateList; +} + +std::vector& Octree::Sample(::Collision3D::ICollideable* collideable, std::vector& updateList) +{ + for(unsigned int i = 0; ileafData.size(); i++) + { + if(this->leafData[i].container.Intersects(*collideable)) + { + updateList.push_back(this->leafData[i].customBodyRef); + } + } + + return updateList; } void Octree::Visit(ICustomBody* customBodyRef, VistorAction hitAction ) @@ -116,6 +127,17 @@ void Octree::Visit(ICustomBody* customBodyRef, VistorAction hitAction ) } } +void Octree::Visit(::Collision3D::ICollideable* collideable, VistorAction hitAction) +{ + for(unsigned int i = 0; ileafData.size(); i++) + { + if(this->leafData[i].container.Intersects(*collideable)) + { + //hitAction(*this, tempRef, i); // @todo TODO: Add typedef to handle function calls with ICollideable + } + } +} + ICustomBody* Octree::GetCustomBody(const unsigned int tempRef) { return this->leafData[tempRef].customBodyRef; diff --git a/Code/GamePhysics/Implementation/Octree.h b/Code/GamePhysics/Implementation/Octree.h index 5ef3b0a8..6340fa58 100644 --- a/Code/GamePhysics/Implementation/Octree.h +++ b/Code/GamePhysics/Implementation/Octree.h @@ -49,8 +49,10 @@ namespace Oyster void DestroyObject(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef); - std::vector Sample(ICustomBody* customBodyRef); + std::vector& Sample(ICustomBody* customBodyRef, std::vector& updateList); + std::vector& Sample(Oyster::Collision3D::ICollideable* collideable, std::vector& updateList); void Visit(ICustomBody* customBodyRef, VistorAction hitAction ); + void Visit(Oyster::Collision3D::ICollideable* collideable, VistorAction hitAction ); ICustomBody* GetCustomBody(const unsigned int tempRef); From bddc3acad2dcc6a55b6bc7f1413d207d7bea6d7e Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Fri, 29 Nov 2013 09:07:52 +0100 Subject: [PATCH 04/18] Changed from pointer to reference Did it in sample and visit functions --- Code/GamePhysics/Implementation/Octree.cpp | 8 ++++---- Code/GamePhysics/Implementation/Octree.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Code/GamePhysics/Implementation/Octree.cpp b/Code/GamePhysics/Implementation/Octree.cpp index 70d2842a..1da6045b 100644 --- a/Code/GamePhysics/Implementation/Octree.cpp +++ b/Code/GamePhysics/Implementation/Octree.cpp @@ -94,11 +94,11 @@ std::vector& Octree::Sample(ICustomBody* customBodyRef, std::vecto return updateList; } -std::vector& Octree::Sample(::Collision3D::ICollideable* collideable, std::vector& updateList) +std::vector& Octree::Sample(const Oyster::Collision3D::ICollideable& collideable, std::vector& updateList) { for(unsigned int i = 0; ileafData.size(); i++) { - if(this->leafData[i].container.Intersects(*collideable)) + if(this->leafData[i].container.Intersects(collideable)) { updateList.push_back(this->leafData[i].customBodyRef); } @@ -127,11 +127,11 @@ void Octree::Visit(ICustomBody* customBodyRef, VistorAction hitAction ) } } -void Octree::Visit(::Collision3D::ICollideable* collideable, VistorAction hitAction) +void Octree::Visit(const Oyster::Collision3D::ICollideable& collideable, VistorAction hitAction) { for(unsigned int i = 0; ileafData.size(); i++) { - if(this->leafData[i].container.Intersects(*collideable)) + if(this->leafData[i].container.Intersects(collideable)) { //hitAction(*this, tempRef, i); // @todo TODO: Add typedef to handle function calls with ICollideable } diff --git a/Code/GamePhysics/Implementation/Octree.h b/Code/GamePhysics/Implementation/Octree.h index 6340fa58..96631605 100644 --- a/Code/GamePhysics/Implementation/Octree.h +++ b/Code/GamePhysics/Implementation/Octree.h @@ -50,9 +50,9 @@ namespace Oyster void DestroyObject(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef); std::vector& Sample(ICustomBody* customBodyRef, std::vector& updateList); - std::vector& Sample(Oyster::Collision3D::ICollideable* collideable, std::vector& updateList); + std::vector& Sample(const Oyster::Collision3D::ICollideable& collideable, std::vector& updateList); void Visit(ICustomBody* customBodyRef, VistorAction hitAction ); - void Visit(Oyster::Collision3D::ICollideable* collideable, VistorAction hitAction ); + void Visit(const Oyster::Collision3D::ICollideable& collideable, VistorAction hitAction ); ICustomBody* GetCustomBody(const unsigned int tempRef); From e4476f7757a79de5fee9ade50bf674584cbc5e4b Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 3 Dec 2013 15:11:13 +0100 Subject: [PATCH 05/18] Added function for ICustomBody void ICustomBody::SetMomentum( const ::Oyster::Math::Float3 &worldG ) - Added and implemented --- Code/GamePhysics/Implementation/SimpleRigidBody.cpp | 5 +++++ Code/GamePhysics/Implementation/SimpleRigidBody.h | 1 + Code/GamePhysics/Implementation/SphericalRigidBody.cpp | 5 +++++ Code/GamePhysics/Implementation/SphericalRigidBody.h | 1 + Code/GamePhysics/PhysicsAPI.h | 6 ++++++ 5 files changed, 18 insertions(+) diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp index 70bc6938..ea75ffe3 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -177,4 +177,9 @@ void SimpleRigidBody::SetOrientation( const Float4x4 &orientation ) void SimpleRigidBody::SetSize( const Float3 &size ) { this->rigid.SetSize( size ); +} + +void SimpleRigidBody::SetMomentum( const Float3 &worldG ) +{ + this->rigid.SetLinearMomentum( worldG ); } \ No newline at end of file diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.h b/Code/GamePhysics/Implementation/SimpleRigidBody.h index a674a20d..5e05c9d7 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.h +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.h @@ -41,6 +41,7 @@ namespace Oyster { namespace Physics void SetRotation( const ::Oyster::Math::Float4x4 &rotation ); void SetOrientation( const ::Oyster::Math::Float4x4 &orientation ); void SetSize( const ::Oyster::Math::Float3 &size ); + void SetMomentum( const ::Oyster::Math::Float3 &worldG ); private: ::Oyster::Physics3D::RigidBody rigid; diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp index c741a68a..03ed7d2a 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp @@ -183,4 +183,9 @@ void SphericalRigidBody::SetSize( const Float3 &size ) { this->rigid.SetSize( size ); this->body.radius = 0.5f * Min( Min( size.x, size.y ), size.z ); // inline Min( FloatN )? +} + +void SphericalRigidBody::SetMomentum( const Float3 &worldG ) +{ + this->rigid.SetLinearMomentum( worldG ); } \ No newline at end of file diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.h b/Code/GamePhysics/Implementation/SphericalRigidBody.h index 37263e91..a25cba2c 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.h +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.h @@ -42,6 +42,7 @@ namespace Oyster { namespace Physics void SetRotation( const ::Oyster::Math::Float4x4 &rotation ); void SetOrientation( const ::Oyster::Math::Float4x4 &orientation ); void SetSize( const ::Oyster::Math::Float3 &size ); + void SetMomentum( const ::Oyster::Math::Float3 &worldG ); private: ::Oyster::Physics3D::RigidBody rigid; diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index 29014214..56e46817 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -390,6 +390,12 @@ namespace Oyster * Use API::SetSize(...) ********************************************************/ virtual void SetSize( const ::Oyster::Math::Float3 &size ) = 0; + + /******************************************************** + * To not be called if is in Engine + * Use API::?? @todo TODO: + ********************************************************/ + virtual void SetMomentum( const ::Oyster::Math::Float3 &worldG ) = 0; }; struct API::SimpleBodyDescription From b03e9af027620da96eaee49bc8d2c0f3726efd21 Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Wed, 4 Dec 2013 09:51:48 +0100 Subject: [PATCH 06/18] Fixed octree and API Rewrote AddObject function in octree and OnPossibleCollision in PhysocsAPI_Impl --- Code/GamePhysics/Implementation/Octree.cpp | 2 +- Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Code/GamePhysics/Implementation/Octree.cpp b/Code/GamePhysics/Implementation/Octree.cpp index 1da6045b..4da48863 100644 --- a/Code/GamePhysics/Implementation/Octree.cpp +++ b/Code/GamePhysics/Implementation/Octree.cpp @@ -39,7 +39,7 @@ void Octree::AddObject(UniquePointer< ICustomBody > customBodyRef) data.next = NULL; data.prev = NULL; data.customBodyRef = customBodyRef; - this->mapReferences.insert(std::pair (customBodyRef, this->leafData.size())); + this->mapReferences.insert(std::pair (data.customBodyRef, this->leafData.size())); this->leafData.push_back(data); /*if(tempPtr != NULL) diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 3d3080da..447a6c68 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -20,7 +20,7 @@ namespace float deltaWhen; Float3 worldWhere; - if( deuter->Intersects(*deuter, 1.0f, deltaWhen, worldWhere) ) + if( proto->Intersects(*deuter, 1.0f, deltaWhen, worldWhere) ) { proto->CallSubscription( proto, deuter ); } From 1d94ed0ddcccde9ffa22b3342dd42ab0029519c2 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 4 Dec 2013 11:30:56 +0100 Subject: [PATCH 07/18] Fixed MomentOfInertia methods --- .../Implementation/PhysicsAPI_Impl.cpp | 20 +++++++++---------- Code/GamePhysics/PhysicsAPI.h | 12 +++++------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 447a6c68..46b3369c 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -27,29 +27,29 @@ namespace } } -Float4x4 & MomentOfInertia::CreateSphereMatrix( const Float mass, const Float radius) +Float4x4 & MomentOfInertia::CreateSphereMatrix( const Float mass, const Float radius, ::Oyster::Math::Float4x4 &targetMem ) { - return Formula::MomentOfInertia::Sphere(mass, radius); + return targetMem = Formula::MomentOfInertia::Sphere(mass, radius); } -Float4x4 & MomentOfInertia::CreateHollowSphereMatrix( const Float mass, const Float radius) +Float4x4 & MomentOfInertia::CreateHollowSphereMatrix( const Float mass, const Float radius, ::Oyster::Math::Float4x4 &targetMem ) { - return Formula::MomentOfInertia::HollowSphere(mass, radius); + return targetMem = Formula::MomentOfInertia::HollowSphere(mass, radius); } -Float4x4 & MomentOfInertia::CreateCuboidMatrix( const Float mass, const Float height, const Float width, const Float depth ) +Float4x4 & MomentOfInertia::CreateCuboidMatrix( const Float mass, const Float height, const Float width, const Float depth, ::Oyster::Math::Float4x4 &targetMem ) { - return Formula::MomentOfInertia::Cuboid(mass, height, width, depth); + return targetMem = Formula::MomentOfInertia::Cuboid(mass, height, width, depth); } -Float4x4 & MomentOfInertia::CreateCylinderMatrix( const Float mass, const Float height, const Float radius ) +Float4x4 & MomentOfInertia::CreateCylinderMatrix( const Float mass, const Float height, const Float radius, ::Oyster::Math::Float4x4 &targetMem ) { - return Formula::MomentOfInertia::Cylinder(mass, height, radius); + return targetMem = Formula::MomentOfInertia::Cylinder(mass, height, radius); } -Float4x4 & MomentOfInertia::CreateRodMatrix( const Float mass, const Float length ) +Float4x4 & MomentOfInertia::CreateRodMatrix( const Float mass, const Float length, ::Oyster::Math::Float4x4 &targetMem ) { - return Formula::MomentOfInertia::RodCenter(mass, length); + return targetMem = Formula::MomentOfInertia::RodCenter(mass, length); } API & API::Instance() diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index 56e46817..cd720abd 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -1,4 +1,4 @@ -#ifndef PHYSICS_API_H + #ifndef PHYSICS_API_H #define PHYSICS_API_H #include "OysterCollision3D.h" @@ -31,15 +31,15 @@ namespace Oyster class PHYSICS_DLL_USAGE MomentOfInertia { public: - static ::Oyster::Math::Float4x4 & CreateSphereMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius); + static ::Oyster::Math::Float4x4 & CreateSphereMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius, ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ); - static ::Oyster::Math::Float4x4 & CreateHollowSphereMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius); + static ::Oyster::Math::Float4x4 & CreateHollowSphereMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius, ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ); - static ::Oyster::Math::Float4x4 & CreateCuboidMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float width, const ::Oyster::Math::Float depth ); + static ::Oyster::Math::Float4x4 & CreateCuboidMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float width, const ::Oyster::Math::Float depth, ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ); - static ::Oyster::Math::Float4x4 & CreateCylinderMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float radius ); + static ::Oyster::Math::Float4x4 & CreateCylinderMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float radius, ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ); - static ::Oyster::Math::Float4x4 & CreateRodMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float length ); + static ::Oyster::Math::Float4x4 & CreateRodMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float length, ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ); }; class PHYSICS_DLL_USAGE API From 080bbf68fdfece5ed2ad184c9018682e065ef1bc Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 4 Dec 2013 11:42:11 +0100 Subject: [PATCH 08/18] Collideables fixed Missing returns --- Code/OysterPhysics3D/Point.cpp | 2 +- Code/OysterPhysics3D/Ray.cpp | 2 +- Code/OysterPhysics3D/Sphere.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Code/OysterPhysics3D/Point.cpp b/Code/OysterPhysics3D/Point.cpp index cf1186c9..d81c91a3 100644 --- a/Code/OysterPhysics3D/Point.cpp +++ b/Code/OysterPhysics3D/Point.cpp @@ -38,7 +38,7 @@ bool Point::Intersects( const ICollideable &target ) const case Type_universe: return true; case Type_point: return Utility::Intersect( *this, *(Point*)&target ); case Type_ray: return Utility::Intersect( *(Ray*)&target, *this, ((Ray*)&target)->collisionDistance ); - case Type_sphere: Utility::Intersect( *(Sphere*)&target, *this ); + case Type_sphere: return Utility::Intersect( *(Sphere*)&target, *this ); case Type_plane: return Utility::Intersect( *(Plane*)&target, *this ); //case Type_triangle: return false; // TODO: case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)&target, *this ); diff --git a/Code/OysterPhysics3D/Ray.cpp b/Code/OysterPhysics3D/Ray.cpp index 09fb13ec..79e4dbd5 100644 --- a/Code/OysterPhysics3D/Ray.cpp +++ b/Code/OysterPhysics3D/Ray.cpp @@ -60,7 +60,7 @@ bool Ray::Contains( const ICollideable &target ) const switch( target.type ) { case Type_point: return Utility::Intersect( *this, *(Point*)&target, this->collisionDistance ); - case Type_ray: Utility::Contains( *this, *(Ray*)&target ); + case Type_ray: return Utility::Contains( *this, *(Ray*)&target ); default: return false; } } \ No newline at end of file diff --git a/Code/OysterPhysics3D/Sphere.cpp b/Code/OysterPhysics3D/Sphere.cpp index 0cc8bc3b..4f6f76f7 100644 --- a/Code/OysterPhysics3D/Sphere.cpp +++ b/Code/OysterPhysics3D/Sphere.cpp @@ -35,7 +35,7 @@ bool Sphere::Intersects( const ICollideable &target ) const case Type_universe: return true; case Type_point: return Utility::Intersect( *this, *(Point*)&target ); case Type_ray: return Utility::Intersect( *this, *(Ray*)&target, ((Ray*)&target)->collisionDistance ); - case Type_sphere: Utility::Intersect( *this, *(Sphere*)&target ); + case Type_sphere: return Utility::Intersect( *this, *(Sphere*)&target ); case Type_plane: return Utility::Intersect( *(Plane*)&target, *this ); // case Type_triangle: return false; // TODO: case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)&target, *this ); From 202ee23b252627be7edf9f3cc37023c33042a18d Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 4 Dec 2013 11:49:33 +0100 Subject: [PATCH 09/18] Octtree::leafData Container should be kept updated now --- Code/GamePhysics/Implementation/Octree.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Code/GamePhysics/Implementation/Octree.cpp b/Code/GamePhysics/Implementation/Octree.cpp index 4da48863..b841b49d 100644 --- a/Code/GamePhysics/Implementation/Octree.cpp +++ b/Code/GamePhysics/Implementation/Octree.cpp @@ -184,6 +184,7 @@ unsigned int Octree::GetTemporaryReferenceOf( const ICustomBody* objRef ) const void Octree::SetAsAltered( unsigned int tempRef ) { + this->leafData[tempRef].container = this->leafData[tempRef].customBodyRef->GetBoundingSphere(); //! @todo TODO: implement stub } From e0adc0ae93d7c8d33c23f6c1ee7dc7dfeb8a2f3e Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 4 Dec 2013 13:52:07 +0100 Subject: [PATCH 10/18] Sphere Vs Box collision detect fix --- Code/OysterPhysics3D/OysterCollision3D.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Code/OysterPhysics3D/OysterCollision3D.cpp b/Code/OysterPhysics3D/OysterCollision3D.cpp index 131cad62..95c56f81 100644 --- a/Code/OysterPhysics3D/OysterCollision3D.cpp +++ b/Code/OysterPhysics3D/OysterCollision3D.cpp @@ -393,8 +393,8 @@ namespace Oyster { namespace Collision3D { namespace Utility bool Intersect( const BoxAxisAligned &box, const Sphere &sphere ) { // by Dan Andersson - Float3 e = Max( box.minVertex - sphere.center, Float3::null ); - e += Max( sphere.center - box.maxVertex, Float3::null ); + Float4 e = Max( Float4(box.minVertex - sphere.center, 0.0f), Float4::null ); + e += Max( Float4(sphere.center - box.maxVertex, 0.0f), Float4::null ); if( e.Dot(e) > (sphere.radius * sphere.radius) ) return false; return true; @@ -459,12 +459,13 @@ namespace Oyster { namespace Collision3D { namespace Utility bool Intersect( const Box &box, const Sphere &sphere ) { // by Dan Andersson - Float3 e = sphere.center - box.center, - centerL = Float3( e.Dot(box.xAxis), e.Dot(box.yAxis), e.Dot(box.zAxis) ); - - e = Max( (box.boundingOffset + centerL)*=-1.0f, Float3::null ); - e += Max( centerL - box.boundingOffset, Float3::null ); - + Float4 vCenter = Float4( sphere.center - box.center, 1.0f ); // sphere's center in the box's view space + vCenter = InverseRotationMatrix( box.rotation ) * vCenter; + vCenter.w = 0.0f; + + Float4 e = Max( Float4(-box.boundingOffset, 0.0f) - vCenter, Float4::null ); + e += Max( vCenter - Float4(-box.boundingOffset, 0.0f), Float4::null ); + if( e.Dot(e) > (sphere.radius * sphere.radius) ) return false; return true; } From 7ad60969fc24912293276b04070c80f0cb55215b Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 4 Dec 2013 14:12:06 +0100 Subject: [PATCH 11/18] Sphere Vs Box collision detect fix second ed. ... Works now! :3 --- Code/OysterPhysics3D/OysterCollision3D.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Code/OysterPhysics3D/OysterCollision3D.cpp b/Code/OysterPhysics3D/OysterCollision3D.cpp index 95c56f81..5df9761c 100644 --- a/Code/OysterPhysics3D/OysterCollision3D.cpp +++ b/Code/OysterPhysics3D/OysterCollision3D.cpp @@ -459,12 +459,11 @@ namespace Oyster { namespace Collision3D { namespace Utility bool Intersect( const Box &box, const Sphere &sphere ) { // by Dan Andersson - Float4 vCenter = Float4( sphere.center - box.center, 1.0f ); // sphere's center in the box's view space - vCenter = InverseRotationMatrix( box.rotation ) * vCenter; - vCenter.w = 0.0f; + // center: sphere's center in the box's view space + Float4 center = TransformVector( InverseRotationMatrix(box.rotation), Float4(sphere.center - box.center, 0.0f) ); - Float4 e = Max( Float4(-box.boundingOffset, 0.0f) - vCenter, Float4::null ); - e += Max( vCenter - Float4(-box.boundingOffset, 0.0f), Float4::null ); + Float4 e = Max( Float4(-box.boundingOffset, 0.0f) - center, Float4::null ); + e += Max( center - Float4(box.boundingOffset, 0.0f), Float4::null ); if( e.Dot(e) > (sphere.radius * sphere.radius) ) return false; return true; From d0936f9133319fdb6edd109e8fefa16d15bd3c8b Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 4 Dec 2013 14:22:25 +0100 Subject: [PATCH 12/18] InverseRotationMatrix fixed Compiler overstepping its bound, doing whatever it wants. --- Code/OysterMath/OysterMath.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Code/OysterMath/OysterMath.cpp b/Code/OysterMath/OysterMath.cpp index a82658ee..421ebc0b 100644 --- a/Code/OysterMath/OysterMath.cpp +++ b/Code/OysterMath/OysterMath.cpp @@ -103,7 +103,8 @@ namespace Oyster { namespace Math3D Float4x4 & InverseRotationMatrix( const Float4x4 &rotation, Float4x4 &targetMem ) { - return targetMem = ::LinearAlgebra3D::InverseRotationMatrix( rotation ); +// return targetMem = ::LinearAlgebra3D::InverseRotationMatrix( rotation ); + return targetMem = rotation.GetTranspose(); } Float4x4 & OrientationMatrix( const Float3x3 &rotation, const Float3 &translation, Float4x4 &targetMem ) From 5835a72acc3d1ca18f037b4fdeaf982025e867ff Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Fri, 6 Dec 2013 09:46:30 +0100 Subject: [PATCH 13/18] Setstruct introduction done Can be found as: Physics::Struct::CustomBodyState Physics::ICustomBody::State Is all inline thus no expensive API calls, as intended. Will be expanded to move API call methods from Physics::ICustomBody to it. --- Code/GamePhysics/GamePhysics.vcxproj | 14 +++ Code/GamePhysics/GamePhysics.vcxproj.filters | 6 + .../Implementation/SimpleRigidBody.cpp | 17 +++ .../Implementation/SimpleRigidBody.h | 4 + .../Implementation/SphericalRigidBody.cpp | 17 +++ .../Implementation/SphericalRigidBody.h | 4 + Code/GamePhysics/PhysicsAPI.h | 78 +++++------- Code/GamePhysics/PhysicsStructs-Impl.h | 117 ++++++++++++++++++ Code/GamePhysics/PhysicsStructs.h | 70 +++++++++++ Code/OysterMath/LinearMath.h | 57 ++++++++- Code/OysterMath/OysterMath.cpp | 35 +++++- Code/OysterMath/OysterMath.h | 9 ++ 12 files changed, 373 insertions(+), 55 deletions(-) create mode 100644 Code/GamePhysics/PhysicsStructs-Impl.h create mode 100644 Code/GamePhysics/PhysicsStructs.h diff --git a/Code/GamePhysics/GamePhysics.vcxproj b/Code/GamePhysics/GamePhysics.vcxproj index 540002a1..06e64fd1 100644 --- a/Code/GamePhysics/GamePhysics.vcxproj +++ b/Code/GamePhysics/GamePhysics.vcxproj @@ -91,9 +91,12 @@ Disabled $(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;%(AdditionalIncludeDirectories) _WINDLL;PHYSICS_DLL_EXPORT;%(PreprocessorDefinitions) + false true + + @@ -102,9 +105,12 @@ Disabled $(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;%(AdditionalIncludeDirectories) _WINDLL;PHYSICS_DLL_EXPORT;%(PreprocessorDefinitions) + false true + + @@ -115,11 +121,14 @@ true $(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;%(AdditionalIncludeDirectories) _WINDLL;PHYSICS_DLL_EXPORT;%(PreprocessorDefinitions) + false true true true + + @@ -130,11 +139,14 @@ true $(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;%(AdditionalIncludeDirectories) _WINDLL;PHYSICS_DLL_EXPORT;%(PreprocessorDefinitions) + false true true true + + @@ -154,6 +166,8 @@ + + diff --git a/Code/GamePhysics/GamePhysics.vcxproj.filters b/Code/GamePhysics/GamePhysics.vcxproj.filters index 694a8ec7..15221691 100644 --- a/Code/GamePhysics/GamePhysics.vcxproj.filters +++ b/Code/GamePhysics/GamePhysics.vcxproj.filters @@ -36,6 +36,12 @@ Header Files\Implementation + + Header Files\Include + + + Header Files\Include + diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp index ea75ffe3..934c843f 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -42,6 +42,23 @@ UniquePointer SimpleRigidBody::Clone() const return new SimpleRigidBody( *this ); } +SimpleRigidBody::State SimpleRigidBody::GetState() const +{ + return State( this->rigid.box.boundingOffset, this->rigid.box.center, AngularAxis(this->rigid.box.rotation).xyz ); +} + +SimpleRigidBody::State & SimpleRigidBody::GetState( SimpleRigidBody::State &targetMem ) const +{ + return targetMem = State( this->rigid.box.boundingOffset, this->rigid.box.center, AngularAxis(this->rigid.box.rotation).xyz ); +} + +void SimpleRigidBody::SetState( const SimpleRigidBody::State &state ) +{ /** @todo TODO: temporary solution! Need to know it's occtree */ + this->rigid.box.boundingOffset = state.GetReach(); + this->rigid.box.center = state.GetCenterPosition(); + this->rigid.box.rotation = state.GetRotation(); +} + void SimpleRigidBody::CallSubscription( const ICustomBody *proto, const ICustomBody *deuter ) { this->collisionAction( proto, deuter ); diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.h b/Code/GamePhysics/Implementation/SimpleRigidBody.h index 5e05c9d7..774420c5 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.h +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.h @@ -15,6 +15,10 @@ namespace Oyster { namespace Physics ::Utility::DynamicMemory::UniquePointer Clone() const; + State GetState() const; + State & GetState( State &targetMem ) const; + void SetState( const State &state ); + void CallSubscription( const ICustomBody *proto, const ICustomBody *deuter ); bool IsAffectedByGravity() const; bool Intersects( const ICustomBody &object, ::Oyster::Math::Float timeStepLength, ::Oyster::Math::Float &deltaWhen, ::Oyster::Math::Float3 &worldPointOfContact ) const; diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp index 03ed7d2a..34160192 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp @@ -44,6 +44,23 @@ UniquePointer SphericalRigidBody::Clone() const return new SphericalRigidBody( *this ); } +SphericalRigidBody::State SphericalRigidBody::GetState() const +{ + return State( this->rigid.box.boundingOffset, this->rigid.box.center, AngularAxis(this->rigid.box.rotation).xyz ); +} + +SphericalRigidBody::State & SphericalRigidBody::GetState( SphericalRigidBody::State &targetMem ) const +{ + return targetMem = State( this->rigid.box.boundingOffset, this->rigid.box.center, AngularAxis(this->rigid.box.rotation).xyz ); +} + +void SphericalRigidBody::SetState( const SphericalRigidBody::State &state ) +{ /** @todo TODO: temporary solution! Need to know it's occtree */ + this->rigid.box.boundingOffset = state.GetReach(); + this->rigid.box.center = state.GetCenterPosition(); + this->rigid.box.rotation = state.GetRotation(); +} + void SphericalRigidBody::CallSubscription( const ICustomBody *proto, const ICustomBody *deuter ) { this->collisionAction( proto, deuter ); diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.h b/Code/GamePhysics/Implementation/SphericalRigidBody.h index a25cba2c..1aca514d 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.h +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.h @@ -16,6 +16,10 @@ namespace Oyster { namespace Physics ::Utility::DynamicMemory::UniquePointer Clone() const; + State GetState() const; + State & GetState( State &targetMem = State() ) const; + void SetState( const State &state ); + void CallSubscription( const ICustomBody *proto, const ICustomBody *deuter ); bool IsAffectedByGravity() const; bool Intersects( const ICustomBody &object, ::Oyster::Math::Float timeStepLength, ::Oyster::Math::Float &deltaWhen, ::Oyster::Math::Float3 &worldPointOfContact ) const; diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index cd720abd..387bf0e6 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -1,4 +1,4 @@ - #ifndef PHYSICS_API_H +#ifndef PHYSICS_API_H #define PHYSICS_API_H #include "OysterCollision3D.h" @@ -17,6 +17,13 @@ namespace Oyster class API; class ICustomBody; + namespace Struct + { + struct SimpleBodyDescription; + struct SphericalBodyDescription; + struct CustomBodyState; + } + enum UpdateState { UpdateState_resting, @@ -32,7 +39,7 @@ namespace Oyster { public: static ::Oyster::Math::Float4x4 & CreateSphereMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius, ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ); - + static ::Oyster::Math::Float4x4 & CreateHollowSphereMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float radius, ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ); static ::Oyster::Math::Float4x4 & CreateCuboidMatrix( const ::Oyster::Math::Float mass, const ::Oyster::Math::Float height, const ::Oyster::Math::Float width, const ::Oyster::Math::Float depth, ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ); @@ -45,8 +52,8 @@ namespace Oyster class PHYSICS_DLL_USAGE API { public: - struct SimpleBodyDescription; - struct SphericalBodyDescription; + typedef Struct::SimpleBodyDescription SimpleBodyDescription; + typedef Struct::SphericalBodyDescription SphericalBodyDescription; typedef void (*EventAction_Destruction)( ::Utility::DynamicMemory::UniquePointer proto ); @@ -237,6 +244,9 @@ namespace Oyster }; typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter ); + typedef Struct::SimpleBodyDescription SimpleBodyDescription; + typedef Struct::SphericalBodyDescription SphericalBodyDescription; + typedef Struct::CustomBodyState State; virtual ~ICustomBody() {}; @@ -251,6 +261,21 @@ namespace Oyster ********************************************************/ virtual void CallSubscription( const ICustomBody *proto, const ICustomBody *deuter ) = 0; + /******************************************************** + * @todo TODO: need doc + ********************************************************/ + virtual State GetState() const = 0; + + /******************************************************** + * @todo TODO: need doc + ********************************************************/ + virtual State & GetState( State &targetMem ) const = 0; + + /******************************************************** + * @todo TODO: need doc + ********************************************************/ + virtual void SetState( const State &state ) = 0; + /******************************************************** * @return true if Engine should apply gravity on this object. ********************************************************/ @@ -397,48 +422,9 @@ namespace Oyster ********************************************************/ virtual void SetMomentum( const ::Oyster::Math::Float3 &worldG ) = 0; }; - - struct API::SimpleBodyDescription - { - ::Oyster::Math::Float4x4 rotation; - ::Oyster::Math::Float3 centerPosition; - ::Oyster::Math::Float3 size; - ::Oyster::Math::Float mass; - ::Oyster::Math::Float4x4 inertiaTensor; - ICustomBody::EventAction_Collision subscription; - bool ignoreGravity; - - SimpleBodyDescription() - { - this->rotation = ::Oyster::Math::Float4x4::identity; - this->centerPosition = ::Oyster::Math::Float3::null; - this->size = ::Oyster::Math::Float3( 1.0f ); - this->mass = 12.0f; - this->inertiaTensor = ::Oyster::Math::Float4x4::identity; - this->subscription = NULL; - this->ignoreGravity = false; - } - }; - - struct API::SphericalBodyDescription - { - ::Oyster::Math::Float4x4 rotation; - ::Oyster::Math::Float3 centerPosition; - ::Oyster::Math::Float radius; - ::Oyster::Math::Float mass; - ICustomBody::EventAction_Collision subscription; - bool ignoreGravity; - - SphericalBodyDescription() - { - this->rotation = ::Oyster::Math::Float4x4::identity; - this->centerPosition = ::Oyster::Math::Float3::null; - this->radius = 0.5f; - this->mass = 10.0f; - this->subscription = NULL; - this->ignoreGravity = false; - } - }; } } + +#include "PhysicsStructs.h" + #endif \ No newline at end of file diff --git a/Code/GamePhysics/PhysicsStructs-Impl.h b/Code/GamePhysics/PhysicsStructs-Impl.h new file mode 100644 index 00000000..3de46ee2 --- /dev/null +++ b/Code/GamePhysics/PhysicsStructs-Impl.h @@ -0,0 +1,117 @@ +#ifndef PHYSICS_STRUCTS_IMPL_H +#define PHYSICS_STRUCTS_IMPL_H + +#include "PhysicsStructs.h" + +namespace Oyster { namespace Physics +{ + namespace Struct + { + inline SimpleBodyDescription::SimpleBodyDescription() + { + this->rotation = ::Oyster::Math::Float4x4::identity; + this->centerPosition = ::Oyster::Math::Float3::null; + this->size = ::Oyster::Math::Float3( 1.0f ); + this->mass = 12.0f; + this->inertiaTensor = ::Oyster::Math::Float4x4::identity; + this->subscription = NULL; + this->ignoreGravity = false; + } + + inline SphericalBodyDescription::SphericalBodyDescription() + { + this->rotation = ::Oyster::Math::Float4x4::identity; + this->centerPosition = ::Oyster::Math::Float3::null; + this->radius = 0.5f; + this->mass = 10.0f; + this->subscription = NULL; + this->ignoreGravity = false; + } + + + inline CustomBodyState::CustomBodyState( const ::Oyster::Math::Float3 &reach, const ::Oyster::Math::Float3 ¢erPos, const ::Oyster::Math::Float3 &rotation ) + { + this->reach = ::Oyster::Math::Float4( reach, 0.0f ); + this->centerPos = ::Oyster::Math::Float4( centerPos, 1.0f ); + this->angularAxis = ::Oyster::Math::Float4( rotation, 0.0f ); + this->isSpatiallyAltered = this->isDisturbed = false; + } + + inline CustomBodyState & CustomBodyState::operator = ( const CustomBodyState &state ) + { + this->reach = state.reach; + this->centerPos = state.centerPos; + this->angularAxis = state.angularAxis; + + this->isSpatiallyAltered = state.isSpatiallyAltered; + this->isDisturbed = state.isDisturbed; + return *this; + } + + inline const ::Oyster::Math::Float4 & CustomBodyState::GetReach() const + { + return this->reach; + } + + inline ::Oyster::Math::Float4 CustomBodyState::GetSize() const + { + return 2.0f * this->GetReach(); + } + + inline const ::Oyster::Math::Float4 & CustomBodyState::GetCenterPosition() const + { + return this->centerPos; + } + + inline const ::Oyster::Math::Float4 & CustomBodyState::GetAngularAxis() const + { + return this->angularAxis; + } + + inline ::Oyster::Math::Float4x4 CustomBodyState::GetRotation() const + { + return ::Oyster::Math3D::RotationMatrix( this->GetAngularAxis().xyz ); + } + + inline void CustomBodyState::SetSize( const ::Oyster::Math::Float3 &size ) + { + this->SetReach( 0.5f * size ); + } + + inline void CustomBodyState::SetReach( const ::Oyster::Math::Float3 &halfSize ) + { + this->reach.xyz = halfSize; + this->reach = ::Utility::Value::Max( this->reach, ::Oyster::Math::Float4::null ); + this->isSpatiallyAltered = this->isDisturbed = true; + } + + inline void CustomBodyState::SetCenterPosition( const ::Oyster::Math::Float3 ¢erPos ) + { + this->centerPos.xyz = centerPos; + this->isSpatiallyAltered = this->isDisturbed = true; + } + + inline void CustomBodyState::SetRotation( const ::Oyster::Math::Float3 &angularAxis ) + { + this->angularAxis.xyz = angularAxis; + this->isSpatiallyAltered = this->isDisturbed = true; + } + + inline void CustomBodyState::SetRotation( const ::Oyster::Math::Float4x4 &rotation ) + { + this->SetRotation( ::Oyster::Math3D::AngularAxis(rotation).xyz ); + } + + inline bool CustomBodyState::IsSpatiallyAltered() const + { + return this->isSpatiallyAltered; + } + + inline bool CustomBodyState::IsDisturbed() const + { + return this->isDisturbed; + } + } +} } + +#endif \ No newline at end of file diff --git a/Code/GamePhysics/PhysicsStructs.h b/Code/GamePhysics/PhysicsStructs.h new file mode 100644 index 00000000..c1f74640 --- /dev/null +++ b/Code/GamePhysics/PhysicsStructs.h @@ -0,0 +1,70 @@ +#ifndef PHYSICS_STRUCTS_H +#define PHYSICS_STRUCTS_H + +#include "OysterMath.h" +#include "PhysicsAPI.h" + +namespace Oyster { namespace Physics +{ + namespace Struct + { + struct SimpleBodyDescription + { + ::Oyster::Math::Float4x4 rotation; + ::Oyster::Math::Float3 centerPosition; + ::Oyster::Math::Float3 size; + ::Oyster::Math::Float mass; + ::Oyster::Math::Float4x4 inertiaTensor; + ::Oyster::Physics::ICustomBody::EventAction_Collision subscription; + bool ignoreGravity; + + SimpleBodyDescription(); + }; + + struct SphericalBodyDescription + { + ::Oyster::Math::Float4x4 rotation; + ::Oyster::Math::Float3 centerPosition; + ::Oyster::Math::Float radius; + ::Oyster::Math::Float mass; + ::Oyster::Physics::ICustomBody::EventAction_Collision subscription; + bool ignoreGravity; + + SphericalBodyDescription(); + }; + + struct CustomBodyState + { + public: + CustomBodyState( const ::Oyster::Math::Float3 &reach = ::Oyster::Math::Float3::null, + const ::Oyster::Math::Float3 ¢erPos = ::Oyster::Math::Float3::null, + const ::Oyster::Math::Float3 &rotation = ::Oyster::Math::Float3::null ); + + CustomBodyState & operator = ( const CustomBodyState &state ); + + const ::Oyster::Math::Float4 & GetReach() const; + ::Oyster::Math::Float4 GetSize() const; + const ::Oyster::Math::Float4 & GetCenterPosition() const; + const ::Oyster::Math::Float4 & GetAngularAxis() const; + ::Oyster::Math::Float4x4 GetRotation() const; + + void SetSize( const ::Oyster::Math::Float3 &size ); + void SetReach( const ::Oyster::Math::Float3 &halfSize ); + void SetCenterPosition( const ::Oyster::Math::Float3 ¢erPos ); + void SetRotation( const ::Oyster::Math::Float3 &angularAxis ); + void SetRotation( const ::Oyster::Math::Float4x4 &rotation ); + + bool IsSpatiallyAltered() const; + bool IsDisturbed() const; + + private: + ::Oyster::Math::Float4 reach, centerPos, angularAxis; + + bool isSpatiallyAltered, isDisturbed; + }; + } +} } + +#include "PhysicsStructs-Impl.h" + +#endif \ No newline at end of file diff --git a/Code/OysterMath/LinearMath.h b/Code/OysterMath/LinearMath.h index 0495939d..8bca1c19 100644 --- a/Code/OysterMath/LinearMath.h +++ b/Code/OysterMath/LinearMath.h @@ -11,6 +11,27 @@ #include "Quaternion.h" #include +namespace std +{ + template + inline ::LinearAlgebra::Vector2 asin( const ::LinearAlgebra::Vector2 &vec ) + { + return ::LinearAlgebra::Vector2( asin(vec.x), asin(vec.y) ); + } + + template + inline ::LinearAlgebra::Vector3 asin( const ::LinearAlgebra::Vector3 &vec ) + { + return ::LinearAlgebra::Vector3( asin(vec.x), asin(vec.y), asin(vec.z) ); + } + + template + inline ::LinearAlgebra::Vector4 asin( const ::LinearAlgebra::Vector4 &vec ) + { + return ::LinearAlgebra::Vector4( asin(vec.x), asin(vec.y), asin(vec.z), asin(vec.w) ); + } +} + // x2 template @@ -233,6 +254,18 @@ namespace LinearAlgebra2D namespace LinearAlgebra3D { + template + inline ::LinearAlgebra::Vector4 AngularAxis( const ::LinearAlgebra::Matrix3x3 &rotationMatrix ) + { + return ::std::asin( ::LinearAlgebra::Vector4(rotationMatrix.v[1].z, rotationMatrix.v[2].x, rotationMatrix.v[0].y, 1) ); + } + + template + inline ::LinearAlgebra::Vector4 AngularAxis( const ::LinearAlgebra::Matrix4x4 &rotationMatrix ) + { + return ::std::asin( ::LinearAlgebra::Vector4(rotationMatrix.v[1].z, rotationMatrix.v[2].x, rotationMatrix.v[0].y, 1) ); + } + template inline ::LinearAlgebra::Matrix4x4 & TranslationMatrix( const ::LinearAlgebra::Vector3 &position, ::LinearAlgebra::Matrix4x4 &targetMem = ::LinearAlgebra::Matrix4x4() ) { @@ -286,7 +319,9 @@ namespace LinearAlgebra3D template inline ::LinearAlgebra::Matrix3x3 & RotationMatrix_AxisZ( const ScalarType &radian, ::LinearAlgebra::Matrix3x3 &targetMem = ::LinearAlgebra::Matrix3x3() ) - { return ::LinearAlgebra2D::RotationMatrix( radian, targetMem ); } + { + return ::LinearAlgebra2D::RotationMatrix( radian, targetMem ); + } template inline ::LinearAlgebra::Matrix4x4 & RotationMatrix_AxisZ( const ScalarType &radian, ::LinearAlgebra::Matrix4x4 &targetMem = ::LinearAlgebra::Matrix4x4() ) @@ -300,7 +335,21 @@ namespace LinearAlgebra3D } template - ::LinearAlgebra::Matrix4x4 & RotationMatrix( const ::LinearAlgebra::Vector3 &normalizedAxis, const ScalarType &radian, ::LinearAlgebra::Matrix4x4 &targetMem ) + inline ::LinearAlgebra::Matrix4x4 RotationMatrix( const ::LinearAlgebra::Vector3 &angularAxis ) + { + ScalarType radian = angularAxis.GetMagnitude(); + if( radian != 0 ) + { + return RotationMatrix( angularAxis / radian, radian ); + } + else + { + return ::LinearAlgebra::Matrix4x4::identity; + } + } + + template + ::LinearAlgebra::Matrix4x4 & RotationMatrix( const ::LinearAlgebra::Vector3 &normalizedAxis, const ScalarType &radian, ::LinearAlgebra::Matrix4x4 &targetMem = ::LinearAlgebra::Matrix4x4() ) { /// TODO: not verified ScalarType r = radian * 0.5f, s = std::sin( r ), @@ -462,7 +511,7 @@ namespace LinearAlgebra3D ::LinearAlgebra::Matrix4x4 & ProjectionMatrix_Perspective( const ScalarType &vertFoV, const ScalarType &aspect, const ScalarType &nearClip, const ScalarType &farClip, ::LinearAlgebra::Matrix4x4 &targetMem = ::LinearAlgebra::Matrix4x4() ) { ScalarType fov = 1 / ::std::tan( vertFoV * 0.5f ), - dDepth = farClip / (farClip - nearClip); + dDepth = farClip / (farClip - nearClip); return targetMem = ::LinearAlgebra::Matrix4x4( fov / aspect, 0, 0, 0, 0, fov, 0, 0, 0, 0, dDepth, -(dDepth * nearClip), @@ -473,7 +522,7 @@ namespace LinearAlgebra3D ::LinearAlgebra::Matrix4x4 & ProjectionMatrix_Perspective( const ScalarType &left, const ScalarType &right, const ScalarType &top, const ScalarType &bottom, const ScalarType &nearClip, const ScalarType &farClip, ::LinearAlgebra::Matrix4x4 &targetMem = ::LinearAlgebra::Matrix4x4() ) { /** @todo TODO: not tested */ ScalarType fov = 1 / ::std::tan( vertFoV * 0.5f ), - dDepth = farClip / (farClip - nearClip); + dDepth = farClip / (farClip - nearClip); return targetMem = ::LinearAlgebra::Matrix4x4( 2*nearClip/(right - left), 0, -(right + left)/(right - left), 0, 0, 2*nearClip/(top - bottom), -(top + bottom)/(top - bottom), 0, 0, 0, dDepth, -(dDepth * nearClip), diff --git a/Code/OysterMath/OysterMath.cpp b/Code/OysterMath/OysterMath.cpp index 421ebc0b..cf9fa8ae 100644 --- a/Code/OysterMath/OysterMath.cpp +++ b/Code/OysterMath/OysterMath.cpp @@ -81,20 +81,45 @@ namespace Oyster { namespace Math2D namespace Oyster { namespace Math3D { + Float4 AngularAxis( const Float3x3 &rotationMatrix ) + { + return ::LinearAlgebra3D::AngularAxis( rotationMatrix ); + } + + Float4 AngularAxis( const Float4x4 &rotationMatrix ) + { + return ::LinearAlgebra3D::AngularAxis( rotationMatrix ); + } + Float4x4 & TranslationMatrix( const Float3 &position, Float4x4 &targetMem ) - { return ::LinearAlgebra3D::TranslationMatrix( position, targetMem ); } + { + return ::LinearAlgebra3D::TranslationMatrix( position, targetMem ); + } Float4x4 & RotationMatrix_AxisX( const Float &radian, Float4x4 &targetMem ) - { return ::LinearAlgebra3D::RotationMatrix_AxisX( radian, targetMem ); } + { + return ::LinearAlgebra3D::RotationMatrix_AxisX( radian, targetMem ); + } Float4x4 & RotationMatrix_AxisY( const Float &radian, Float4x4 &targetMem ) - { return ::LinearAlgebra3D::RotationMatrix_AxisY( radian, targetMem ); } + { + return ::LinearAlgebra3D::RotationMatrix_AxisY( radian, targetMem ); + } Float4x4 & RotationMatrix_AxisZ( const Float &radian, Float4x4 &targetMem ) - { return ::LinearAlgebra3D::RotationMatrix_AxisZ( radian, targetMem ); } + { + return ::LinearAlgebra3D::RotationMatrix_AxisZ( radian, targetMem ); + } + + Float4x4 & RotationMatrix( const Float3 &angularAxis, Float4x4 &targetMem ) + { + return targetMem = ::LinearAlgebra3D::RotationMatrix( angularAxis ); + } Float4x4 & RotationMatrix( const Float &radian, const Float3 &normalizedAxis, Float4x4 &targetMem ) - { return ::LinearAlgebra3D::RotationMatrix( normalizedAxis, radian, targetMem ); } + { + return ::LinearAlgebra3D::RotationMatrix( normalizedAxis, radian, targetMem ); + } Float3x3 & InverseRotationMatrix( const Float3x3 &rotation, Float3x3 &targetMem ) { diff --git a/Code/OysterMath/OysterMath.h b/Code/OysterMath/OysterMath.h index ab3b307f..72fe7478 100644 --- a/Code/OysterMath/OysterMath.h +++ b/Code/OysterMath/OysterMath.h @@ -147,6 +147,12 @@ namespace Oyster { namespace Math3D /// Oyster's native math library specialized { using namespace ::Oyster::Math; // deliberate inheritance from ::Oyster::Math namespace + //! Extracts the angularAxis from rotationMatrix + Float4 AngularAxis( const Float3x3 &rotationMatrix ); + + //! Extracts the angularAxis from rotationMatrix + Float4 AngularAxis( const Float4x4 &rotationMatrix ); + /// Sets and returns targetMem to a translationMatrix with position as translation. Float4x4 & TranslationMatrix( const Float3 &position, Float4x4 &targetMem = Float4x4() ); @@ -159,6 +165,9 @@ namespace Oyster { namespace Math3D /// Oyster's native math library specialized /// Sets and returns targetMem as an counterclockwise rotation matrix around the global Z-axis Float4x4 & RotationMatrix_AxisZ( const Float &radian, Float4x4 &targetMem = Float4x4() ); + /// Sets and returns targetMem as an counterclockwise rotation matrix around the angularAxis. + Float4x4 & RotationMatrix( const Float3 &angularAxis, Float4x4 &targetMem = Float4x4() ); + /// Sets and returns targetMem as an counterclockwise rotation matrix around the normalizedAxis. /// Please make sure normalizedAxis is normalized. Float4x4 & RotationMatrix( const Float &radian, const Float3 &normalizedAxis, Float4x4 &targetMem = Float4x4() ); From 22665bc44ba801f0e9c27b76456504b5aa40afe7 Mon Sep 17 00:00:00 2001 From: Linda Andersson Date: Wed, 11 Dec 2013 12:14:00 +0100 Subject: [PATCH 14/18] GL - started using network and protocols for sending/recieveing --- Code/DanBias.sln | 2 + Code/Game/DanBiasGame/DanBiasGame.vcxproj | 19 +++--- Code/Game/DanBiasGame/DanBiasGame_Impl.cpp | 44 +++++++++++- .../DanBiasGame/GameClientState/GameState.cpp | 3 + Code/Game/DanBiasGame/Include/DanBiasGame.h | 2 + Code/Game/DanBiasLauncher/Launcher.cpp | 4 +- Code/Game/GameProtocols/GameProtocols.vcxproj | 1 + Code/Game/GameProtocols/ObjectProtocols.h | 67 +++++++++++++++++++ Code/Game/GameProtocols/PlayerProtocols.h | 59 +++++++++++----- .../GameProtocols/ProtocolIdentificationID.h | 4 +- 10 files changed, 177 insertions(+), 28 deletions(-) create mode 100644 Code/Game/GameProtocols/ObjectProtocols.h diff --git a/Code/DanBias.sln b/Code/DanBias.sln index 9ef6f418..90a7843f 100644 --- a/Code/DanBias.sln +++ b/Code/DanBias.sln @@ -163,6 +163,7 @@ Global {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Mixed Platforms.ActiveCfg = Release|x64 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Mixed Platforms.Build.0 = Release|x64 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Win32.ActiveCfg = Debug|Win32 + {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|Win32.Build.0 = Debug|Win32 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|x64.ActiveCfg = Debug|x64 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Debug|x64.Build.0 = Debug|x64 {C5AA09D0-6594-4CD3-BD92-1D380C7B3B50}.Release|Mixed Platforms.ActiveCfg = Release|x64 @@ -240,6 +241,7 @@ Global {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|Mixed Platforms.Build.0 = Debug|Win32 {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|Win32.ActiveCfg = Debug|Win32 + {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|Win32.Build.0 = Debug|Win32 {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|x64.ActiveCfg = Debug|x64 {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Debug|x64.Build.0 = Debug|x64 {460D625F-2AC9-4559-B809-0BA89CEAEDF4}.Release|Mixed Platforms.ActiveCfg = Release|Win32 diff --git a/Code/Game/DanBiasGame/DanBiasGame.vcxproj b/Code/Game/DanBiasGame/DanBiasGame.vcxproj index 1784ca35..76a7554e 100644 --- a/Code/Game/DanBiasGame/DanBiasGame.vcxproj +++ b/Code/Game/DanBiasGame/DanBiasGame.vcxproj @@ -72,7 +72,7 @@ $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ $(ProjectName)_$(PlatformShortName)D $(SolutionDir)..\External\Lib\Input;$(SolutionDir)..\Bin\DLL;$(LibraryPath) - $(SolutionDir)..\External\Include\;$(IncludePath) + $(SolutionDir)Network/NetworkAPI;$(IncludePath) true @@ -106,7 +106,7 @@ Disabled DANBIAS_CLIENT;DANBIAS_GAME_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) + $(SolutionDir)Game/GameProtocols;$(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;%(AdditionalIncludeDirectories) Windows @@ -123,12 +123,12 @@ Disabled DANBIAS_CLIENT;DANBIAS_GAME_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) + $(SolutionDir)GameProtocols;$(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) Windows true - OysterGraphics_$(PlatformShortName)D.lib;Input_$(PlatformShortName)D.lib;%(AdditionalDependencies) + GameProtocols_$(PlatformShortName)D.lib;OysterGraphics_$(PlatformShortName)D.lib;Input_$(PlatformShortName)D.lib;%(AdditionalDependencies) OysterGraphics_$(PlatformShortName)D.dll;%(DelayLoadDLLs) @@ -142,14 +142,14 @@ true DANBIAS_CLIENT;DANBIAS_GAME_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) + $(SolutionDir)GameProtocols;$(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) Windows true true true - OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;%(AdditionalDependencies) + GameProtocols_$(PlatformShortName).lib;OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;%(AdditionalDependencies) OysterGraphics_x86.dll;%(DelayLoadDLLs) @@ -163,14 +163,14 @@ true DANBIAS_CLIENT;DANBIAS_GAME_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) + $(SolutionDir)GameProtocols;$(SolutionDir)OysterMath;$(SolutionDir)Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc;$(SolutionDir)OysterMath;%(AdditionalIncludeDirectories) Windows true true true - OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;%(AdditionalDependencies) + GameProtocols_$(PlatformShortName).lib;OysterGraphics_$(PlatformShortName).lib;Input_$(PlatformShortName).lib;%(AdditionalDependencies) OysterGraphics_x86.dll;%(DelayLoadDLLs) @@ -181,6 +181,9 @@ {2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee} + + {460d625f-2ac9-4559-b809-0ba89ceaedf4} + {0ec83e64-230e-48ef-b08c-6ac9651b4f82} diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index 64fc0bc4..e38b8cc9 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -5,7 +5,8 @@ #include "GameClientState/GameClientState.h" #include "GameClientState\GameState.h" #include "GameClientState\LobbyState.h" - +#include "PlayerProtocols.h" +#include "NetworkClient.h" #include "L_inputClass.h" #include "vld.h" @@ -19,6 +20,36 @@ namespace DanBias HWND DanBiasGame::g_hWnd = NULL; #pragma region Game Data + + + struct MyRecieverObject // :public PontusRecieverObject + { + Oyster::Network::NetworkClient nwClient; + + static void ProtocolRecieved(Network::CustomNetProtocol* p) + { + int pType = ((*p)[0]).value.netInt; + switch (pType) + { + case protocol_PlayerNavigation: + + break; + case protocol_PlayerPosition: + //int x = ((*p)[1]).value.netInt; + //int y = ((*p)[2]).value.netInt; + //int z = ((*p)[3]).value.netInt; + break; + + + case protocol_ObjectPosition: + // DanBiasGame::protocolRecived(); + break; + + default: + break; + } + } + }; class DanBiasGamePrivateData { @@ -35,12 +66,21 @@ namespace DanBias public: Client::GameClientState* gameClientState; InputClass* inputObj; + GameLogic::Protocol_PlayerMovement player_move; + //Oyster::Network::NetworkClient nwClient; + MyRecieverObject r; + // gameClient; } data; #pragma endregion - DanBiasGamePrivateData* DanBiasGame::m_data = new DanBiasGamePrivateData(); + + DanBiasGamePrivateData* DanBiasGame::m_data = new DanBiasGamePrivateData(); + void DanBiasGame::protocolRecived() + { + //m_data->gameClientState.setPos() + } //-------------------------------------------------------------------------------------- // Interface API functions //-------------------------------------------------------------------------------------- diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index fb81e23a..a95b6798 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -12,6 +12,7 @@ struct GameState::myData Oyster::Math3D::Float4x4 proj; C_Object* object[3]; int modelCount; + //Oyster::Network::NetworkClient* nwClient; gameStateState state; }privData; @@ -86,6 +87,8 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI case gameStateState_playing: // read server data // update objects + // Client.send(obj); + if(KeyInput->IsKeyPressed(DIK_L)) privData->state = GameState::gameStateState_end; break; diff --git a/Code/Game/DanBiasGame/Include/DanBiasGame.h b/Code/Game/DanBiasGame/Include/DanBiasGame.h index 924caac7..deaafdb9 100644 --- a/Code/Game/DanBiasGame/Include/DanBiasGame.h +++ b/Code/Game/DanBiasGame/Include/DanBiasGame.h @@ -54,6 +54,8 @@ namespace DanBias static HRESULT Update(float deltaTime); static HRESULT Render(float deltaTime); static HRESULT CleanUp(); + + static void protocolRecived(); private: static __int64 cntsPerSec; static __int64 prevTimeStamp; diff --git a/Code/Game/DanBiasLauncher/Launcher.cpp b/Code/Game/DanBiasLauncher/Launcher.cpp index 28b89485..0440d973 100644 --- a/Code/Game/DanBiasLauncher/Launcher.cpp +++ b/Code/Game/DanBiasLauncher/Launcher.cpp @@ -4,8 +4,8 @@ #define NOMINMAX #include -#define DANBIAS_SERVER -//#define DANBIAS_CLIENT +//#define DANBIAS_SERVER +#define DANBIAS_CLIENT #if defined(DANBIAS_SERVER) diff --git a/Code/Game/GameProtocols/GameProtocols.vcxproj b/Code/Game/GameProtocols/GameProtocols.vcxproj index 629ecf72..a7ebcca0 100644 --- a/Code/Game/GameProtocols/GameProtocols.vcxproj +++ b/Code/Game/GameProtocols/GameProtocols.vcxproj @@ -154,6 +154,7 @@ + diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h new file mode 100644 index 00000000..32a86259 --- /dev/null +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -0,0 +1,67 @@ +#ifndef GAMELOGIC_PLAYER_PROTOCOLS_H +#define GAMELOGIC_PLAYER_PROTOCOLS_H + +#include +#include "ProtocolIdentificationID.h" + + + +namespace GameLogic +{ + struct Protocol_ObjectPosition :public Network::CustomProtocolObject + { + float worldMatrix[16]; + // look at dir + + Protocol_ObjectPosition() + { + this->protocol[0].value = protocol_PlayerPosition; + this->protocol[0].type = Network::NetAttributeType_Int; + + this->protocol[1].type = Network::NetAttributeType_Float; + this->protocol[2].type = Network::NetAttributeType_Float; + this->protocol[3].type = Network::NetAttributeType_Float; + this->protocol[4].type = Network::NetAttributeType_Float; + this->protocol[5].type = Network::NetAttributeType_Float; + this->protocol[6].type = Network::NetAttributeType_Float; + this->protocol[7].type = Network::NetAttributeType_Float; + this->protocol[8].type = Network::NetAttributeType_Float; + this->protocol[9].type = Network::NetAttributeType_Float; + this->protocol[10].type = Network::NetAttributeType_Float; + this->protocol[11].type = Network::NetAttributeType_Float; + this->protocol[12].type = Network::NetAttributeType_Float; + this->protocol[13].type = Network::NetAttributeType_Float; + this->protocol[14].type = Network::NetAttributeType_Float; + this->protocol[15].type = Network::NetAttributeType_Float; + this->protocol[16].type = Network::NetAttributeType_Float; + + } + Network::CustomNetProtocol* GetProtocol() override + { + + this->protocol[1].value = worldMatrix[0]; + this->protocol[2].value = worldMatrix[1]; + this->protocol[3].value = worldMatrix[2]; + this->protocol[4].value = worldMatrix[4]; + this->protocol[5].value = worldMatrix[5]; + this->protocol[6].value = worldMatrix[6]; + this->protocol[7].value = worldMatrix[7]; + this->protocol[8].value = worldMatrix[8]; + this->protocol[9].value = worldMatrix[9]; + this->protocol[10].value = worldMatrix[10]; + this->protocol[11].value = worldMatrix[11]; + this->protocol[12].value = worldMatrix[12]; + this->protocol[13].value = worldMatrix[13]; + this->protocol[14].value = worldMatrix[14]; + this->protocol[15].value = worldMatrix[15]; + this->protocol[16].value = worldMatrix[16]; + return &protocol; + } + + private: + Network::CustomNetProtocol protocol; + }; + +} + +#endif // !GAMELOGIC_PLAYER_PROTOCOLS_H \ No newline at end of file diff --git a/Code/Game/GameProtocols/PlayerProtocols.h b/Code/Game/GameProtocols/PlayerProtocols.h index b091ba34..3375a87c 100644 --- a/Code/Game/GameProtocols/PlayerProtocols.h +++ b/Code/Game/GameProtocols/PlayerProtocols.h @@ -1,7 +1,7 @@ #ifndef GAMELOGIC_PLAYER_PROTOCOLS_H #define GAMELOGIC_PLAYER_PROTOCOLS_H -#include "CustomNetProtocol.h" +#include #include "ProtocolIdentificationID.h" @@ -20,24 +20,24 @@ namespace GameLogic Protocol_PlayerMovement() { - protocol[0]->value = ProtocolID = protocol_PlayerNavigation; + this->protocol[0].value = ProtocolID = protocol_PlayerNavigation; - protocol[0]->type = Network::NetAttributeType_Int; - protocol[1]->type = Network::NetAttributeType_Bool; - protocol[2]->type = Network::NetAttributeType_Bool; - protocol[3]->type = Network::NetAttributeType_Bool; - protocol[4]->type = Network::NetAttributeType_Bool; - protocol[5]->type = Network::NetAttributeType_Bool; - protocol[6]->type = Network::NetAttributeType_Bool; + this->protocol[0].type = Network::NetAttributeType_Int; + this->protocol[1].type = Network::NetAttributeType_Bool; + this->protocol[2].type = Network::NetAttributeType_Bool; + this->protocol[3].type = Network::NetAttributeType_Bool; + this->protocol[4].type = Network::NetAttributeType_Bool; + this->protocol[5].type = Network::NetAttributeType_Bool; + this->protocol[6].type = Network::NetAttributeType_Bool; } Network::CustomNetProtocol* GetProtocol() override { - protocol[1]->value = bForward; - protocol[2]->value = bBackward; - protocol[3]->value = bTurnLeft; - protocol[4]->value = bTurnRight; - protocol[5]->value = bStrafeRight; - protocol[6]->value = bStrafeRight; + this->protocol[1].value = bForward; + this->protocol[2].value = bBackward; + this->protocol[3].value = bTurnLeft; + this->protocol[4].value = bTurnRight; + this->protocol[5].value = bStrafeRight; + this->protocol[6].value = bStrafeRight; return &protocol; } @@ -45,6 +45,35 @@ namespace GameLogic private: Network::CustomNetProtocol protocol; }; + + struct Protocol_PlayerPosition :public Network::CustomProtocolObject + { + float position[3]; + // look at dir + + Protocol_PlayerPosition() + { + this->protocol[0].value = protocol_PlayerPosition; + this->protocol[0].type = Network::NetAttributeType_Int; + + this->protocol[1].type = Network::NetAttributeType_Float; + this->protocol[2].type = Network::NetAttributeType_Float; + this->protocol[3].type = Network::NetAttributeType_Float; + + } + Network::CustomNetProtocol* GetProtocol() override + { + + this->protocol[1].value = position[0]; + this->protocol[2].value = position[1]; + this->protocol[3].value = position[2]; + return &protocol; + } + + private: + Network::CustomNetProtocol protocol; + }; + } #endif // !GAMELOGIC_PLAYER_PROTOCOLS_H diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index 1af8c920..46a1b72f 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -3,6 +3,8 @@ /* THERE CAN ABSOLUTLEY NOT BE TWO DEFINITIONS WITH THE SAME ID!! */ -#define protocol_PlayerNavigation 0; +#define protocol_PlayerNavigation 0 +#define protocol_PlayerPosition 1 +#define protocol_ObjectPosition 2 #endif // !GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H From e11d7d94f72a011b30eb739600037ceb3549f75b Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Thu, 12 Dec 2013 09:36:14 +0100 Subject: [PATCH 15/18] updated the weapon system, collisionManager and redid the "object" heirarki --- Bin/Content/Shaders/DebugVertex.cso | Bin 12292 -> 12292 bytes Code/Game/GameLogic/AttatchmentSocket.cpp | 22 ++++++- Code/Game/GameLogic/AttatchmentSocket.h | 2 + Code/Game/GameLogic/CollisionManager.cpp | 24 ++++--- Code/Game/GameLogic/CollisionManager.h | 9 ++- Code/Game/GameLogic/DynamicObject.cpp | 26 +++----- Code/Game/GameLogic/DynamicObject.h | 11 ++-- Code/Game/GameLogic/GameLogicStates.h | 9 ++- Code/Game/GameLogic/Level.cpp | 8 +-- Code/Game/GameLogic/Level.h | 2 + Code/Game/GameLogic/Object.cpp | 40 ++++++------ Code/Game/GameLogic/Object.h | 27 ++------ Code/Game/GameLogic/Player.cpp | 14 ++-- Code/Game/GameLogic/Player.h | 5 +- Code/Game/GameLogic/RefManager.h | 1 - Code/Game/GameLogic/StaticObject.cpp | 24 +++---- Code/Game/GameLogic/StaticObject.h | 6 +- Code/Game/GameLogic/Weapon.cpp | 75 ++++++++++++++++++++-- Code/Game/GameLogic/Weapon.h | 13 +++- 19 files changed, 197 insertions(+), 121 deletions(-) diff --git a/Bin/Content/Shaders/DebugVertex.cso b/Bin/Content/Shaders/DebugVertex.cso index e35466e14dca7c76b79bb799b061e06a02989cce..4e8292c6b9d3cd124bebd03c7ec3fd0a25ae8a33 100644 GIT binary patch delta 535 zcmZokXh{%piEwgmxMmkFX%Q`bU2x&g3!(w(8%4fwOFX=}EQpbTfgySASH20`1^m~P z1_{cp`Ovvpf#(goQ3puM*(xTqIJKxa#^rGHp(VKmi7uJxF)sPZrManjCB-rBnI#^j zNii;oc}bax#glzC?RAr_VoJd}QVuT$>qr6WNP+7}&n(FR>PUg=kP@}iMzVtl8|)@W zh@FlMgcLPj(R#kp=0| z0Ai4e1hH*wZa_BNyv>eG{fwJgB;GJG-q`$6(wvX6VzQ=&KXbwBrpeVB<%)-iaH9R> zF3qaR0ZbOMQ}hfOafR}X$%P)WD}cBj=s61@4FWqhE9yLE1^|$krx*YL delta 697 zcmZokXh{%piEwh3v=b>QobD)osN7LnV|p9cMv*Vv68m4w4Ps+-<>w zXwza<8{^FiJa5>u`ax38RxzQ)sYS&xE~$BWnINh-yClCLrZ_u4Co#q)%+SQ#TtQbM zxFo-*M4`AKHK(+sEHybhCo?a-xS%LMD>b`BAyXl}sI;IUCIG}wE>Q^2FUkhWE4XA9 z0lE1_m6Pp6Jfk7zr=XahQU*1@m>BcH_5sZ=hnk-PH@{BHZgQZgwC61LQRz z08vXP$4dDKNF!=KrpCx3FaMmf||v&X*Mc@)Uqr X2Pjklq_+cU3m^>w`!_4Attatchment; + return myData->attatchment; +} + +void AttatchmentSocket::SetAttatchment(IAttatchment *attatchment) +{ + if (myData->attatchment) + { + delete myData->attatchment; + } + + myData->attatchment = attatchment; +} + +void AttatchmentSocket::RemoveAttatchment() +{ + if (myData->attatchment) + { + delete myData->attatchment; + } } diff --git a/Code/Game/GameLogic/AttatchmentSocket.h b/Code/Game/GameLogic/AttatchmentSocket.h index 1067e339..f9be588b 100644 --- a/Code/Game/GameLogic/AttatchmentSocket.h +++ b/Code/Game/GameLogic/AttatchmentSocket.h @@ -11,6 +11,8 @@ namespace GameLogic ~AttatchmentSocket(void); IAttatchment* GetAttatchment(); + void SetAttatchment(IAttatchment *attatchment); + void RemoveAttatchment(); private: struct PrivateData; diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 52eaa4f3..b19c7de3 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -1,4 +1,9 @@ #include "CollisionManager.h" +#include "RefManager.h" +#include "PhysicsAPI.h" +#include "Object.h" +#include "DynamicObject.h" +#include "Player.h" using namespace Oyster; @@ -15,22 +20,21 @@ namespace GameLogic switch (realObj->GetType()) { - case Object::OBJECT_TYPE_BOX: - PlayerVBox(*player,(*(DynamicObject*) realObj)); + case OBJECT_TYPE_BOX: + //PlayerVBox(*player,(*(DynamicObject*) realObj)); break; - case Object::OBJECT_TYPE_PLAYER: + case OBJECT_TYPE_PLAYER: break; } - //spela ljud? ta skada? etc etc return Physics::ICustomBody::SubscriptMessage_none; } - void PlayerVBox(Player &player, DynamicObject &box) + /* void PlayerVBox(Player &player, DynamicObject &box) { - //spela ljud? ta skada? etc etc - } + spela ljud? ta skada? etc etc + }*/ Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj) { @@ -39,11 +43,11 @@ namespace GameLogic switch (realObj->GetType()) { - case Object::OBJECT_TYPE_BOX: + case OBJECT_TYPE_BOX: break; - case Object::OBJECT_TYPE_PLAYER: - PlayerVBox(*(Player*)realObj,*box); + case OBJECT_TYPE_PLAYER: + //PlayerVBox(*(Player*)realObj,*box); break; } diff --git a/Code/Game/GameLogic/CollisionManager.h b/Code/Game/GameLogic/CollisionManager.h index f88404cc..86a05906 100644 --- a/Code/Game/GameLogic/CollisionManager.h +++ b/Code/Game/GameLogic/CollisionManager.h @@ -3,9 +3,8 @@ #include "Object.h" #include "PhysicsAPI.h" -#include "RefManager.h" -#include "DynamicObject.h" -#include "Player.h" +//#include "DynamicObject.h" +//#include "Player.h" namespace GameLogic { @@ -18,8 +17,8 @@ namespace GameLogic Oyster::Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj); //these are the specific collision case functions - void PlayerVBox(Player &player, DynamicObject &box); - void BoxVBox(DynamicObject &box1, DynamicObject &box2); + //void PlayerVBox(Player &player, DynamicObject &box); + //void BoxVBox(DynamicObject &box1, DynamicObject &box2); }; diff --git a/Code/Game/GameLogic/DynamicObject.cpp b/Code/Game/GameLogic/DynamicObject.cpp index 8786255c..a8ea1ab4 100644 --- a/Code/Game/GameLogic/DynamicObject.cpp +++ b/Code/Game/GameLogic/DynamicObject.cpp @@ -1,29 +1,23 @@ #include "DynamicObject.h" +#include "CollisionManager.h" using namespace GameLogic; -struct DynamicObject::PrivateData -{ - PrivateData() - { - - } - - ~PrivateData() - { - - } - -}myData; - DynamicObject::DynamicObject() + :Object() { - myData = new PrivateData(); + +} + +DynamicObject::DynamicObject(void* collisionFunc, OBJECT_TYPE type) + :Object(collisionFunc, type) +{ + } DynamicObject::~DynamicObject(void) { - delete myData; + } \ No newline at end of file diff --git a/Code/Game/GameLogic/DynamicObject.h b/Code/Game/GameLogic/DynamicObject.h index ecf1e905..70bb8c11 100644 --- a/Code/Game/GameLogic/DynamicObject.h +++ b/Code/Game/GameLogic/DynamicObject.h @@ -1,27 +1,24 @@ ////////////////////////////////////////////////// //Created by Erik and Linda of the GameLogic team ////////////////////////////////////////////////// - - #ifndef DYNAMICOBJECT_H #define DYNAMICOBJECT_H +#include "Object.h" namespace GameLogic { - class DynamicObject + class DynamicObject : public Object { public: DynamicObject(); + DynamicObject(void* collisionFunc, OBJECT_TYPE type); ~DynamicObject(void); - void Update(); - private: - struct PrivateData; - PrivateData *myData; + }; } diff --git a/Code/Game/GameLogic/GameLogicStates.h b/Code/Game/GameLogic/GameLogicStates.h index 3c2b9997..3e72647e 100644 --- a/Code/Game/GameLogic/GameLogicStates.h +++ b/Code/Game/GameLogic/GameLogicStates.h @@ -36,6 +36,13 @@ namespace GameLogic WEAPON_STATE_IDLE = 1, WEAPON_STATE_RELOADING = 2, }; -} + + enum OBJECT_TYPE + { + OBJECT_TYPE_PLAYER = 0, + OBJECT_TYPE_BOX = 1, + OBJECT_TYPE_UNKNOWN = 2, + }; +}; #endif \ No newline at end of file diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index c83056c6..38865f63 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -9,14 +9,10 @@ struct Level::PrivateData { PrivateData() { - gameMode = new GameMode(); + } ~PrivateData() { - if (gameMode) - { - delete gameMode; - } } @@ -40,3 +36,5 @@ Level::~Level(void) { delete myData; } + + diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 217a60e4..9c7adb1a 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -14,6 +14,8 @@ namespace GameLogic Level(void); ~Level(void); + void CreateBox(); + private: struct PrivateData; PrivateData *myData; diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 67385874..7eb4b57f 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -1,23 +1,15 @@ #include "Object.h" #include "OysterMath.h" -#include "DllInterfaces\GFXAPI.h" -#include "CollisionManager.h" +#include "RefManager.h" using namespace GameLogic; using namespace Oyster::Math; -using namespace Oyster::Graphics::Model; - -using namespace Utility::DynamicMemory; using namespace Oyster::Physics; -Object::Object(std::wstring objFile) -{ - - //model = new Model(); - model = Oyster::Graphics::API::CreateModel(objFile); - +Object::Object() +{ API::SimpleBodyDescription sbDesc; //sbDesc.centerPosition = @@ -26,23 +18,33 @@ Object::Object(std::wstring objFile) GameLogic::RefManager::getInstance()->AddMapping(*rigidBody, *this); + this->type = OBJECT_TYPE_UNKNOWN; + +} + +Object::Object(void* collisionFunc, OBJECT_TYPE type) +{ + API::SimpleBodyDescription sbDesc; + //sbDesc.centerPosition = + + //poi + ICustomBody* temp = rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); + + rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc)); + + GameLogic::RefManager::getInstance()->AddMapping(*rigidBody, *this); + + this->type = type; } Object::~Object(void) { - Oyster::Graphics::API::DeleteModel(model); } -void Object::Render() -{ - this->rigidBody->GetOrientation(model->WorldMatrix); - Oyster::Graphics::API::RenderScene(model, 1); -} - -Object::OBJECT_TYPE Object::GetType() +OBJECT_TYPE Object::GetType() { return this->type; } diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index 1c1c2830..e2c1bee4 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -7,41 +7,24 @@ #define OBJECT_H #include "PhysicsAPI.h" -#include "DllInterfaces/GFXAPI.h" - -#include "Model/Model.h" -#include "Utilities.h" - - +#include "GameLogicStates.h" +#include "CollisionManager.h" namespace GameLogic { class Object { public: - - enum OBJECT_TYPE - { - OBJECT_TYPE_PLAYER, - OBJECT_TYPE_BOX, - }; - Object(std::wstring objFile ); - virtual ~Object(void); - - void Render(); + Object(); + Object(void* collisionFunc, OBJECT_TYPE type); + ~Object(void); OBJECT_TYPE GetType(); private: OBJECT_TYPE type; - protected: - //either a model pointer or an ID to an arraypos filled with models that are to be rendered - //rigidBody - Oyster::Physics::ICustomBody *rigidBody; - Oyster::Graphics::Model::Model *model; - }; } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 9bc9d752..ad81bf61 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -15,8 +15,6 @@ struct Player::PrivateData life = 100; playerState = PLAYER_STATE_IDLE; - rigidBody->SetSubscription(CollisionManager::PlayerCollision); - } ~PrivateData() @@ -30,16 +28,16 @@ struct Player::PrivateData int life; Weapon *weapon; PLAYER_STATE playerState; - - ICustomBody *rigidBody; + Oyster::Math::Float3 lookDir; }myData; Player::Player() + :Object(CollisionManager::PlayerCollision, OBJECT_TYPE_PLAYER) { myData = new PrivateData(); - } + Player::~Player(void) { delete myData; @@ -83,9 +81,9 @@ void Player::Move(const PLAYER_MOVEMENT &movement) /******************************************************** * Uses the players weapon based on user input ********************************************************/ -void Player::Shoot(const WEAPON_FIRE &fireInput) +void Player::UseWeapon(const WEAPON_FIRE &fireInput) { - myData->weapon->UseWeapon(fireInput); + myData->weapon->Use(fireInput); } /******************************************************** @@ -112,7 +110,7 @@ bool Player::IsIdle() Oyster::Math::Float3 Player::GetPos() { - return myData->rigidBody->GetCenter(); + return rigidBody->GetCenter(); } /******************************************************** diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 20fc8de6..44b28ceb 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -5,10 +5,11 @@ #define PLAYER_H #include "GameLogicStates.h" #include "OysterMath.h" +#include "Object.h" namespace GameLogic { - class Player + class Player : public Object { public: @@ -17,7 +18,7 @@ namespace GameLogic void Update(); void Move(const PLAYER_MOVEMENT &movement); - void Shoot(const WEAPON_FIRE &fireInput); + void UseWeapon(const WEAPON_FIRE &fireInput); void Jump(); bool IsWalking(); diff --git a/Code/Game/GameLogic/RefManager.h b/Code/Game/GameLogic/RefManager.h index a184e220..fa4080c9 100644 --- a/Code/Game/GameLogic/RefManager.h +++ b/Code/Game/GameLogic/RefManager.h @@ -8,7 +8,6 @@ #include #include "Object.h" -#include "PhysicsAPI.h" namespace GameLogic { diff --git a/Code/Game/GameLogic/StaticObject.cpp b/Code/Game/GameLogic/StaticObject.cpp index c58fb83c..155834fe 100644 --- a/Code/Game/GameLogic/StaticObject.cpp +++ b/Code/Game/GameLogic/StaticObject.cpp @@ -2,28 +2,22 @@ using namespace GameLogic; -struct StaticObject::PrivateData -{ - PrivateData() - { - - } - - ~PrivateData() - { - - } - -}myData; StaticObject::StaticObject() + :Object() { - myData = new PrivateData(); + +} + +StaticObject::StaticObject(void* collisionFunc, OBJECT_TYPE type) + :Object(collisionFunc,type) +{ + } StaticObject::~StaticObject(void) { - delete myData; + } diff --git a/Code/Game/GameLogic/StaticObject.h b/Code/Game/GameLogic/StaticObject.h index 2f292795..31121447 100644 --- a/Code/Game/GameLogic/StaticObject.h +++ b/Code/Game/GameLogic/StaticObject.h @@ -11,16 +11,16 @@ namespace GameLogic { - class StaticObject + class StaticObject : public Object { public: StaticObject(); + StaticObject(void* collisionFunc, OBJECT_TYPE type); ~StaticObject(void); private: - struct PrivateData; - PrivateData *myData; + }; } diff --git a/Code/Game/GameLogic/Weapon.cpp b/Code/Game/GameLogic/Weapon.cpp index 2a575039..4bf4311c 100644 --- a/Code/Game/GameLogic/Weapon.cpp +++ b/Code/Game/GameLogic/Weapon.cpp @@ -9,20 +9,23 @@ struct Weapon::PrivateData PrivateData() { weaponState = WEAPON_STATE_IDLE; - SelectedAttatchment = new AttatchmentMassDriver(); + SelectedAttatchment = 0; + currentNrOfAttatchments = 0; + selectedSocketID = 0; } ~PrivateData() { - delete SelectedAttatchment; } WEAPON_STATE weaponState; AttatchmentSocket **attatchmentSockets; - int nrOfAttatchmentSockets; + int MaxNrOfSockets; + int currentNrOfAttatchments; IAttatchment *SelectedAttatchment; + int selectedSocketID; }myData; @@ -31,6 +34,17 @@ Weapon::Weapon() myData = new PrivateData(); } +Weapon::Weapon(int MaxNrOfSockets) +{ + myData = new PrivateData(); + myData->MaxNrOfSockets = MaxNrOfSockets; + myData->attatchmentSockets = new AttatchmentSocket*[MaxNrOfSockets]; + for (int i = 0; i < MaxNrOfSockets; i++) + { + myData->attatchmentSockets[i] = new AttatchmentSocket(); + } +} + Weapon::~Weapon(void) { @@ -40,7 +54,7 @@ Weapon::~Weapon(void) /******************************************************** * Uses the weapon based on the input given and the current chosen attatchment ********************************************************/ -void Weapon::UseWeapon(const WEAPON_FIRE &fireInput) +void Weapon::Use(const WEAPON_FIRE &fireInput) { myData->SelectedAttatchment->UseAttatchment(fireInput); } @@ -67,3 +81,56 @@ bool Weapon::IsReloading() return (myData->weaponState == WEAPON_STATE::WEAPON_STATE_RELOADING); } +bool Weapon::IsValidSocket(int socketID) +{ + if(socketID < myData->MaxNrOfSockets && socketID >= 0) + { + if (myData->attatchmentSockets[socketID]->GetAttatchment() != 0) + { + return true; + } + } + + return false; +} + +int Weapon::GetCurrentSocketID() +{ + return myData->selectedSocketID; +} + + +void Weapon::AddNewAttatchment(IAttatchment *attatchment) +{ + if(myData->currentNrOfAttatchments < myData->MaxNrOfSockets) + { + myData->attatchmentSockets[myData->currentNrOfAttatchments]->SetAttatchment(attatchment); + myData->currentNrOfAttatchments++; + } +} + +void Weapon::SwitchAttatchment(IAttatchment *attatchment, int socketID) +{ + if (IsValidSocket(socketID)) + { + myData->attatchmentSockets[socketID]->SetAttatchment(attatchment); + } +} + +void Weapon::RemoveAttatchment(int socketID) +{ + if (IsValidSocket(socketID)) + { + myData->attatchmentSockets[socketID]->RemoveAttatchment(); + } +} + +void Weapon::SelectAttatchment(int socketID) +{ + if (IsValidSocket(socketID)) + { + myData->SelectedAttatchment = myData->attatchmentSockets[socketID]->GetAttatchment(); + myData->selectedSocketID = socketID; + } + +} \ No newline at end of file diff --git a/Code/Game/GameLogic/Weapon.h b/Code/Game/GameLogic/Weapon.h index 74a408e9..b5239b6e 100644 --- a/Code/Game/GameLogic/Weapon.h +++ b/Code/Game/GameLogic/Weapon.h @@ -4,6 +4,7 @@ #ifndef WEAPON_H #define WEAPON_H #include "GameLogicStates.h" +#include "IAttatchment.h" namespace GameLogic { @@ -15,14 +16,24 @@ namespace GameLogic Weapon(void); + Weapon(int nrOfAttatchmentSockets); ~Weapon(void); - void UseWeapon(const WEAPON_FIRE &fireInput); + void Use(const WEAPON_FIRE &fireInput); + void AddNewAttatchment(IAttatchment *attatchment); + void SwitchAttatchment(IAttatchment *attatchment, int socketID); + void RemoveAttatchment(int socketID); + + void SelectAttatchment(int socketID); bool IsFireing(); bool IsIdle(); bool IsReloading(); + bool IsValidSocket(int socketID); + + int GetCurrentSocketID(); + private: From c740bd593566070d744d1eb562ede6e1c88bd5b9 Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Thu, 12 Dec 2013 10:02:35 +0100 Subject: [PATCH 16/18] Added some data to PhysicsAPI GetRigidLinearVelocity() and void* as reference to game object. --- Bin/Content/Shaders/TextureDebug.cso | Bin 14560 -> 14560 bytes .../Implementation/SimpleRigidBody.cpp | 6 ++++++ .../Implementation/SimpleRigidBody.h | 1 + .../Implementation/SphericalRigidBody.cpp | 5 +++++ .../Implementation/SphericalRigidBody.h | 1 + Code/GamePhysics/PhysicsAPI.h | 10 ++++++++++ 6 files changed, 23 insertions(+) diff --git a/Bin/Content/Shaders/TextureDebug.cso b/Bin/Content/Shaders/TextureDebug.cso index 0dc6bcffa9d17cf2aa80d41dbe8b05fa689ed0ac..23c9aa238f2caca3ef27eaef75cc83f52464c37c 100644 GIT binary patch delta 623 zcmaD*_@Ge4CBn&h70aI$-5H{x-{K2bK8^fgxKZQ+kA#2a${;*$!r)yt7q|OPHaFxp|CxW{E;jYC(Q+W=Vcg<>Xo7rjvEV#YM`%lIcLnB7~%; zxVH!nT`stEm`;|I=ogTFWWcxvXs_n8s5{6Ojs6XSu+du84E8Ba`R z)%9m~=t!L$uA3_p4^%|Jzd{mt6gW&y)=QlHfQLmASLD2({8!HeR{*$AuG8noB?$^0 zZcA363%P(86j^pa3<82c%nrmoK+FlmAOKRQ1jHOb3{uZFS&(EqQO9|2|#=v Qh%JCJAaG*yUxUZ&0A8h{KmY&$ delta 494 zcmaD*_@Ge4CBn&>|Fq1T6$_ab$!`j??QVUnv{B>&kHmxQIYEpJ3=Hz;J|3t}>GPdk z_Pus_LGp~ve|VlSZkFIrVAKo-N(TY)5+HsD#1BF0(SQX|jB)Zp0sF}dm@GCw5a3|r z4`2qWakh$aNz8M~Oe~)KK-Zm{A=xS>B{44v#9yy(I(e437#m#Lbn;Jeejpbr>o7S+ zqGfW5u~EaaNE_@McBkWX8=8r0y^=F4??S)}5bm&16bNK>+icp;I zjp|hH$@O}PK<~;-e!#;bi7Om0PyVZCg7B2-rigid.GetView(); } +Float3 SimpleRigidBody::GetRigidLinearVelocity() const +{ + return this->rigid.GetLinearVelocity(); +} + + UpdateState SimpleRigidBody::Update( Float timeStepLength ) { this->rigid.Update_LeapFrog( timeStepLength ); diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.h b/Code/GamePhysics/Implementation/SimpleRigidBody.h index 774420c5..9eefeb48 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.h +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.h @@ -18,6 +18,7 @@ namespace Oyster { namespace Physics State GetState() const; State & GetState( State &targetMem ) const; void SetState( const State &state ); + ::Oyster::Math::Float3 GetRigidLinearVelocity() const; void CallSubscription( const ICustomBody *proto, const ICustomBody *deuter ); bool IsAffectedByGravity() const; diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp index 34160192..364d7454 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp @@ -126,6 +126,11 @@ Float4x4 & SphericalRigidBody::GetView( Float4x4 &targetMem ) const return targetMem = this->rigid.GetView(); } +Float3 SphericalRigidBody::GetRigidLinearVelocity() const +{ + return this->rigid.GetLinearVelocity(); +} + UpdateState SphericalRigidBody::Update( Float timeStepLength ) { this->rigid.Update_LeapFrog( timeStepLength ); diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.h b/Code/GamePhysics/Implementation/SphericalRigidBody.h index 1aca514d..4d003f99 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.h +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.h @@ -19,6 +19,7 @@ namespace Oyster { namespace Physics State GetState() const; State & GetState( State &targetMem = State() ) const; void SetState( const State &state ); + ::Oyster::Math::Float3 GetRigidLinearVelocity() const; void CallSubscription( const ICustomBody *proto, const ICustomBody *deuter ); bool IsAffectedByGravity() const; diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index 387bf0e6..84a3d639 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -243,6 +243,11 @@ namespace Oyster SubscriptMessage_ignore_collision_response }; + /******************************************************** + * @param gameObjectRef: a pointer to the object in the game owning the rigid body. + ********************************************************/ + void* gameObjectRef; + typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter ); typedef Struct::SimpleBodyDescription SimpleBodyDescription; typedef Struct::SphericalBodyDescription SphericalBodyDescription; @@ -271,6 +276,11 @@ namespace Oyster ********************************************************/ virtual State & GetState( State &targetMem ) const = 0; + /******************************************************** + * @return the linear velocity of the rigid body in a vector. + ********************************************************/ + virtual Math::Float3 GetRigidLinearVelocity() const = 0; + /******************************************************** * @todo TODO: need doc ********************************************************/ From 8f36f64c4f3420a1bb0059c19c883cdb9a423051 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Thu, 12 Dec 2013 12:16:13 +0100 Subject: [PATCH 17/18] updated AttatchmentMassDriver and CollisionManager weapon attatchments now have a owner(player) to facillitate the weapon manipulating the player using it. CollisionManager now works with a tag void* in the rigidbody to link with a game object instead of the RefManager component --- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 30 +++++++++++++++++-- Code/Game/GameLogic/AttatchmentMassDriver.h | 2 ++ Code/Game/GameLogic/CollisionManager.cpp | 20 +++++++------ Code/Game/GameLogic/CollisionManager.h | 2 -- Code/Game/GameLogic/GameLogic.vcxproj | 2 -- Code/Game/GameLogic/IAttatchment.cpp | 16 ---------- Code/Game/GameLogic/IAttatchment.h | 8 +++-- Code/Game/GameLogic/Object.cpp | 11 +++++-- Code/Game/GameLogic/Object.h | 4 ++- Code/Game/GameLogic/Player.cpp | 18 +++++++++-- Code/Game/GameLogic/Player.h | 4 +++ Code/Game/GameLogic/Weapon.h | 5 ++-- 12 files changed, 80 insertions(+), 42 deletions(-) diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 18324149..c6639953 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -1,4 +1,5 @@ #include "AttatchmentMassDriver.h" +#include "PhysicsAPI.h" using namespace GameLogic; @@ -19,11 +20,20 @@ struct AttatchmentMassDriver::PrivateData AttatchmentMassDriver::AttatchmentMassDriver(void) { + myData = new PrivateData(); + this->owner = 0; +} + +AttatchmentMassDriver::AttatchmentMassDriver(Player &owner) +{ + myData = new PrivateData(); + this->owner = &owner; } AttatchmentMassDriver::~AttatchmentMassDriver(void) { + delete myData; } /******************************************************** @@ -31,7 +41,17 @@ AttatchmentMassDriver::~AttatchmentMassDriver(void) ********************************************************/ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &fireInput) { - ForcePush(fireInput); + //switch case to determin what functionallity to use in the attatchment + switch (fireInput) + { + case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS: + ForcePush(fireInput); + break; + case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS: + ForcePull(fireInput); + break; + } + } /******************************************************** @@ -39,7 +59,13 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &fireInp ********************************************************/ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &fireInput) { - + //create coneRigidBody that will then collide with object and push them in the aimed direction +} + + +void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &fireInput) +{ + Oyster::Physics::API::Instance().ApplyForceAt(owner->GetRigidBody(), owner->GetRigidBody()->GetCenter(), owner->GetLookDir() * 100); } diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.h b/Code/Game/GameLogic/AttatchmentMassDriver.h index bc95c327..879938fe 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.h +++ b/Code/Game/GameLogic/AttatchmentMassDriver.h @@ -8,6 +8,7 @@ namespace GameLogic { public: AttatchmentMassDriver(void); + AttatchmentMassDriver(Player &owner); ~AttatchmentMassDriver(void); @@ -15,6 +16,7 @@ namespace GameLogic private: void ForcePush(const WEAPON_FIRE &fireInput); + void ForcePull(const WEAPON_FIRE &fireInput); private: struct PrivateData; diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index b19c7de3..3d1af2a1 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -1,5 +1,4 @@ #include "CollisionManager.h" -#include "RefManager.h" #include "PhysicsAPI.h" #include "Object.h" #include "DynamicObject.h" @@ -13,15 +12,18 @@ namespace GameLogic namespace CollisionManager { + void PlayerVBox(Player &player, DynamicObject &box); + + Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj) { - Player *player = ((Player*)GameLogic::RefManager::getInstance()->GetMap(*rigidBodyPlayer)); - Object *realObj = GameLogic::RefManager::getInstance()->GetMap(*obj); + Player *player = ((Player*)(rigidBodyPlayer->gameObjectRef)); + Object *realObj = (Object*)obj->gameObjectRef; switch (realObj->GetType()) { case OBJECT_TYPE_BOX: - //PlayerVBox(*player,(*(DynamicObject*) realObj)); + PlayerVBox(*player,(*(DynamicObject*) realObj)); break; case OBJECT_TYPE_PLAYER: @@ -31,15 +33,15 @@ namespace GameLogic return Physics::ICustomBody::SubscriptMessage_none; } - /* void PlayerVBox(Player &player, DynamicObject &box) + void PlayerVBox(Player &player, DynamicObject &box) { - spela ljud? ta skada? etc etc - }*/ + player.DamageLife(20); + } Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj) { - DynamicObject *box = ((DynamicObject*)GameLogic::RefManager::getInstance()->GetMap(*rigidBodyBox)); - Object *realObj = GameLogic::RefManager::getInstance()->GetMap(*obj); + DynamicObject *box = (DynamicObject*)rigidBodyBox->gameObjectRef; + Object *realObj = (Object*)obj->gameObjectRef; switch (realObj->GetType()) { diff --git a/Code/Game/GameLogic/CollisionManager.h b/Code/Game/GameLogic/CollisionManager.h index 86a05906..d19ce8e3 100644 --- a/Code/Game/GameLogic/CollisionManager.h +++ b/Code/Game/GameLogic/CollisionManager.h @@ -3,8 +3,6 @@ #include "Object.h" #include "PhysicsAPI.h" -//#include "DynamicObject.h" -//#include "Player.h" namespace GameLogic { diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index 03430feb..13491d28 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -176,7 +176,6 @@ - @@ -191,7 +190,6 @@ - diff --git a/Code/Game/GameLogic/IAttatchment.cpp b/Code/Game/GameLogic/IAttatchment.cpp index c1e2a997..4b0b1961 100644 --- a/Code/Game/GameLogic/IAttatchment.cpp +++ b/Code/Game/GameLogic/IAttatchment.cpp @@ -3,22 +3,6 @@ using namespace GameLogic; -struct IAttatchment::PrivateData -{ - PrivateData() - { - - } - - ~PrivateData() - { - - } - - - -}myData; - IAttatchment::IAttatchment(void) { } diff --git a/Code/Game/GameLogic/IAttatchment.h b/Code/Game/GameLogic/IAttatchment.h index c134026f..0b6cb061 100644 --- a/Code/Game/GameLogic/IAttatchment.h +++ b/Code/Game/GameLogic/IAttatchment.h @@ -1,6 +1,7 @@ #ifndef IATTATCHMENT_H #define IATTATCHMENT_H #include "GameLogicStates.h" +#include "Player.h" namespace GameLogic { @@ -16,9 +17,10 @@ namespace GameLogic virtual void UseAttatchment(const WEAPON_FIRE &fireInput) = 0; - private: - struct PrivateData; - PrivateData *myData; + private: + + protected: + Player *owner; }; } diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 7eb4b57f..dcd32bf1 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -1,6 +1,6 @@ #include "Object.h" #include "OysterMath.h" -#include "RefManager.h" +#include "CollisionManager.h" using namespace GameLogic; @@ -16,7 +16,7 @@ Object::Object() //poi ICustomBody* temp = rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); - GameLogic::RefManager::getInstance()->AddMapping(*rigidBody, *this); + rigidBody->gameObjectRef = this; this->type = OBJECT_TYPE_UNKNOWN; @@ -32,7 +32,7 @@ Object::Object(void* collisionFunc, OBJECT_TYPE type) rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc)); - GameLogic::RefManager::getInstance()->AddMapping(*rigidBody, *this); + rigidBody->gameObjectRef = this; this->type = type; } @@ -48,3 +48,8 @@ OBJECT_TYPE Object::GetType() { return this->type; } + +Oyster::Physics::ICustomBody* Object::GetRigidBody() +{ + return this->rigidBody; +} diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index e2c1bee4..c79c5de1 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -8,7 +8,7 @@ #include "PhysicsAPI.h" #include "GameLogicStates.h" -#include "CollisionManager.h" + namespace GameLogic { @@ -21,6 +21,8 @@ namespace GameLogic OBJECT_TYPE GetType(); + Oyster::Physics::ICustomBody* GetRigidBody(); + private: OBJECT_TYPE type; protected: diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index f7bdc4a6..3ebf979f 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -59,13 +59,16 @@ void Player::Update() ********************************************************/ void Player::Move(const PLAYER_MOVEMENT &movement) { + Oyster::Math::Float3 currentVelocity = rigidBody->GetRigidLinearVelocity(); + switch(movement) { case PLAYER_MOVEMENT_FORWARD: - + API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),myData->lookDir * 100); break; case PLAYER_MOVEMENT_BACKWARD: + API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-myData->lookDir * 100); break; case PLAYER_MOVEMENT_LEFT: @@ -93,7 +96,7 @@ void Player::UseWeapon(const WEAPON_FIRE &fireInput) ********************************************************/ void Player::Jump() { - + API::Instance().ApplyForceAt(rigidBody,rigidBody->GetCenter(),-Oyster::Math::Float3(0,1,0) * 100); } bool Player::IsWalking() @@ -114,6 +117,11 @@ Oyster::Math::Float3 Player::GetPos() return rigidBody->GetCenter(); } +Oyster::Math::Float3 Player::GetLookDir() +{ + return myData->lookDir; +} + /******************************************************** * Respawns the player on a new chosen position * This resets a set of variables such as life, ammo etcetc @@ -122,3 +130,9 @@ void Player::Respawn() { } + + +void Player::DamageLife(int damage) +{ + myData->life -= damage; +} \ No newline at end of file diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 44b28ceb..7cf7187b 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -26,8 +26,12 @@ namespace GameLogic bool IsIdle(); Oyster::Math::Float3 GetPos(); + Oyster::Math::Float3 GetLookDir(); + void Respawn(); + void DamageLife(int damage); + private: struct PrivateData; PrivateData *myData; diff --git a/Code/Game/GameLogic/Weapon.h b/Code/Game/GameLogic/Weapon.h index b5239b6e..cdd1a3b7 100644 --- a/Code/Game/GameLogic/Weapon.h +++ b/Code/Game/GameLogic/Weapon.h @@ -5,6 +5,7 @@ #define WEAPON_H #include "GameLogicStates.h" #include "IAttatchment.h" +#include "Player.h" namespace GameLogic { @@ -21,8 +22,8 @@ namespace GameLogic void Use(const WEAPON_FIRE &fireInput); - void AddNewAttatchment(IAttatchment *attatchment); - void SwitchAttatchment(IAttatchment *attatchment, int socketID); + void AddNewAttatchment(IAttatchment *attatchment, Player *owner); + void SwitchAttatchment(IAttatchment *attatchment, int socketID, Player *owner); void RemoveAttatchment(int socketID); void SelectAttatchment(int socketID); From c63e9f1c084adb0a705448e1f745ae602ecc783f Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Thu, 12 Dec 2013 12:21:19 +0100 Subject: [PATCH 18/18] Some comments on the massdriver and player --- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 6 ++++-- Code/Game/GameLogic/Player.cpp | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index c6639953..b7687acb 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -55,14 +55,16 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &fireInp } /******************************************************** -* This is a specific functionallity of the weapon +* Pushes objects in a cone in front of the weapon when fired ********************************************************/ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &fireInput) { //create coneRigidBody that will then collide with object and push them in the aimed direction } - +/******************************************************** +* Pulls the player in the direction he is looking, used for fast movement(kinda like a jetpack) +********************************************************/ void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &fireInput) { Oyster::Physics::API::Instance().ApplyForceAt(owner->GetRigidBody(), owner->GetRigidBody()->GetCenter(), owner->GetLookDir() * 100); diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 3ebf979f..bae54e9a 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -15,6 +15,7 @@ struct Player::PrivateData life = 100; playerState = PLAYER_STATE_IDLE; + lookDir = Oyster::Math::Float3(1,0,0); } ~PrivateData()