From ef71b365ab10abe6260a6197a1ce93add3839de3 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Mon, 3 Feb 2014 10:42:40 +0100 Subject: [PATCH 01/34] asd --- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 3 +++ Code/Game/GameLogic/GameLogic.vcxproj.user | 2 +- Code/Game/GameLogic/Game_PlayerData.cpp | 6 ++++++ Code/Game/GameLogic/Level.cpp | 7 +++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index a63b6e1d..bca972fd 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -46,7 +46,10 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, ********************************************************/ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float dt) { +<<<<<<< HEAD +======= +>>>>>>> GL - mergeissues Oyster::Math::Float4 pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (500 * dt); Oyster::Math::Float4x4 aim = Oyster::Math3D::ViewMatrix_LookAtDirection(owner->GetLookDir(), owner->GetRigidBody()->GetGravityNormal(), owner->GetPosition()); diff --git a/Code/Game/GameLogic/GameLogic.vcxproj.user b/Code/Game/GameLogic/GameLogic.vcxproj.user index 2e28d6f7..4b847ee6 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj.user +++ b/Code/Game/GameLogic/GameLogic.vcxproj.user @@ -1,7 +1,7 @@  - true + false $(OutDir) diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index e19af2f3..1626f5b3 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -9,8 +9,14 @@ Game::PlayerData::PlayerData() Oyster::Physics::API::SimpleBodyDescription sbDesc; sbDesc.centerPosition = Oyster::Math::Float3(0,308,0); sbDesc.size = Oyster::Math::Float3(4,7,4); +<<<<<<< HEAD sbDesc.mass = 70; sbDesc.restitutionCoeff = 0.5; +======= + + sbDesc.mass = 90; + +>>>>>>> GL - mergeissues //create rigid body Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release(); diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 50737eb9..0a1a37e6 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -43,8 +43,15 @@ void Level::InitiateLevel(float radius) API::SimpleBodyDescription sbDesc_TestBox; sbDesc_TestBox.centerPosition = Oyster::Math::Float4(10,320,0,0); sbDesc_TestBox.ignoreGravity = false; +<<<<<<< HEAD sbDesc_TestBox.mass = 50; sbDesc_TestBox.size = Oyster::Math::Float4(4,4,4,0); +======= + + sbDesc_TestBox.mass = 10; + sbDesc_TestBox.size = Oyster::Math::Float4(4,4,4,0); + +>>>>>>> GL - mergeissues ICustomBody* rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release(); rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel); From 50d895d37c5d305f7de05df9dc5a75040bc13286 Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Mon, 3 Feb 2014 10:45:25 +0100 Subject: [PATCH 02/34] Applied friction Needs to be tested. --- Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 12c46cd5..ee47eeba 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -78,10 +78,14 @@ namespace deuterState.GetMass(), deuterG_Magnitude ); Float4 bounce = Average( bounceD, bounceP ); + + Float4 friction = Formula::CollisionResponse::Friction( protoG_Magnitude, normal, + Float4(protoState.GetLinearMomentum(), 0), protoState.GetFrictionCoeff_Static(), protoState.GetFrictionCoeff_Kinetic(), protoState.GetMass(), + Float4(deuterState.GetLinearMomentum(), 0), deuterState.GetFrictionCoeff_Static(), deuterState.GetFrictionCoeff_Kinetic(), deuterState.GetMass()); Float kineticEnergyPBefore = Oyster::Physics3D::Formula::LinearKineticEnergy( protoState.GetMass(), protoState.GetLinearMomentum()/protoState.GetMass() ); - protoState.ApplyImpulse( bounce.xyz, worldPointOfContact.xyz, normal.xyz ); + protoState.ApplyImpulse( bounce.xyz - friction.xyz, worldPointOfContact.xyz, normal.xyz ); proto->SetState( protoState ); Float kineticEnergyPAFter = Oyster::Physics3D::Formula::LinearKineticEnergy( protoState.GetMass(), (protoState.GetLinearMomentum() + protoState.GetLinearImpulse())/protoState.GetMass() ); From 8f234611d2c9691506876132ba1f6119937d4d20 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Mon, 3 Feb 2014 10:48:12 +0100 Subject: [PATCH 03/34] GL - mergeissues fixed --- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 4 ---- Code/Game/GameLogic/Game_PlayerData.cpp | 5 ----- Code/Game/GameLogic/Level.cpp | 7 +------ 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index bca972fd..5f5834bb 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -46,10 +46,6 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, ********************************************************/ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float dt) { -<<<<<<< HEAD - -======= ->>>>>>> GL - mergeissues Oyster::Math::Float4 pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (500 * dt); Oyster::Math::Float4x4 aim = Oyster::Math3D::ViewMatrix_LookAtDirection(owner->GetLookDir(), owner->GetRigidBody()->GetGravityNormal(), owner->GetPosition()); diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index 1626f5b3..18bb10a7 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -9,14 +9,9 @@ Game::PlayerData::PlayerData() Oyster::Physics::API::SimpleBodyDescription sbDesc; sbDesc.centerPosition = Oyster::Math::Float3(0,308,0); sbDesc.size = Oyster::Math::Float3(4,7,4); -<<<<<<< HEAD sbDesc.mass = 70; sbDesc.restitutionCoeff = 0.5; -======= - sbDesc.mass = 90; - ->>>>>>> GL - mergeissues //create rigid body Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release(); diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 0a1a37e6..b070eb56 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -43,15 +43,10 @@ void Level::InitiateLevel(float radius) API::SimpleBodyDescription sbDesc_TestBox; sbDesc_TestBox.centerPosition = Oyster::Math::Float4(10,320,0,0); sbDesc_TestBox.ignoreGravity = false; -<<<<<<< HEAD + sbDesc_TestBox.mass = 50; sbDesc_TestBox.size = Oyster::Math::Float4(4,4,4,0); -======= - sbDesc_TestBox.mass = 10; - sbDesc_TestBox.size = Oyster::Math::Float4(4,4,4,0); - ->>>>>>> GL - mergeissues ICustomBody* rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release(); rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel); From b8e6b83148014baa487bb47b44ddd9964255a678 Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Mon, 3 Feb 2014 11:10:04 +0100 Subject: [PATCH 04/34] Momentum "fall-off" added Temporary till real fluid drag is implemented. --- Code/OysterPhysics3D/RigidBody.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Code/OysterPhysics3D/RigidBody.cpp b/Code/OysterPhysics3D/RigidBody.cpp index f053e8dd..70ded863 100644 --- a/Code/OysterPhysics3D/RigidBody.cpp +++ b/Code/OysterPhysics3D/RigidBody.cpp @@ -49,6 +49,10 @@ void RigidBody::Update_LeapFrog( Float updateFrameLength ) { // by Dan Andersson: Euler leap frog update when Runga Kutta is not needed // updating the linear + //Decrease momentum with 1% as "fall-off" + //! HACK: @todo Add real solution with fluid drag + this->momentum_Linear = this->momentum_Linear*0.99f; + this->momentum_Angular = this->momentum_Angular*0.99f; // ds = dt * Formula::LinearVelocity( m, avg_G ) = dt * avg_G / m = (dt / m) * avg_G Float3 deltaPos = ( updateFrameLength / this->mass ) * AverageWithDelta( this->momentum_Linear, this->impulse_Linear ); if( deltaPos.GetLength() < 0.001f ) From e7fee8b2e7161d2768e914d398a424da151edb6a Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Mon, 3 Feb 2014 14:50:15 +0100 Subject: [PATCH 05/34] GL - Updated LevelLoader. Added lights. Added lights. Changed the return type to vector> Hid the LevelParser from the outside. --- Bin/Level.txt | Bin 156 -> 0 bytes Bin/map | Bin 156 -> 0 bytes Bin/map.txt | Bin 60 -> 0 bytes .../GameLogic/LevelLoader/LevelLoader.cpp | 22 ++++- Code/Game/GameLogic/LevelLoader/LevelLoader.h | 44 +++++----- .../GameLogic/LevelLoader/LevelParser.cpp | 81 +++++++++++++----- Code/Game/GameLogic/LevelLoader/LevelParser.h | 3 +- .../GameLogic/LevelLoader/ObjectDefines.h | 47 +++++++++- .../GameLogic/LevelLoader/ParseFunctions.h | 10 ++- 9 files changed, 156 insertions(+), 51 deletions(-) delete mode 100644 Bin/Level.txt delete mode 100644 Bin/map delete mode 100644 Bin/map.txt diff --git a/Bin/Level.txt b/Bin/Level.txt deleted file mode 100644 index d86dd3db4f89e0c84adfa01d7b0ec5a42dd61adb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 156 zcmZQzU|?VYV!y=PR7M~T0wBIiYH>0$&A`y$pam3X0x19jkXjHMgqeXjYRNaJ8F^XG hjYrow<6?ux*}DpzTmbMiDYF0o diff --git a/Bin/map b/Bin/map deleted file mode 100644 index a578cc3216cf4c730d47a3cae791ddccf2b29610..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 156 zcmZQ#U|?VZVrC$YTJp_lMqZY47AJ$m6N^*QIDs?+LxY1BkYob085kIWGyuTm1-1YH diff --git a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp b/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp index d60aac66..5bb916ab 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp @@ -3,16 +3,30 @@ ////////////////////////////////// #include "LevelLoader.h" +#include "LevelParser.h" using namespace GameLogic; using namespace GameLogic::LevelFileLoader; - -std::vector LevelLoader::LoadLevel(std::string fileName) +struct LevelLoader::PrivData { - return parser.Parse(fileName); + LevelParser parser; +}; + +LevelLoader::LevelLoader() + : pData(new PrivData) +{ +} + +LevelLoader::~LevelLoader() +{ +} + +std::vector> LevelLoader::LoadLevel(std::string fileName) +{ + return pData->parser.Parse(fileName); } LevelMetaData LevelLoader::LoadLevelHeader(std::string fileName) { - return parser.ParseHeader(fileName); + return pData->parser.ParseHeader(fileName); } \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/LevelLoader.h b/Code/Game/GameLogic/LevelLoader/LevelLoader.h index 4ac7a950..bcd6e587 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.h +++ b/Code/Game/GameLogic/LevelLoader/LevelLoader.h @@ -7,36 +7,36 @@ #include #include -#include +#include "../Misc/Utilities.h" #include "ObjectDefines.h" -#include "LevelParser.h" namespace GameLogic { - class LevelLoader - { + class LevelLoader + { - public: - LevelLoader(){this->parser = GameLogic::LevelFileLoader::LevelParser(); } - ~LevelLoader(){} + public: + LevelLoader(); + ~LevelLoader(); - /******************************************************** - * Loads the level and objects from file. - * @param fileName: Path to the level-file that you want to load. - * @return: Returns all structs with objects and information about the level. - ********************************************************/ - std::vector LoadLevel(std::string fileName); + /******************************************************** + * Loads the level and objects from file. + * @param fileName: Path to the level-file that you want to load. + * @return: Returns all structs with objects and information about the level. + ********************************************************/ + std::vector> LoadLevel(std::string fileName); - /******************************************************** - * Just for fast access for the meta information about the level. - * @param fileName: Path to the level-file that you want to load. - * @return: Returns the meta information about the level. - ********************************************************/ - LevelMetaData LoadLevelHeader(std::string fileName); //. + /******************************************************** + * Just for fast access for the meta information about the level. + * @param fileName: Path to the level-file that you want to load. + * @return: Returns the meta information about the level. + ********************************************************/ + LevelMetaData LoadLevelHeader(std::string fileName); //. - private: - GameLogic::LevelFileLoader::LevelParser parser; - }; + private: + struct PrivData; + Utility::DynamicMemory::SmartPointer pData; + }; } #endif \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp index 3ab3c203..3a20f192 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp @@ -5,6 +5,7 @@ using namespace GameLogic; using namespace ::LevelFileLoader; +using namespace Utility::DynamicMemory; LevelParser::LevelParser() { @@ -16,12 +17,12 @@ LevelParser::~LevelParser() { } -std::vector LevelParser::Parse(std::string filename) +std::vector> LevelParser::Parse(std::string filename) { int bufferSize = 0; int counter = 0; - std::vector objects; + std::vector> objects; //Read entire level file. Loader loader; @@ -42,26 +43,66 @@ std::vector LevelParser::Parse(std::string filename) ParseObject(&buffer[counter], &typeID, sizeof(typeID)); switch((int)typeID.typeID) { - case ObjectType_LevelMetaData: - { - LevelMetaData header; - ParseLevelMetaData(&buffer[counter], header, counter); - objects.push_back(header); - break; - } + case ObjectType_LevelMetaData: + { + LevelMetaData* header = new LevelMetaData; + ParseLevelMetaData(&buffer[counter], *header, counter); + objects.push_back(header); + break; + } - case ObjectType_Dynamic: - { - ObjectHeader header; - ParseObject(&buffer[counter], &header, sizeof(header)); - objects.push_back(header); - counter += sizeof(header); - break; - } + //This is by design, static and dynamic is using the same converter. Do not add anything inbetween them. + case ObjectType_Static: case ObjectType_Dynamic: + { + ObjectHeader* header = new ObjectHeader; + ParseObject(&buffer[counter], header, sizeof(*header)); + objects.push_back(header); + counter += sizeof(*header); + break; + } - default: - //Couldn't find typeID. FAIL!!!!!! - break; + case ObjectType_Light: + { + LightType lightType; + + //Get Light type + ParseObject(&buffer[counter+4], &lightType, sizeof(lightType)); + + switch(lightType) + { + case LightType_PointLight: + { + PointLight* header = new PointLight; + ParseObject(&buffer[counter], header, sizeof(*header)); + counter += sizeof(*header); + objects.push_back(header); + break; + } + case LightType_DirectionalLight: + { + DirectionalLight* header = new DirectionalLight; + ParseObject(&buffer[counter], header, sizeof(*header)); + counter += sizeof(*header); + objects.push_back(header); + break; + } + case LightType_SpotLight: + { + SpotLight* header = new SpotLight; + ParseObject(&buffer[counter], header, sizeof(*header)); + counter += sizeof(*header); + objects.push_back(header); + break; + } + default: + //Undefined LightType. + break; + } + break; + } + default: + //Couldn't find typeID. FAIL!!!!!! + break; } } diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.h b/Code/Game/GameLogic/LevelLoader/LevelParser.h index 6dce25f8..9ad30642 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.h +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.h @@ -4,6 +4,7 @@ #include #include #include "ObjectDefines.h" +#include "../Misc/Utilities.h" namespace GameLogic { @@ -16,7 +17,7 @@ namespace GameLogic ~LevelParser(); // - std::vector Parse(std::string filename); + std::vector> Parse(std::string filename); // LevelMetaData ParseHeader(std::string filename); diff --git a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h index dcf960a5..21e3a7e3 100644 --- a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h +++ b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h @@ -15,11 +15,12 @@ namespace GameLogic ObjectType_LevelMetaData, ObjectType_Static, ObjectType_Dynamic, + ObjectType_Light, //Etc ObjectType_NUM_OF_TYPES, - ObjectType_Unknown = -1, + ObjectType_Unknown = -1 }; enum UsePhysics @@ -29,7 +30,17 @@ namespace GameLogic UsePhysics_IgnorePhysics, UsePhysics_Count, - UsePhysics_Unknown = -1, + UsePhysics_Unknown = -1 + }; + + enum LightType + { + LightType_PointLight, + LightType_DirectionalLight, + LightType_SpotLight, + + LightType_Count, + LightType_Unknown = -1 }; //Should this be moved somewhere else? @@ -40,7 +51,7 @@ namespace GameLogic //Etc GameMode_Count, - GameMode_Unknown = -1, + GameMode_Unknown = -1 }; @@ -104,6 +115,36 @@ namespace GameLogic //Scale float scale[3]; }; + + + /************************************ + Lights + *************************************/ + + struct BasicLight : public ObjectTypeHeader + { + LightType lightType; + float ambientColor[3]; + float diffuseColor[3]; + float specularColor[3]; + }; + + struct PointLight : public BasicLight + { + float position[3]; + }; + + struct DirectionalLight : public BasicLight + { + float direction[3]; + }; + + struct SpotLight : public BasicLight + { + float direction[3]; + float range; + float attenuation[3]; + }; } #endif \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h index 08962b4a..554b95db 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h @@ -10,8 +10,16 @@ namespace GameLogic { namespace LevelFileLoader { + /* + These functions will copy data from where the buffer pointer points. + header is the destination where the data will be copied. + size is either the size of the data to be copied (if it is NOT sent by reference). + Or the current index that is being used to parse the entire file (if it is sent by reference) this means you have to increase size with the appropiate size after you have copied. + + */ + void ParseObject(char* buffer, void *header, int size); - void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size); + void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size); } } From f527d329a270b78e4a0a86783d4d4c0363afcb0f Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Mon, 3 Feb 2014 15:15:47 +0100 Subject: [PATCH 06/34] Added limbo functionality --- Code/GamePhysics/Implementation/Octree.cpp | 36 ++++++++++++++++--- Code/GamePhysics/Implementation/Octree.h | 7 ++++ .../Implementation/PhysicsAPI_Impl.cpp | 7 ++-- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/Code/GamePhysics/Implementation/Octree.cpp b/Code/GamePhysics/Implementation/Octree.cpp index b4395516..47bf3e39 100644 --- a/Code/GamePhysics/Implementation/Octree.cpp +++ b/Code/GamePhysics/Implementation/Octree.cpp @@ -40,6 +40,7 @@ void Octree::AddObject(UniquePointer< ICustomBody > customBodyRef) data.next = NULL; data.prev = NULL; data.customBodyRef = customBodyRef; + data.limbo = false; this->mapReferences.insert(std::pair (data.customBodyRef, this->leafData.size())); this->leafData.push_back(data); @@ -64,6 +65,33 @@ void Octree::MoveToUpdateQueue(UniquePointer< ICustomBody > customBodyRef) this->updateQueue.push_back(&this->leafData[this->mapReferences[customBodyRef]]);*/ } +void Octree::MoveToLimbo(const ICustomBody* customBodyRef) +{ + auto object = this->mapReferences.find(customBodyRef); + + unsigned int tempRef = object->second; + + this->leafData[tempRef].limbo = true; +} + +bool Octree::IsInLimbo(const ICustomBody* customBodyRef) +{ + auto object = this->mapReferences.find(customBodyRef); + + unsigned int tempRef = object->second; + + return this->leafData[tempRef].limbo; +} + +void Octree::ReleaseFromLimbo(const ICustomBody* customBodyRef) +{ + auto object = this->mapReferences.find(customBodyRef); + + unsigned int tempRef = object->second; + + this->leafData[tempRef].limbo = false; +} + void Octree::DestroyObject(UniquePointer< ICustomBody > customBodyRef) { std::map::iterator it = this->mapReferences.find(customBodyRef); @@ -86,7 +114,7 @@ std::vector& Octree::Sample(ICustomBody* customBodyRef, std::vecto for(unsigned int i = 0; ileafData.size(); i++) { - if(tempRef != i) if(this->leafData[tempRef].container.Intersects(this->leafData[i].container)) + if(tempRef != i && !this->leafData[i].limbo) if(this->leafData[tempRef].container.Intersects(this->leafData[i].container)) { updateList.push_back(this->leafData[i].customBodyRef); } @@ -99,7 +127,7 @@ std::vector& Octree::Sample(const Oyster::Collision3D::ICollideabl { for(unsigned int i = 0; ileafData.size(); i++) { - if(this->leafData[i].container.Intersects(collideable)) + if(!this->leafData[i].limbo && this->leafData[i].container.Intersects(collideable)) { updateList.push_back(this->leafData[i].customBodyRef); } @@ -121,7 +149,7 @@ void Octree::Visit(ICustomBody* customBodyRef, VisitorAction hitAction ) for(unsigned int i = 0; ileafData.size(); i++) { - if(tempRef != i) if(this->leafData[tempRef].container.Intersects(this->leafData[i].container)) + if(tempRef != i && !this->leafData[i].limbo) if(this->leafData[tempRef].container.Intersects(this->leafData[i].container)) { hitAction(*this, tempRef, i); } @@ -132,7 +160,7 @@ void Octree::Visit(const Oyster::Collision3D::ICollideable& collideable, void* a { for(unsigned int i = 0; ileafData.size(); i++) { - if(collideable.Intersects(this->leafData[i].container)) + if(!this->leafData[i].limbo && collideable.Intersects(this->leafData[i].container)) { hitAction( this->GetCustomBody(i), args ); } diff --git a/Code/GamePhysics/Implementation/Octree.h b/Code/GamePhysics/Implementation/Octree.h index 50b9569a..573738f2 100644 --- a/Code/GamePhysics/Implementation/Octree.h +++ b/Code/GamePhysics/Implementation/Octree.h @@ -29,6 +29,8 @@ namespace Oyster ::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef; + bool limbo; + unsigned int queueRef; }; @@ -48,6 +50,10 @@ namespace Oyster void MoveToUpdateQueue(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef); + void MoveToLimbo(const ICustomBody* customBodyRef); + bool IsInLimbo(const ICustomBody* customBodyRef); + void ReleaseFromLimbo(const ICustomBody* customBodyRef); + void DestroyObject(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef); std::vector& Sample(ICustomBody* customBodyRef, std::vector& updateList); @@ -66,6 +72,7 @@ namespace Oyster private: std::vector < Data > leafData; std::vector < Data* > updateQueue; + std::vector < Data* > limbo; std::map< const ICustomBody*, unsigned int > mapReferences; diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index ee47eeba..9880526d 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -237,17 +237,16 @@ void API_Impl::Update() bool API_Impl::IsInLimbo( const ICustomBody* objRef ) { - //! @todo TODO: implement stub - return true; + return this->worldScene.IsInLimbo( objRef ); } void API_Impl::MoveToLimbo( const ICustomBody* objRef ) { - /** @todo TODO: Fix this function.*/ + this->worldScene.MoveToLimbo( objRef ); } void API_Impl::ReleaseFromLimbo( const ICustomBody* objRef ) { - /** @todo TODO: Fix this function.*/ + this->worldScene.ReleaseFromLimbo( objRef ); } void API_Impl::AddObject( ::Utility::DynamicMemory::UniquePointer handle ) From dc5b4081962654e9f1d473eb62761f795258d309 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Mon, 3 Feb 2014 15:32:20 +0100 Subject: [PATCH 07/34] Network - Updated network api with comment. --- Code/Network/NetworkAPI/NetworkServer.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Code/Network/NetworkAPI/NetworkServer.h b/Code/Network/NetworkAPI/NetworkServer.h index 97a3e024..1a6af478 100644 --- a/Code/Network/NetworkAPI/NetworkServer.h +++ b/Code/Network/NetworkAPI/NetworkServer.h @@ -84,8 +84,8 @@ namespace Oyster */ std::string GetLanAddress(); - /** - * + /** Returns the port the server is listening on. + * @return Returns the port the server has been initiated with. */ int NetworkServer::GetPort(); From 99b041f1650009ebe1fed77706313db717a9c6b3 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Mon, 3 Feb 2014 15:32:46 +0100 Subject: [PATCH 08/34] GL - first implementation of weapons forcepull with pickup functionallity --- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 72 ++++++++++++++++++- Code/Game/GameLogic/AttatchmentMassDriver.h | 21 ++++-- Code/Game/GameLogic/CollisionManager.cpp | 37 ++++++++++ Code/Game/GameLogic/CollisionManager.h | 1 + Code/Game/GameLogic/IAttatchment.h | 1 + Code/Game/GameLogic/Object.h | 4 +- Code/Game/GameLogic/Player.cpp | 12 ++++ Code/Game/GameLogic/Player.h | 3 + Code/Game/GameLogic/StaticObject.cpp | 4 +- Code/Game/GameLogic/Weapon.cpp | 5 ++ Code/Game/GameLogic/Weapon.h | 1 + 11 files changed, 152 insertions(+), 9 deletions(-) diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 5f5834bb..837393db 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -9,12 +9,16 @@ using namespace GameLogic; AttatchmentMassDriver::AttatchmentMassDriver(void) { this->owner = 0; + this->heldObject = NULL; + this->hasObject = false; } AttatchmentMassDriver::AttatchmentMassDriver(Player &owner) { this->owner = &owner; + this->heldObject = NULL; + this->hasObject = false; } @@ -37,16 +41,51 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS: ForcePull(usage,dt); break; + case WEAPON_FIRE::WEAPON_USE_UTILLITY_PRESS: + ForceZip(usage,dt); + break; } } +void AttatchmentMassDriver::Update(float dt) +{ + + //update position of heldObject if there is an object being held + if(hasObject) + { + Oyster::Physics::ICustomBody::State state; + state = heldObject->GetState(); + + Oyster::Math::Float3 pos = owner->GetPosition() + owner->GetLookDir().GetNormalized(); + + state.SetCenterPosition(pos); + + heldObject->SetState(state); + } +} + /******************************************************** * Pushes objects in a cone in front of the weapon when fired +*alternativly it puts a large force on the currently held object ********************************************************/ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float dt) { - Oyster::Math::Float4 pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (500 * dt); + //if the weapon has an object then it is only the object that will be shot away + Oyster::Math::Float4 pushForce; + + if(hasObject) + { + pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (800 * dt); + Oyster::Physics::ICustomBody::State state = heldObject->GetState(); + state.ApplyLinearImpulse((Oyster::Math::Float3)pushForce); + heldObject->SetState(state); + hasObject = false; + heldObject = NULL; + return; + } + + pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (500 * dt); Oyster::Math::Float4x4 aim = Oyster::Math3D::ViewMatrix_LookAtDirection(owner->GetLookDir(), owner->GetRigidBody()->GetGravityNormal(), owner->GetPosition()); Oyster::Math::Float4x4 hitSpace = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/4,1,1,20); @@ -60,7 +99,7 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float /******************************************************** * Pulls the player in the direction he is looking, used for fast movement(kinda like a jetpack) ********************************************************/ -void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage, float dt) +void AttatchmentMassDriver::ForceZip(const WEAPON_FIRE &usage, float dt) { Oyster::Physics::Struct::CustomBodyState state = this->owner->GetRigidBody()->GetState(); @@ -71,3 +110,32 @@ void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage, float dt) } +void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage, float dt) +{ + if(hasObject) return; //this test checks if the weapon already has something picked up, if so then it cant use this function + + PickUpObject(usage,dt); //first test if there is a nearby object to pickup + + if(hasObject) return; //this test checks if the weapon has now picked up an object, if so then it shall not apply a force to suck in objects + + + //if no object has been picked up then suck objects towards you + Oyster::Math::Float4 pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (100 * dt); + Oyster::Math::Float4x4 aim = Oyster::Math3D::ViewMatrix_LookAtDirection(owner->GetLookDir(), owner->GetRigidBody()->GetGravityNormal(), owner->GetPosition()); + + Oyster::Math::Float4x4 hitSpace = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/4,1,1,20); + Oyster::Collision3D::Frustrum hitFrustum = Oyster::Collision3D::Frustrum(Oyster::Math3D::ViewProjectionMatrix(aim,hitSpace)); + forcePushData args; + args.pushForce = -pushForce; + + Oyster::Physics::API::Instance().ApplyEffect(hitFrustum,&args,ForcePushAction); +} + +void AttatchmentMassDriver::PickUpObject(const WEAPON_FIRE &usage, float dt) +{ + Oyster::Math::Float4 pos = owner->GetPosition() + owner->GetLookDir().GetNormalized(); + Oyster::Collision3D::Sphere hitSphere = Oyster::Collision3D::Sphere(pos,1); + + Oyster::Physics::API::Instance().ApplyEffect(hitSphere,this,AttemptPickUp); + +} diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.h b/Code/Game/GameLogic/AttatchmentMassDriver.h index 594ea4fd..51368e91 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.h +++ b/Code/Game/GameLogic/AttatchmentMassDriver.h @@ -16,29 +16,42 @@ namespace GameLogic void UseAttatchment(const WEAPON_FIRE &usage, float dt); + void Update(float dt); private: /******************************************************** * Pushes objects and players in a cone in front of the player - * @param fireInput: allows switching on different functionality in this specific function + * @param usage: allows switching on different functionality in this specific function ********************************************************/ void ForcePush(const WEAPON_FIRE &usage, float dt); /******************************************************** * Pulls the player forward, this is a movement tool - * @param fireInput: allows switching on different functionality in this specific function + * @param usage: allows switching on different functionality in this specific function + ********************************************************/ + void ForceZip(const WEAPON_FIRE &usage, float dt); + + /******************************************************** + * Sucks objects towards the player, the player can then pick up an object and throw it as a projectile + * @param usage: allows switching on different functionality in this specific function ********************************************************/ void ForcePull(const WEAPON_FIRE &usage, float dt); /******************************************************** * Sucks objects towards the player, the player can then pick up an object and throw it as a projectile - * @param fireInput: allows switching on different functionality in this specific function + * @param usage: allows switching on different functionality in this specific function ********************************************************/ - void ForceSuck(const WEAPON_FIRE &usage, float dt); + void PickUpObject(const WEAPON_FIRE &usage, float dt); + static void ForcePushAction(Oyster::Physics::ICustomBody *obj, void* args); + static void AttemptPickUp(Oyster::Physics::ICustomBody *obj, void* args); + + private: + Oyster::Physics::ICustomBody *heldObject; + bool hasObject; }; } diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 019df6f4..afb94035 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -5,6 +5,7 @@ #include "Level.h" #include "AttatchmentMassDriver.h" #include "Game.h" +#include "CollisionManager.h" using namespace Oyster; @@ -77,6 +78,13 @@ using namespace GameLogic; { return Physics::ICustomBody::SubscriptMessage_ignore_collision_response; } + + Oyster::Physics::ICustomBody::SubscriptMessage CollisionManager::IgnoreCollision(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody *obj) + { + return Physics::ICustomBody::SubscriptMessage_ignore_collision_response; + } + + Oyster::Physics::ICustomBody::SubscriptMessage Level::LevelCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) { return Physics::ICustomBody::SubscriptMessage_ignore_collision_response; @@ -93,4 +101,33 @@ using namespace GameLogic; state = obj->GetState(); state.ApplyLinearImpulse(((forcePushData*)(args))->pushForce); obj->SetState(state); + } + + void AttatchmentMassDriver::AttemptPickUp(Oyster::Physics::ICustomBody *obj, void* args) + { + AttatchmentMassDriver *weapon = ((AttatchmentMassDriver*)args); + + if(weapon->hasObject) + { + //do nothing + } + else + { + Object* realObj = (Object*)(obj->GetCustomTag()); + //check so that it is an object that you can pickup + + switch(realObj->GetObjectType()) + { + case OBJECT_TYPE::OBJECT_TYPE_BOX: + obj->SetGravity(true); //will now ignore gravity, dont mind the naming + //move obj to limbo in physics to make sure it wont collide with anything + weapon->heldObject = obj; //weapon now holds the object + weapon->hasObject = true; + + break; + } + + } + + } \ No newline at end of file diff --git a/Code/Game/GameLogic/CollisionManager.h b/Code/Game/GameLogic/CollisionManager.h index 6179333f..d3be9809 100644 --- a/Code/Game/GameLogic/CollisionManager.h +++ b/Code/Game/GameLogic/CollisionManager.h @@ -11,6 +11,7 @@ namespace GameLogic { public: //put general collision functions here that are not part of a specific object + static Oyster::Physics::ICustomBody::SubscriptMessage IgnoreCollision(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody *obj); }; diff --git a/Code/Game/GameLogic/IAttatchment.h b/Code/Game/GameLogic/IAttatchment.h index e458fdbf..9984303a 100644 --- a/Code/Game/GameLogic/IAttatchment.h +++ b/Code/Game/GameLogic/IAttatchment.h @@ -20,6 +20,7 @@ namespace GameLogic ~IAttatchment(void); virtual void UseAttatchment(const WEAPON_FIRE &usage, float dt) = 0; + virtual void Update(float dt) = 0; private: diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index d3a3690f..96d97591 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -35,8 +35,8 @@ namespace GameLogic Oyster::Physics::ICustomBody* GetRigidBody(); void ApplyLinearImpulse(Oyster::Math::Float3 force); - void BeginFrame(); - void EndFrame(); + virtual void BeginFrame(); + virtual void EndFrame(); void setBeforeCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter)); void setAfterCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss)); diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index ea36b284..73ddb9fc 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -58,6 +58,18 @@ Player::~Player(void) } } +void Player::BeginFrame() +{ + weapon->Update(0.002f); + Object::BeginFrame(); +} + +void Player::EndFrame() +{ + + Object::EndFrame(); +} + void Player::Move(const PLAYER_MOVEMENT &movement) { switch(movement) diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 0df0d040..f44f98d1 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -71,6 +71,9 @@ namespace GameLogic void DamageLife(int damage); + void BeginFrame(); + void EndFrame(); + private: void Jump(); diff --git a/Code/Game/GameLogic/StaticObject.cpp b/Code/Game/GameLogic/StaticObject.cpp index 21b339be..c007b919 100644 --- a/Code/Game/GameLogic/StaticObject.cpp +++ b/Code/Game/GameLogic/StaticObject.cpp @@ -1,4 +1,5 @@ #include "StaticObject.h" +#include "CollisionManager.h" using namespace GameLogic; @@ -17,7 +18,8 @@ StaticObject::StaticObject(OBJECT_TYPE type) StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type) :Object(rigidBody,type) { - + this->rigidBody->SetGravity(true); + this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse)(CollisionManager::IgnoreCollision)); } StaticObject::StaticObject(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type) diff --git a/Code/Game/GameLogic/Weapon.cpp b/Code/Game/GameLogic/Weapon.cpp index a4c87e9e..19b53a31 100644 --- a/Code/Game/GameLogic/Weapon.cpp +++ b/Code/Game/GameLogic/Weapon.cpp @@ -125,4 +125,9 @@ void Weapon::SelectAttatchment(int socketID) selectedSocketID = socketID; } +} + +void Weapon::Update(float dt) +{ + selectedAttatchment->Update(dt); } \ No newline at end of file diff --git a/Code/Game/GameLogic/Weapon.h b/Code/Game/GameLogic/Weapon.h index 5138b2ac..8f226f12 100644 --- a/Code/Game/GameLogic/Weapon.h +++ b/Code/Game/GameLogic/Weapon.h @@ -20,6 +20,7 @@ namespace GameLogic ~Weapon(void); void Use(const WEAPON_FIRE &usage, float dt); + void Update(float dt); void AddNewAttatchment(IAttatchment *attatchment, Player *owner); void SwitchAttatchment(IAttatchment *attatchment, int socketID, Player *owner); From d77b3d92d8195447737ecad503554b3a5a5802aa Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Mon, 3 Feb 2014 15:45:48 +0100 Subject: [PATCH 09/34] GL - using movetolimbo in massdriver pickup functionallity --- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 1 + Code/Game/GameLogic/CollisionManager.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 837393db..d5de9baa 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -80,6 +80,7 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float Oyster::Physics::ICustomBody::State state = heldObject->GetState(); state.ApplyLinearImpulse((Oyster::Math::Float3)pushForce); heldObject->SetState(state); + Oyster::Physics::API::Instance().ReleaseFromLimbo(heldObject); hasObject = false; heldObject = NULL; return; diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index afb94035..d1e9a324 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -119,8 +119,8 @@ using namespace GameLogic; switch(realObj->GetObjectType()) { case OBJECT_TYPE::OBJECT_TYPE_BOX: - obj->SetGravity(true); //will now ignore gravity, dont mind the naming //move obj to limbo in physics to make sure it wont collide with anything + Oyster::Physics::API::Instance().MoveToLimbo(obj); weapon->heldObject = obj; //weapon now holds the object weapon->hasObject = true; From 8b0e1b242630de3e4ff27a679a1125ff928b3d6a Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Mon, 3 Feb 2014 15:48:42 +0100 Subject: [PATCH 10/34] Big patch! New feature :) Objects will now rebound back when colliding. --- .../Implementation/PhysicsAPI_Impl.cpp | 2 + .../Implementation/SimpleRigidBody.cpp | 88 +++++++++++-- .../Implementation/SimpleRigidBody.h | 10 ++ .../Implementation/SphericalRigidBody.cpp | 83 +++++++++++-- .../Implementation/SphericalRigidBody.h | 9 ++ Code/GamePhysics/PhysicsAPI.h | 5 + Code/GamePhysics/PhysicsStructs-Impl.h | 4 +- Code/GamePhysics/PhysicsStructs.h | 4 +- Code/Misc/Utilities.h | 8 ++ Code/OysterMath/LinearMath.h | 117 ++++++++++++++---- Code/OysterMath/OysterMath.h | 3 + Code/OysterPhysics3D/Box.cpp | 25 +++- Code/OysterPhysics3D/Box.h | 59 +++++---- Code/OysterPhysics3D/BoxAxisAligned.cpp | 12 ++ Code/OysterPhysics3D/BoxAxisAligned.h | 2 + Code/OysterPhysics3D/Frustrum.cpp | 12 ++ Code/OysterPhysics3D/Frustrum.h | 2 + Code/OysterPhysics3D/ICollideable.h | 2 + Code/OysterPhysics3D/Line.cpp | 12 ++ Code/OysterPhysics3D/Line.h | 2 + Code/OysterPhysics3D/OysterCollision3D.cpp | 39 ++++++ Code/OysterPhysics3D/OysterCollision3D.h | 3 + .../OysterPhysics3D.vcxproj.filters | 6 +- Code/OysterPhysics3D/Plane.cpp | 12 ++ Code/OysterPhysics3D/Plane.h | 2 + Code/OysterPhysics3D/Point.cpp | 14 +++ Code/OysterPhysics3D/Point.h | 2 + Code/OysterPhysics3D/Ray.cpp | 12 ++ Code/OysterPhysics3D/Ray.h | 2 + Code/OysterPhysics3D/RigidBody.cpp | 14 ++- Code/OysterPhysics3D/RigidBody.h | 2 +- Code/OysterPhysics3D/Sphere.cpp | 28 ++++- Code/OysterPhysics3D/Sphere.h | 51 +++++--- Code/OysterPhysics3D/Universe.cpp | 5 + Code/OysterPhysics3D/Universe.h | 2 + 35 files changed, 553 insertions(+), 102 deletions(-) diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 9880526d..614014e2 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -60,6 +60,8 @@ namespace return; } + // calculate and store time interpolation value, for later rebound. + proto->SetTimeOfContact( worldPointOfContact ); // bounce Float4 bounceD = normal * -Formula::CollisionResponse::Bounce( deuterState.GetRestitutionCoeff(), diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp index a2871229..d1be7d61 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -49,14 +49,21 @@ SimpleRigidBody::SimpleRigidBody() this->onCollision = Default::EventAction_BeforeCollisionResponse; this->onCollisionResponse = Default::EventAction_AfterCollisionResponse; this->onMovement = Default::EventAction_Move; + + this->collisionRebound.previousSpatial.center = this->rigid.centerPos; + this->collisionRebound.previousSpatial.axis = this->rigid.axis; + this->collisionRebound.previousSpatial.reach = this->rigid.boundingReach; + this->collisionRebound.timeOfContact = 1.0f; + this->scene = nullptr; this->customTag = nullptr; this->ignoreGravity = this->isForwarded = false; } SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc ) -{ - //this->rigid.SetRotation( desc.rotation ); +{ + this->rigid = RigidBody(); + this->rigid.SetRotation( desc.rotation ); this->rigid.centerPos = desc.centerPosition; this->rigid.SetSize( desc.size ); this->rigid.SetMass_KeepMomentum( desc.mass ); @@ -66,6 +73,11 @@ SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc ) this->gravityNormal = Float3::null; + this->collisionRebound.previousSpatial.center = this->rigid.centerPos; + this->collisionRebound.previousSpatial.axis = this->rigid.axis; + this->collisionRebound.previousSpatial.reach = this->rigid.boundingReach; + this->collisionRebound.timeOfContact = 1.0f; + if( desc.subscription_onCollision ) { this->onCollision = desc.subscription_onCollision; @@ -198,6 +210,26 @@ bool SimpleRigidBody::Intersects( const ICustomBody &object, Float4 &worldPointO return object.Intersects( Box(this->rigid.GetRotationMatrix(), this->rigid.centerPos, this->rigid.GetSize()), worldPointOfContact ); } +void SimpleRigidBody::SetTimeOfContact( Float4 &worldPointOfContact ) +{ + Point pointOfContact = Point( worldPointOfContact ); + Box start = Box(); + { + start.rotation = RotationMatrix( this->collisionRebound.previousSpatial.axis ); + start.center = this->collisionRebound.previousSpatial.center; + start.boundingOffset = this->collisionRebound.previousSpatial.reach; + } + Box end = Box(); + { + end.rotation = RotationMatrix( this->rigid.axis ); + end.center = this->rigid.centerPos; + end.boundingOffset = this->rigid.boundingReach; + } + Float timeOfContact = ::Oyster::Collision3D::Utility::TimeOfContact( start, end, pointOfContact ); + + this->collisionRebound.timeOfContact = Min( this->collisionRebound.timeOfContact, timeOfContact ); +} + Sphere & SimpleRigidBody::GetBoundingSphere( Sphere &targetMem ) const { return targetMem = Sphere( this->rigid.centerPos, this->rigid.boundingReach.GetMagnitude() ); @@ -293,18 +325,52 @@ void * SimpleRigidBody::GetCustomTag() const UpdateState SimpleRigidBody::Update( Float timeStepLength ) { - if( this->isForwarded ) - { - this->rigid.Move( this->deltaPos.xyz, this->deltaAxis.xyz ); - this->deltaPos = Float4::null; - this->deltaAxis = Float4::null; - this->isForwarded = false; - } + //if( this->isForwarded ) + //{ + // this->rigid.Move( this->deltaPos.xyz, this->deltaAxis.xyz ); + // this->deltaPos = Float4::null; + // this->deltaAxis = Float4::null; + // this->isForwarded = false; + //} this->rigid.Update_LeapFrog( timeStepLength ); - //! @todo TODO: compare previous and new state and return result - //return this->current == this->previous ? UpdateState_resting : UpdateState_altered; + { // Rebound if needed + if( this->collisionRebound.timeOfContact < 1.0f ) + { + this->rigid.centerPos = Lerp( this->collisionRebound.previousSpatial.center, this->rigid.centerPos, this->collisionRebound.timeOfContact ); + this->rigid.SetRotation( Lerp(this->collisionRebound.previousSpatial.axis, this->rigid.axis, this->collisionRebound.timeOfContact) ); + this->rigid.boundingReach = Lerp( this->collisionRebound.previousSpatial.reach, this->rigid.boundingReach, this->collisionRebound.timeOfContact ); + } + + // Update rebound data + this->collisionRebound.previousSpatial.center = this->rigid.centerPos; + this->collisionRebound.previousSpatial.axis = this->rigid.axis; + this->collisionRebound.previousSpatial.reach = this->rigid.boundingReach; + this->collisionRebound.timeOfContact = 1.0f; + } + + { // Maintain rotation resolution by keeping axis within [0, 2pi] (trigonometric methods gets faster too) + Float3 n; + ::std::modf( this->rigid.axis * (0.5f / pi), n ); + this->rigid.axis -= (2.0f * pi) * n; + } + + { // Check if this is close enough to be set resting + unsigned char resting = 0; + if( this->rigid.momentum_Linear.Dot(this->rigid.momentum_Linear) <= (Constant::epsilon * Constant::epsilon) ) + { + this->rigid.momentum_Linear = Float3::null; + resting = 1; + } + if( this->rigid.momentum_Angular.Dot(this->rigid.momentum_Angular) <= (Constant::epsilon * Constant::epsilon) ) + { + this->rigid.momentum_Angular = Float3::null; + ++resting; + } + if( resting == 2 ) return UpdateState_resting; + } + return UpdateState_altered; } diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.h b/Code/GamePhysics/Implementation/SimpleRigidBody.h index 9e61cee3..1811c911 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.h +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.h @@ -30,6 +30,8 @@ namespace Oyster { namespace Physics bool Intersects( const ::Oyster::Collision3D::ICollideable &shape, ::Oyster::Math::Float4 &worldPointOfContact ) const; bool Intersects( const ICustomBody &object, ::Oyster::Math::Float4 &worldPointOfContact ) const; + void SetTimeOfContact( ::Oyster::Math::Float4 &worldPointOfContact ); + ::Oyster::Collision3D::Sphere & GetBoundingSphere( ::Oyster::Collision3D::Sphere &targetMem = ::Oyster::Collision3D::Sphere() ) const; ::Oyster::Math::Float4 & GetNormalAt( const ::Oyster::Math::Float4 &worldPos, ::Oyster::Math::Float4 &targetMem = ::Oyster::Math::Float4() ) const; ::Oyster::Math::Float3 & GetGravityNormal( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const; @@ -65,9 +67,17 @@ namespace Oyster { namespace Physics ::Oyster::Physics3D::RigidBody rigid; ::Oyster::Math::Float4 deltaPos, deltaAxis; ::Oyster::Math::Float3 gravityNormal; + + struct + { + struct { ::Oyster::Math::Float3 center, axis, reach; } previousSpatial; + ::Oyster::Math::Float timeOfContact; + } collisionRebound; + EventAction_BeforeCollisionResponse onCollision; EventAction_AfterCollisionResponse onCollisionResponse; EventAction_Move onMovement; + Octree *scene; void *customTag; bool ignoreGravity, isForwarded; diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp index f6f89c64..49aed408 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp @@ -11,11 +11,17 @@ using namespace ::Utility::Value; SphericalRigidBody::SphericalRigidBody() { this->rigid = RigidBody(); - this->rigid.SetMass_KeepMomentum( 10.0f ); + this->rigid.SetMass_KeepMomentum( 16.0f ); this->gravityNormal = Float3::null; this->onCollision = Default::EventAction_BeforeCollisionResponse; this->onCollisionResponse = Default::EventAction_AfterCollisionResponse; this->onMovement = Default::EventAction_Move; + + this->collisionRebound.previousSpatial.center = this->rigid.centerPos; + this->collisionRebound.previousSpatial.axis = this->rigid.axis; + this->collisionRebound.previousSpatial.reach = this->rigid.boundingReach; + this->collisionRebound.timeOfContact = 1.0f; + this->scene = nullptr; this->customTag = nullptr; this->ignoreGravity = this->isForwarded = false; @@ -24,7 +30,7 @@ SphericalRigidBody::SphericalRigidBody() SphericalRigidBody::SphericalRigidBody( const API::SphericalBodyDescription &desc ) { this->rigid = RigidBody(); - //this->rigid.SetRotation( desc.rotation ); + this->rigid.SetRotation( desc.rotation ); this->rigid.centerPos = desc.centerPosition; this->rigid.boundingReach = Float4( desc.radius, desc.radius, desc.radius, 0.0f ); this->rigid.SetMass_KeepMomentum( desc.mass ); @@ -34,6 +40,11 @@ SphericalRigidBody::SphericalRigidBody( const API::SphericalBodyDescription &des this->gravityNormal = Float3::null; + this->collisionRebound.previousSpatial.center = this->rigid.centerPos; + this->collisionRebound.previousSpatial.axis = this->rigid.axis; + this->collisionRebound.previousSpatial.reach = this->rigid.boundingReach; + this->collisionRebound.timeOfContact = 1.0f; + if( desc.subscription_onCollision ) { this->onCollision = desc.subscription_onCollision; @@ -64,6 +75,11 @@ SphericalRigidBody::SphericalRigidBody( const API::SphericalBodyDescription &des this->scene = nullptr; this->customTag = nullptr; this->ignoreGravity = desc.ignoreGravity; + + this->collisionRebound.previousSpatial.center = this->rigid.centerPos; + this->collisionRebound.previousSpatial.axis = this->rigid.axis; + this->collisionRebound.previousSpatial.reach = this->rigid.boundingReach; + this->collisionRebound.timeOfContact = 1.0f; } SphericalRigidBody::~SphericalRigidBody() {} @@ -165,6 +181,17 @@ bool SphericalRigidBody::Intersects( const ICustomBody &object, Float4 &worldPoi return object.Intersects( Sphere(this->rigid.centerPos, this->rigid.boundingReach.x), worldPointOfContact ); } +void SphericalRigidBody::SetTimeOfContact( Float4 &worldPointOfContact ) +{ + Point pointOfContact = Point( worldPointOfContact ); + Sphere start = Sphere( this->collisionRebound.previousSpatial.center, this->collisionRebound.previousSpatial.reach.x ); + Sphere end = Sphere( this->rigid.centerPos, this->rigid.boundingReach.x ); + + Float timeOfContact = ::Oyster::Collision3D::Utility::TimeOfContact( start, end, pointOfContact ); + + this->collisionRebound.timeOfContact = Min( this->collisionRebound.timeOfContact, timeOfContact ); +} + Sphere & SphericalRigidBody::GetBoundingSphere( Sphere &targetMem ) const { return targetMem = Sphere( this->rigid.centerPos, this->rigid.boundingReach.x ); @@ -219,18 +246,52 @@ void * SphericalRigidBody::GetCustomTag() const UpdateState SphericalRigidBody::Update( Float timeStepLength ) { - if( this->isForwarded ) - { - this->rigid.Move( this->deltaPos.xyz, this->deltaAxis.xyz ); - this->deltaPos = Float4::null; - this->deltaAxis = Float4::null; - this->isForwarded = false; - } + //if( this->isForwarded ) + //{ + // this->rigid.Move( this->deltaPos.xyz, this->deltaAxis.xyz ); + // this->deltaPos = Float4::null; + // this->deltaAxis = Float4::null; + // this->isForwarded = false; + //} this->rigid.Update_LeapFrog( timeStepLength ); - // compare previous and new state and return result - //return this->current == this->previous ? UpdateState_resting : UpdateState_altered; + { // Rebound if needed + if( this->collisionRebound.timeOfContact < 1.0f ) + { + this->rigid.centerPos = Lerp( this->collisionRebound.previousSpatial.center, this->rigid.centerPos, this->collisionRebound.timeOfContact ); + this->rigid.SetRotation( Lerp(this->collisionRebound.previousSpatial.axis, this->rigid.axis, this->collisionRebound.timeOfContact) ); + this->rigid.boundingReach = Lerp( this->collisionRebound.previousSpatial.reach, this->rigid.boundingReach, this->collisionRebound.timeOfContact ); + } + + // Update rebound data + this->collisionRebound.previousSpatial.center = this->rigid.centerPos; + this->collisionRebound.previousSpatial.axis = this->rigid.axis; + this->collisionRebound.previousSpatial.reach = this->rigid.boundingReach; + this->collisionRebound.timeOfContact = 1.0f; + } + + { // Maintain rotation resolution by keeping axis within [0, 2pi] (trigonometric methods gets faster too) + Float3 n; + ::std::modf( this->rigid.axis * (0.5f / pi), n ); + this->rigid.axis -= (2.0f * pi) * n; + } + + { // Check if this is close enough to be set resting + unsigned char resting = 0; + if( this->rigid.momentum_Linear.Dot(this->rigid.momentum_Linear) <= (Constant::epsilon * Constant::epsilon) ) + { + this->rigid.momentum_Linear = Float3::null; + resting = 1; + } + if( this->rigid.momentum_Angular.Dot(this->rigid.momentum_Angular) <= (Constant::epsilon * Constant::epsilon) ) + { + this->rigid.momentum_Angular = Float3::null; + ++resting; + } + if( resting == 2 ) return UpdateState_resting; + } + return UpdateState_altered; } diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.h b/Code/GamePhysics/Implementation/SphericalRigidBody.h index 390b7171..c2dc8131 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.h +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.h @@ -31,6 +31,8 @@ namespace Oyster { namespace Physics bool Intersects( const ::Oyster::Collision3D::ICollideable &shape, ::Oyster::Math::Float4 &worldPointOfContact ) const; bool Intersects( const ICustomBody &object, ::Oyster::Math::Float4 &worldPointOfContact ) const; + void SetTimeOfContact( ::Oyster::Math::Float4 &worldPointOfContact ); + ::Oyster::Collision3D::Sphere & GetBoundingSphere( ::Oyster::Collision3D::Sphere &targetMem = ::Oyster::Collision3D::Sphere() ) const; ::Oyster::Math::Float4 & GetNormalAt( const ::Oyster::Math::Float4 &worldPos, ::Oyster::Math::Float4 &targetMem = ::Oyster::Math::Float4() ) const; ::Oyster::Math::Float3 & GetGravityNormal( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const; @@ -66,6 +68,13 @@ namespace Oyster { namespace Physics ::Oyster::Physics3D::RigidBody rigid; ::Oyster::Math::Float4 deltaPos, deltaAxis; ::Oyster::Math::Float3 gravityNormal; + + struct + { + struct { ::Oyster::Math::Float3 center, axis, reach; } previousSpatial; + ::Oyster::Math::Float timeOfContact; + } collisionRebound; + EventAction_BeforeCollisionResponse onCollision; EventAction_AfterCollisionResponse onCollisionResponse; EventAction_Move onMovement; diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index 080b8d30..f636bb73 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -322,6 +322,11 @@ namespace Oyster ********************************************************/ virtual bool Intersects( const ICustomBody &object, ::Oyster::Math::Float4 &worldPointOfContact ) const = 0; + /******************************************************** + * Sets how far back it needs to be interpolated to not be overlapping worldPointOfContact. + ********************************************************/ + virtual void SetTimeOfContact( ::Oyster::Math::Float4 &worldPointOfContact ) = 0; + /******************************************************** * Required by Engine's Collision Search. * @param targetMem: Provided memory that written into and then returned. diff --git a/Code/GamePhysics/PhysicsStructs-Impl.h b/Code/GamePhysics/PhysicsStructs-Impl.h index af2fb91c..311b81f8 100644 --- a/Code/GamePhysics/PhysicsStructs-Impl.h +++ b/Code/GamePhysics/PhysicsStructs-Impl.h @@ -12,7 +12,7 @@ namespace Oyster { inline SimpleBodyDescription::SimpleBodyDescription() { - this->rotation = ::Oyster::Math::Float4x4::identity; + this->rotation = ::Oyster::Math::Float3::null; this->centerPosition = ::Oyster::Math::Float3::null; this->size = ::Oyster::Math::Float3( 1.0f ); this->mass = 6.0f; @@ -28,7 +28,7 @@ namespace Oyster inline SphericalBodyDescription::SphericalBodyDescription() { - this->rotation = ::Oyster::Math::Float4x4::identity; + this->rotation = ::Oyster::Math::Float3::null; this->centerPosition = ::Oyster::Math::Float3::null; this->radius = 0.5f; this->mass = 10.0f; diff --git a/Code/GamePhysics/PhysicsStructs.h b/Code/GamePhysics/PhysicsStructs.h index aef157a8..61a0569f 100644 --- a/Code/GamePhysics/PhysicsStructs.h +++ b/Code/GamePhysics/PhysicsStructs.h @@ -11,7 +11,7 @@ namespace Oyster { namespace Physics { struct SimpleBodyDescription { - ::Oyster::Math::Float4x4 rotation; + ::Oyster::Math::Float3 rotation; ::Oyster::Math::Float3 centerPosition; ::Oyster::Math::Float3 size; ::Oyster::Math::Float mass; @@ -29,7 +29,7 @@ namespace Oyster { namespace Physics struct SphericalBodyDescription { - ::Oyster::Math::Float4x4 rotation; + ::Oyster::Math::Float3 rotation; ::Oyster::Math::Float3 centerPosition; ::Oyster::Math::Float radius; ::Oyster::Math::Float mass; diff --git a/Code/Misc/Utilities.h b/Code/Misc/Utilities.h index 9c71a515..9b3abac0 100644 --- a/Code/Misc/Utilities.h +++ b/Code/Misc/Utilities.h @@ -315,6 +315,14 @@ namespace Utility { using ::std::numeric_limits; + template + inline bool Within( const ValueType &value, const ValueType &lower, const ValueType &upper ) + { + if( value < lower ) return false; + if( value > upper ) return false; + return true; + } + template inline ValueType Abs( const ValueType &value ) { return value < 0 ? value * -1 : value; } diff --git a/Code/OysterMath/LinearMath.h b/Code/OysterMath/LinearMath.h index dce7a026..ebb1e375 100644 --- a/Code/OysterMath/LinearMath.h +++ b/Code/OysterMath/LinearMath.h @@ -11,27 +11,6 @@ #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 @@ -112,6 +91,69 @@ inline ::LinearAlgebra::Vector4 operator * ( const ::LinearAlgebra:: (vector.x * matrix.m14) + (vector.y * matrix.m24) + (vector.z * matrix.m34) + (vector.w * matrix.m44) ); } +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) ); + } + + /******************************************************************* + * @param numerator of the vector vec + * @return the denomiator of the vector vec. + *******************************************************************/ + template + inline ::LinearAlgebra::Vector2 modf( const ::LinearAlgebra::Vector2 &vec, ::LinearAlgebra::Vector2 &numerator ) + { + ::LinearAlgebra::Vector2 denominator; + denominator.x = (ScalarType)modf( vec.x, &numerator.x ); + denominator.y = (ScalarType)modf( vec.y, &numerator.y ); + return denominator; + } + + /******************************************************************* + * @param numerator of the vector vec + * @return the denomiator of the vector vec. + *******************************************************************/ + template + inline ::LinearAlgebra::Vector3 modf( const ::LinearAlgebra::Vector3 &vec, ::LinearAlgebra::Vector3 &numerator ) + { + ::LinearAlgebra::Vector3 denominator; + denominator.x = (ScalarType)modf( vec.x, &numerator.x ); + denominator.y = (ScalarType)modf( vec.y, &numerator.y ); + denominator.z = (ScalarType)modf( vec.z, &numerator.z ); + return denominator; + } + + /******************************************************************* + * @param numerator of the vector vec + * @return the denomiator of the vector vec. + *******************************************************************/ + template + inline ::LinearAlgebra::Vector4 modf( const ::LinearAlgebra::Vector4 &vec, ::LinearAlgebra::Vector4 &numerator ) + { + ::LinearAlgebra::Vector4 denominator; + denominator.x = (ScalarType)modf( vec.x, &numerator.x ); + denominator.y = (ScalarType)modf( vec.y, &numerator.y ); + denominator.z = (ScalarType)modf( vec.z, &numerator.z ); + denominator.w = (ScalarType)modf( vec.w, &numerator.w ); + return denominator; + } +} + namespace LinearAlgebra { // Creates a solution matrix for 'out´= 'targetMem' * 'in'. @@ -795,11 +837,42 @@ namespace LinearAlgebra3D } template - ::LinearAlgebra::Matrix4x4 & InterpolateOrientation_UsingNonRigidNlerp( const ::LinearAlgebra::Matrix4x4 &start, const ::LinearAlgebra::Matrix4x4 &end, ScalarType t, ::LinearAlgebra::Matrix4x4 &targetMem ) + inline ::LinearAlgebra::Matrix4x4 & InterpolateRotation_UsingNonRigidNlerp( const ::LinearAlgebra::Matrix4x4 &start, const ::LinearAlgebra::Matrix4x4 &end, ScalarType t, ::LinearAlgebra::Matrix4x4 &targetMem ) { targetMem.v[0] = ::LinearAlgebra::Nlerp( start.v[0], end.v[0], t ); targetMem.v[1] = ::LinearAlgebra::Nlerp( start.v[1], end.v[1], t ); targetMem.v[2] = ::LinearAlgebra::Nlerp( start.v[2], end.v[2], t ); + return targetMem; + } + + template + inline ::LinearAlgebra::Matrix4x4 & InterpolateOrientation_UsingNonRigidNlerp( const ::LinearAlgebra::Matrix4x4 &start, const ::LinearAlgebra::Matrix4x4 &end, ScalarType t, ::LinearAlgebra::Matrix4x4 &targetMem ) + { + InterpolateRotation_UsingNonRigidNlerp( start, end, t, targetMem ); + targetMem.v[3] = ::LinearAlgebra::Lerp( start.v[3], end.v[3], t ); + return targetMem; + } + + template + ::LinearAlgebra::Matrix4x4 & InterpolateRotation_UsingRigidNlerp( const ::LinearAlgebra::Matrix4x4 &start, const ::LinearAlgebra::Matrix4x4 &end, ScalarType t, ::LinearAlgebra::Matrix4x4 &targetMem ) + { + // Nlerp y axis + targetMem.v[1] = ::LinearAlgebra::Nlerp( start.v[1], end.v[1], t ); + + // Lerp z axis and orthogonolize against y axis + targetMem.v[2] = ::LinearAlgebra::Lerp( start.v[2], end.v[2], t ); + targetMem.v[2] -= targetMem.v[2].Dot(targetMem.v[1]) * targetMem.v[1]; + targetMem.v[2].Normalize(); + + // Cross product x axis from y and z + targetMem.v[0].xyz = targetMem.v[1].xyz.Cross(targetMem.v[2].xyz); + return targetMem; + } + + template + inline ::LinearAlgebra::Matrix4x4 & InterpolateOrientation_UsingRigidNlerp( const ::LinearAlgebra::Matrix4x4 &start, const ::LinearAlgebra::Matrix4x4 &end, ScalarType t, ::LinearAlgebra::Matrix4x4 &targetMem ) + { + InterpolateRotation_UsingRigidNlerp( start, end, t, targetMem ); targetMem.v[3] = ::LinearAlgebra::Lerp( start.v[3], end.v[3], t ); return targetMem; } diff --git a/Code/OysterMath/OysterMath.h b/Code/OysterMath/OysterMath.h index 7e123183..23ee06db 100644 --- a/Code/OysterMath/OysterMath.h +++ b/Code/OysterMath/OysterMath.h @@ -322,7 +322,10 @@ namespace Oyster { namespace Math3D //! Oyster's native math library specialized using ::LinearAlgebra3D::SnapAxisYToNormal_UsingNlerp; using ::LinearAlgebra3D::InterpolateAxisYToNormal_UsingNlerp; + using ::LinearAlgebra3D::InterpolateRotation_UsingNonRigidNlerp; + using ::LinearAlgebra3D::InterpolateRotation_UsingRigidNlerp; using ::LinearAlgebra3D::InterpolateOrientation_UsingNonRigidNlerp; + using ::LinearAlgebra3D::InterpolateOrientation_UsingRigidNlerp; using ::LinearAlgebra3D::InterpolateOrientation_UsingSlerp; using ::LinearAlgebra3D::SnapAngularAxis; } } diff --git a/Code/OysterPhysics3D/Box.cpp b/Code/OysterPhysics3D/Box.cpp index f55415b7..56950e24 100644 --- a/Code/OysterPhysics3D/Box.cpp +++ b/Code/OysterPhysics3D/Box.cpp @@ -92,4 +92,27 @@ bool Box::Contains( const ICollideable &target ) const //case Type_frustrum: return false; // TODO: default: return false; } -} \ No newline at end of file +} + +Float Box::TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const +{ + if( deuterStart.type != deuterEnd.type ) + return -1.0f; + + switch( deuterStart.type ) + { // TODO: more to implement + case Type_universe: return 0.0f; + default: return 1.0f; + } +} + +namespace Oyster { namespace Math +{ + Box & Nlerp( const Box &start, const Box &end, Float t, Box &targetMem ) + { + InterpolateRotation_UsingRigidNlerp( start.rotation, end.rotation, t, targetMem.rotation ); + targetMem.center = Lerp( start.center, end.center, t ); + targetMem.boundingOffset = Lerp( start.boundingOffset, end.boundingOffset, t ); + return targetMem; + } +} } \ No newline at end of file diff --git a/Code/OysterPhysics3D/Box.h b/Code/OysterPhysics3D/Box.h index f98ae362..553037be 100644 --- a/Code/OysterPhysics3D/Box.h +++ b/Code/OysterPhysics3D/Box.h @@ -9,35 +9,48 @@ #include "OysterMath.h" #include "ICollideable.h" -namespace Oyster { namespace Collision3D +namespace Oyster { - class Box : public ICollideable + namespace Collision3D { - public: - union + class Box : public ICollideable { - struct{ ::Oyster::Math::Float4x4 rotation; ::Oyster::Math::Float4 center, boundingOffset; }; - struct + public: + union { - ::Oyster::Math::Float4 xAxis; - ::Oyster::Math::Float4 yAxis; - ::Oyster::Math::Float4 zAxis; + struct{ ::Oyster::Math::Float4x4 rotation; ::Oyster::Math::Float4 center, boundingOffset; }; + struct + { + ::Oyster::Math::Float4 xAxis; + ::Oyster::Math::Float4 yAxis; + ::Oyster::Math::Float4 zAxis; + }; + char byte[sizeof(::Oyster::Math::Float4x4) + 2*sizeof(::Oyster::Math::Float4)]; }; - char byte[sizeof(::Oyster::Math::Float4x4) + 2*sizeof(::Oyster::Math::Float4)]; + + Box( ); + Box( const ::Oyster::Math::Float4x4 &rotation, const ::Oyster::Math::Float3 &worldPos, const ::Oyster::Math::Float3 &size ); + Box( const ::Oyster::Math::Float4x4 &rotation, const ::Oyster::Math::Float4 &worldPos, const ::Oyster::Math::Float4 &size ); + virtual ~Box( ); + + Box & operator = ( const Box &box ); + + virtual ::Utility::DynamicMemory::UniquePointer Clone( ) const; + bool Intersects( const ICollideable &target ) const; + bool Intersects( const ICollideable &target, ::Oyster::Math::Float4 &worldPointOfContact ) const; + bool Contains( const ICollideable &target ) const; + + ::Oyster::Math::Float TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const; }; + } - Box( ); - Box( const ::Oyster::Math::Float4x4 &rotation, const ::Oyster::Math::Float3 &worldPos, const ::Oyster::Math::Float3 &size ); - Box( const ::Oyster::Math::Float4x4 &rotation, const ::Oyster::Math::Float4 &worldPos, const ::Oyster::Math::Float4 &size ); - virtual ~Box( ); - - Box & operator = ( const Box &box ); - - virtual ::Utility::DynamicMemory::UniquePointer Clone( ) const; - bool Intersects( const ICollideable &target ) const; - bool Intersects( const ICollideable &target, ::Oyster::Math::Float4 &worldPointOfContact ) const; - bool Contains( const ICollideable &target ) const; - }; -} } + namespace Math + { + /******************************************************************** + * Normalized Linear Interpolation + ********************************************************************/ + ::Oyster::Collision3D::Box & Nlerp( const ::Oyster::Collision3D::Box &start, const ::Oyster::Collision3D::Box &end, ::Oyster::Math::Float t, ::Oyster::Collision3D::Box &targetMem = ::Oyster::Collision3D::Box() ); + } +} #endif \ No newline at end of file diff --git a/Code/OysterPhysics3D/BoxAxisAligned.cpp b/Code/OysterPhysics3D/BoxAxisAligned.cpp index bd10016f..8c934617 100644 --- a/Code/OysterPhysics3D/BoxAxisAligned.cpp +++ b/Code/OysterPhysics3D/BoxAxisAligned.cpp @@ -76,4 +76,16 @@ bool BoxAxisAligned::Contains( const ICollideable &target ) const //default: return false; //} return false; +} + +Float BoxAxisAligned::TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const +{ + if( deuterStart.type != deuterEnd.type ) + return -1.0f; + + switch( deuterStart.type ) + { // TODO: more to implement + case Type_universe: return 0.0f; + default: return 1.0f; + } } \ No newline at end of file diff --git a/Code/OysterPhysics3D/BoxAxisAligned.h b/Code/OysterPhysics3D/BoxAxisAligned.h index 2ff39463..9ad55165 100644 --- a/Code/OysterPhysics3D/BoxAxisAligned.h +++ b/Code/OysterPhysics3D/BoxAxisAligned.h @@ -31,6 +31,8 @@ namespace Oyster { namespace Collision3D bool Intersects( const ICollideable &target ) const; bool Intersects( const ICollideable &target, ::Oyster::Math::Float4 &worldPointOfContact ) const; bool Contains( const ICollideable &target ) const; + + ::Oyster::Math::Float TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const; }; } } diff --git a/Code/OysterPhysics3D/Frustrum.cpp b/Code/OysterPhysics3D/Frustrum.cpp index ce2c5256..32e6357b 100644 --- a/Code/OysterPhysics3D/Frustrum.cpp +++ b/Code/OysterPhysics3D/Frustrum.cpp @@ -243,6 +243,18 @@ bool Frustrum::Contains( const ICollideable &target ) const } } +Float Frustrum::TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const +{ + if( deuterStart.type != deuterEnd.type ) + return -1.0f; + + switch( deuterStart.type ) + { // TODO: more to implement + case Type_universe: return 0.0f; + default: return 1.0f; + } +} + ::Oyster::Math::Float3 Frustrum::ExtractForwad() { return this->bottomPlane.normal.xyz; diff --git a/Code/OysterPhysics3D/Frustrum.h b/Code/OysterPhysics3D/Frustrum.h index ae0f086c..0c4cc04f 100644 --- a/Code/OysterPhysics3D/Frustrum.h +++ b/Code/OysterPhysics3D/Frustrum.h @@ -42,6 +42,8 @@ namespace Oyster { namespace Collision3D bool Intersects( const ICollideable &target, Oyster::Math::Float4 &worldPointOfContact ) const; bool Contains( const ICollideable &target ) const; + ::Oyster::Math::Float TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const; + ::Oyster::Math::Float3 ExtractForwad(); }; diff --git a/Code/OysterPhysics3D/ICollideable.h b/Code/OysterPhysics3D/ICollideable.h index b3f61671..3e63200e 100644 --- a/Code/OysterPhysics3D/ICollideable.h +++ b/Code/OysterPhysics3D/ICollideable.h @@ -38,6 +38,8 @@ namespace Oyster { namespace Collision3D //! Contains a collection of 3D shapes virtual bool Intersects( const ICollideable &target, ::Oyster::Math::Float4 &worldPointOfContact ) const = 0; virtual bool Intersects( const ICollideable &target ) const = 0; virtual bool Contains( const ICollideable &target ) const = 0; + + virtual ::Oyster::Math::Float TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const = 0; }; } } #endif \ No newline at end of file diff --git a/Code/OysterPhysics3D/Line.cpp b/Code/OysterPhysics3D/Line.cpp index cebceaff..fc81791d 100644 --- a/Code/OysterPhysics3D/Line.cpp +++ b/Code/OysterPhysics3D/Line.cpp @@ -76,3 +76,15 @@ bool Line::Intersects( const ICollideable &target, Float4 &worldPointOfContact ) bool Line::Contains( const ICollideable &target ) const { /* TODO: : */ return false; } + +Float Line::TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const +{ + if( deuterStart.type != deuterEnd.type ) + return -1.0f; + + switch( deuterStart.type ) + { // TODO: more to implement + case Type_universe: return 0.0f; + default: return 1.0f; + } +} \ No newline at end of file diff --git a/Code/OysterPhysics3D/Line.h b/Code/OysterPhysics3D/Line.h index 2e6d2d55..a305622f 100644 --- a/Code/OysterPhysics3D/Line.h +++ b/Code/OysterPhysics3D/Line.h @@ -32,6 +32,8 @@ namespace Oyster { namespace Collision3D bool Intersects( const ICollideable &target ) const; bool Intersects( const ICollideable &target, ::Oyster::Math::Float4 &worldPointOfContact ) const; bool Contains( const ICollideable &target ) const; + + ::Oyster::Math::Float TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const; }; } } diff --git a/Code/OysterPhysics3D/OysterCollision3D.cpp b/Code/OysterPhysics3D/OysterCollision3D.cpp index 89b3af8a..cc68d536 100644 --- a/Code/OysterPhysics3D/OysterCollision3D.cpp +++ b/Code/OysterPhysics3D/OysterCollision3D.cpp @@ -1061,4 +1061,43 @@ namespace Oyster { namespace Collision3D { namespace Utility return container.normal == -plane.normal; return false; } + + Float TimeOfContact( const Sphere &protoStart, const Sphere &protoEnd, const Point &deuter ) + { // Bisection with 5 levels of detail + Float t = 0.5f; + Sphere s; + for( int i = 0; i < 5; ++i ) + { + Nlerp( protoStart, protoEnd, t, s ); + if( Intersect(s, deuter) ) + { + t *= 0.5f; + } + else + { + t *= 1.5f; + } + } + return t; + } + + Float TimeOfContact( const Box &protoStart, const Box &protoEnd, const Point &deuter ) + { // Bisection with 5 levels of detail + Float t = 0.5f; + Box b; + for( int i = 0; i < 5; ++i ) + { + Nlerp( protoStart, protoEnd, t, b ); + if( Intersect(b, deuter) ) + { + t *= 0.5f; + } + else + { + t *= 1.5f; + } + } + return t; + } + } } } \ No newline at end of file diff --git a/Code/OysterPhysics3D/OysterCollision3D.h b/Code/OysterPhysics3D/OysterCollision3D.h index 20a55a18..83a6239e 100644 --- a/Code/OysterPhysics3D/OysterCollision3D.h +++ b/Code/OysterPhysics3D/OysterCollision3D.h @@ -121,6 +121,9 @@ namespace Oyster { namespace Collision3D { namespace Utility // bool Contains( const Frustrum &container, const BoxAxisAligned &box ); // bool Contains( const Frustrum &container, const Box &box ); // bool Contains( const Frustrum &container, const Frustrum &frustrum ); + + ::Oyster::Math::Float TimeOfContact( const Sphere &protoStart, const Sphere &protoEnd, const Point &deuter ); + ::Oyster::Math::Float TimeOfContact( const Box &protoStart, const Box &protoEnd, const Point &deuter ); } } } #endif \ No newline at end of file diff --git a/Code/OysterPhysics3D/OysterPhysics3D.vcxproj.filters b/Code/OysterPhysics3D/OysterPhysics3D.vcxproj.filters index da336ce5..f6b6d934 100644 --- a/Code/OysterPhysics3D/OysterPhysics3D.vcxproj.filters +++ b/Code/OysterPhysics3D/OysterPhysics3D.vcxproj.filters @@ -27,9 +27,6 @@ - - Header Files\Collision - Header Files\Collision @@ -81,6 +78,9 @@ Header Files\Physics + + Header Files\Collision + diff --git a/Code/OysterPhysics3D/Plane.cpp b/Code/OysterPhysics3D/Plane.cpp index 59ffbc47..2923a802 100644 --- a/Code/OysterPhysics3D/Plane.cpp +++ b/Code/OysterPhysics3D/Plane.cpp @@ -83,4 +83,16 @@ bool Plane::Contains( const ICollideable &target ) const //case Type_triangle: return false; // TODO: default: return false; } +} + +Float Plane::TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const +{ + if( deuterStart.type != deuterEnd.type ) + return -1.0f; + + switch( deuterStart.type ) + { // TODO: more to implement + case Type_universe: return 0.0f; + default: return 1.0f; + } } \ No newline at end of file diff --git a/Code/OysterPhysics3D/Plane.h b/Code/OysterPhysics3D/Plane.h index f148ed8e..a66e7f3b 100644 --- a/Code/OysterPhysics3D/Plane.h +++ b/Code/OysterPhysics3D/Plane.h @@ -31,6 +31,8 @@ namespace Oyster { namespace Collision3D bool Intersects( const ICollideable &target ) const; bool Intersects( const ICollideable &target, ::Oyster::Math::Float4 &worldPointOfContact ) const; bool Contains( const ICollideable &target ) const; + + ::Oyster::Math::Float TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const; }; } } diff --git a/Code/OysterPhysics3D/Point.cpp b/Code/OysterPhysics3D/Point.cpp index 788ab32d..dd879e27 100644 --- a/Code/OysterPhysics3D/Point.cpp +++ b/Code/OysterPhysics3D/Point.cpp @@ -81,4 +81,18 @@ bool Point::Contains( const ICollideable &target ) const case Type_point: return Utility::Intersect( *this, (const Point&)target ); default: return false; } +} + +Float Point::TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const +{ + if( deuterStart.type != deuterEnd.type ) + return -1.0f; + + switch( deuterStart.type ) + { // TODO: more to implement + case Type_sphere: return Utility::TimeOfContact( (const Sphere&)deuterStart, (const Sphere&)deuterEnd, *this ); + case Type_box: return Utility::TimeOfContact( (const Box&)deuterStart, (const Box&)deuterEnd, *this ); + case Type_universe: return 0.0f; + default: return 1.0f; + } } \ No newline at end of file diff --git a/Code/OysterPhysics3D/Point.h b/Code/OysterPhysics3D/Point.h index 60486373..15abc488 100644 --- a/Code/OysterPhysics3D/Point.h +++ b/Code/OysterPhysics3D/Point.h @@ -31,6 +31,8 @@ namespace Oyster { namespace Collision3D bool Intersects( const ICollideable &target ) const; bool Intersects( const ICollideable &target, ::Oyster::Math::Float4 &worldPointOfContact ) const; bool Contains( const ICollideable &target ) const; + + ::Oyster::Math::Float TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const; }; } } diff --git a/Code/OysterPhysics3D/Ray.cpp b/Code/OysterPhysics3D/Ray.cpp index e7f21de8..5e58d14b 100644 --- a/Code/OysterPhysics3D/Ray.cpp +++ b/Code/OysterPhysics3D/Ray.cpp @@ -92,4 +92,16 @@ bool Ray::Contains( const ICollideable &target ) const case Type_ray: return Utility::Contains( *this, (const Ray&)target ); default: return false; } +} + +Float Ray::TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const +{ + if( deuterStart.type != deuterEnd.type ) + return -1.0f; + + switch( deuterStart.type ) + { // TODO: more to implement + case Type_universe: return 0.0f; + default: return 1.0f; + } } \ No newline at end of file diff --git a/Code/OysterPhysics3D/Ray.h b/Code/OysterPhysics3D/Ray.h index a85580b3..cd797539 100644 --- a/Code/OysterPhysics3D/Ray.h +++ b/Code/OysterPhysics3D/Ray.h @@ -39,6 +39,8 @@ namespace Oyster { namespace Collision3D bool Intersects( const ICollideable &target ) const; bool Intersects( const ICollideable &target, ::Oyster::Math::Float4 &worldPointOfContact ) const; bool Contains( const ICollideable &target ) const; + + ::Oyster::Math::Float TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const; }; } } diff --git a/Code/OysterPhysics3D/RigidBody.cpp b/Code/OysterPhysics3D/RigidBody.cpp index 70ded863..68f435e9 100644 --- a/Code/OysterPhysics3D/RigidBody.cpp +++ b/Code/OysterPhysics3D/RigidBody.cpp @@ -53,13 +53,9 @@ void RigidBody::Update_LeapFrog( Float updateFrameLength ) //! HACK: @todo Add real solution with fluid drag this->momentum_Linear = this->momentum_Linear*0.99f; this->momentum_Angular = this->momentum_Angular*0.99f; + // ds = dt * Formula::LinearVelocity( m, avg_G ) = dt * avg_G / m = (dt / m) * avg_G - Float3 deltaPos = ( updateFrameLength / this->mass ) * AverageWithDelta( this->momentum_Linear, this->impulse_Linear ); - if( deltaPos.GetLength() < 0.001f ) - { - deltaPos = Float3::null; - } - this->centerPos += deltaPos; + this->centerPos += ( updateFrameLength / this->mass ) * AverageWithDelta( this->momentum_Linear, this->impulse_Linear ); // updating the angular // dO = dt * Formula::AngularVelocity( (RI)^-1, avg_H ) = dt * (RI)^-1 * avg_H @@ -185,6 +181,12 @@ void RigidBody::SetMass_KeepMomentum( const Float &m ) } } +void RigidBody::SetRotation( const Float3 &axis ) +{ // by Dan Andersson + this->axis = axis; + this->rotation = Rotation( this->axis ); +} + void RigidBody::SetMomentum_Linear( const Float3 &worldG, const Float3 &atWorldPos ) { // by Dan Andersson Float3 worldOffset = atWorldPos - this->centerPos; diff --git a/Code/OysterPhysics3D/RigidBody.h b/Code/OysterPhysics3D/RigidBody.h index c666662a..f7aebd22 100644 --- a/Code/OysterPhysics3D/RigidBody.h +++ b/Code/OysterPhysics3D/RigidBody.h @@ -64,7 +64,7 @@ namespace Oyster { namespace Physics3D void SetMass_KeepMomentum( const ::Oyster::Math::Float &m ); //void SetOrientation( const ::Oyster::Math::Float4x4 &o ); - //void SetRotation( const ::Oyster::Math::Float4x4 &r ); + void SetRotation( const ::Oyster::Math::Float3 &axis ); void SetSize( const ::Oyster::Math::Float3 &widthHeight ); void SetMomentum_Linear( const ::Oyster::Math::Float3 &worldG, const ::Oyster::Math::Float3 &atWorldPos ); diff --git a/Code/OysterPhysics3D/Sphere.cpp b/Code/OysterPhysics3D/Sphere.cpp index c402b2ef..86230508 100644 --- a/Code/OysterPhysics3D/Sphere.cpp +++ b/Code/OysterPhysics3D/Sphere.cpp @@ -86,4 +86,30 @@ bool Sphere::Contains( const ICollideable &target ) const //case Type_frustrum: return false; // TODO: default: return false; } -} \ No newline at end of file +} + +Float Sphere::TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const +{ + if( deuterStart.type != deuterEnd.type ) + return -1.0f; + + switch( deuterStart.type ) + { + //case Type_point: // not implemented + //case Type_sphere: // not implemented + //case Type_box: // not implemented + case Type_universe: return 0.0f; + default: return 1.0f; + } +} + +namespace Oyster { namespace Math +{ + Sphere & Nlerp( const Sphere &start, const Sphere &end, Float t, Sphere &targetMem ) + { + Float4 i = Lerp( Float4(start.center.xyz, start.radius), Float4(end.center.xyz, end.radius), t ); + targetMem.center.xyz = i.xyz; + targetMem.radius = i.w; + return targetMem; + } +} } \ No newline at end of file diff --git a/Code/OysterPhysics3D/Sphere.h b/Code/OysterPhysics3D/Sphere.h index 2f483ecd..c3cc32a3 100644 --- a/Code/OysterPhysics3D/Sphere.h +++ b/Code/OysterPhysics3D/Sphere.h @@ -9,29 +9,42 @@ #include "OysterMath.h" #include "ICollideable.h" -namespace Oyster { namespace Collision3D +namespace Oyster { - class Sphere : public ICollideable + namespace Collision3D { - public: - union + class Sphere : public ICollideable { - struct{ ::Oyster::Math::Float4 center; ::Oyster::Math::Float radius; }; - char byte[sizeof(::Oyster::Math::Float4) + sizeof(::Oyster::Math::Float)]; + public: + union + { + struct{ ::Oyster::Math::Float4 center; ::Oyster::Math::Float radius; }; + char byte[sizeof(::Oyster::Math::Float4) + sizeof(::Oyster::Math::Float)]; + }; + + Sphere( ); + Sphere( const ::Oyster::Math::Float3 ¢er, const ::Oyster::Math::Float &radius ); + Sphere( const ::Oyster::Math::Float4 ¢er, const ::Oyster::Math::Float &radius ); + virtual ~Sphere( ); + + Sphere & operator = ( const Sphere &sphere ); + + virtual ::Utility::DynamicMemory::UniquePointer Clone( ) const; + bool Intersects( const ICollideable &target ) const; + bool Intersects( const ICollideable &target, ::Oyster::Math::Float4 &worldPointOfContact ) const; + bool Contains( const ICollideable &target ) const; + + ::Oyster::Math::Float TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const; }; + } - Sphere( ); - Sphere( const ::Oyster::Math::Float3 ¢er, const ::Oyster::Math::Float &radius ); - Sphere( const ::Oyster::Math::Float4 ¢er, const ::Oyster::Math::Float &radius ); - virtual ~Sphere( ); - - Sphere & operator = ( const Sphere &sphere ); - - virtual ::Utility::DynamicMemory::UniquePointer Clone( ) const; - bool Intersects( const ICollideable &target ) const; - bool Intersects( const ICollideable &target, ::Oyster::Math::Float4 &worldPointOfContact ) const; - bool Contains( const ICollideable &target ) const; - }; -} } + namespace Math + { + /******************************************************************** + * Normalized Linear Interpolation + ********************************************************************/ + ::Oyster::Collision3D::Sphere & Nlerp( const ::Oyster::Collision3D::Sphere &start, const ::Oyster::Collision3D::Sphere &end, ::Oyster::Math::Float t, ::Oyster::Collision3D::Sphere &targetMem = ::Oyster::Collision3D::Sphere() ); + } +} #endif \ No newline at end of file diff --git a/Code/OysterPhysics3D/Universe.cpp b/Code/OysterPhysics3D/Universe.cpp index 7eb788ae..a3548ad9 100644 --- a/Code/OysterPhysics3D/Universe.cpp +++ b/Code/OysterPhysics3D/Universe.cpp @@ -78,4 +78,9 @@ bool Universe::Intersects( const ICollideable &target, Float4 &worldPointOfConta bool Universe::Contains( const ICollideable &target ) const { // universe contains everything return true; +} + +Float Universe::TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const +{ + return 0.0f; } \ No newline at end of file diff --git a/Code/OysterPhysics3D/Universe.h b/Code/OysterPhysics3D/Universe.h index 5f009e0b..7b5fb969 100644 --- a/Code/OysterPhysics3D/Universe.h +++ b/Code/OysterPhysics3D/Universe.h @@ -23,6 +23,8 @@ namespace Oyster { namespace Collision3D bool Intersects( const ICollideable &target ) const; bool Intersects( const ICollideable &target, ::Oyster::Math::Float4 &worldPointOfContact ) const; bool Contains( const ICollideable &target ) const; + + ::Oyster::Math::Float TimeOfContact( const ICollideable &deuterStart, const ICollideable &deuterEnd ) const; }; } } From a3886c4f1f688a5b95cafee0ccc829891d67fcf1 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Mon, 3 Feb 2014 15:52:00 +0100 Subject: [PATCH 11/34] GL - added models and started to fix camera movement --- .../DanBiasGame/GameClientState/GameState.cpp | 45 ++++++++++++++--- Code/Game/GameLogic/Game.h | 2 +- Code/Game/GameLogic/GameAPI.h | 2 +- Code/Game/GameLogic/Game_PlayerData.cpp | 9 +++- Code/Game/GameLogic/Object.cpp | 48 ++++++++++--------- Code/Game/GameLogic/Object.h | 7 +-- Code/Game/GameLogic/Player.cpp | 43 +++++++++++------ Code/Game/GameLogic/Player.h | 2 +- Code/Game/GameProtocols/PlayerProtocols.h | 6 +++ .../Implementation/GameSession_Gameplay.cpp | 3 +- 10 files changed, 115 insertions(+), 52 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index cd281717..638d954d 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -107,7 +107,7 @@ bool GameState::LoadModels(std::wstring mapFile) modelData.world = modelData.world * translate; modelData.visible = true; - modelData.modelPath = L"..\\Content\\Models\\char_white.dan"; + modelData.modelPath = L"char_renderTest.dan"; modelData.id = 2; // load models obj = new C_Player(); @@ -116,17 +116,43 @@ bool GameState::LoadModels(std::wstring mapFile) // add player model 2 modelData.world = Oyster::Math3D::Float4x4::identity; - translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(10, 320, 0)); + translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(50, 320, 0)); modelData.world = modelData.world * translate; modelData.visible = true; - modelData.modelPath = L"..\\Content\\Models\\char_white.dan"; + modelData.modelPath = L"char_renderTest.dan"; modelData.id = 3; // load models obj = new C_Player(); privData->object.push_back(obj); privData->object[privData->object.size() -1 ]->Init(modelData); + // add house model + modelData.world = Oyster::Math3D::Float4x4::identity; + translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(50, 300, 0)); + //Oyster::Math3D::RotationMatrix_AxisZ() + modelData.world = modelData.world * translate; + modelData.visible = true; + modelData.modelPath = L"building_corporation.dan"; + modelData.id = 4; + // load models + obj = new C_Player(); + privData->object.push_back(obj); + privData->object[privData->object.size() -1 ]->Init(modelData); + + // add crystal model + modelData.world = Oyster::Math3D::Float4x4::identity; + translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(10, 305, 0)); + + modelData.world = modelData.world * translate; + modelData.visible = true; + modelData.modelPath = L"crystalformation_b.dan"; + modelData.id = 5; + // load models + obj = new C_Player(); + privData->object.push_back(obj); + privData->object[privData->object.size() -1 ]->Init(modelData); + return true; } @@ -282,14 +308,16 @@ void GameState::readKeyInput(InputClass* KeyInput) //send delta mouse movement if (KeyInput->IsMousePressed()) { - camera->Yaw(KeyInput->GetYaw()); + camera->Yaw(-KeyInput->GetYaw()); camera->Pitch(KeyInput->GetPitch()); camera->UpdateViewMatrix(); GameLogic::Protocol_PlayerLook playerLookDir; - Oyster::Math::Float3 look = camera->GetLook(); + Oyster::Math::Float4 look = camera->GetLook(); playerLookDir.lookDirX = look.x; playerLookDir.lookDirY = look.y; playerLookDir.lookDirZ = look.z; + playerLookDir.deltaX = -KeyInput->GetYaw(); + privData->nwClient->Send(playerLookDir); } @@ -357,11 +385,14 @@ void GameState::Protocol( ObjPos* pos ) { privData->object[i]->setPos(world); //camera->setRight((Oyster::Math::Float3(world[0], world[1], world[2]))); - //camera->setUp((Oyster::Math::Float3(world[4], world[5], world[6]))); + // //camera->setLook((Oyster::Math::Float3(world[8], world[9], world[10]))); if(i == myId) // playerobj { - camera->SetPosition(Oyster::Math::Float3(world[12], world[13]+2.2f, world[14]-1)); + Oyster::Math::Float3 up = (Oyster::Math::Float3(world[4], world[5]+2, world[6])); + Oyster::Math::Float3 pos = Oyster::Math::Float3(world[12], world[13]+2, world[14]); + Oyster::Math::Float3 cameraPos = up + pos; + camera->SetPosition(pos); camera->UpdateViewMatrix(); } } diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index 3ea76b61..55f3e4cf 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -39,7 +39,7 @@ namespace GameLogic Oyster::Math::Float4x4 GetOrientation() override; int GetID() const override; OBJECT_TYPE GetObjectType() const override; - void Rotate(const Oyster::Math3D::Float3 lookDir) override; + void Rotate(const Oyster::Math3D::Float4 lookDir) override; Player *player; }; diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index ee4bad83..f0ce50b1 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -79,7 +79,7 @@ namespace GameLogic * @param x: The relative x axis * @param y: The relative y axis **/ - virtual void Rotate(const Oyster::Math3D::Float3 lookDir) = 0; + virtual void Rotate(const Oyster::Math3D::Float4 lookDir) = 0; /******************************************************** * Uses the chosen players weapon based on input diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index e19af2f3..18d058d0 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -11,13 +11,18 @@ Game::PlayerData::PlayerData() sbDesc.size = Oyster::Math::Float3(4,7,4); sbDesc.mass = 70; sbDesc.restitutionCoeff = 0.5; + sbDesc.rotation = Oyster::Math3D::RotationMatrix_AxisY(Utility::Value::Radian(180)); //create rigid body Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release(); //create player with this rigid body this->player = new Player(rigidBody,Object::DefaultCollisionBefore, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER); this->player->GetRigidBody()->SetCustomTag(this); - + Oyster::Physics::ICustomBody::State state; + this->player->GetRigidBody()->GetState(state); + state.SetRotation(Oyster::Math::Float3(0, Oyster::Math::pi, 0)); + this->player->GetRigidBody()->SetState(state); + player->EndFrame(); } Game::PlayerData::PlayerData(int playerID,int teamID) { @@ -61,7 +66,7 @@ OBJECT_TYPE Game::PlayerData::GetObjectType() const { return this->player->GetObjectType(); } -void Game::PlayerData::Rotate(const Oyster::Math3D::Float3 lookDir) +void Game::PlayerData::Rotate(const Oyster::Math3D::Float4 lookDir) { this->player->Rotate(lookDir); } \ No newline at end of file diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index a0823247..8692aa72 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -22,8 +22,8 @@ Object::Object() this->type = OBJECT_TYPE::OBJECT_TYPE_UNKNOWN; this->objectID = GID(); - this->getState = this->rigidBody->GetState(); - this->setState = this->getState; + this->currPhysicsState = this->rigidBody->GetState(); + this->newPhysicsState = this->currPhysicsState; } Object::Object(OBJECT_TYPE type) @@ -34,8 +34,8 @@ Object::Object(OBJECT_TYPE type) Oyster::Physics::API::Instance().AddObject(rigidBody); this->type = type; this->objectID = GID(); - this->getState = this->rigidBody->GetState(); - this->setState = this->getState; + this->currPhysicsState = this->rigidBody->GetState(); + this->newPhysicsState = this->currPhysicsState; } Object::Object(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type) @@ -44,8 +44,8 @@ Object::Object(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type) this->rigidBody = rigidBody; this->type = type; this->objectID = GID(); - this->getState = this->rigidBody->GetState(); - this->setState = this->getState; + this->currPhysicsState = this->rigidBody->GetState(); + this->newPhysicsState = this->currPhysicsState; } Object::Object(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type) @@ -57,8 +57,8 @@ Object::Object(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE this->type = type; this->objectID = GID(); - this->getState = this->rigidBody->GetState(); - this->setState = this->getState; + this->currPhysicsState = this->rigidBody->GetState(); + this->newPhysicsState = this->currPhysicsState; } Object::Object(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type) @@ -71,8 +71,8 @@ Object::Object(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefor this->type = type; this->objectID = GID(); - this->getState = this->rigidBody->GetState(); - this->setState = this->getState; + this->currPhysicsState = this->rigidBody->GetState(); + this->newPhysicsState = this->currPhysicsState; } Object::Object(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) @@ -86,13 +86,13 @@ Object::Object(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustom this->type = type; this->objectID = GID(); - this->getState = this->rigidBody->GetState(); - this->setState = this->getState; + this->currPhysicsState = this->rigidBody->GetState(); + this->newPhysicsState = this->currPhysicsState; } void Object::ApplyLinearImpulse(Oyster::Math::Float3 force) { - setState.ApplyLinearImpulse(force); + newPhysicsState.ApplyLinearImpulse(force); } @@ -118,24 +118,28 @@ Oyster::Physics::ICustomBody* Object::GetRigidBody() void Object::BeginFrame() { + + this->rigidBody->SetState(this->newPhysicsState); + this->rigidBody->GetState(this->newPhysicsState); + Oyster::Math::Float4 axis; - if(setState.GetGravityNormal()!= Float3::null) + if(newPhysicsState.GetGravityNormal()!= Float3::null) { - Oyster::Math3D::SnapAngularAxis(Oyster::Math::Float4(setState.GetAngularAxis(), 0), Oyster::Math::Float4::standard_unit_y, -Oyster::Math::Float4(setState.GetGravityNormal()), axis); - setState.SetRotation(axis.xyz); - setState.SetAngularMomentum(Float3::null); + Oyster::Math3D::SnapAngularAxis(Oyster::Math::Float4(newPhysicsState.GetAngularAxis(), 0), Oyster::Math::Float4::standard_unit_y, -Oyster::Math::Float4(newPhysicsState.GetGravityNormal()), axis); + newPhysicsState.SetRotation(axis.xyz); + newPhysicsState.SetAngularMomentum(Float3::null); Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y); - debug += setState.GetGravityNormal(); + debug += newPhysicsState.GetGravityNormal(); } + - - this->rigidBody->SetState(this->setState); + this->rigidBody->SetState(this->newPhysicsState); } // update physic void Object::EndFrame() { - this->getState = this->rigidBody->GetState(); - this->setState = this->getState; + this->currPhysicsState = this->rigidBody->GetState(); + this->newPhysicsState = this->currPhysicsState; } void Object::setBeforeCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter)) diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index d3a3690f..07437661 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -49,11 +49,12 @@ namespace GameLogic protected: Oyster::Physics::ICustomBody *rigidBody; - Oyster::Physics::ICustomBody::State setState; - Oyster::Physics::ICustomBody::State getState; + Oyster::Physics::ICustomBody::State newPhysicsState; + Oyster::Physics::ICustomBody::State currPhysicsState; static const Game* gameInstance; - + Oyster::Math::Float3 currLook; + Oyster::Math::Float3 newLook; }; } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index ea36b284..1ab58d11 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -86,24 +86,28 @@ void Player::Move(const PLAYER_MOVEMENT &movement) void Player::MoveForward() { - setState.ApplyLinearImpulse(this->lookDir * (2000 * this->gameInstance->GetFrameTime())); + Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; + newPhysicsState.ApplyLinearImpulse(forward * (2000 * this->gameInstance->GetFrameTime())); } void Player::MoveBackwards() { - setState.ApplyLinearImpulse(-this->lookDir * 2000 * this->gameInstance->GetFrameTime()); + Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; + newPhysicsState.ApplyLinearImpulse(-forward * 2000 * this->gameInstance->GetFrameTime()); } void Player::MoveRight() { //Do cross product with forward vector and negative gravity vector - Oyster::Math::Float3 r = (-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); - setState.ApplyLinearImpulse(r * 2000 * this->gameInstance->GetFrameTime()); + Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; + Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward); + newPhysicsState.ApplyLinearImpulse(r * 2000 * this->gameInstance->GetFrameTime()); } void Player::MoveLeft() { //Do cross product with forward vector and negative gravity vector - Oyster::Math::Float3 r = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); //Still get zero - setState.ApplyLinearImpulse(-r * 2000 * this->gameInstance->GetFrameTime()); + Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; + Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward); //Still get zero + newPhysicsState.ApplyLinearImpulse(-r * 2000 * this->gameInstance->GetFrameTime()); } void Player::UseWeapon(const WEAPON_FIRE &usage) @@ -119,20 +123,31 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint) this->lookDir = Oyster::Math::Float4(1,0,0); } -void Player::Rotate(const Oyster::Math3D::Float3 lookDir) +void Player::Rotate(const Oyster::Math3D::Float4 lookDir) { - this->lookDir = lookDir; - - Oyster::Math::Float4 up = -setState.GetGravityNormal(); - Oyster::Math::Float4 pos = setState.GetCenterPosition(); - Oyster::Math::Float4x4 world = Oyster::Math3D::OrientationMatrix_LookAtDirection(lookDir, up.xyz, pos.xyz); + Oyster::Math::Float dx = lookDir.w; + //deltaLook = this->lookDir - lookDir; + + //Oyster::Math::Float4 up = -setState.GetGravityNormal(); + //Oyster::Math::Float4 pos = setState.GetCenterPosition(); + //Oyster::Math::Float4x4 world = Oyster::Math3D::OrientationMatrix_LookAtDirection(lookDir, up.xyz, pos.xyz); + // cant set rotation + //setState.AddRotation(); + + Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1]; + Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ; + //setState.SetOrientation(world); + newPhysicsState.AddRotation(deltaAxis); + //setState.SetOrientation() //this->lookDir = lookDir - up.xyz; //this->lookDir = lookDir; //this->setState.AddRotation(Oyster::Math::Float4(x, y)); //this->setState.SetRotation(); + + this->lookDir = lookDir.xyz; } void Player::Jump() @@ -155,11 +170,11 @@ bool Player::IsIdle() Oyster::Math::Float3 Player::GetPosition() const { - return (Oyster::Math::Float3)getState.GetCenterPosition(); + return (Oyster::Math::Float3)currPhysicsState.GetCenterPosition(); } Oyster::Math::Float4x4 Player::GetOrientation() const { - return this->getState.GetOrientation(); + return this->currPhysicsState.GetOrientation(); } Oyster::Math::Float3 Player::GetLookDir() const { diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 0df0d040..0dcb6043 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -48,7 +48,7 @@ namespace GameLogic void Respawn(Oyster::Math::Float3 spawnPoint); - void Rotate(const Oyster::Math3D::Float3 lookDir); + void Rotate(const Oyster::Math3D::Float4 lookDir); /******************************************************** * Collision function for player, this is to be sent to physics through the subscribe function with the rigidbody diff --git a/Code/Game/GameProtocols/PlayerProtocols.h b/Code/Game/GameProtocols/PlayerProtocols.h index 2413aa92..216dec73 100644 --- a/Code/Game/GameProtocols/PlayerProtocols.h +++ b/Code/Game/GameProtocols/PlayerProtocols.h @@ -69,6 +69,7 @@ namespace GameLogic float lookDirX; float lookDirY; float lookDirZ; + float deltaX; Protocol_PlayerLook() { @@ -78,6 +79,7 @@ namespace GameLogic this->protocol[1].type = Oyster::Network::NetAttributeType_Float; this->protocol[2].type = Oyster::Network::NetAttributeType_Float; this->protocol[3].type = Oyster::Network::NetAttributeType_Float; + this->protocol[4].type = Oyster::Network::NetAttributeType_Float; } Protocol_PlayerLook(Oyster::Network::CustomNetProtocol& p) @@ -85,12 +87,14 @@ namespace GameLogic lookDirX = p[1].value.netFloat; lookDirY = p[2].value.netFloat; lookDirZ = p[3].value.netFloat; + deltaX = p[4].value.netFloat; } const Protocol_PlayerLook& operator=(Oyster::Network::CustomNetProtocol& val) { lookDirX = val[1].value.netFloat; lookDirY = val[2].value.netFloat; lookDirZ = val[3].value.netFloat; + deltaX = val[4].value.netFloat; return *this; } @@ -99,6 +103,8 @@ namespace GameLogic this->protocol[1].value = lookDirX; this->protocol[2].value = lookDirY; this->protocol[3].value = lookDirZ; + this->protocol[4].value = deltaX; + return &protocol; } diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index 8235c903..826cfd7c 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -172,10 +172,11 @@ namespace DanBias } void GameSession::Gameplay_PlayerLookDir ( Protocol_PlayerLook& p, DanBias::GameClient* c ) { - Oyster::Math3D::Float3 lookDir; + Oyster::Math3D::Float4 lookDir; lookDir.x = p.lookDirX; lookDir.y = p.lookDirY; lookDir.z = p.lookDirZ; + lookDir.w = p.deltaX; c->GetPlayer()->Rotate(lookDir); } void GameSession::Gameplay_PlayerChangeWeapon ( Protocol_PlayerChangeWeapon& p, DanBias::GameClient* c ) From 7f29b62c6fd4214ecfd07ebb5ef6e693cce22ca7 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Mon, 3 Feb 2014 16:19:24 +0100 Subject: [PATCH 12/34] GL - YOU CAN NOW SHOOT STUFF YAAAAY --- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 27 ++++++++++++++----- .../Implementation/GameSession_Gameplay.cpp | 4 ++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index d5de9baa..babb4916 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -39,6 +39,12 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, ForcePush(usage,dt); break; case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS: + + if(hasObject) + { + ForcePush(usage,dt);//WARNING THIS IS A CRAP TEST TO MAKE SURE YOU CAN SHOOT BOXES + break; + } ForcePull(usage,dt); break; case WEAPON_FIRE::WEAPON_USE_UTILLITY_PRESS: @@ -56,8 +62,9 @@ void AttatchmentMassDriver::Update(float dt) { Oyster::Physics::ICustomBody::State state; state = heldObject->GetState(); - - Oyster::Math::Float3 pos = owner->GetPosition() + owner->GetLookDir().GetNormalized(); + Oyster::Math::Float3 ownerPos = owner->GetPosition(); + ownerPos.y += 2; + Oyster::Math::Float3 pos = ownerPos + owner->GetLookDir().GetNormalized()*2; state.SetCenterPosition(pos); @@ -76,11 +83,12 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float if(hasObject) { - pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (800 * dt); + Oyster::Physics::API::Instance().ReleaseFromLimbo(heldObject); + pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (2000); Oyster::Physics::ICustomBody::State state = heldObject->GetState(); state.ApplyLinearImpulse((Oyster::Math::Float3)pushForce); heldObject->SetState(state); - Oyster::Physics::API::Instance().ReleaseFromLimbo(heldObject); + hasObject = false; heldObject = NULL; return; @@ -134,9 +142,14 @@ void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage, float dt) void AttatchmentMassDriver::PickUpObject(const WEAPON_FIRE &usage, float dt) { - Oyster::Math::Float4 pos = owner->GetPosition() + owner->GetLookDir().GetNormalized(); - Oyster::Collision3D::Sphere hitSphere = Oyster::Collision3D::Sphere(pos,1); + //Oyster::Math::Float4 pos = owner->GetPosition() + owner->GetLookDir().GetNormalized(); + //Oyster::Collision3D::Sphere hitSphere = Oyster::Collision3D::Sphere(pos,2000); + Oyster::Math::Float4x4 aim = Oyster::Math3D::ViewMatrix_LookAtDirection(owner->GetLookDir(), owner->GetRigidBody()->GetGravityNormal(), owner->GetPosition()); - Oyster::Physics::API::Instance().ApplyEffect(hitSphere,this,AttemptPickUp); + Oyster::Math::Float4x4 hitSpace = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/4,1,1,20); + Oyster::Collision3D::Frustrum hitFrustum = Oyster::Collision3D::Frustrum(Oyster::Math3D::ViewProjectionMatrix(aim,hitSpace)); + + + Oyster::Physics::API::Instance().ApplyEffect(hitFrustum,this,AttemptPickUp); } diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index 8235c903..2b87e9cc 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -184,7 +184,9 @@ namespace DanBias } void GameSession::Gameplay_PlayerShot ( Protocol_PlayerShot& p, DanBias::GameClient* c ) { - c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS); + //c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS); + c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_SECONDARY_PRESS); + //c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS); } void GameSession::Gameplay_PlayerJump ( Protocol_PlayerJump& p, DanBias::GameClient* c ) { From ab962eea99671e0ca079ea286e3e6e9b94af99f1 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Mon, 3 Feb 2014 16:20:05 +0100 Subject: [PATCH 13/34] GL - added error check --- Code/Game/GameLogic/Game_PlayerData.cpp | 6 +++--- Code/Game/GameLogic/Object.cpp | 7 ++++++- Code/Game/GameLogic/Player.cpp | 18 ------------------ 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index 18d058d0..bfd352ae 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -11,18 +11,18 @@ Game::PlayerData::PlayerData() sbDesc.size = Oyster::Math::Float3(4,7,4); sbDesc.mass = 70; sbDesc.restitutionCoeff = 0.5; - sbDesc.rotation = Oyster::Math3D::RotationMatrix_AxisY(Utility::Value::Radian(180)); + sbDesc.rotation = Oyster::Math::Float3(0, Oyster::Math::pi, 0); //create rigid body Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release(); //create player with this rigid body this->player = new Player(rigidBody,Object::DefaultCollisionBefore, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER); this->player->GetRigidBody()->SetCustomTag(this); - Oyster::Physics::ICustomBody::State state; + /*Oyster::Physics::ICustomBody::State state; this->player->GetRigidBody()->GetState(state); state.SetRotation(Oyster::Math::Float3(0, Oyster::Math::pi, 0)); this->player->GetRigidBody()->SetState(state); - player->EndFrame(); + player->EndFrame();*/ } Game::PlayerData::PlayerData(int playerID,int teamID) { diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 8692aa72..e04e1b8f 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -126,13 +126,18 @@ void Object::BeginFrame() if(newPhysicsState.GetGravityNormal()!= Float3::null) { Oyster::Math3D::SnapAngularAxis(Oyster::Math::Float4(newPhysicsState.GetAngularAxis(), 0), Oyster::Math::Float4::standard_unit_y, -Oyster::Math::Float4(newPhysicsState.GetGravityNormal()), axis); + if(axis !=axis) + { + //error + int i =0 ; + } newPhysicsState.SetRotation(axis.xyz); newPhysicsState.SetAngularMomentum(Float3::null); Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y); debug += newPhysicsState.GetGravityNormal(); } - + this->rigidBody->SetState(this->newPhysicsState); } // update physic diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 1ab58d11..b891ac25 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -117,7 +117,6 @@ void Player::UseWeapon(const WEAPON_FIRE &usage) void Player::Respawn(Oyster::Math::Float3 spawnPoint) { - this->life = 100; this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; this->lookDir = Oyster::Math::Float4(1,0,0); @@ -126,26 +125,9 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint) void Player::Rotate(const Oyster::Math3D::Float4 lookDir) { Oyster::Math::Float dx = lookDir.w; - //deltaLook = this->lookDir - lookDir; - - //Oyster::Math::Float4 up = -setState.GetGravityNormal(); - //Oyster::Math::Float4 pos = setState.GetCenterPosition(); - //Oyster::Math::Float4x4 world = Oyster::Math3D::OrientationMatrix_LookAtDirection(lookDir, up.xyz, pos.xyz); - - // cant set rotation - //setState.AddRotation(); - Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1]; Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ; - - //setState.SetOrientation(world); newPhysicsState.AddRotation(deltaAxis); - //setState.SetOrientation() - //this->lookDir = lookDir - up.xyz; - //this->lookDir = lookDir; - - //this->setState.AddRotation(Oyster::Math::Float4(x, y)); - //this->setState.SetRotation(); this->lookDir = lookDir.xyz; } From 358cddfd9a159e41fc5a3a7e31e93bd99f39938a Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Mon, 3 Feb 2014 16:20:16 +0100 Subject: [PATCH 14/34] SnapAngularAxis fix floating point error there acos param could be slightly higher than 1. Caused it to return undefined. A clamp ought to fix it. --- Code/OysterMath/LinearMath.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/OysterMath/LinearMath.h b/Code/OysterMath/LinearMath.h index ebb1e375..9b21fc02 100644 --- a/Code/OysterMath/LinearMath.h +++ b/Code/OysterMath/LinearMath.h @@ -794,7 +794,7 @@ namespace LinearAlgebra3D { ::LinearAlgebra::Vector4 worldStartNormal( WorldAxisOf(Rotation(startAngularAxis.xyz), localStartNormal.xyz), (ScalarType)0 ); targetMem = ::LinearAlgebra::Vector4( worldStartNormal.xyz.Cross(worldEndNormal.xyz), (ScalarType)0); - targetMem *= (ScalarType)::std::acos( worldStartNormal.Dot(worldEndNormal) ); + targetMem *= (ScalarType)::std::acos( ::Utility::Value::Clamp(worldStartNormal.Dot(worldEndNormal), (ScalarType)0, (ScalarType)1) ); return targetMem += startAngularAxis; } From 2c3b1e50382dd5012e8ec1eb9b449dbb1ef5f239 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Mon, 3 Feb 2014 16:20:50 +0100 Subject: [PATCH 15/34] GL - using real dmg algorithm --- Code/Game/GameLogic/CollisionManager.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index d1e9a324..5c226362 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -11,7 +11,6 @@ using namespace Oyster; using namespace GameLogic; - void PlayerVBox(Player &player, DynamicObject &box, Oyster::Math::Float kineticEnergyLoss); void PlayerVObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss); //Physics::ICustomBody::SubscriptMessage @@ -29,7 +28,7 @@ using namespace GameLogic; break; case OBJECT_TYPE::OBJECT_TYPE_BOX: - PlayerVBox(*player,(*(DynamicObject*) realObj), kineticEnergyLoss); + PlayerVObject(*player,*realObj, kineticEnergyLoss); //return Physics::ICustomBody::SubscriptMessage_none; break; case OBJECT_TYPE::OBJECT_TYPE_PLAYER: @@ -42,13 +41,7 @@ using namespace GameLogic; //return Physics::ICustomBody::SubscriptMessage_none; } - - void PlayerVBox(Player &player, DynamicObject &box, Oyster::Math::Float kineticEnergyLoss) - { - //use kinetic energyloss of the collision in order too determin how much damage to take - //use as part of the damage algorithm - player.DamageLife(20); - } + void PlayerVObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss) { From 1f28c0598396b8c757fc7b495530fd8358f4c385 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Mon, 3 Feb 2014 16:30:47 +0100 Subject: [PATCH 16/34] GL - added jump --- Code/Game/GameLogic/Player.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index bc862553..235fab13 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -146,7 +146,8 @@ void Player::Rotate(const Oyster::Math3D::Float4 lookDir) void Player::Jump() { - + Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1]; + newPhysicsState.ApplyLinearImpulse(up * 2000 * this->gameInstance->GetFrameTime()); } bool Player::IsWalking() From d4bd72bb4a9210dd6349e31da11a072f6a7bcd1c Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 4 Feb 2014 08:55:57 +0100 Subject: [PATCH 17/34] Friction fix special case; no movement special case; movement directly into surface .. dealt with --- Code/GamePhysics/PhysicsFormula-Impl.h | 36 +++++++++++++++----------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/Code/GamePhysics/PhysicsFormula-Impl.h b/Code/GamePhysics/PhysicsFormula-Impl.h index 323fd732..189691f6 100644 --- a/Code/GamePhysics/PhysicsFormula-Impl.h +++ b/Code/GamePhysics/PhysicsFormula-Impl.h @@ -48,26 +48,32 @@ namespace Oyster { namespace Physics { namespace Formula // Relative momentum after normal impulse ::Oyster::Math::Float4 relativeMomentum = momB - momA; - ::Oyster::Math::Float4 tanFriction = relativeMomentum - relativeMomentum.Dot( iN )*iN; - tanFriction.Normalize(); + ::Oyster::Math::Float4 tanFriction = relativeMomentum - relativeMomentum.Dot( iN ) * iN; - ::Oyster::Math::Float magnitudeFriction = -relativeMomentum.Dot( tanFriction ); - magnitudeFriction = magnitudeFriction*mA*mB/( mA + mB ); + if( tanFriction.Dot(tanFriction) > 0.0f ) + { // no friction if moving directly into surface, or not at all. + tanFriction.Normalize(); - ::Oyster::Math::Float mu = 0.5f*( sFA + sFB ); + ::Oyster::Math::Float magnitudeFriction = -relativeMomentum.Dot( tanFriction ); + magnitudeFriction = magnitudeFriction * mA * mB / ( mA + mB ); + + ::Oyster::Math::Float mu = 0.5f * ( sFA + sFB ); - ::Oyster::Math::Float4 frictionImpulse; - if( abs(magnitudeFriction) < i*mu ) - { - frictionImpulse = magnitudeFriction*tanFriction; + ::Oyster::Math::Float4 frictionImpulse; + if( abs(magnitudeFriction) < i * mu ) + { + frictionImpulse = magnitudeFriction * tanFriction; + } + else + { + ::Oyster::Math::Float dynamicFriction = 0.5f * ( dFA + dFB ); + frictionImpulse = ( -i * dynamicFriction ) * tanFriction; + } + + return ( 1 / mA ) * frictionImpulse; } else - { - ::Oyster::Math::Float dynamicFriction = 0.5f*( dFA + dFB ); - frictionImpulse = -i*tanFriction*dynamicFriction; - } - - return ( 1 / mA )*frictionImpulse; + return ::Oyster::Math::Float4::null; } } From 9817f844efe289201ffb8772ea66f788e4e59596 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 4 Feb 2014 10:23:14 +0100 Subject: [PATCH 18/34] Rebound adjustment trial Rebound had a strong friction-like effect. Testing to see if it works better if applied before the leapfrog update --- Code/GamePhysics/Implementation/SimpleRigidBody.cpp | 6 +++--- Code/GamePhysics/Implementation/SphericalRigidBody.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp index d1be7d61..46abac8f 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -333,23 +333,23 @@ UpdateState SimpleRigidBody::Update( Float timeStepLength ) // this->isForwarded = false; //} - this->rigid.Update_LeapFrog( timeStepLength ); - { // Rebound if needed if( this->collisionRebound.timeOfContact < 1.0f ) { this->rigid.centerPos = Lerp( this->collisionRebound.previousSpatial.center, this->rigid.centerPos, this->collisionRebound.timeOfContact ); this->rigid.SetRotation( Lerp(this->collisionRebound.previousSpatial.axis, this->rigid.axis, this->collisionRebound.timeOfContact) ); this->rigid.boundingReach = Lerp( this->collisionRebound.previousSpatial.reach, this->rigid.boundingReach, this->collisionRebound.timeOfContact ); + this->collisionRebound.timeOfContact = 1.0f; } // Update rebound data this->collisionRebound.previousSpatial.center = this->rigid.centerPos; this->collisionRebound.previousSpatial.axis = this->rigid.axis; this->collisionRebound.previousSpatial.reach = this->rigid.boundingReach; - this->collisionRebound.timeOfContact = 1.0f; } + this->rigid.Update_LeapFrog( timeStepLength ); + { // Maintain rotation resolution by keeping axis within [0, 2pi] (trigonometric methods gets faster too) Float3 n; ::std::modf( this->rigid.axis * (0.5f / pi), n ); diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp index 49aed408..a3eecae2 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp @@ -254,23 +254,23 @@ UpdateState SphericalRigidBody::Update( Float timeStepLength ) // this->isForwarded = false; //} - this->rigid.Update_LeapFrog( timeStepLength ); - { // Rebound if needed if( this->collisionRebound.timeOfContact < 1.0f ) { this->rigid.centerPos = Lerp( this->collisionRebound.previousSpatial.center, this->rigid.centerPos, this->collisionRebound.timeOfContact ); this->rigid.SetRotation( Lerp(this->collisionRebound.previousSpatial.axis, this->rigid.axis, this->collisionRebound.timeOfContact) ); this->rigid.boundingReach = Lerp( this->collisionRebound.previousSpatial.reach, this->rigid.boundingReach, this->collisionRebound.timeOfContact ); + this->collisionRebound.timeOfContact = 1.0f; } // Update rebound data this->collisionRebound.previousSpatial.center = this->rigid.centerPos; this->collisionRebound.previousSpatial.axis = this->rigid.axis; this->collisionRebound.previousSpatial.reach = this->rigid.boundingReach; - this->collisionRebound.timeOfContact = 1.0f; } + this->rigid.Update_LeapFrog( timeStepLength ); + { // Maintain rotation resolution by keeping axis within [0, 2pi] (trigonometric methods gets faster too) Float3 n; ::std::modf( this->rigid.axis * (0.5f / pi), n ); From fcadd5b4c30cc698b6c2bcdb1298649fe435101a Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Tue, 4 Feb 2014 10:29:02 +0100 Subject: [PATCH 19/34] GL - testing physics --- Code/Game/DanBiasGame/DanBiasGame_Impl.cpp | 6 ++-- .../DanBiasGame/GameClientState/GameState.cpp | 6 ++-- Code/Game/GameLogic/Level.cpp | 5 ++-- Code/Game/GameLogic/Object.cpp | 8 +++--- Code/Game/GameLogic/Player.cpp | 28 +++++++++++-------- .../Implementation/GameSession_Gameplay.cpp | 2 +- Code/OysterPhysics3D/RigidBody.cpp | 4 +-- 7 files changed, 34 insertions(+), 25 deletions(-) diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index d0a435b2..83e48713 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -85,6 +85,9 @@ namespace DanBias float dt = (float)m_data->timer.getElapsedSeconds(); m_data->timer.reset(); + if(m_data->recieverObj->IsConnected()) + m_data->recieverObj->Update(); + capFrame += dt; if(capFrame > 0.03) { @@ -130,8 +133,7 @@ namespace DanBias HRESULT DanBiasGame::Update(float deltaTime) { - if(m_data->recieverObj->IsConnected()) - m_data->recieverObj->Update(); + m_data->inputObj->Update(); diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 638d954d..b1bc4881 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -378,7 +378,7 @@ void GameState::Protocol( ObjPos* pos ) { world[i] = pos->worldPos[i]; } - + //printf("pos for obj %d, ",pos->object_ID ); for (unsigned int i = 0; i < privData->object.size(); i++) { if(privData->object[i]->GetId() == pos->object_ID) @@ -389,10 +389,10 @@ void GameState::Protocol( ObjPos* pos ) //camera->setLook((Oyster::Math::Float3(world[8], world[9], world[10]))); if(i == myId) // playerobj { - Oyster::Math::Float3 up = (Oyster::Math::Float3(world[4], world[5]+2, world[6])); + Oyster::Math::Float3 up = (Oyster::Math::Float3(world[4], world[5], world[6])); Oyster::Math::Float3 pos = Oyster::Math::Float3(world[12], world[13]+2, world[14]); Oyster::Math::Float3 cameraPos = up + pos; - camera->SetPosition(pos); + camera->SetPosition(cameraPos); camera->UpdateViewMatrix(); } } diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index b070eb56..858818f6 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -27,7 +27,8 @@ void Level::InitiateLevel(float radius) sbDesc.ignoreGravity = true; sbDesc.radius = 300; sbDesc.mass = 10e12f; - + sbDesc.frictionCoeff_Static = 0; + sbDesc.frictionCoeff_Dynamic = 0; ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); ICustomBody::State state; @@ -61,7 +62,7 @@ void Level::InitiateLevel(float radius) // add gravitation API::Gravity gravityWell; gravityWell.gravityType = API::Gravity::GravityType_Well; - gravityWell.well.mass = 1e15f; + gravityWell.well.mass = 1e18f; gravityWell.well.position = Oyster::Math::Float4(0,0,0,1); API::Instance().AddGravity(gravityWell); } diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index e04e1b8f..b55ed661 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -118,9 +118,9 @@ Oyster::Physics::ICustomBody* Object::GetRigidBody() void Object::BeginFrame() { - - this->rigidBody->SetState(this->newPhysicsState); - this->rigidBody->GetState(this->newPhysicsState); + //newPhysicsState.SetAngularMomentum(Float3::null); + //this->rigidBody->SetState(this->newPhysicsState); + //this->rigidBody->GetState(this->newPhysicsState); Oyster::Math::Float4 axis; if(newPhysicsState.GetGravityNormal()!= Float3::null) @@ -131,7 +131,7 @@ void Object::BeginFrame() //error int i =0 ; } - newPhysicsState.SetRotation(axis.xyz); + //newPhysicsState.SetRotation(axis.xyz); newPhysicsState.SetAngularMomentum(Float3::null); Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y); debug += newPhysicsState.GetGravityNormal(); diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 235fab13..f205a516 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -98,28 +98,32 @@ void Player::Move(const PLAYER_MOVEMENT &movement) void Player::MoveForward() { - Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; - newPhysicsState.ApplyLinearImpulse(forward * (2000 * this->gameInstance->GetFrameTime())); + //Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; + Oyster::Math::Float3 forward = lookDir; + newPhysicsState.ApplyLinearImpulse(forward * (30000 * this->gameInstance->GetFrameTime())); } void Player::MoveBackwards() { - Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; - newPhysicsState.ApplyLinearImpulse(-forward * 2000 * this->gameInstance->GetFrameTime()); + //Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; + Oyster::Math::Float3 forward = lookDir; + newPhysicsState.ApplyLinearImpulse(-forward * 30000 * this->gameInstance->GetFrameTime()); } void Player::MoveRight() { //Do cross product with forward vector and negative gravity vector - Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; + //Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; + Oyster::Math::Float3 forward = lookDir; Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward); - newPhysicsState.ApplyLinearImpulse(r * 2000 * this->gameInstance->GetFrameTime()); + newPhysicsState.ApplyLinearImpulse(-r * 30000 * this->gameInstance->GetFrameTime()); } void Player::MoveLeft() { //Do cross product with forward vector and negative gravity vector - Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; + //Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; + Oyster::Math::Float3 forward = lookDir; Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward); //Still get zero - newPhysicsState.ApplyLinearImpulse(-r * 2000 * this->gameInstance->GetFrameTime()); + newPhysicsState.ApplyLinearImpulse(r * 30000 * this->gameInstance->GetFrameTime()); } void Player::UseWeapon(const WEAPON_FIRE &usage) @@ -138,8 +142,10 @@ void Player::Rotate(const Oyster::Math3D::Float4 lookDir) { Oyster::Math::Float dx = lookDir.w; Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1]; - Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ; - newPhysicsState.AddRotation(deltaAxis); + Oyster::Math::Float3 deltaAxis = up * (-dx * 0.2) ; + Oyster::Math::Float3 oldOrt = currPhysicsState.GetRotation(); + + //newPhysicsState.SetRotation(oldOrt + deltaAxis); this->lookDir = lookDir.xyz; } @@ -147,7 +153,7 @@ void Player::Rotate(const Oyster::Math3D::Float4 lookDir) void Player::Jump() { Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1]; - newPhysicsState.ApplyLinearImpulse(up * 2000 * this->gameInstance->GetFrameTime()); + newPhysicsState.ApplyLinearImpulse(up * 30000 * this->gameInstance->GetFrameTime()); } bool Player::IsWalking() diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index 4325f955..73ccba1a 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -106,7 +106,7 @@ namespace DanBias Oyster::Math::Float4x4 world =obj->GetOrientation(); Protocol_ObjectPosition p(world, id); - GameSession::gameSession->Send(*p.GetProtocol()); + //GameSession::gameSession->Send(*p.GetProtocol()); } } diff --git a/Code/OysterPhysics3D/RigidBody.cpp b/Code/OysterPhysics3D/RigidBody.cpp index 68f435e9..ca6dcdec 100644 --- a/Code/OysterPhysics3D/RigidBody.cpp +++ b/Code/OysterPhysics3D/RigidBody.cpp @@ -51,8 +51,8 @@ void RigidBody::Update_LeapFrog( Float updateFrameLength ) // updating the linear //Decrease momentum with 1% as "fall-off" //! HACK: @todo Add real solution with fluid drag - this->momentum_Linear = this->momentum_Linear*0.99f; - this->momentum_Angular = this->momentum_Angular*0.99f; + this->momentum_Linear = this->momentum_Linear*0.9999f; + this->momentum_Angular = this->momentum_Angular*0.9999f; // ds = dt * Formula::LinearVelocity( m, avg_G ) = dt * avg_G / m = (dt / m) * avg_G this->centerPos += ( updateFrameLength / this->mass ) * AverageWithDelta( this->momentum_Linear, this->impulse_Linear ); From 42cb1dab1dc935206bb62d36ed54db7417b8be2a Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 4 Feb 2014 10:32:43 +0100 Subject: [PATCH 20/34] API::SimpleBodyDescription API::SphericalBodyDescription fix 3 coeffs were not saved in factory constructor --- Code/GamePhysics/Implementation/SimpleRigidBody.cpp | 9 ++++++--- .../Implementation/SphericalRigidBody.cpp | 13 ++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp index 46abac8f..9c66e736 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -64,12 +64,15 @@ SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc ) { this->rigid = RigidBody(); this->rigid.SetRotation( desc.rotation ); - this->rigid.centerPos = desc.centerPosition; + this->rigid.centerPos = desc.centerPosition; this->rigid.SetSize( desc.size ); + this->rigid.restitutionCoeff = desc.restitutionCoeff; + this->rigid.frictionCoeff_Static = desc.frictionCoeff_Static; + this->rigid.frictionCoeff_Kinetic = desc.frictionCoeff_Dynamic; this->rigid.SetMass_KeepMomentum( desc.mass ); this->rigid.SetMomentOfInertia_KeepMomentum( desc.inertiaTensor ); - this->deltaPos = Float4::null; - this->deltaAxis = Float4::null; + this->deltaPos = Float4::null; + this->deltaAxis = Float4::null; this->gravityNormal = Float3::null; diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp index a3eecae2..448dbb4f 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp @@ -29,14 +29,17 @@ SphericalRigidBody::SphericalRigidBody() SphericalRigidBody::SphericalRigidBody( const API::SphericalBodyDescription &desc ) { - this->rigid = RigidBody(); + this->rigid = RigidBody(); this->rigid.SetRotation( desc.rotation ); - this->rigid.centerPos = desc.centerPosition; - this->rigid.boundingReach = Float4( desc.radius, desc.radius, desc.radius, 0.0f ); + this->rigid.centerPos = desc.centerPosition; + this->rigid.boundingReach = Float4( desc.radius, desc.radius, desc.radius, 0.0f ); + this->rigid.restitutionCoeff = desc.restitutionCoeff; + this->rigid.frictionCoeff_Static = desc.frictionCoeff_Static; + this->rigid.frictionCoeff_Kinetic = desc.frictionCoeff_Dynamic; this->rigid.SetMass_KeepMomentum( desc.mass ); this->rigid.SetMomentOfInertia_KeepMomentum( MomentOfInertia::Sphere(desc.mass, desc.radius) ); - this->deltaPos = Float4::null; - this->deltaAxis = Float4::null; + this->deltaPos = Float4::null; + this->deltaAxis = Float4::null; this->gravityNormal = Float3::null; From 00400a7d32bdb789761112f71b3654c94699e39b Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Tue, 4 Feb 2014 10:38:59 +0100 Subject: [PATCH 21/34] GL - camera testing --- Code/Game/DanBiasGame/GameClientState/GameState.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index b1bc4881..e57d004d 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -389,10 +389,12 @@ void GameState::Protocol( ObjPos* pos ) //camera->setLook((Oyster::Math::Float3(world[8], world[9], world[10]))); if(i == myId) // playerobj { - Oyster::Math::Float3 up = (Oyster::Math::Float3(world[4], world[5], world[6])); - Oyster::Math::Float3 pos = Oyster::Math::Float3(world[12], world[13]+2, world[14]); - Oyster::Math::Float3 cameraPos = up + pos; - camera->SetPosition(cameraPos); + camera->setRight((Oyster::Math::Float3(world[0], world[1], world[2]))); + camera->setUp(Oyster::Math::Float3(world[4], world[5], world[6])); + //camera->setLook((Oyster::Math::Float3(world[8], world[9], world[10]))); + Oyster::Math::Float3 pos = Oyster::Math::Float3(world[12], world[13]+2, world[14]+2); + //Oyster::Math::Float3 cameraPos = up + pos; + camera->SetPosition(pos); camera->UpdateViewMatrix(); } } From 3bf9f59f5a752311104a1c53c768b63457910661 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Tue, 4 Feb 2014 11:13:02 +0100 Subject: [PATCH 22/34] GL - Player dies and respawns --- Code/Game/GameLogic/CollisionManager.cpp | 2 +- Code/Game/GameLogic/Player.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 5c226362..37916799 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -35,7 +35,7 @@ using namespace GameLogic; //return Physics::ICustomBody::SubscriptMessage_none; break; case OBJECT_TYPE::OBJECT_TYPE_WORLD: - int test = 5; + PlayerVObject(*player,*realObj, kineticEnergyLoss); break; } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 235fab13..81c1b6d8 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -61,6 +61,7 @@ Player::~Player(void) void Player::BeginFrame() { weapon->Update(0.002f); + if(playerState == PLAYER_STATE_DEAD) Respawn(Oyster::Math::Float3(0,308,0)); Object::BeginFrame(); } @@ -132,6 +133,7 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint) this->life = 100; this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; this->lookDir = Oyster::Math::Float4(1,0,0); + this->setState.SetCenterPosition(spawnPoint); } void Player::Rotate(const Oyster::Math3D::Float4 lookDir) @@ -187,5 +189,13 @@ PLAYER_STATE Player::GetState() const void Player::DamageLife(int damage) { this->life -= damage; + this->life = 0; + + if(this->life <= 0) + { + this->life = 0; + playerState = PLAYER_STATE_DEAD; + //do stuff that makes you dead + } } From 1261ed734fd4547f614e6ffca42a0d22586311cc Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 4 Feb 2014 11:36:10 +0100 Subject: [PATCH 23/34] GL - Updated level loader. --- .../GameLogic/LevelLoader/LevelParser.cpp | 50 +++++++++++++++---- .../GameLogic/LevelLoader/ObjectDefines.h | 16 +++--- .../GameLogic/LevelLoader/ParseFunctions.cpp | 30 ++++++++++- .../GameLogic/LevelLoader/ParseFunctions.h | 1 + 4 files changed, 78 insertions(+), 19 deletions(-) diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp index 3a20f192..088c3916 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp @@ -30,13 +30,14 @@ std::vector> LevelParser::Parse(std::string filen //Read format version FormatVersion levelFormatVersion; - //ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion)); + ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion)); + counter += sizeof(levelFormatVersion); if(this->formatVersion != levelFormatVersion) { //Do something if it's not the same version } - while(counter < bufferSize) + while(counter < bufferSize) { //Get typeID ObjectTypeHeader typeID; @@ -55,9 +56,8 @@ std::vector> LevelParser::Parse(std::string filen case ObjectType_Static: case ObjectType_Dynamic: { ObjectHeader* header = new ObjectHeader; - ParseObject(&buffer[counter], header, sizeof(*header)); + ParseObject(&buffer[counter], *header, counter); objects.push_back(header); - counter += sizeof(*header); break; } @@ -124,7 +124,8 @@ LevelMetaData LevelParser::ParseHeader(std::string filename) //Read format version FormatVersion levelFormatVersion; - //ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion)); + ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion)); + counter += sizeof(levelFormatVersion); if(this->formatVersion != levelFormatVersion) { //Do something if it's not the same version @@ -142,11 +143,42 @@ LevelMetaData LevelParser::ParseHeader(std::string filename) ParseLevelMetaData(&buffer[counter], levelHeader, counter); return levelHeader; break; - case ObjectType_Dynamic: - //Do not call parse this object, since we are only interested in the LevelMetaData - //Only increase the counter size - counter += sizeof(ObjectHeader); + + //This is by design, static and dynamic is using the same converter. Do not add anything inbetween them. + case ObjectType_Static: case ObjectType_Dynamic: + { + ObjectHeader header; + ParseObject(&buffer[counter], header, counter); break; + } + + case ObjectType_Light: + { + LightType lightType; + ParseObject(&buffer[counter+4], &lightType, sizeof(lightType)); + + switch(lightType) + { + case LightType_PointLight: + { + counter += sizeof(PointLight); + break; + } + case LightType_DirectionalLight: + { + counter += sizeof(DirectionalLight); + break; + } + case LightType_SpotLight: + { + counter += sizeof(SpotLight); + break; + } + default: + //Undefined LightType. + break; + } + } default: //Couldn't find typeID. FAIL!!!!!! diff --git a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h index 21e3a7e3..553db824 100644 --- a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h +++ b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h @@ -28,6 +28,7 @@ namespace GameLogic UsePhysics_UseFullPhysics, UsePhysics_IgnoreGravity, UsePhysics_IgnorePhysics, + UsePhysics_IgnoreCollision, UsePhysics_Count, UsePhysics_Unknown = -1 @@ -82,12 +83,13 @@ namespace GameLogic struct PhysicsObject { + UsePhysics usePhysics; float mass; - float elasticity; + float inertiaMagnitude[3]; + float inertiaRotation[3]; float frictionCoeffStatic; float frictionCoeffDynamic; - float inertiaTensor[16]; - UsePhysics usePhysics; + }; struct LevelMetaData : ObjectTypeHeader @@ -97,17 +99,15 @@ namespace GameLogic std::string levelDescription; std::string levelAuthor; int maxNumberOfPlayer; - float worldSize; - int overviewPictureID; + int worldSize; + std::string overviewPicturePath; std::vector gameModesSupported; }; struct ObjectHeader : public ObjectTypeHeader { //Model, - int ModelID; - //Texture - int TextureID; + std::string ModelFile; //Position float position[3]; //Rotation diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp index f456b2d7..8d51f308 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp @@ -20,11 +20,33 @@ namespace GameLogic memcpy(header, buffer, size); } + void ParseObject(char* buffer, ObjectHeader& header, int& size) + { + char tempName[128]; + int tempSize = 0; + int start = 0; + + memcpy(&header.typeID, &buffer[start], 4); + start += 4; + + memcpy(&tempSize, &buffer[start], 4); + start += 4; + + memcpy(&tempName, &buffer[start], tempSize); + header.ModelFile.assign(&tempName[0], &tempName[tempSize]); + start += tempSize; + + memcpy(&header.position, &buffer[start], 36); + start += 36; + + size += start; + } + void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size) { int start = 0; int tempSize; - char tempName[100]; + char tempName[128]; memcpy(&header.typeID, &buffer[start], 4); start += 4; @@ -59,9 +81,13 @@ namespace GameLogic memcpy(&header.worldSize, &buffer[start], 4); start += 4; - memcpy(&header.overviewPictureID, &buffer[start], 4); + memcpy(&tempSize, &buffer[start], 4); start += 4; + memcpy(&tempName, &buffer[start], tempSize); + header.overviewPicturePath.assign(&tempName[0], &tempName[tempSize]); + start += tempSize; + memcpy(&tempSize, &buffer[start], 4); start += 4; diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h index 554b95db..f68a9289 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h @@ -19,6 +19,7 @@ namespace GameLogic */ void ParseObject(char* buffer, void *header, int size); + void ParseObject(char* buffer, ObjectHeader& header, int& size); void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size); } } From e39eb5fb4b91dd9380e698535d37b8a6ebcc3044 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 4 Feb 2014 11:48:50 +0100 Subject: [PATCH 24/34] RigidBody update adjusted Spherical and Simple --- .../Implementation/SimpleRigidBody.cpp | 52 ++++++++----------- .../Implementation/SphericalRigidBody.cpp | 51 ++++++++---------- 2 files changed, 46 insertions(+), 57 deletions(-) diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp index 9c66e736..034cedea 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -325,41 +325,30 @@ void * SimpleRigidBody::GetCustomTag() const // return this->rigid.GetLinearVelocity(); //} - UpdateState SimpleRigidBody::Update( Float timeStepLength ) { - //if( this->isForwarded ) - //{ - // this->rigid.Move( this->deltaPos.xyz, this->deltaAxis.xyz ); - // this->deltaPos = Float4::null; - // this->deltaAxis = Float4::null; - // this->isForwarded = false; - //} - + if( this->collisionRebound.timeOfContact < 1.0f ) { // Rebound if needed - if( this->collisionRebound.timeOfContact < 1.0f ) - { - this->rigid.centerPos = Lerp( this->collisionRebound.previousSpatial.center, this->rigid.centerPos, this->collisionRebound.timeOfContact ); - this->rigid.SetRotation( Lerp(this->collisionRebound.previousSpatial.axis, this->rigid.axis, this->collisionRebound.timeOfContact) ); - this->rigid.boundingReach = Lerp( this->collisionRebound.previousSpatial.reach, this->rigid.boundingReach, this->collisionRebound.timeOfContact ); - this->collisionRebound.timeOfContact = 1.0f; - } - - // Update rebound data - this->collisionRebound.previousSpatial.center = this->rigid.centerPos; - this->collisionRebound.previousSpatial.axis = this->rigid.axis; - this->collisionRebound.previousSpatial.reach = this->rigid.boundingReach; + this->rigid.centerPos = Lerp( this->collisionRebound.previousSpatial.center, this->rigid.centerPos, this->collisionRebound.timeOfContact ); + this->rigid.SetRotation( Lerp(this->collisionRebound.previousSpatial.axis, this->rigid.axis, this->collisionRebound.timeOfContact) ); + this->rigid.boundingReach = Lerp( this->collisionRebound.previousSpatial.reach, this->rigid.boundingReach, this->collisionRebound.timeOfContact ); + this->collisionRebound.timeOfContact = 1.0f; } - this->rigid.Update_LeapFrog( timeStepLength ); + // Maintain rotation resolution by keeping axis within [0, 2pi] (trigonometric methods gets faster too) + Float4 temp; + ::std::modf( this->rigid.axis * (0.5f / pi), temp.xyz ); + this->rigid.axis -= ((2.0f * pi) * temp).xyz; - { // Maintain rotation resolution by keeping axis within [0, 2pi] (trigonometric methods gets faster too) - Float3 n; - ::std::modf( this->rigid.axis * (0.5f / pi), n ); - this->rigid.axis -= (2.0f * pi) * n; - } + // Update rebound data + this->collisionRebound.previousSpatial.center = this->rigid.centerPos; + this->collisionRebound.previousSpatial.axis = this->rigid.axis; + this->collisionRebound.previousSpatial.reach = this->rigid.boundingReach; - { // Check if this is close enough to be set resting + // Check if this is close enough to be set resting + temp = Float4( this->rigid.impulse_Linear, 0.0f ) + Float4( this->rigid.impulse_Angular, 0.0f ); + if( temp.Dot(temp) <= (Constant::epsilon * Constant::epsilon) ) + { unsigned char resting = 0; if( this->rigid.momentum_Linear.Dot(this->rigid.momentum_Linear) <= (Constant::epsilon * Constant::epsilon) ) { @@ -371,9 +360,14 @@ UpdateState SimpleRigidBody::Update( Float timeStepLength ) this->rigid.momentum_Angular = Float3::null; ++resting; } - if( resting == 2 ) return UpdateState_resting; + if( resting == 2 ) + { + this->rigid.impulse_Linear = this->rigid.impulse_Angular = Float3::null; + return UpdateState_resting; + } } + this->rigid.Update_LeapFrog( timeStepLength ); return UpdateState_altered; } diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp index 448dbb4f..6b4cd4ed 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp @@ -249,38 +249,28 @@ void * SphericalRigidBody::GetCustomTag() const UpdateState SphericalRigidBody::Update( Float timeStepLength ) { - //if( this->isForwarded ) - //{ - // this->rigid.Move( this->deltaPos.xyz, this->deltaAxis.xyz ); - // this->deltaPos = Float4::null; - // this->deltaAxis = Float4::null; - // this->isForwarded = false; - //} - + if( this->collisionRebound.timeOfContact < 1.0f ) { // Rebound if needed - if( this->collisionRebound.timeOfContact < 1.0f ) - { - this->rigid.centerPos = Lerp( this->collisionRebound.previousSpatial.center, this->rigid.centerPos, this->collisionRebound.timeOfContact ); - this->rigid.SetRotation( Lerp(this->collisionRebound.previousSpatial.axis, this->rigid.axis, this->collisionRebound.timeOfContact) ); - this->rigid.boundingReach = Lerp( this->collisionRebound.previousSpatial.reach, this->rigid.boundingReach, this->collisionRebound.timeOfContact ); - this->collisionRebound.timeOfContact = 1.0f; - } - - // Update rebound data - this->collisionRebound.previousSpatial.center = this->rigid.centerPos; - this->collisionRebound.previousSpatial.axis = this->rigid.axis; - this->collisionRebound.previousSpatial.reach = this->rigid.boundingReach; + this->rigid.centerPos = Lerp( this->collisionRebound.previousSpatial.center, this->rigid.centerPos, this->collisionRebound.timeOfContact ); + this->rigid.SetRotation( Lerp(this->collisionRebound.previousSpatial.axis, this->rigid.axis, this->collisionRebound.timeOfContact) ); + this->rigid.boundingReach = Lerp( this->collisionRebound.previousSpatial.reach, this->rigid.boundingReach, this->collisionRebound.timeOfContact ); + this->collisionRebound.timeOfContact = 1.0f; } - this->rigid.Update_LeapFrog( timeStepLength ); + // Maintain rotation resolution by keeping axis within [0, 2pi] (trigonometric methods gets faster too) + Float4 temp; + ::std::modf( this->rigid.axis * (0.5f / pi), temp.xyz ); + this->rigid.axis -= ((2.0f * pi) * temp).xyz; - { // Maintain rotation resolution by keeping axis within [0, 2pi] (trigonometric methods gets faster too) - Float3 n; - ::std::modf( this->rigid.axis * (0.5f / pi), n ); - this->rigid.axis -= (2.0f * pi) * n; - } + // Update rebound data + this->collisionRebound.previousSpatial.center = this->rigid.centerPos; + this->collisionRebound.previousSpatial.axis = this->rigid.axis; + this->collisionRebound.previousSpatial.reach = this->rigid.boundingReach; - { // Check if this is close enough to be set resting + // Check if this is close enough to be set resting + temp = Float4( this->rigid.impulse_Linear, 0.0f ) + Float4( this->rigid.impulse_Angular, 0.0f ); + if( temp.Dot(temp) <= (Constant::epsilon * Constant::epsilon) ) + { unsigned char resting = 0; if( this->rigid.momentum_Linear.Dot(this->rigid.momentum_Linear) <= (Constant::epsilon * Constant::epsilon) ) { @@ -292,9 +282,14 @@ UpdateState SphericalRigidBody::Update( Float timeStepLength ) this->rigid.momentum_Angular = Float3::null; ++resting; } - if( resting == 2 ) return UpdateState_resting; + if( resting == 2 ) + { + this->rigid.impulse_Linear = this->rigid.impulse_Angular = Float3::null; + return UpdateState_resting; + } } + this->rigid.Update_LeapFrog( timeStepLength ); return UpdateState_altered; } From d54cffee8e0c785daedb0bc6457f71e52db5a3b4 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Tue, 4 Feb 2014 11:50:15 +0100 Subject: [PATCH 25/34] GL - camera follows player --- .../DanBiasGame/GameClientState/GameState.cpp | 24 +++++++++---- .../DanBiasGame/GameClientState/GameState.h | 1 + Code/Game/GameLogic/Object.cpp | 34 +++++++++---------- Code/Game/GameLogic/Player.cpp | 24 +++++++------ 4 files changed, 50 insertions(+), 33 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index e57d004d..3e058619 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -43,7 +43,7 @@ bool GameState::Init(Oyster::Network::NetworkClient* nwClient) privData->state = gameStateState_loading; privData->nwClient = nwClient; privData->state = LoadGame(); - + pitch = 0; return true; } GameState::gameStateState GameState::LoadGame() @@ -309,7 +309,8 @@ void GameState::readKeyInput(InputClass* KeyInput) if (KeyInput->IsMousePressed()) { camera->Yaw(-KeyInput->GetYaw()); - camera->Pitch(KeyInput->GetPitch()); + //camera->Pitch(KeyInput->GetPitch()); + //pitch = KeyInput->GetPitch(); camera->UpdateViewMatrix(); GameLogic::Protocol_PlayerLook playerLookDir; Oyster::Math::Float4 look = camera->GetLook(); @@ -391,10 +392,21 @@ void GameState::Protocol( ObjPos* pos ) { camera->setRight((Oyster::Math::Float3(world[0], world[1], world[2]))); camera->setUp(Oyster::Math::Float3(world[4], world[5], world[6])); - //camera->setLook((Oyster::Math::Float3(world[8], world[9], world[10]))); - Oyster::Math::Float3 pos = Oyster::Math::Float3(world[12], world[13]+2, world[14]+2); - //Oyster::Math::Float3 cameraPos = up + pos; - camera->SetPosition(pos); + Oyster::Math::Float3 cameraLook = camera->GetLook(); + Oyster::Math::Float3 objForward = (Oyster::Math::Float3(world[8], world[9], world[10])); + + camera->setLook(objForward); + camera->UpdateViewMatrix(); + Oyster::Math::Float3 pos = Oyster::Math::Float3(world[12], world[13], world[14]); + Oyster::Math::Float3 up = Oyster::Math::Float3(world[4], world[5], world[6]); + + up *= 2; + objForward *= -3; + Oyster::Math::Float3 cameraPos = up + pos + objForward; + //camera->Pitch(pitch); + camera->SetPosition(cameraPos); + //camera->LookAt(pos, dir, up); + //Oyster::Math::Float3 newLook = objForward; camera->UpdateViewMatrix(); } } diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.h b/Code/Game/DanBiasGame/GameClientState/GameState.h index 04d5b791..d555134c 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.h +++ b/Code/Game/DanBiasGame/GameClientState/GameState.h @@ -27,6 +27,7 @@ private: Camera* camera; int myId; + float pitch; struct myData; myData* privData; public: diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index b55ed661..a000eaed 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -118,24 +118,9 @@ Oyster::Physics::ICustomBody* Object::GetRigidBody() void Object::BeginFrame() { - //newPhysicsState.SetAngularMomentum(Float3::null); - //this->rigidBody->SetState(this->newPhysicsState); - //this->rigidBody->GetState(this->newPhysicsState); - Oyster::Math::Float4 axis; - if(newPhysicsState.GetGravityNormal()!= Float3::null) - { - Oyster::Math3D::SnapAngularAxis(Oyster::Math::Float4(newPhysicsState.GetAngularAxis(), 0), Oyster::Math::Float4::standard_unit_y, -Oyster::Math::Float4(newPhysicsState.GetGravityNormal()), axis); - if(axis !=axis) - { - //error - int i =0 ; - } - //newPhysicsState.SetRotation(axis.xyz); - newPhysicsState.SetAngularMomentum(Float3::null); - Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y); - debug += newPhysicsState.GetGravityNormal(); - } + + this->rigidBody->SetState(this->newPhysicsState); @@ -144,6 +129,21 @@ void Object::BeginFrame() void Object::EndFrame() { this->currPhysicsState = this->rigidBody->GetState(); + + if(currPhysicsState.GetGravityNormal()!= Float3::null) + { + Oyster::Math::Float4 axis; + Oyster::Math3D::SnapAngularAxis(Oyster::Math::Float4(currPhysicsState.GetAngularAxis(), 0), Oyster::Math::Float4::standard_unit_y, -Oyster::Math::Float4(currPhysicsState.GetGravityNormal()), axis); + if(axis !=axis) + { + //error + int i =0 ; + } + currPhysicsState.SetRotation(axis.xyz); + currPhysicsState.SetAngularMomentum(Float3::null); + Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y); + debug += currPhysicsState.GetGravityNormal(); + } this->newPhysicsState = this->currPhysicsState; } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index f205a516..2ca1cc2d 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -98,21 +98,21 @@ void Player::Move(const PLAYER_MOVEMENT &movement) void Player::MoveForward() { - //Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; - Oyster::Math::Float3 forward = lookDir; + Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; + //Oyster::Math::Float3 forward = lookDir; newPhysicsState.ApplyLinearImpulse(forward * (30000 * this->gameInstance->GetFrameTime())); } void Player::MoveBackwards() { - //Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; - Oyster::Math::Float3 forward = lookDir; + Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; + //Oyster::Math::Float3 forward = lookDir; newPhysicsState.ApplyLinearImpulse(-forward * 30000 * this->gameInstance->GetFrameTime()); } void Player::MoveRight() { //Do cross product with forward vector and negative gravity vector - //Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; - Oyster::Math::Float3 forward = lookDir; + Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; + //Oyster::Math::Float3 forward = lookDir; Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward); newPhysicsState.ApplyLinearImpulse(-r * 30000 * this->gameInstance->GetFrameTime()); @@ -120,8 +120,8 @@ void Player::MoveRight() void Player::MoveLeft() { //Do cross product with forward vector and negative gravity vector - //Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; - Oyster::Math::Float3 forward = lookDir; + Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; + //Oyster::Math::Float3 forward = lookDir; Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward); //Still get zero newPhysicsState.ApplyLinearImpulse(r * 30000 * this->gameInstance->GetFrameTime()); } @@ -141,11 +141,15 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint) void Player::Rotate(const Oyster::Math3D::Float4 lookDir) { Oyster::Math::Float dx = lookDir.w; + if(dx > 0.0f) + { + int i =0 ; + } Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1]; - Oyster::Math::Float3 deltaAxis = up * (-dx * 0.2) ; + Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ; Oyster::Math::Float3 oldOrt = currPhysicsState.GetRotation(); - //newPhysicsState.SetRotation(oldOrt + deltaAxis); + newPhysicsState.SetRotation(oldOrt + deltaAxis); this->lookDir = lookDir.xyz; } From e859df65d39136a6abe507a0722a17c11857983d Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Tue, 4 Feb 2014 11:51:31 +0100 Subject: [PATCH 26/34] GL - compiles --- Code/Game/GameLogic/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 81c1b6d8..5b18dabf 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -133,7 +133,7 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint) this->life = 100; this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; this->lookDir = Oyster::Math::Float4(1,0,0); - this->setState.SetCenterPosition(spawnPoint); + this->newPhysicsState.SetCenterPosition(spawnPoint); } void Player::Rotate(const Oyster::Math3D::Float4 lookDir) From f88e16c5810838e76078ec16b109fdd4d9a1eecf Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Tue, 4 Feb 2014 11:53:40 +0100 Subject: [PATCH 27/34] GL - merge --- Code/Game/GameLogic/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 6d6d8bf7..ccd3e8f4 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -137,7 +137,7 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint) this->life = 100; this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; this->lookDir = Oyster::Math::Float4(1,0,0); - this->setState.SetCenterPosition(spawnPoint); + this->newPhysicsState.SetCenterPosition(spawnPoint); } void Player::Rotate(const Oyster::Math3D::Float4 lookDir) From 54deef7f2b6092b77096936de8ecdeeafea27ccf Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 4 Feb 2014 12:16:06 +0100 Subject: [PATCH 28/34] Project file fixes for GL --- Code/Game/DanBiasLauncher/DanBiasLauncher.vcxproj | 5 +++++ Code/Game/GameLogic/Player.cpp | 2 +- Code/Game/GameServer/GameServer.vcxproj | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Code/Game/DanBiasLauncher/DanBiasLauncher.vcxproj b/Code/Game/DanBiasLauncher/DanBiasLauncher.vcxproj index 5e543af9..fec9d7dd 100644 --- a/Code/Game/DanBiasLauncher/DanBiasLauncher.vcxproj +++ b/Code/Game/DanBiasLauncher/DanBiasLauncher.vcxproj @@ -173,6 +173,11 @@ + + + {2a1bc987-af42-4500-802d-89cd32fc1309} + + diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index ccd3e8f4..6d6d8bf7 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -137,7 +137,7 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint) this->life = 100; this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; this->lookDir = Oyster::Math::Float4(1,0,0); - this->newPhysicsState.SetCenterPosition(spawnPoint); + this->setState.SetCenterPosition(spawnPoint); } void Player::Rotate(const Oyster::Math3D::Float4 lookDir) diff --git a/Code/Game/GameServer/GameServer.vcxproj b/Code/Game/GameServer/GameServer.vcxproj index 6c0f3ea9..23bf0eb0 100644 --- a/Code/Game/GameServer/GameServer.vcxproj +++ b/Code/Game/GameServer/GameServer.vcxproj @@ -200,6 +200,9 @@ {f10cbc03-9809-4cba-95d8-327c287b18ee} + + {b1195bb9-b3a5-47f0-906c-8dea384d1520} + From 9efa4fcb23db82779d0cd0d9c5fa3c74aa02e31f Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 4 Feb 2014 13:08:03 +0100 Subject: [PATCH 29/34] Commit error fix for some odd reason Player.cpp change followed the last one --- Code/Game/GameLogic/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 6d6d8bf7..ccd3e8f4 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -137,7 +137,7 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint) this->life = 100; this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; this->lookDir = Oyster::Math::Float4(1,0,0); - this->setState.SetCenterPosition(spawnPoint); + this->newPhysicsState.SetCenterPosition(spawnPoint); } void Player::Rotate(const Oyster::Math3D::Float4 lookDir) From bd9e4599cbf4a2a933b59d9b818f7e52567673e9 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Tue, 4 Feb 2014 13:58:37 +0100 Subject: [PATCH 30/34] GL - fixed respawning and also fixed weapon --- .../DanBiasGame/GameClientState/GameState.cpp | 2 +- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 19 +++++++++++-------- Code/Game/GameLogic/CollisionManager.cpp | 2 +- Code/OysterPhysics3D/Frustrum.cpp | 12 ++++++------ 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 3e058619..ad86797f 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -132,7 +132,7 @@ bool GameState::LoadModels(std::wstring mapFile) translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(50, 300, 0)); //Oyster::Math3D::RotationMatrix_AxisZ() modelData.world = modelData.world * translate; - modelData.visible = true; + modelData.visible = false; modelData.modelPath = L"building_corporation.dan"; modelData.id = 4; // load models diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index babb4916..1d8e06a4 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -93,11 +93,14 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float heldObject = NULL; return; } + Oyster::Math::Float3 up = owner->GetOrientation().v[1]; + Oyster::Math::Float3 look = owner->GetLookDir(); + Oyster::Math::Float3 pos = owner->GetPosition(); - pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (500 * dt); - Oyster::Math::Float4x4 aim = Oyster::Math3D::ViewMatrix_LookAtDirection(owner->GetLookDir(), owner->GetRigidBody()->GetGravityNormal(), owner->GetPosition()); + pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (50000 * dt); + Oyster::Math::Float4x4 aim = Oyster::Math3D::ViewMatrix_LookAtDirection(look, up, pos); - Oyster::Math::Float4x4 hitSpace = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/4,1,1,20); + Oyster::Math::Float4x4 hitSpace = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/8,1,1,5); Oyster::Collision3D::Frustrum hitFrustum = Oyster::Collision3D::Frustrum(Oyster::Math3D::ViewProjectionMatrix(aim,hitSpace)); forcePushData args; args.pushForce = pushForce; @@ -142,14 +145,14 @@ void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage, float dt) void AttatchmentMassDriver::PickUpObject(const WEAPON_FIRE &usage, float dt) { - //Oyster::Math::Float4 pos = owner->GetPosition() + owner->GetLookDir().GetNormalized(); - //Oyster::Collision3D::Sphere hitSphere = Oyster::Collision3D::Sphere(pos,2000); - Oyster::Math::Float4x4 aim = Oyster::Math3D::ViewMatrix_LookAtDirection(owner->GetLookDir(), owner->GetRigidBody()->GetGravityNormal(), owner->GetPosition()); + Oyster::Math::Float3 pos = owner->GetPosition() + owner->GetLookDir().GetNormalized()*5; + Oyster::Collision3D::Sphere hitSphere = Oyster::Collision3D::Sphere(pos,20); + /*Oyster::Math::Float4x4 aim = Oyster::Math3D::ViewMatrix_LookAtDirection(owner->GetLookDir(), owner->GetRigidBody()->GetGravityNormal(), owner->GetPosition()); Oyster::Math::Float4x4 hitSpace = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/4,1,1,20); Oyster::Collision3D::Frustrum hitFrustum = Oyster::Collision3D::Frustrum(Oyster::Math3D::ViewProjectionMatrix(aim,hitSpace)); +*/ - - Oyster::Physics::API::Instance().ApplyEffect(hitFrustum,this,AttemptPickUp); + Oyster::Physics::API::Instance().ApplyEffect(hitSphere,this,AttemptPickUp); } diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 37916799..d5311ece 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -49,7 +49,7 @@ using namespace GameLogic; //use kinetic energyloss of the collision in order too determin how much damage to take //use as part of the damage algorithm int damageDone = 0; - int forceThreashHold = 200; + int forceThreashHold = 200000; if(kineticEnergyLoss > forceThreashHold) //should only take damage if the force is high enough { diff --git a/Code/OysterPhysics3D/Frustrum.cpp b/Code/OysterPhysics3D/Frustrum.cpp index 32e6357b..ea7a49d2 100644 --- a/Code/OysterPhysics3D/Frustrum.cpp +++ b/Code/OysterPhysics3D/Frustrum.cpp @@ -15,37 +15,37 @@ namespace PrivateStatic Float4x4 m = vp.GetTranspose(); // left - lp.normal = m.v[3].xyz + m.v[0].xyz; + lp.normal = Float4(m.v[3].xyz + m.v[0].xyz,0); lp.phasing = lp.normal.GetMagnitude(); lp.normal /= lp.phasing; lp.phasing = (m.v[3].w + m.v[0].w) / lp.phasing; // right - rp.normal = m.v[3].xyz - m.v[0].xyz; + rp.normal = Float4(m.v[3].xyz - m.v[0].xyz,0); rp.phasing = rp.normal.GetMagnitude(); rp.normal /= rp.phasing; rp.phasing = (m.v[3].w - m.v[0].w) / rp.phasing; // bottom - bp.normal = m.v[3].xyz + m.v[1].xyz; + bp.normal = Float4(m.v[3].xyz + m.v[1].xyz,0); bp.phasing = bp.normal.GetMagnitude(); bp.normal /= bp.phasing; bp.phasing = (m.v[3].w + m.v[1].w) / bp.phasing; // top - tp.normal = m.v[3].xyz - m.v[1].xyz; + tp.normal = Float4(m.v[3].xyz - m.v[1].xyz,0); tp.phasing = tp.normal.GetMagnitude(); tp.normal /= tp.phasing; tp.phasing = (m.v[3].w - m.v[1].w) / tp.phasing; // near leftHanded DirectX - np.normal = m.v[2].xyz; + np.normal = Float4(m.v[2].xyz,0); np.phasing = np.normal.GetMagnitude(); np.normal /= np.phasing; np.phasing = m.v[2].w / np.phasing; // far lefthanded - fp.normal = m.v[3].xyz - m.v[2].xyz; + fp.normal = Float4(m.v[3].xyz - m.v[2].xyz,0); fp.phasing = fp.normal.GetMagnitude(); fp.normal /= fp.phasing; fp.phasing = (m.v[3].w - m.v[2].w) / fp.phasing; From 15798bfca9bf61b53461b3ffc56ec495d4ab1bfe Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 4 Feb 2014 14:00:33 +0100 Subject: [PATCH 31/34] minor bug found and fixed in rebound --- Code/OysterPhysics3D/OysterCollision3D.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Code/OysterPhysics3D/OysterCollision3D.cpp b/Code/OysterPhysics3D/OysterCollision3D.cpp index cc68d536..41e11875 100644 --- a/Code/OysterPhysics3D/OysterCollision3D.cpp +++ b/Code/OysterPhysics3D/OysterCollision3D.cpp @@ -1064,38 +1064,42 @@ namespace Oyster { namespace Collision3D { namespace Utility Float TimeOfContact( const Sphere &protoStart, const Sphere &protoEnd, const Point &deuter ) { // Bisection with 5 levels of detail - Float t = 0.5f; + Float t = 0.5f, + d = 0.25f; Sphere s; for( int i = 0; i < 5; ++i ) { Nlerp( protoStart, protoEnd, t, s ); if( Intersect(s, deuter) ) { - t *= 0.5f; + t -= d; } else { - t *= 1.5f; + t += d; } + d *= 0.5f; } return t; } Float TimeOfContact( const Box &protoStart, const Box &protoEnd, const Point &deuter ) { // Bisection with 5 levels of detail - Float t = 0.5f; + Float t = 0.5f, + d = 0.25f; Box b; for( int i = 0; i < 5; ++i ) { Nlerp( protoStart, protoEnd, t, b ); if( Intersect(b, deuter) ) { - t *= 0.5f; + t -= d; } else { - t *= 1.5f; + t += d; } + d *= 0.5f; } return t; } From 502d0c85861b0ca6693790607fbe4a5e95e44139 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Tue, 4 Feb 2014 14:07:02 +0100 Subject: [PATCH 32/34] GL - actually fixed respawning(turned off) --- Code/Game/GameLogic/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index ccd3e8f4..29fc77cb 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -61,7 +61,7 @@ Player::~Player(void) void Player::BeginFrame() { weapon->Update(0.002f); - if(playerState == PLAYER_STATE_DEAD) Respawn(Oyster::Math::Float3(0,308,0)); + //if(playerState == PLAYER_STATE_DEAD) Respawn(Oyster::Math::Float3(0,308,0)); Object::BeginFrame(); } From 8834f6a2ec17e90a34ac3925e8ca7782680d54f3 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 4 Feb 2014 14:30:45 +0100 Subject: [PATCH 33/34] GL - LevelLoader update. --- Code/Game/GameLogic/LevelLoader/ObjectDefines.h | 2 +- Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h index 553db824..7c924976 100644 --- a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h +++ b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h @@ -95,7 +95,7 @@ namespace GameLogic struct LevelMetaData : ObjectTypeHeader { std::string levelName; - FormatVersion levelVersion; + int levelVersion; std::string levelDescription; std::string levelAuthor; int maxNumberOfPlayer; diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp index 8d51f308..68631bf0 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp @@ -58,8 +58,8 @@ namespace GameLogic header.levelName.assign(&tempName[0], &tempName[tempSize]); start += tempSize; - memcpy(&header.levelVersion, &buffer[start], 8); - start += 8; + memcpy(&header.levelVersion, &buffer[start], 4); + start += 4; memcpy(&tempSize, &buffer[start], 4); start +=4; From 4ad86ae83b89e7aa69d01852d79e5aca5444bc5c Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Tue, 4 Feb 2014 16:24:37 +0100 Subject: [PATCH 34/34] GL - Added jumppad(implemented but not tested) --- Code/Game/GameLogic/CollisionManager.cpp | 30 ++++++++++++++++++++++++ Code/Game/GameLogic/Game.cpp | 6 ++--- Code/Game/GameLogic/Game.h | 4 +--- Code/Game/GameLogic/GameLogic.vcxproj | 2 ++ Code/Game/GameLogic/JumpPad.cpp | 21 +++++++++++++++++ Code/Game/GameLogic/JumpPad.h | 26 ++++++++++++++++++++ Code/Game/GameLogic/Player.cpp | 5 ++-- 7 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 Code/Game/GameLogic/JumpPad.cpp create mode 100644 Code/Game/GameLogic/JumpPad.h diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index d5311ece..24bb6bba 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -6,12 +6,14 @@ #include "AttatchmentMassDriver.h" #include "Game.h" #include "CollisionManager.h" +#include "JumpPad.h" using namespace Oyster; using namespace GameLogic; void PlayerVObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss); + void SendObjectFlying(Oyster::Physics::ICustomBody &obj, Oyster::Math::Float3 force); //Physics::ICustomBody::SubscriptMessage void Player::PlayerCollision(Oyster::Physics::ICustomBody *rigidBodyPlayer, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) @@ -41,6 +43,34 @@ using namespace GameLogic; //return Physics::ICustomBody::SubscriptMessage_none; } + + void JumpPad::JumpPadActivated(Oyster::Physics::ICustomBody *rigidBodyJumpPad, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) + { + JumpPad *jumpPad = (JumpPad*)(rigidBodyJumpPad->GetCustomTag()); + Object *realObj = (Object*)obj->GetCustomTag(); //needs to be changed? + + switch (realObj->GetObjectType()) + { + case OBJECT_TYPE::OBJECT_TYPE_GENERIC: + break; + case OBJECT_TYPE::OBJECT_TYPE_BOX: + break; + case OBJECT_TYPE::OBJECT_TYPE_PLAYER: + SendObjectFlying(*obj, jumpPad->pushForce); + break; + case OBJECT_TYPE::OBJECT_TYPE_WORLD: + break; + } + } + + void SendObjectFlying(Oyster::Physics::ICustomBody &obj, Oyster::Math::Float3 force) + { + Oyster::Physics::ICustomBody::State state; + + state = obj.GetState(); + state.ApplyLinearImpulse(force); + obj.SetState(state); + } void PlayerVObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss) diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index d9973821..6aecc900 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -42,7 +42,7 @@ GameAPI& GameAPI::Instance() Game::Game(void) : initiated(false) , onMoveFnc(0) - , onDeadFnc(0) + , onDisableFnc(0) , frameTime(1.0f/120.0f) {} @@ -151,7 +151,7 @@ void Game::SetSubscription(GameEvent::ObjectEventFunctionType type, GameEvent::O this->onMoveFnc = functionPointer; break; case GameLogic::GameEvent::ObjectEventFunctionType_OnDead: - this->onDeadFnc = functionPointer; + this->onDisableFnc = functionPointer; break; } @@ -183,6 +183,6 @@ void Game::PhysicsOnMove(const ICustomBody *object) } void Game::PhysicsOnDestroy(::Utility::DynamicMemory::UniquePointer proto) { - if(gameInstance.onDeadFnc) gameInstance.onDeadFnc(0); + if(gameInstance.onDisableFnc) gameInstance.onDisableFnc(0); } diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index 55f3e4cf..ddcfc086 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -73,16 +73,14 @@ namespace GameLogic float GetFrameTime() const; - private: static void PhysicsOnMove(const Oyster::Physics::ICustomBody *object); static void PhysicsOnDestroy(::Utility::DynamicMemory::UniquePointer proto); - private: Utility::DynamicMemory::DynamicArray players; LevelData* level; float frameTime; bool initiated; - GameEvent::ObjectEventFunction onDeadFnc; + GameEvent::ObjectEventFunction onDisableFnc; GameEvent::ObjectEventFunction onMoveFnc; }; diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index 809c82b5..674773bf 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -183,6 +183,7 @@ + @@ -206,6 +207,7 @@ + diff --git a/Code/Game/GameLogic/JumpPad.cpp b/Code/Game/GameLogic/JumpPad.cpp new file mode 100644 index 00000000..c60e248c --- /dev/null +++ b/Code/Game/GameLogic/JumpPad.cpp @@ -0,0 +1,21 @@ +#include "JumpPad.h" +#include "PhysicsAPI.h" + +using namespace GameLogic; +using namespace Oyster::Physics; + +JumpPad::JumpPad(void) +{ +} + +JumpPad::JumpPad(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type, Oyster::Math::Float3 pushForce) + :StaticObject(rigidBody, collisionFuncBefore, collisionFuncAfter, type) +{ + +} + + + +JumpPad::~JumpPad(void) +{ +} diff --git a/Code/Game/GameLogic/JumpPad.h b/Code/Game/GameLogic/JumpPad.h new file mode 100644 index 00000000..b9fe2253 --- /dev/null +++ b/Code/Game/GameLogic/JumpPad.h @@ -0,0 +1,26 @@ +#ifndef JUMPPAD_H +#define JUMPPAD_H +#include "StaticObject.h" +namespace GameLogic +{ + class JumpPad : public StaticObject + { + public: + JumpPad(void); + + JumpPad(Oyster::Physics::ICustomBody *rigidBody + ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter) + ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss) + ,OBJECT_TYPE type, Oyster::Math::Float3 pushForce); + + ~JumpPad(void); + + static void JumpPadActivated(Oyster::Physics::ICustomBody *rigidBodyJumpPad, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); + + private: + Oyster::Math::Float3 pushForce; + + + }; +} +#endif diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 29fc77cb..e9510f57 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -60,8 +60,7 @@ Player::~Player(void) void Player::BeginFrame() { - weapon->Update(0.002f); - //if(playerState == PLAYER_STATE_DEAD) Respawn(Oyster::Math::Float3(0,308,0)); + weapon->Update(0.002f); Object::BeginFrame(); } @@ -205,7 +204,7 @@ void Player::DamageLife(int damage) { this->life = 0; playerState = PLAYER_STATE_DEAD; - //do stuff that makes you dead + this->gameInstance->onDisableFnc(this); } }