GL - first implementation of weapons forcepull with pickup functionallity

This commit is contained in:
Erik Persson 2014-02-03 15:32:46 +01:00
parent dc5b408196
commit 99b041f165
11 changed files with 152 additions and 9 deletions

View File

@ -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);
}

View File

@ -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;
};
}

View File

@ -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;
@ -94,3 +102,32 @@ using namespace GameLogic;
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;
}
}
}

View File

@ -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);
};

View File

@ -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:

View File

@ -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));

View File

@ -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)

View File

@ -71,6 +71,9 @@ namespace GameLogic
void DamageLife(int damage);
void BeginFrame();
void EndFrame();
private:
void Jump();

View File

@ -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)

View File

@ -126,3 +126,8 @@ void Weapon::SelectAttatchment(int socketID)
}
}
void Weapon::Update(float dt)
{
selectedAttatchment->Update(dt);
}

View File

@ -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);