Recoil while firing, clamp inputs, merge Helicopter
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef Events_ApplyPointImpulse_h__
|
||||||
|
#define Events_ApplyPointImpulse_h__
|
||||||
|
#include "Entity.h"
|
||||||
|
#include "EventBroker.h"
|
||||||
|
|
||||||
|
namespace Events
|
||||||
|
{
|
||||||
|
|
||||||
|
struct ApplyPointImpulse : Event
|
||||||
|
{
|
||||||
|
EntityID Entity;
|
||||||
|
glm::vec3 Position;
|
||||||
|
glm::vec3 Impulse;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // Events_ApplyPointImpulse_h__
|
||||||
+2
-2
@@ -222,7 +222,7 @@ void GameWorld::Initialize()
|
|||||||
transform->Position = glm::vec3(0, 5, 0);
|
transform->Position = glm::vec3(0, 5, 0);
|
||||||
//transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0));
|
//transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0));
|
||||||
auto physics = AddComponent<Components::Physics>(tank);
|
auto physics = AddComponent<Components::Physics>(tank);
|
||||||
physics->Mass = 25000;
|
physics->Mass = 63000 - 16000;
|
||||||
physics->Static = false;
|
physics->Static = false;
|
||||||
auto vehicle = AddComponent<Components::Vehicle>(tank);
|
auto vehicle = AddComponent<Components::Vehicle>(tank);
|
||||||
vehicle->MaxTorque = 5200.f;
|
vehicle->MaxTorque = 5200.f;
|
||||||
@@ -280,7 +280,7 @@ void GameWorld::Initialize()
|
|||||||
transform->Scale = glm::vec3(3.f);
|
transform->Scale = glm::vec3(3.f);
|
||||||
AddComponent<Components::Template>(shot);
|
AddComponent<Components::Template>(shot);
|
||||||
auto physics = AddComponent<Components::Physics>(shot);
|
auto physics = AddComponent<Components::Physics>(shot);
|
||||||
physics->Mass = 10.f;
|
physics->Mass = 25.f;
|
||||||
physics->Static = false;
|
physics->Static = false;
|
||||||
auto modelComponent = AddComponent<Components::Model>(shot);
|
auto modelComponent = AddComponent<Components::Model>(shot);
|
||||||
modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj";
|
modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj";
|
||||||
|
|||||||
@@ -97,6 +97,19 @@ void InputManager::Update(double dt)
|
|||||||
dwResult = XInputGetState(i, &state);
|
dwResult = XInputGetState(i, &state);
|
||||||
if (dwResult == 0)
|
if (dwResult == 0)
|
||||||
{
|
{
|
||||||
|
if(std::abs(state.Gamepad.sThumbLX) <= XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
|
||||||
|
state.Gamepad.sThumbLX = 0;
|
||||||
|
if(std::abs(state.Gamepad.sThumbLY) <= XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
|
||||||
|
state.Gamepad.sThumbLY = 0;
|
||||||
|
if(std::abs(state.Gamepad.sThumbRX) <= XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
|
||||||
|
state.Gamepad.sThumbRX = 0;
|
||||||
|
if(std::abs(state.Gamepad.sThumbRY) <= XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
|
||||||
|
state.Gamepad.sThumbRY = 0;
|
||||||
|
if(std::abs(state.Gamepad.bLeftTrigger) <= XINPUT_GAMEPAD_TRIGGER_THRESHOLD)
|
||||||
|
state.Gamepad.bLeftTrigger = 0;
|
||||||
|
if(std::abs(state.Gamepad.bRightTrigger) <= XINPUT_GAMEPAD_TRIGGER_THRESHOLD)
|
||||||
|
state.Gamepad.bRightTrigger = 0;
|
||||||
|
|
||||||
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::LeftX)] = state.Gamepad.sThumbLX / 32767.f;
|
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::LeftX)] = state.Gamepad.sThumbLX / 32767.f;
|
||||||
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::LeftY)] = state.Gamepad.sThumbLY / 32767.f;
|
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::LeftY)] = state.Gamepad.sThumbLY / 32767.f;
|
||||||
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::RightX)] = state.Gamepad.sThumbRX / 32767.f;
|
m_CurrentGamepadAxisState[i][static_cast<int>(Gamepad::Axis::RightX)] = state.Gamepad.sThumbRX / 32767.f;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
void Systems::HelicopterSteeringSystem::RegisterComponents(ComponentFactory* cf)
|
void Systems::HelicopterSteeringSystem::RegisterComponents(ComponentFactory* cf)
|
||||||
{
|
{
|
||||||
cf->Register("HelicopterSteering", []() { return new Components::HelicopterSteering(); });
|
cf->Register<Components::HelicopterSteering>([]() { return new Components::HelicopterSteering(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::HelicopterSteeringSystem::Initialize()
|
void Systems::HelicopterSteeringSystem::Initialize()
|
||||||
@@ -19,11 +19,11 @@ void Systems::HelicopterSteeringSystem::Update(double dt)
|
|||||||
|
|
||||||
void Systems::HelicopterSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
void Systems::HelicopterSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||||
{
|
{
|
||||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||||
if (!transform)
|
if (!transform)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto helicopterComponent = m_World->GetComponent<Components::HelicopterSteering>(entity, "HelicopterSteering");
|
auto helicopterComponent = m_World->GetComponent<Components::HelicopterSteering>(entity);
|
||||||
if (helicopterComponent)
|
if (helicopterComponent)
|
||||||
{
|
{
|
||||||
glm::vec3 controllerRotationEuler = m_InputController->Rotation * (float)dt;
|
glm::vec3 controllerRotationEuler = m_InputController->Rotation * (float)dt;
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ void Systems::PhysicsSystem::Initialize()
|
|||||||
EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnTankSteer);
|
EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnTankSteer);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_ESetVelocity, &Systems::PhysicsSystem::OnSetVelocity);
|
EVENT_SUBSCRIBE_MEMBER(m_ESetVelocity, &Systems::PhysicsSystem::OnSetVelocity);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EApplyForce, &Systems::PhysicsSystem::OnApplyForce);
|
EVENT_SUBSCRIBE_MEMBER(m_EApplyForce, &Systems::PhysicsSystem::OnApplyForce);
|
||||||
|
EVENT_SUBSCRIBE_MEMBER(m_EApplyPointImpulse, &Systems::PhysicsSystem::OnApplyPointImpulse);
|
||||||
|
|
||||||
hkMemorySystem::FrameInfo finfo(6000 * 1024); // Allocate 6MB of Physics solver buffer
|
hkMemorySystem::FrameInfo finfo(6000 * 1024); // Allocate 6MB of Physics solver buffer
|
||||||
hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo);
|
hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo);
|
||||||
hkBaseSystem::init(memoryRouter, HavokErrorReport);
|
hkBaseSystem::init(memoryRouter, HavokErrorReport);
|
||||||
@@ -605,3 +606,12 @@ bool Systems::PhysicsSystem::OnApplyForce(const Events::ApplyForce &event)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Systems::PhysicsSystem::OnApplyPointImpulse( const Events::ApplyPointImpulse &event )
|
||||||
|
{
|
||||||
|
m_PhysicsWorld->markForWrite();
|
||||||
|
m_RigidBodies[event.Entity]->applyPointImpulse(ConvertPosition(event.Impulse), ConvertPosition(event.Position));
|
||||||
|
m_PhysicsWorld->unmarkForWrite();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "Events/TankSteer.h"
|
#include "Events/TankSteer.h"
|
||||||
#include "Events/SetVelocity.h"
|
#include "Events/SetVelocity.h"
|
||||||
#include "Events/ApplyForce.h"
|
#include "Events/ApplyForce.h"
|
||||||
|
#include "Events/ApplyPointImpulse.h"
|
||||||
#include "OBJ.h"
|
#include "OBJ.h"
|
||||||
|
|
||||||
// Math and base include
|
// Math and base include
|
||||||
@@ -108,6 +109,8 @@ private:
|
|||||||
bool OnSetVelocity(const Events::SetVelocity &event);
|
bool OnSetVelocity(const Events::SetVelocity &event);
|
||||||
EventRelay<Events::ApplyForce> m_EApplyForce;
|
EventRelay<Events::ApplyForce> m_EApplyForce;
|
||||||
bool OnApplyForce(const Events::ApplyForce &event);
|
bool OnApplyForce(const Events::ApplyForce &event);
|
||||||
|
EventRelay<Events::ApplyPointImpulse> m_EApplyPointImpulse;
|
||||||
|
bool OnApplyPointImpulse(const Events::ApplyPointImpulse &event);
|
||||||
|
|
||||||
void SetUpPhysicsState(EntityID entity, EntityID parent);
|
void SetUpPhysicsState(EntityID entity, EntityID parent);
|
||||||
void TearDownPhysicsState(EntityID entity, EntityID parent);
|
void TearDownPhysicsState(EntityID entity, EntityID parent);
|
||||||
|
|||||||
@@ -62,6 +62,17 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
|||||||
e.Velocity = absoluteTransform.Orientation * (glm::vec3(0.f, 0.f, -1.f) * barrelSteeringComponent->ShotSpeed);
|
e.Velocity = absoluteTransform.Orientation * (glm::vec3(0.f, 0.f, -1.f) * barrelSteeringComponent->ShotSpeed);
|
||||||
EventBroker->Publish(e);
|
EventBroker->Publish(e);
|
||||||
m_TimeSinceLastShot[entity] = 0;
|
m_TimeSinceLastShot[entity] = 0;
|
||||||
|
|
||||||
|
|
||||||
|
auto clonePhysicsComponent = m_World->GetComponent<Components::Physics>(clone);
|
||||||
|
//1,670m/s
|
||||||
|
//25kg
|
||||||
|
EntityID baseParent = m_World->GetEntityBaseParent(entity);
|
||||||
|
Events::ApplyPointImpulse ePointImpulse ;
|
||||||
|
ePointImpulse.Entity = baseParent;
|
||||||
|
ePointImpulse.Position = absoluteTransform.Position;
|
||||||
|
ePointImpulse.Impulse = glm::normalize(absoluteTransform.Orientation * glm::vec3(0, 0, 1)) * clonePhysicsComponent->Mass * 1670.f;
|
||||||
|
EventBroker->Publish(ePointImpulse);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_TimeSinceLastShot[entity] += dt;
|
m_TimeSinceLastShot[entity] += dt;
|
||||||
@@ -83,7 +94,16 @@ void Systems::TankSteeringSystem::TowerSteeringInputController::Update( double d
|
|||||||
|
|
||||||
bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const Events::InputCommand &event)
|
bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const Events::InputCommand &event)
|
||||||
{
|
{
|
||||||
float val = event.Value;
|
float val;
|
||||||
|
if(abs(event.Value) < 0.3f)
|
||||||
|
{
|
||||||
|
val = 0.f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
val = event.Value;
|
||||||
|
}
|
||||||
|
|
||||||
if (event.Command == "horizontal")
|
if (event.Command == "horizontal")
|
||||||
{
|
{
|
||||||
m_Horizontal = val;
|
m_Horizontal = val;
|
||||||
|
|||||||
@@ -3,10 +3,13 @@
|
|||||||
#include "System.h"
|
#include "System.h"
|
||||||
#include "Events/TankSteer.h"
|
#include "Events/TankSteer.h"
|
||||||
#include "Events/SetVelocity.h"
|
#include "Events/SetVelocity.h"
|
||||||
|
#include "Events/ApplyForce.h"
|
||||||
|
#include "Events/ApplyPointImpulse.h"
|
||||||
#include "Components/Transform.h"
|
#include "Components/Transform.h"
|
||||||
#include "Components/TankSteering.h"
|
#include "Components/TankSteering.h"
|
||||||
#include "Components/TowerSteering.h"
|
#include "Components/TowerSteering.h"
|
||||||
#include "Components/BarrelSteering.h"
|
#include "Components/BarrelSteering.h"
|
||||||
|
#include "Components/Physics.h"
|
||||||
#include "Components/Vehicle.h"
|
#include "Components/Vehicle.h"
|
||||||
#include "Systems/TransformSystem.h"
|
#include "Systems/TransformSystem.h"
|
||||||
#include "InputController.h"
|
#include "InputController.h"
|
||||||
|
|||||||
@@ -60,7 +60,7 @@
|
|||||||
<CompileAsManaged>false</CompileAsManaged>
|
<CompileAsManaged>false</CompileAsManaged>
|
||||||
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
||||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||||
<Optimization>MaxSpeed</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
@@ -156,6 +156,7 @@
|
|||||||
<ClInclude Include="..\..\src\Engine.h" />
|
<ClInclude Include="..\..\src\Engine.h" />
|
||||||
<ClInclude Include="..\..\src\Entity.h" />
|
<ClInclude Include="..\..\src\Entity.h" />
|
||||||
<ClInclude Include="..\..\src\Events\ApplyForce.h" />
|
<ClInclude Include="..\..\src\Events\ApplyForce.h" />
|
||||||
|
<ClInclude Include="..\..\src\Events\ApplyPointImpulse.h" />
|
||||||
<ClInclude Include="..\..\src\Events\BindGamepadAxis.h" />
|
<ClInclude Include="..\..\src\Events\BindGamepadAxis.h" />
|
||||||
<ClInclude Include="..\..\src\Events\BindGamepadButton.h" />
|
<ClInclude Include="..\..\src\Events\BindGamepadButton.h" />
|
||||||
<ClInclude Include="..\..\src\Events\BindKey.h" />
|
<ClInclude Include="..\..\src\Events\BindKey.h" />
|
||||||
|
|||||||
@@ -63,7 +63,9 @@
|
|||||||
<ClCompile Include="..\..\src\Systems\TankSteeringSystem.cpp">
|
<ClCompile Include="..\..\src\Systems\TankSteeringSystem.cpp">
|
||||||
<Filter>Physics\Systems</Filter>
|
<Filter>Physics\Systems</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\Systems\HelicopterSteeringSystem.cpp" />
|
<ClCompile Include="..\..\src\Systems\HelicopterSteeringSystem.cpp">
|
||||||
|
<Filter>Gameplay\Vehicles\Helicopter\Systems</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Filter Include="Util">
|
<Filter Include="Util">
|
||||||
@@ -383,6 +385,10 @@
|
|||||||
<ClInclude Include="..\..\src\Events\ApplyForce.h">
|
<ClInclude Include="..\..\src\Events\ApplyForce.h">
|
||||||
<Filter>Physics\Events</Filter>
|
<Filter>Physics\Events</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Util\defferedUtil.h" />
|
||||||
|
<ClInclude Include="..\..\src\Events\ApplyPointImpulse.h">
|
||||||
|
<Filter>Physics\Events</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\..\src\Shaders\Fragment2.glsl">
|
<None Include="..\..\src\Shaders\Fragment2.glsl">
|
||||||
|
|||||||
Reference in New Issue
Block a user