diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 409fa683..6ec70e1b 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -39,16 +39,16 @@ AttatchmentMassDriver::~AttatchmentMassDriver(void) /******************************************************** * Uses the attatchment and will from here switch case the different WEAPON_FIRE's that are to be used ********************************************************/ -void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &fireInput) +void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage) { //switch case to determin what functionallity to use in the attatchment - switch (fireInput) + switch (usage) { case WEAPON_FIRE::WEAPON_USE_PRIMARY_PRESS: - ForcePush(fireInput); + ForcePush(usage); break; case WEAPON_FIRE::WEAPON_USE_SECONDARY_PRESS: - ForcePull(fireInput); + ForcePull(usage); break; } @@ -57,7 +57,7 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &fireInp /******************************************************** * Pushes objects in a cone in front of the weapon when fired ********************************************************/ -void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &fireInput) +void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage) { //create coneRigidBody that will then collide with object and push them in the aimed direction } @@ -65,7 +65,7 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &fireInput) /******************************************************** * Pulls the player in the direction he is looking, used for fast movement(kinda like a jetpack) ********************************************************/ -void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &fireInput) +void AttatchmentMassDriver::ForcePull(const WEAPON_FIRE &usage) { //Oyster::Physics::API::Instance().ApplyForceAt(owner->GetRigidBody(), owner->GetRigidBody()->GetCenter(), owner->GetLookDir() * 100); } diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.h b/Code/Game/GameLogic/AttatchmentMassDriver.h index 4c4fc124..a1ededd0 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.h +++ b/Code/Game/GameLogic/AttatchmentMassDriver.h @@ -15,26 +15,26 @@ namespace GameLogic ~AttatchmentMassDriver(void); - void UseAttatchment(const WEAPON_FIRE &fireInput); + void UseAttatchment(const WEAPON_FIRE &usage); private: /******************************************************** * Pushes objects and players in a cone in front of the player * @param fireInput: allows switching on different functionality in this specific function ********************************************************/ - void ForcePush(const WEAPON_FIRE &fireInput); + void ForcePush(const WEAPON_FIRE &usage); /******************************************************** * Pulls the player forward, this is a movement tool * @param fireInput: allows switching on different functionality in this specific function ********************************************************/ - void ForcePull(const WEAPON_FIRE &fireInput); + void ForcePull(const WEAPON_FIRE &usage); /******************************************************** * 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 ********************************************************/ - void ForceSuck(const WEAPON_FIRE &fireInput); + void ForceSuck(const WEAPON_FIRE &usage); private: struct PrivateData; diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 698fb88f..a16d63fe 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -55,3 +55,8 @@ using namespace GameLogic; return Physics::ICustomBody::SubscriptMessage_none; } + + Oyster::Physics::ICustomBody::SubscriptMessage LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj) + { + return Physics::ICustomBody::SubscriptMessage_ignore_collision_response; + } diff --git a/Code/Game/GameLogic/CollisionManager.h b/Code/Game/GameLogic/CollisionManager.h index 18d482b4..21723885 100644 --- a/Code/Game/GameLogic/CollisionManager.h +++ b/Code/Game/GameLogic/CollisionManager.h @@ -14,7 +14,7 @@ namespace GameLogic //typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter ); static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj); static Oyster::Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj); - + static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollision(const Oyster::Physics::ICustomBody *rigidBodyLevel, const Oyster::Physics::ICustomBody *obj); //these are the specific collision case functions //void PlayerVBox(Player &player, DynamicObject &box); //void BoxVBox(DynamicObject &box1, DynamicObject &box2); diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 64ab7c57..d102aa16 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -55,7 +55,7 @@ struct Game::PrivateData } DynamicArray players; - SmartPointer level; + SmartPointer level; Utility::WinTimer timer; }myData; @@ -88,6 +88,16 @@ Game::PlayerData* Game::CreatePlayer() return this->myData->players[id]; } +Game::LevelData* Game::CreateLevel() +{ + Level *newLevel = new Level(); + newLevel->InitiateLevel(1000); + LevelData *newLdata = new LevelData(); + newLdata->level = newLevel; + myData->level = newLdata; + return myData->level; +} + void Game::CreateTeam() { diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index 28d4c7fc..0cd9b2a8 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -38,7 +38,7 @@ namespace GameLogic * @param playerID: ID of the player you want to recieve the message * @param Usage: enum value on what kind of action is to be taken ********************************************************/ - void UseWeapon(int playerID, const WEAPON_FIRE &Usage); + void UseWeapon(int playerID, const WEAPON_FIRE &usage); /******************************************************** * Gets players position @@ -65,6 +65,19 @@ namespace GameLogic int GetTeamID() const; }; + struct DANBIAS_GAMELOGIC_DLL LevelData + { + private: + friend class Game; + Level *level; + LevelData(); + ~LevelData(); + + public: + + + }; + public: Game(void); ~Game(void); @@ -75,10 +88,15 @@ namespace GameLogic void GetAllPlayerPositions() const; /******************************************************** - * Creates a player and returns PlayerData containing ID of the player + * Creates a player and returns PlayerData ********************************************************/ PlayerData* CreatePlayer(); + /******************************************************** + * Creates a level and returns LevelData + ********************************************************/ + LevelData* CreateLevel(); + /******************************************************** * Creates a team ********************************************************/ diff --git a/Code/Game/GameLogic/Game_LevelData.cpp b/Code/Game/GameLogic/Game_LevelData.cpp new file mode 100644 index 00000000..a9a5394e --- /dev/null +++ b/Code/Game/GameLogic/Game_LevelData.cpp @@ -0,0 +1,14 @@ +#include "Game.h" +#include "Level.h" + +using namespace GameLogic; + +Game::LevelData::LevelData() +{ + +} + +Game::LevelData::~LevelData() +{ + +} \ No newline at end of file diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index 881cdb58..c393a18d 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -20,7 +20,7 @@ void Game::PlayerData::Move(const PLAYER_MOVEMENT &movement) { this->player->Move(movement); } -void Game::PlayerData::UseWeapon(int playerID, const WEAPON_FIRE &Usage) +void Game::PlayerData::UseWeapon(int playerID, const WEAPON_FIRE &usage) { } diff --git a/Code/Game/GameLogic/IAttatchment.h b/Code/Game/GameLogic/IAttatchment.h index 2192ffcf..5bc400e6 100644 --- a/Code/Game/GameLogic/IAttatchment.h +++ b/Code/Game/GameLogic/IAttatchment.h @@ -19,7 +19,7 @@ namespace GameLogic IAttatchment(void); ~IAttatchment(void); - virtual void UseAttatchment(const WEAPON_FIRE &fireInput) = 0; + virtual void UseAttatchment(const WEAPON_FIRE &usage) = 0; private: diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 9b3c90ff..4ce96dee 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -9,7 +9,7 @@ using namespace GameLogic; using namespace Utility::DynamicMemory; - +using namespace Oyster::Physics; struct Level::PrivateData { @@ -29,7 +29,7 @@ struct Level::PrivateData SmartPointer gameMode; - SmartPointer rigidBodyLevel; + SmartPointer rigidBodyLevel; }myData; @@ -47,6 +47,27 @@ Level::~Level(void) void Level::InitiateLevel(std::string levelPath) { +} +void Level::InitiateLevel(float radius) +{ + API::SphericalBodyDescription sbDesc; + sbDesc.centerPosition = Oyster::Math::Float4(0,0,0,1); + sbDesc.ignoreGravity = true; + sbDesc.radius = radius; + sbDesc.mass = 1e16; //10^16 + sbDesc.subscription = CollisionManager::LevelCollision; + + ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); + API::Instance().AddObject(rigidBody); + + API::Gravity gravityWell; + + gravityWell.gravityType = API::Gravity::GravityType_Well; + gravityWell.well.mass = (float)1e16; + gravityWell.well.position = Oyster::Math::Float4(0,0,0,1); + + API::Instance().AddGravity(gravityWell); + } void Level::AddPlayerToTeam(Player *player, int teamID) diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index fa450dc4..68dfca0f 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -21,6 +21,7 @@ namespace GameLogic * @param levelPath: Path to a file that contains all information on the level ********************************************************/ void InitiateLevel(std::string levelPath); + void Level::InitiateLevel(float radius); /******************************************************** * Creates a team in the level diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 85cd8db7..05a20503 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -79,9 +79,9 @@ void Player::MoveLeft() setState.ApplyLinearImpulse(-r * 100); } -void Player::UseWeapon(const WEAPON_FIRE &Usage) +void Player::UseWeapon(const WEAPON_FIRE &usage) { - this->weapon->Use(Usage); + this->weapon->Use(usage); } void Player::Respawn(Oyster::Math::Float3 spawnPoint) diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 9f190faf..0f080b3b 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -37,7 +37,7 @@ namespace GameLogic * Uses the weapon based on input * @param fireInput: enum value on what kind of action is to be taken ********************************************************/ - void UseWeapon(const WEAPON_FIRE &Usage); + void UseWeapon(const WEAPON_FIRE &usage); /******************************************************** * Respawns the player, this resets several stats and settings on the player diff --git a/Code/Game/GameLogic/Weapon.cpp b/Code/Game/GameLogic/Weapon.cpp index f9c4a4b6..9e6b6bd2 100644 --- a/Code/Game/GameLogic/Weapon.cpp +++ b/Code/Game/GameLogic/Weapon.cpp @@ -50,11 +50,11 @@ Weapon::~Weapon(void) /******************************************************** * Uses the weapon based on the input given and the current chosen attatchment ********************************************************/ -void Weapon::Use(const WEAPON_FIRE &fireInput) +void Weapon::Use(const WEAPON_FIRE &usage) { if (myData->selectedAttatchment) { - myData->selectedAttatchment->UseAttatchment(fireInput); + myData->selectedAttatchment->UseAttatchment(usage); } } diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index b3abf32c..ae190608 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -3,6 +3,7 @@ #include "SimpleRigidBody.h" #include "SphericalRigidBody.h" +using namespace ::Oyster; using namespace ::Oyster::Physics; using namespace ::Oyster::Math; using namespace ::Oyster::Collision3D; @@ -113,6 +114,7 @@ API_Impl::API_Impl() this->gravityConstant = Constant::gravity_constant; this->updateFrameLength = 1.0f / 120.0f; this->destructionAction = Default::EventAction_Destruction; + this->gravity = ::std::vector(); this->worldScene = Octree(); } @@ -121,6 +123,8 @@ API_Impl::~API_Impl() {} void API_Impl::Init( unsigned int numObjects, unsigned int numGravityWells , const Float3 &worldSize ) { unsigned char numLayers = 4; //!< @todo TODO: calc numLayers from worldSize + this->gravity.resize( 0 ); + this->gravity.reserve( numGravityWells ); this->worldScene = Octree( numObjects, numLayers, worldSize ); } @@ -153,14 +157,39 @@ float API_Impl::GetFrameTimeLength() const void API_Impl::Update() { /** @todo TODO: Update is a temporary solution .*/ - - - ::std::vector updateList; + ICustomBody::State state; auto proto = this->worldScene.Sample( Universe(), updateList ).begin(); for( ; proto != updateList.end(); ++proto ) { - // Step 1: @todo TODO: Apply Gravity + // Step 1: Apply Gravity + (*proto)->GetState( state ); + for( ::std::vector::size_type i = 0; i < this->gravity.size(); ++i ) + { + switch( this->gravity[i].gravityType ) + { + case Gravity::GravityType_Well: + { + Float4 d = state.GetCenterPosition() - Float4( this->gravity[i].well.position, 1.0f ); + Float rSquared = d.Dot( d ); + if( rSquared != 0.0 ) + { + Float force = Physics3D::Formula::ForceField( this->gravityConstant, state.GetMass(), this->gravity[i].well.mass, rSquared ); + state.ApplyLinearImpulse( (this->updateFrameLength * force / ::std::sqrt(rSquared)) * d ); + } + break; + } + case Gravity::GravityType_Directed: + state.ApplyLinearImpulse( Float4(this->gravity[i].directed.impulse, 0.0f) ); + break; +// case Gravity::GravityType_DirectedField: +// //this->gravity[i].directedField. +// //! TODO: @todo rethink +// break; + default: break; + } + } + (*proto)->SetState( state ); // Step 2: Apply Collision Response this->worldScene.Visit( *proto, OnPossibleCollision ); @@ -213,6 +242,24 @@ void API_Impl::DestroyObject( const ICustomBody* objRef ) } } +void API_Impl::AddGravity( const API::Gravity &g ) +{ + this->gravity.push_back( g ); +} + +void API_Impl::RemoveGravity( const API::Gravity &g ) +{ + for( ::std::vector::size_type i = this->gravity.size() - 1; i >= 0; --i ) + { + if( g == this->gravity[i] ) + { + int end = this->gravity.size() - 1; + this->gravity[i] = this->gravity[end]; + this->gravity.resize( end ); + } + } +} + //void API_Impl::ApplyForceAt( const ICustomBody* objRef, const Float3 &worldPos, const Float3 &worldF ) //{ // unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef ); diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h index 0c08bf11..314e0657 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h @@ -32,6 +32,9 @@ namespace Oyster ::Utility::DynamicMemory::UniquePointer ExtractObject( const ICustomBody* objRef ); void DestroyObject( const ICustomBody* objRef ); + void AddGravity( const Gravity &g ); + void RemoveGravity( const Gravity &g ); + //void ApplyForceAt( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos, const ::Oyster::Math::Float3 &worldF ); //void SetMomentOfInertiaTensor_KeepVelocity( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &localI ); @@ -49,6 +52,7 @@ namespace Oyster private: ::Oyster::Math::Float gravityConstant, updateFrameLength; EventAction_Destruction destructionAction; + ::std::vector gravity; Octree worldScene; }; diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index 0904551d..019a4af7 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -22,6 +22,7 @@ namespace Oyster struct SimpleBodyDescription; struct SphericalBodyDescription; struct CustomBodyState; + struct Gravity; } enum UpdateState @@ -40,6 +41,7 @@ namespace Oyster public: typedef Struct::SimpleBodyDescription SimpleBodyDescription; typedef Struct::SphericalBodyDescription SphericalBodyDescription; + typedef Struct::Gravity Gravity; typedef void (*EventAction_Destruction)( ::Utility::DynamicMemory::UniquePointer proto ); @@ -124,6 +126,16 @@ namespace Oyster ********************************************************/ virtual void DestroyObject( const ICustomBody* objRef ) = 0; + /******************************************************** + * TODO: @todo doc + ********************************************************/ + virtual void AddGravity( const Gravity &g ) = 0; + + /******************************************************** + * TODO: @todo doc + ********************************************************/ + virtual void RemoveGravity( const Gravity &g ) = 0; + ///******************************************************** // * Apply force on an object. // * @param objRef: A pointer to the ICustomBody representing a physical object. diff --git a/Code/GamePhysics/PhysicsStructs-Impl.h b/Code/GamePhysics/PhysicsStructs-Impl.h index c74c6537..17c18ba2 100644 --- a/Code/GamePhysics/PhysicsStructs-Impl.h +++ b/Code/GamePhysics/PhysicsStructs-Impl.h @@ -353,6 +353,26 @@ namespace Oyster return *this; } + inline bool GravityWell::operator == ( const GravityWell &gravity ) const + { + if( this->position == gravity.position ) + if( this->mass == gravity.mass ) + { + return true; + } + return false; + } + + inline bool GravityWell::operator != ( const GravityWell &gravity ) const + { + if( this->position == gravity.position ) + if( this->mass == gravity.mass ) + { + return false; + } + return true; + } + inline GravityDirected::GravityDirected( ) { this->impulse = ::Oyster::Math::Float3::null; @@ -370,6 +390,16 @@ namespace Oyster return *this; } + inline bool GravityDirected::operator == ( const GravityDirected &gravity ) const + { + return this->impulse == gravity.impulse; + } + + inline bool GravityDirected::operator != ( const GravityDirected &gravity ) const + { + return this->impulse != gravity.impulse; + } + inline GravityDirectedField::GravityDirectedField( ) { this->normalizedDirection = ::Oyster::Math::Float3::null; @@ -393,6 +423,28 @@ namespace Oyster return *this; } + inline bool GravityDirectedField::operator == ( const GravityDirectedField &gravity ) const + { + if( this->normalizedDirection == gravity.normalizedDirection ) + if( this->mass == gravity.mass ) + if( this->magnitude == gravity.magnitude ) + { + return true; + } + return false; + } + + inline bool GravityDirectedField::operator != ( const GravityDirectedField &gravity ) const + { + if( this->normalizedDirection == gravity.normalizedDirection ) + if( this->mass == gravity.mass ) + if( this->magnitude == gravity.magnitude ) + { + return false; + } + return true; + } + inline Gravity::Gravity() { this->gravityType = GravityType_Undefined; @@ -437,6 +489,36 @@ namespace Oyster return *this; } + + inline bool Gravity::operator == ( const Gravity &gravity ) const + { + if( this->gravityType == gravity.gravityType ) + { + switch( this->gravityType ) + { + case GravityType_Well: return this->well == gravity.well; + case GravityType_Directed: return this->directed == gravity.directed; + case GravityType_DirectedField: return this->directedField == gravity.directedField; + default: return true; + } + } + return false; + } + + inline bool Gravity::operator != ( const Gravity &gravity ) const + { + if( this->gravityType == gravity.gravityType ) + { + switch( this->gravityType ) + { + case GravityType_Well: return this->well != gravity.well; + case GravityType_Directed: return this->directed != gravity.directed; + case GravityType_DirectedField: return this->directedField != gravity.directedField; + default: return false; + } + } + return true; + } } } } diff --git a/Code/GamePhysics/PhysicsStructs.h b/Code/GamePhysics/PhysicsStructs.h index bf6c0618..7ed37c59 100644 --- a/Code/GamePhysics/PhysicsStructs.h +++ b/Code/GamePhysics/PhysicsStructs.h @@ -123,7 +123,10 @@ namespace Oyster { namespace Physics GravityWell( ); GravityWell( const GravityWell &gravityWell ); - GravityWell& operator=( const GravityWell &gravityWell ); + GravityWell & operator = ( const GravityWell &gravityWell ); + + bool operator == ( const GravityWell &gravity ) const; + bool operator != ( const GravityWell &gravity ) const; }; struct GravityDirected @@ -133,6 +136,9 @@ namespace Oyster { namespace Physics GravityDirected( ); GravityDirected( const GravityDirected &gravityDirected ); GravityDirected & operator = ( const GravityDirected &gravityDirected ); + + bool operator == ( const GravityDirected &gravity ) const; + bool operator != ( const GravityDirected &gravity ) const; }; struct GravityDirectedField @@ -143,7 +149,10 @@ namespace Oyster { namespace Physics GravityDirectedField( ); GravityDirectedField( const GravityDirectedField &gravityDirectedField ); - GravityDirectedField & operator=( const GravityDirectedField &gravityDirectedField ); + GravityDirectedField & operator = ( const GravityDirectedField &gravityDirectedField ); + + bool operator == ( const GravityDirectedField &gravity ) const; + bool operator != ( const GravityDirectedField &gravity ) const; }; struct Gravity @@ -177,6 +186,9 @@ namespace Oyster { namespace Physics Gravity( ); Gravity( const Gravity &gravity ); Gravity & operator = ( const Gravity &gravity ); + + bool operator == ( const Gravity &gravity ) const; + bool operator != ( const Gravity &gravity ) const; }; } } } diff --git a/Code/OysterPhysics3D/OysterCollision3D.cpp b/Code/OysterPhysics3D/OysterCollision3D.cpp index 3ef44974..169b5add 100644 --- a/Code/OysterPhysics3D/OysterCollision3D.cpp +++ b/Code/OysterPhysics3D/OysterCollision3D.cpp @@ -204,7 +204,7 @@ namespace Oyster { namespace Collision3D { namespace Utility return true; } - bool SeperatingAxisTest_AxisAlignedVsTransformedBox( const Float4 &boundingOffsetA, const Float4 &boundingOffsetB, const Float4x4 &rotationB, const Float4 &worldOffset, Float4 &worldPointOfContact ) + bool SeperatingAxisTest_AxisAlignedVsTransformedBox( const Float4 &boundingOffsetA, const Float4 &boundingOffsetB, const Float4x4 &rotationB, const Float4 &worldOffset, Float4 &localPointOfContact ) { // by Dan Andersson /***************************************************************** @@ -241,7 +241,7 @@ namespace Oyster { namespace Collision3D { namespace Utility { // no intersection return false; } - worldPointOfContact = s * ( centerSeperation * eA / edgeSeperation ); + localPointOfContact = s * ( centerSeperation * eA / edgeSeperation ); s = Float4::standard_unit_y; centerSeperation = t.Dot(s); @@ -251,7 +251,7 @@ namespace Oyster { namespace Collision3D { namespace Utility { // no intersection return false; } - worldPointOfContact += s * ( centerSeperation * eA / edgeSeperation ); + localPointOfContact += s * ( centerSeperation * eA / edgeSeperation ); s = Float4::standard_unit_z; centerSeperation = t.Dot(s); @@ -261,7 +261,7 @@ namespace Oyster { namespace Collision3D { namespace Utility { // no intersection return false; } - worldPointOfContact += s * ( centerSeperation * eA / edgeSeperation ); + localPointOfContact += s * ( centerSeperation * eA / edgeSeperation ); s = rotationB.v[0]; centerSeperation = t.Dot(s); @@ -271,7 +271,7 @@ namespace Oyster { namespace Collision3D { namespace Utility { // no intersection return false; } - worldPointOfContact += s * ( centerSeperation * eA / edgeSeperation ); + localPointOfContact += s * ( centerSeperation * eA / edgeSeperation ); s = rotationB.v[1]; centerSeperation = t.Dot(s); @@ -281,7 +281,7 @@ namespace Oyster { namespace Collision3D { namespace Utility { // no intersection return false; } - worldPointOfContact += s * ( centerSeperation * eA / edgeSeperation ); + localPointOfContact += s * ( centerSeperation * eA / edgeSeperation ); s = rotationB.v[2]; centerSeperation = t.Dot(s); @@ -291,7 +291,7 @@ namespace Oyster { namespace Collision3D { namespace Utility { // no intersection return false; } - worldPointOfContact += s * ( centerSeperation * eA / edgeSeperation ); // enough point of contact data gathered for approximative result. + localPointOfContact += s * ( centerSeperation * eA / edgeSeperation ); // enough point of contact data gathered for approximative result. s = Float4( Float3::standard_unit_x.Cross(rotationB.v[0].xyz), 0.0f ); centerSeperation = t.Dot(s); @@ -374,7 +374,7 @@ namespace Oyster { namespace Collision3D { namespace Utility return false; } - worldPointOfContact *= 0.5f; + localPointOfContact *= 0.5f; return true; } } @@ -821,10 +821,11 @@ namespace Oyster { namespace Collision3D { namespace Utility Float4 alignedOffsetBoundaries = (boxB.maxVertex - boxB.minVertex) * 0.5f, offset = boxA.center - Average( boxB.maxVertex, boxB.minVertex ); - Float4 pointOfContact; - if( Private::SeperatingAxisTest_AxisAlignedVsTransformedBox( alignedOffsetBoundaries, boxA.boundingOffset, boxA.rotation, offset, pointOfContact ) ) + Float4 localPointOfContact; + if( Private::SeperatingAxisTest_AxisAlignedVsTransformedBox( alignedOffsetBoundaries, boxA.boundingOffset, boxA.rotation, offset, localPointOfContact ) ) { - worldPointOfContact = pointOfContact.xyz; + worldPointOfContact = localPointOfContact + boxA.center; + worldPointOfContact.w = 1.0f; return true; } else return false; @@ -843,10 +844,12 @@ namespace Oyster { namespace Collision3D { namespace Utility Float4x4 rotationB = TransformMatrix( InverseRotationMatrix(boxA.rotation), boxB.rotation ); Float4 posB = boxB.center - boxA.center; - Float4 pointOfContact; - if( Private::SeperatingAxisTest_AxisAlignedVsTransformedBox( boxA.boundingOffset, boxB.boundingOffset, rotationB, posB, pointOfContact ) ) + Float4 localPointOfContact; + if( Private::SeperatingAxisTest_AxisAlignedVsTransformedBox( boxA.boundingOffset, boxB.boundingOffset, rotationB, posB, localPointOfContact ) ) { - worldPointOfContact = TransformVector( boxA.rotation, pointOfContact, pointOfContact ).xyz; + worldPointOfContact = TransformVector( boxA.rotation, localPointOfContact, localPointOfContact ); + worldPointOfContact += boxA.center; + worldPointOfContact.w = 1.0f; return true; } else return false; diff --git a/Code/OysterPhysics3D/OysterPhysics3D.h b/Code/OysterPhysics3D/OysterPhysics3D.h index 970d739e..f814ff46 100644 --- a/Code/OysterPhysics3D/OysterPhysics3D.h +++ b/Code/OysterPhysics3D/OysterPhysics3D.h @@ -273,6 +273,22 @@ namespace Oyster { namespace Physics3D return momentOfInertia * angularImpulseAcceleration; } + /****************************************************************** + * @todo TODO: doc + ******************************************************************/ + inline ::Oyster::Math::Float ForceField( ::Oyster::Math::Float g, ::Oyster::Math::Float massA, ::Oyster::Math::Float massB, ::Oyster::Math::Float radiusSquared ) + { + return g * massA * massB / radiusSquared; + } + + /****************************************************************** + * @todo TODO: doc + ******************************************************************/ + inline ::Oyster::Math::Float ForceField( ::Oyster::Math::Float g, ::Oyster::Math::Float massA, ::Oyster::Math::Float massB, const ::Oyster::Math::Float4 &deltaPos ) + { + return g * massA * massB / deltaPos.Dot( deltaPos ); + } + namespace MomentOfInertia { /// Library of Formulas to calculate moment of inerta for simple shapes /** @todo TODO: add MomentOfInertia tensor formulas */