Shots need more work

This commit is contained in:
ViktorLjung
2014-05-13 01:50:58 +02:00
parent 38482431a1
commit b9231e4d46
12 changed files with 207 additions and 14 deletions
+1 -1
Submodule assets updated: 8b6c48b26b...05b3d22b01
+1 -1
View File
@@ -10,9 +10,9 @@ namespace Components
{
BarrelSteering()
: Velocity(1.f), Axis(glm::vec3(0,1,0)){ }
float Velocity;
glm::vec3 Axis;
EntityID ShotTemplate;
};
}
+17
View File
@@ -0,0 +1,17 @@
#ifndef Shot_h__
#define Shot_h__
#include "Component.h"
namespace Components
{
struct Shot : Component
{
Shot();
float Speed;
};
}
#endif // Shot_h__
+17
View File
@@ -0,0 +1,17 @@
#ifndef Events_SetVelocity_h__
#define Events_SetVelocity_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct SetVelocity : Event
{
EntityID Entity;
glm::vec3 Velocity;
};
}
#endif // Events_SetVelocity_h__
+125 -10
View File
@@ -19,6 +19,8 @@ void GameWorld::Initialize()
BindKey(GLFW_KEY_RIGHT, "tower_rotation", -1.f);
BindKey(GLFW_KEY_SPACE, "handbrake", 1.f);
BindKey(GLFW_KEY_Z, "shoot", 1.f);
//
// BindKey(GLFW_KEY_UP, "vertical", -1.f);
// BindKey(GLFW_KEY_DOWN, "vertical", 1.f);
@@ -264,7 +266,7 @@ void GameWorld::Initialize()
auto tower = CreateEntity(tank);
SetProperty(tower, "Name", "tower");
auto transform = AddComponent<Components::Transform>(tower, "Transform");
transform->Position = glm::vec3(0, 1.2, 1.95);
transform->Position = glm::vec3(0.f, 1.2f, 1.8f);
auto model = AddComponent<Components::Model>(tower, "Model");
model->ModelFile = "Models/Tank/Fix/Top.obj";
auto towerSteering = AddComponent<Components::TowerSteering>(tower, "TowerSteering");
@@ -273,12 +275,37 @@ void GameWorld::Initialize()
{
auto barrel = CreateEntity(tower);
auto transform = AddComponent<Components::Transform>(barrel, "Transform");
transform->Position = glm::vec3(0, 0, -2.f);
transform->Position = glm::vec3(-0.018f, -0.2, -1.3f);
auto model = AddComponent<Components::Model>(barrel, "Model");
model->ModelFile = "Models/Tank/Fix/Barrel.obj";
auto barrelSteering = AddComponent<Components::BarrelSteering>(barrel, "BarrelSteering");
barrelSteering->Axis = glm::vec3(1.f, 0.f, 0.f);
barrelSteering->Velocity = glm::pi<float>()/4.f;
{
auto shot = CreateEntity(barrel);
auto transform = AddComponent<Components::Transform>(shot, "Transform");
transform->Position = glm::vec3(0.35f, 1.f, -2.f);
auto shotComponent = AddComponent<Components::Shot>(shot, "Shot");
shotComponent->Speed = 5;
auto physics = AddComponent<Components::Physics>(shot, "Physics");
physics->Mass = 10.f;
physics->Static = false;
auto modelComponent = AddComponent<Components::Model>(shot, "Model");
modelComponent->ModelFile = "Models/Placeholders/PhysicsTest/Cube.obj";
{
auto shape = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(shape, "Transform");
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
boxShape->Width = 0.5f;
boxShape->Height = 0.5f;
boxShape->Depth = 0.5f;
CommitEntity(shape);
}
CommitEntity(shot);
barrelSteering->ShotTemplate = shot;
}
CommitEntity(barrel);
}
}
@@ -306,7 +333,7 @@ void GameWorld::Initialize()
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
transform->Position = glm::vec3(1.88f, -0.83f - wheelOffset, -2.6f);
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -2.6f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel, "Model");
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
@@ -320,12 +347,23 @@ void GameWorld::Initialize()
Wheel->Friction = 4.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
transform->Position = glm::vec3(1.88f, -0.83f - wheelOffset, -0.83f);
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -0.83f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel, "Model");
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
@@ -339,13 +377,24 @@ void GameWorld::Initialize()
Wheel->Friction = 4.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
transform->Position = glm::vec3(-1.88f, -0.83f - wheelOffset, -2.6f);
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, -2.6f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel, "Model");
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
@@ -359,12 +408,23 @@ void GameWorld::Initialize()
Wheel->Friction = 4.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
transform->Position = glm::vec3(-1.88f, -0.83f - wheelOffset, -0.83f);
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, -0.83f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel, "Model");
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
@@ -378,6 +438,17 @@ void GameWorld::Initialize()
Wheel->Friction = 4.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
@@ -386,7 +457,7 @@ void GameWorld::Initialize()
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
transform->Position = glm::vec3(1.88f, -0.83f - wheelOffset, 1.f);
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 1.f);
auto model = AddComponent<Components::Model>(wheel, "Model");
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
@@ -399,12 +470,23 @@ void GameWorld::Initialize()
Wheel->Friction = 4.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
transform->Position = glm::vec3(1.88f, -0.83f - wheelOffset, 2.95f);
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 2.95f);
auto model = AddComponent<Components::Model>(wheel, "Model");
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
@@ -417,13 +499,24 @@ void GameWorld::Initialize()
Wheel->Friction = 4.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
transform->Position = glm::vec3(-1.88f, -0.83f - wheelOffset, 1.f);
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, 1.f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel, "Model");
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
@@ -437,12 +530,23 @@ void GameWorld::Initialize()
Wheel->Friction = 4.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
transform->Position = glm::vec3(-1.88f, -0.83f - wheelOffset, 2.95f);
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, 2.95f);
auto model = AddComponent<Components::Model>(wheel, "Model");
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
@@ -455,6 +559,17 @@ void GameWorld::Initialize()
Wheel->Friction = 4.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape, "Transform");
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape, "BoxShape");
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
+1 -1
View File
@@ -37,7 +37,7 @@
#include "Components/TankSteering.h"
#include "Components/TowerSteering.h"
#include "Components/BarrelSteering.h"
#include "Components/Shot.h"
class GameWorld : public World
{
+6
View File
@@ -31,6 +31,7 @@ void Systems::PhysicsSystem::Initialize()
// Events
EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnTankSteer);
EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnSetVelocity);
hkMemorySystem::FrameInfo finfo(6000 * 1024); // Allocate 6MB of Physics solver buffer
hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo);
@@ -579,3 +580,8 @@ bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event)
return true;
}
bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event )
{
}
+4
View File
@@ -14,6 +14,7 @@
#include "Components/WheelPair.h"
#include "Components/TowerSteering.h"
#include "Events/TankSteer.h"
#include "Events/SetVelocity.h"
#include "OBJ.h"
// Math and base include
@@ -85,6 +86,9 @@ private:
EventRelay<Events::TankSteer> m_ETankSteer;
bool OnTankSteer(const Events::TankSteer &event);
EventRelay<Events::SetVelocity> m_ESetVelocity;
bool OnSetVelocity(const Events::SetVelocity &event);
void SetUpPhysicsState(EntityID entity, EntityID parent);
void TearDownPhysicsState(EntityID entity, EntityID parent);
+19
View File
@@ -49,6 +49,19 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
glm::quat orientation = glm::angleAxis(barrelSteeringComponent->Velocity * m_TowerInputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis);
transformComponent->Orientation *= orientation;
}
auto shotComponent = m_World->GetComponent<Components::Shot>(entity, "Shot");
if(shotComponent)
{
if(m_TowerInputController->shoot)
{
auto absoluteOrientation = m_World->GetSystem<Systems::TransformSystem>("TransformSystem")->AbsoluteOrientation(entity);
Events::SetVelocity e;
e.Entity = entity;
e.Velocity = absoluteOrientation * (glm::vec3(0.f, 0.f, 1.f) * shotComponent->Speed * (float)dt);
EventBroker->Publish(e);
}
}
}
void Systems::TankSteeringSystem::TankSteeringInputController::Update( double dt )
@@ -61,6 +74,7 @@ void Systems::TankSteeringSystem::TowerSteeringInputController::Update( double d
{
TowerDirection = m_TowerDirection;
BarrelDirection = m_BarrelDirection;
shoot = m_Shoot;
}
bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const Events::InputCommand &event)
@@ -94,6 +108,11 @@ bool Systems::TankSteeringSystem::TowerSteeringInputController::OnCommand( const
{
m_BarrelDirection = val;
}
else if (event.Command == "shoot")
{
shoot = (bool)val;
}
return true;
}
+8 -1
View File
@@ -2,11 +2,14 @@
#include "System.h"
#include "Events/TankSteer.h"
#include "Events/SetVelocity.h"
#include "Components/Transform.h"
#include "Components/TankSteering.h"
#include "Components/TowerSteering.h"
#include "Components/BarrelSteering.h"
#include "Components/Vehicle.h"
#include "Components/Shot.h"
#include "Systems/TransformSystem.h"
#include "InputController.h"
namespace Systems
@@ -67,10 +70,13 @@ namespace Systems
m_BarrelDirection = 0.f;
TowerDirection = 0.f;
BarrelDirection = 0.f;
m_Shoot = false;
}
float TowerDirection;
float BarrelDirection;
bool shoot;
void Update(double dt);
protected:
virtual bool OnCommand(const Events::InputCommand &event);
@@ -78,7 +84,8 @@ namespace Systems
private:
float m_TowerDirection;
float m_BarrelDirection;
float m_BarrelDirection;
bool m_Shoot;
};
}
+2
View File
@@ -137,6 +137,7 @@
<ClInclude Include="..\..\src\Components\ParticleEmitter.h" />
<ClInclude Include="..\..\src\Components\Physics.h" />
<ClInclude Include="..\..\src\Components\PointLight.h" />
<ClInclude Include="..\..\src\Components\Shot.h" />
<ClInclude Include="..\..\src\Components\SoundEmitter.h" />
<ClInclude Include="..\..\src\Components\SphereShape.h" />
<ClInclude Include="..\..\src\Components\Sprite.h" />
@@ -159,6 +160,7 @@
<ClInclude Include="..\..\src\Events\MousePress.h" />
<ClInclude Include="..\..\src\Events\MouseRelease.h" />
<ClInclude Include="..\..\src\Events\PlaySound.h" />
<ClInclude Include="..\..\src\Events\SetVelocity.h" />
<ClInclude Include="..\..\src\Events\TankSteer.h" />
<ClInclude Include="..\..\src\Factory.h" />
<ClInclude Include="..\..\src\GameWorld.h" />
@@ -328,6 +328,12 @@
<ClInclude Include="..\..\src\Components\BarrelSteering.h">
<Filter>Physics\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\Shot.h">
<Filter>Physics\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\SetVelocity.h">
<Filter>Physics\Events</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\src\Shaders\AABB.frag.glsl">