From 99b041f1650009ebe1fed77706313db717a9c6b3 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Mon, 3 Feb 2014 15:32:46 +0100 Subject: [PATCH] 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);