12 Commits

Author SHA1 Message Date
Jace 397188b855 Fixed frame scissor test 2014-06-04 00:46:03 +02:00
Jace 0addc672b4 Multiple vehicle selection 2014-06-03 20:36:35 +02:00
Jace 80846a29ad Terrain creation stuff 2014-06-03 20:36:23 +02:00
Jace e15474c3d4 Fixed filters 2014-06-03 19:09:10 +02:00
ViktorLjung 486922a7c5 Tank tuning 2014-06-03 18:59:41 +02:00
Jace a00c145616 Safety check for spawns 2014-06-03 18:47:08 +02:00
Jace aeb29cde8b Merge branch 'deffered_rendering'
Conflicts:
	assets
	src/Components/Physics.h
	src/GameWorld.cpp
	src/GameWorld.h
	src/Systems/PhysicsSystem.cpp
	vs11/Returngeance/Returngeance.vcxproj
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-03 18:46:49 +02:00
Tleety f5f6a5cf3a Fixed transparency 2014-06-02 22:15:52 +02:00
Tleety 179c5c1feb Merge remote-tracking branch 'origin/particles' into deffered_rendering
Conflicts:
	assets
	src/GameWorld.cpp
	vs11/Returngeance/Returngeance.vcxproj.filters
2014-06-02 20:20:36 +02:00
Tleety f1a9afc097 Fixed a createWall function. 2014-06-02 20:01:28 +02:00
Tleety 00268f027a Walls are now destroyable! 2014-06-02 18:21:39 +02:00
Tleety 0e2934647c Added a movable tree or somthing dunno lol tired-. 2014-06-01 03:01:37 +02:00
21 changed files with 1006 additions and 254 deletions
+1 -1
Submodule assets updated: 3c4d81137f...75977fd865
+29 -4
View File
@@ -16,13 +16,38 @@ struct Physics : Component
EXPLOSION = 4, EXPLOSION = 4,
}; };
enum class MotionTypeEnum
{
Dynamic,
Fixed,
Keyframed
};
Physics() Physics()
: Mass(1.f), Static(false), Phantom(false), CalculateCenterOfMass(true), CenterOfMass(glm::vec3(0)), InitialLinearVelocity(glm::vec3(0)), InitialAngularVelocity(glm::vec3(0)), : Mass(1.f)
LinearDamping(0.f), AngularDamping(0.05f), GravityFactor(1.f), Friction(0.5f), Restitution(0.4f), MaxLinearVelocity(200.f), MaxAngularVelocity(200.f), //, Static(false)
CollisionLayer(0), CollisionSystemGroup(0), CollisionSubSystemId(0), CollisionSubSystemDontCollideWith(0), CollisionEvent(false){} , MotionType(MotionTypeEnum::Fixed)
, Phantom(false)
, CalculateCenterOfMass(true)
, CenterOfMass(glm::vec3(0))
, InitialLinearVelocity(glm::vec3(0))
, InitialAngularVelocity(glm::vec3(0))
, LinearDamping(0.f)
, AngularDamping(0.05f)
, GravityFactor(1.f)
, Friction(0.5f)
, Restitution(0.4f)
, MaxLinearVelocity(200.f)
, MaxAngularVelocity(200.f)
, CollisionLayer(0)
, CollisionSystemGroup(0)
, CollisionSubSystemId(0)
, CollisionSubSystemDontCollideWith(0)
, CollisionEvent(false)
{ }
float Mass; float Mass;
bool Static; MotionTypeEnum MotionType;
bool Phantom; bool Phantom;
bool CalculateCenterOfMass; bool CalculateCenterOfMass;
+3 -4
View File
@@ -10,10 +10,9 @@ namespace Components
struct Vehicle : Component struct Vehicle : Component
{ {
Vehicle() Vehicle()
: MaxTorque(1000.0f), MinRPM(0.0f), OptimalRPM(2000.0f), MaxRPM(3000.0f), MaxSteeringAngle(35), TopSpeed(70.0f), : MaxTorque(1000.0f), MinRPM(200.0f), OptimalRPM(3000.0f), MaxRPM(6000.0f), MaxSteeringAngle(35), TopSpeed(90.0f),
MaxSpeedFullSteeringAngle(40.0f), SpringDamping(1.f), UpshiftRPM(2500.0f), DownshiftRPM(500.0f), MaxSpeedFullSteeringAngle(40.0f), SpringDamping(1.f), UpshiftRPM(5500.0f), DownshiftRPM(1000.0f),
gearsRatio0(4.5f), gearsRatio1(2.5f), gearsRatio2(1.0f), gearsRatio3(0.5f){ } gearsRatio0(3.0f), gearsRatio1(2.25f), gearsRatio2(1.5f), gearsRatio3(1.0f){ }
//gearsRatio0(3.0f), gearsRatio1(2.25f), gearsRatio2(1.5f), gearsRatio3(1.0f)
float MaxTorque; float MaxTorque;
float MinRPM; float MinRPM;
float OptimalRPM; float OptimalRPM;
+20
View File
@@ -0,0 +1,20 @@
#ifndef Components_Wall_h__
#define Components_Wall_h__
#include "Component.h"
#include <string>
#include <vector>
namespace Components
{
struct Wall : Component
{
std::vector<EntityID> Walldebris;
virtual Wall* Clone() const override { return new Wall(*this); }
};
}
#endif // Components_TankShell_h__
+16
View File
@@ -0,0 +1,16 @@
#ifndef Events_OnDead_h__
#define Events_OnDead_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct OnDead : Event
{
EntityID Entity;
};
}
#endif // Events_OnDead_h__
+4
View File
@@ -132,7 +132,11 @@ public:
Rectangle AbsoluteRectangle() Rectangle AbsoluteRectangle()
{ {
int left = Left(); int left = Left();
if (m_Parent)
left = std::max(left, m_Parent->Left());
int top = Top(); int top = Top();
if (m_Parent)
top = std::max(top, m_Parent->Top());
int width = Right() - left; int width = Right() - left;
int height = Bottom() - top; int height = Bottom() - top;
return Rectangle(left, top, width, height); return Rectangle(left, top, width, height);
+3 -1
View File
@@ -26,12 +26,14 @@ public:
vp1->X = 0; vp1->X = 0;
vp1->Width = this->Width / 2.f; vp1->Width = this->Width / 2.f;
//new PlayerHUD(vp1, "PlayerHUD", m_World, 1); //new PlayerHUD(vp1, "PlayerHUD", m_World, 1);
auto vehicleSelection = new VehicleSelection(vp1, "VehicleSelection", m_World, 1); new VehicleSelection(vp1, "VehicleSelection", m_World, 1);
vp2 = new Viewport(worldFrame, "Viewport2", m_World); vp2 = new Viewport(worldFrame, "Viewport2", m_World);
vp2->X = vp1->Right(); vp2->X = vp1->Right();
vp2->Width = this->Width / 2.f; vp2->Width = this->Width / 2.f;
//new PlayerHUD(vp2, "PlayerHUD", m_World, 2); //new PlayerHUD(vp2, "PlayerHUD", m_World, 2);
new VehicleSelection(vp2, "VehicleSelection", m_World, 2);
m_FreeCamViewport = new Viewport(worldFrame, "ViewportFreeCam", m_World); m_FreeCamViewport = new Viewport(worldFrame, "ViewportFreeCam", m_World);
m_FreeCamViewport->Hide(); m_FreeCamViewport->Hide();
+728 -206
View File
File diff suppressed because it is too large Load Diff
+6 -1
View File
@@ -22,6 +22,7 @@
#include "Systems/DamageSystem.h" #include "Systems/DamageSystem.h"
#include "Systems/WheelPairSystem.h" #include "Systems/WheelPairSystem.h"
#include "Systems/FollowSystem.h" #include "Systems/FollowSystem.h"
#include "Systems/WallSystem.h"
#include "Systems/GarageSystem.h" #include "Systems/GarageSystem.h"
#include "Components/Camera.h" #include "Components/Camera.h"
@@ -77,10 +78,14 @@ private:
void BindGamepadAxis(Gamepad::Axis axis, std::string command, float value); void BindGamepadAxis(Gamepad::Axis axis, std::string command, float value);
void BindGamepadButton(Gamepad::Button button, std::string command, float value); void BindGamepadButton(Gamepad::Button button, std::string command, float value);
EntityID CreateTank(int playerID);
void CreateGate(glm::vec3 Position); void CreateGate(glm::vec3 Position);
void AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool steering); void AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool steering);
EntityID CreateJeep(int playerID); EntityID CreateJeep(int playerID);
EntityID CreateWall(glm::vec3 pos, glm::quat orientation);
EntityID CreateGarage(glm::vec3 Position, glm::quat orientation, int playerID);
void CreateTerrain();
void CreateBase(glm::quat orientation);
std::vector<EntityID> m_WallDebrisTemplates;
}; };
#endif // GameWorld_h__ #endif // GameWorld_h__
+1 -1
View File
@@ -93,7 +93,7 @@ Model::Model(std::shared_ptr<ResourceManager> rm, OBJ &obj)
if (Vertices.size() > 0) if (Vertices.size() > 0)
{ {
CreateTangents(); CreateTangents();
getSimilarVertexIndex(); //getSimilarVertexIndex();
CreateBuffers(Vertices, Normals, TangentNormals, BiTangentNormals, TextureCoords); CreateBuffers(Vertices, Normals, TangentNormals, BiTangentNormals, TextureCoords);
} }
else else
+16 -17
View File
@@ -276,6 +276,7 @@ void Renderer::DrawFrame(RenderQueuePair &rq)
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glClearColor(0.0f, 0.5f, 0.0f, 1.0f); //glClearColor(0.0f, 0.5f, 0.0f, 1.0f);
glEnable(GL_SCISSOR_TEST);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glCullFace(GL_BACK); glCullFace(GL_BACK);
@@ -377,9 +378,9 @@ void Renderer::DrawWorld(RenderQueuePair &rq)
for(auto job : rq.Forward) for(auto job : rq.Forward)
{ {
glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height); glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height);
glm::mat4 cameraMatrix = cameraProjection * m_Camera->ViewMatrix(); glm::mat4 cameraMatrix = m_Camera->ViewMatrix();
glm::vec3 spritePos = glm::vec3(cameraMatrix * job->ModelMatrix * glm::vec4(1, 1, 1, 0)); glm::vec3 spritePos = glm::vec3((cameraMatrix * job->ModelMatrix) * glm::vec4(1, 1, 1, 1));
job->Depth = spritePos.z; job->Depth = spritePos.z;
} }
rq.Forward.Jobs.sort(Renderer::DepthSort); rq.Forward.Jobs.sort(Renderer::DepthSort);
@@ -389,7 +390,7 @@ void Renderer::DrawWorld(RenderQueuePair &rq)
/* /*
Base pass Base pass
*/ */
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass);
glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glScissor(m_Scissor.X, m_Height - m_Scissor.Y - m_Scissor.Height, m_Scissor.Width, m_Scissor.Height); glScissor(m_Scissor.X, m_Height - m_Scissor.Y - m_Scissor.Height, m_Scissor.Width, m_Scissor.Height);
//glViewport(0, 0, m_Width, m_Height); //glViewport(0, 0, m_Width, m_Height);
@@ -475,10 +476,10 @@ void Renderer::ForwardRendering(RenderQueue &rq)
glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
// Clear G-buffer // Clear G-buffer
GLenum attachments[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 }; GLenum attachments[] = { GL_COLOR_ATTACHMENT0, GL_NONE , GL_NONE , GL_NONE };
glDrawBuffers(4, attachments); glDrawBuffers(4, attachments);
glClearColor(0.f, 0.f, 0.f, 0.f); //glClearColor(0.f, 0.f, 0.f, 1.f);
glClear(GL_COLOR_BUFFER_BIT); //glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -512,23 +513,21 @@ void Renderer::ForwardRendering(RenderQueue &rq)
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture); glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture);
if (modelJob->NormalTexture != 0) /*if (modelJob->NormalTexture != 0)
{ {
glActiveTexture(GL_TEXTURE2); glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture); glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture);
} }
if (modelJob->SpecularTexture) if (modelJob->SpecularTexture)
{ {
glActiveTexture(GL_TEXTURE3); glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture); glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture);
} }*/
glDrawArrays(GL_TRIANGLES, modelJob->StartIndex, modelJob->EndIndex - modelJob->StartIndex + 1); glDrawArrays(GL_TRIANGLES, modelJob->StartIndex, modelJob->EndIndex - modelJob->StartIndex + 1);
continue; continue;
} }
auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job); auto spriteJob = std::dynamic_pointer_cast<SpriteJob>(job);
if (spriteJob) if (spriteJob)
{ {
@@ -559,9 +558,9 @@ void Renderer::ForwardRendering(RenderQueue &rq)
glViewport(0, 0, m_Width, m_Height); glViewport(0, 0, m_Width, m_Height);
glScissor(0, 0, m_Width, m_Height); glScissor(0, 0, m_Width, m_Height);
glDepthMask(GL_FALSE);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND); glDisable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
m_FinalForwardPassProgram.Bind(); m_FinalForwardPassProgram.Bind();
//ShaderProgramHandle = m_FinalForwardPassProgram.GetHandle(); //ShaderProgramHandle = m_FinalForwardPassProgram.GetHandle();
@@ -947,7 +946,7 @@ void Renderer::FrameBufferTextures()
//Generate and bind diffuse texture //Generate and bind diffuse texture
glGenTextures(1, &m_fDiffuseTexture); glGenTextures(1, &m_fDiffuseTexture);
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture); glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+1 -1
View File
@@ -219,7 +219,7 @@ private:
void CreateNormalMapTangent(); void CreateNormalMapTangent();
void ForwardRendering(RenderQueue &rq); void ForwardRendering(RenderQueue &rq);
static bool DepthSort(const std::shared_ptr<RenderJob> &i, const std::shared_ptr<RenderJob> &j) { return (i->Depth > j->Depth); } static bool DepthSort(const std::shared_ptr<RenderJob> &i, const std::shared_ptr<RenderJob> &j) { return (i->Depth < j->Depth); }
GLuint CreateQuad(); GLuint CreateQuad();
void DrawDebugShadowMap(); void DrawDebugShadowMap();
+8 -1
View File
@@ -1,7 +1,6 @@
#include "PrecompiledHeader.h" #include "PrecompiledHeader.h"
#include "DamageSystem.h" #include "DamageSystem.h"
#include "World.h" #include "World.h"
void Systems::DamageSystem::RegisterComponents( ComponentFactory* cf ) void Systems::DamageSystem::RegisterComponents( ComponentFactory* cf )
{ {
cf->Register<Components::Health>([]() { return new Components::Health(); }); cf->Register<Components::Health>([]() { return new Components::Health(); });
@@ -15,8 +14,16 @@ void Systems::DamageSystem::Initialize()
bool Systems::DamageSystem::OnDamage( const Events::Damage &event ) bool Systems::DamageSystem::OnDamage( const Events::Damage &event )
{ {
if(!m_World->ValidEntity(event.Entity))
return false;
auto health = m_World->GetComponent<Components::Health>(event.Entity); auto health = m_World->GetComponent<Components::Health>(event.Entity);
health->Amount -= event.Amount; health->Amount -= event.Amount;
if(health->Amount <= 0)
{
Events::OnDead e;
e.Entity = event.Entity;
EventBroker->Publish(e);
}
LOG_INFO("Damaged entity %i, Health left: %f", event.Entity, health->Amount); LOG_INFO("Damaged entity %i, Health left: %f", event.Entity, health->Amount);
return true; return true;
} }
+1
View File
@@ -5,6 +5,7 @@
#include "System.h" #include "System.h"
#include "Components/Health.h" #include "Components/Health.h"
#include "Events/Damage.h" #include "Events/Damage.h"
#include "Events/OnDead.h"
namespace Systems namespace Systems
{ {
+41 -10
View File
@@ -80,7 +80,7 @@ void Systems::PhysicsSystem::Initialize()
worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_FIX_ENTITY; worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_FIX_ENTITY;
// You must specify the size of the broad phase - objects should not be simulated outside this region // You must specify the size of the broad phase - objects should not be simulated outside this region
worldInfo.setBroadPhaseWorldSize(1500.0f); worldInfo.setBroadPhaseWorldSize(1000.0f);
m_PhysicsWorld = new hkpWorld(worldInfo); m_PhysicsWorld = new hkpWorld(worldInfo);
// When the simulation type is SIMULATION_TYPE_MULTITHREADED, in the debug build, the sdk performs checks // When the simulation type is SIMULATION_TYPE_MULTITHREADED, in the debug build, the sdk performs checks
@@ -151,6 +151,10 @@ void Systems::PhysicsSystem::Update(double dt)
EntityID entity = pair.first; EntityID entity = pair.first;
EntityID parent = pair.second; EntityID parent = pair.second;
auto templateComponent = m_World->GetComponent<Components::Template>(entity);
if(templateComponent)
continue;
if (m_RigidBodies.find(entity) == m_RigidBodies.end()) if (m_RigidBodies.find(entity) == m_RigidBodies.end())
continue; continue;
@@ -218,6 +222,10 @@ void Systems::PhysicsSystem::Update(double dt)
void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
{ {
auto templateComponent = m_World->GetComponent<Components::Template>(entity);
if(templateComponent)
return;
auto transformComponent = m_World->GetComponent<Components::Transform>(entity); auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
if (!transformComponent) if (!transformComponent)
return; return;
@@ -229,6 +237,19 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
if(m_Vehicles.find(car) != m_Vehicles.end()) if(m_Vehicles.find(car) != m_Vehicles.end())
{ {
m_PhysicsWorld->markForWrite(); m_PhysicsWorld->markForWrite();
/*auto player = m_World->GetComponent<Components::Player>(car);
if(player)
{
if(player->ID == 1)
{
LOG_INFO("Speed: %f, Gear: %i, RPM: %f", m_Vehicles[car]->calcKMPH(), m_Vehicles[car]->m_currentGear, m_Vehicles[car]->m_rpm);
}
}*/
m_Vehicles[car]->getChassis()->activate(); m_Vehicles[car]->getChassis()->activate();
hkVector4 hardPoint = m_Vehicles[car]->m_suspension->m_wheelParams[wheelComponent->ID].m_hardpointChassisSpace; hkVector4 hardPoint = m_Vehicles[car]->m_suspension->m_wheelParams[wheelComponent->ID].m_hardpointChassisSpace;
@@ -297,14 +318,14 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity); auto physicsComponent = m_World->GetComponent<Components::Physics>(entity);
if (physicsComponent && m_Shapes[entity].size() > 0) if (physicsComponent && m_Shapes[entity].size() > 0)
{ {
if(entityParent != 0 && !physicsComponent->Static) if(entityParent != 0 && physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Dynamic)
{ {
LOG_ERROR("Entity: %i, Only the baseparent can have a dynamic PhysicsComponent", entity); LOG_ERROR("Entity: %i, Only the baseparent can have a dynamic PhysicsComponent", entity);
return; return;
} }
hkpShape* shape; hkpShape* shape;
if(! physicsComponent->Static) // Not static if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Dynamic)
{ {
hkArray<hkpShape*> shapeArray; hkArray<hkpShape*> shapeArray;
for (auto &shapeData : m_Shapes[entity]) for (auto &shapeData : m_Shapes[entity])
@@ -368,6 +389,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor; rigidBodyInfo.m_inertiaTensor = massProperties.m_inertiaTensor;
if(physicsComponent->CalculateCenterOfMass) if(physicsComponent->CalculateCenterOfMass)
physicsComponent->CenterOfMass = HKVECTOR4_TO_GLMVEC3(massProperties.m_centerOfMass); physicsComponent->CenterOfMass = HKVECTOR4_TO_GLMVEC3(massProperties.m_centerOfMass);
rigidBodyInfo.m_centerOfMass = GLMVEC3_TO_HKVECTOR4(physicsComponent->CenterOfMass); rigidBodyInfo.m_centerOfMass = GLMVEC3_TO_HKVECTOR4(physicsComponent->CenterOfMass);
rigidBodyInfo.m_mass = massProperties.m_mass; rigidBodyInfo.m_mass = massProperties.m_mass;
rigidBodyInfo.m_linearVelocity = GLMVEC3_TO_HKVECTOR4(physicsComponent->InitialLinearVelocity); rigidBodyInfo.m_linearVelocity = GLMVEC3_TO_HKVECTOR4(physicsComponent->InitialLinearVelocity);
@@ -381,7 +403,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
rigidBodyInfo.m_maxLinearVelocity = physicsComponent->MaxLinearVelocity; rigidBodyInfo.m_maxLinearVelocity = physicsComponent->MaxLinearVelocity;
rigidBodyInfo.m_maxAngularVelocity = physicsComponent->MaxAngularVelocity; rigidBodyInfo.m_maxAngularVelocity = physicsComponent->MaxAngularVelocity;
rigidBodyInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(physicsComponent->CollisionLayer, physicsComponent->CollisionSystemGroup, physicsComponent->CollisionSubSystemId, physicsComponent->CollisionSubSystemDontCollideWith); rigidBodyInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(physicsComponent->CollisionLayer, physicsComponent->CollisionSystemGroup, physicsComponent->CollisionSubSystemId, physicsComponent->CollisionSubSystemDontCollideWith);
rigidBodyInfo.m_enableDeactivation = false; rigidBodyInfo.m_enableDeactivation = true;;
} }
// Create RigidBody // Create RigidBody
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo); hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
@@ -400,7 +422,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
} }
} }
VehicleSetup vehicleSetup; VehicleSetup vehicleSetup;
// Create the basic vehicle. // Create the basic vehicle.
m_Vehicles[entity] = new hkpVehicleInstance(m_RigidBodies[entity]); m_Vehicles[entity] = new hkpVehicleInstance(m_RigidBodies[entity]);
@@ -438,7 +459,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
rigidBody->removeReference(); rigidBody->removeReference();
} }
} }
else // Static else if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Fixed || physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Keyframed)
{ {
// Create the hkpStaticCompoundShape and add the instances. // Create the hkpStaticCompoundShape and add the instances.
// "meshShape" should not be modified by the user in any way after adding it as an instance. // "meshShape" should not be modified by the user in any way after adding it as an instance.
@@ -490,7 +511,15 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
hkpRigidBodyCinfo rigidBodyInfo; hkpRigidBodyCinfo rigidBodyInfo;
{ {
rigidBodyInfo.m_shape = shape; rigidBodyInfo.m_shape = shape;
rigidBodyInfo.m_motionType = hkpMotion::MOTION_KEYFRAMED; if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Fixed)
{
rigidBodyInfo.m_motionType = hkpMotion::MOTION_FIXED;
}
else if(physicsComponent->MotionType == Components::Physics::MotionTypeEnum::Keyframed)
{
rigidBodyInfo.m_motionType = hkpMotion::MOTION_KEYFRAMED;
}
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity); auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
hkVector4 position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position); hkVector4 position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position);
hkQuaternion rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation); hkQuaternion rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation);
@@ -513,7 +542,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
rigidBodyInfo.m_maxLinearVelocity = physicsComponent->MaxLinearVelocity; rigidBodyInfo.m_maxLinearVelocity = physicsComponent->MaxLinearVelocity;
rigidBodyInfo.m_maxAngularVelocity = physicsComponent->MaxAngularVelocity; rigidBodyInfo.m_maxAngularVelocity = physicsComponent->MaxAngularVelocity;
rigidBodyInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(physicsComponent->CollisionLayer, physicsComponent->CollisionSystemGroup, physicsComponent->CollisionSubSystemId, physicsComponent->CollisionSubSystemDontCollideWith); rigidBodyInfo.m_collisionFilterInfo = hkpGroupFilter::calcFilterInfo(physicsComponent->CollisionLayer, physicsComponent->CollisionSystemGroup, physicsComponent->CollisionSubSystemId, physicsComponent->CollisionSubSystemDontCollideWith);
rigidBodyInfo.m_enableDeactivation = false; rigidBodyInfo.m_enableDeactivation = true;
} }
// Create RigidBody // Create RigidBody
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo); hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
@@ -621,6 +650,8 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
std::vector<hkReal>* vertices = new std::vector<hkReal>; std::vector<hkReal>* vertices = new std::vector<hkReal>;
std::vector<hkUint16>* vertexIndices = new std::vector<hkUint16>; std::vector<hkUint16>* vertexIndices = new std::vector<hkUint16>;
auto meshShape = ResourceManager->Load<OBJ>("OBJ", meshShapeComponent->ResourceName); auto meshShape = ResourceManager->Load<OBJ>("OBJ", meshShapeComponent->ResourceName);
if(!meshShape)
return;
for (auto &vertex : meshShape->Vertices) for (auto &vertex : meshShape->Vertices)
{ {
@@ -732,7 +763,7 @@ bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event)
} }
else else
{ {
deviceStatus->m_positionX = steeringX; deviceStatus->m_positionX = event.PositionX;
deviceStatus->m_positionY = event.PositionY; deviceStatus->m_positionY = event.PositionY;
} }
@@ -752,6 +783,7 @@ bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event )
{ {
m_PhysicsWorld->markForWrite(); m_PhysicsWorld->markForWrite();
m_RigidBodies[event.Entity]->activate();
m_RigidBodies[event.Entity]->setLinearVelocity(GLMVEC3_TO_HKVECTOR4(event.Velocity)); m_RigidBodies[event.Entity]->setLinearVelocity(GLMVEC3_TO_HKVECTOR4(event.Velocity));
auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity); auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
transformComponent->Velocity = event.Velocity; transformComponent->Velocity = event.Velocity;
@@ -795,7 +827,6 @@ void Systems::PhysicsSystem::OnComponentRemoved(EntityID entity, std::string typ
m_RigidBodies.erase(entity); m_RigidBodies.erase(entity);
m_PhysicsWorld->unmarkForWrite(); m_PhysicsWorld->unmarkForWrite();
} }
} }
+1
View File
@@ -23,6 +23,7 @@
#include "Components/HingeConstraint.h" #include "Components/HingeConstraint.h"
#include "Components/WheelPair.h" #include "Components/WheelPair.h"
#include "Components/TowerSteering.h" #include "Components/TowerSteering.h"
#include "Components/Player.h"
#include "Events/TankSteer.h" #include "Events/TankSteer.h"
#include "Events/SetVelocity.h" #include "Events/SetVelocity.h"
#include "Events/ApplyForce.h" #include "Events/ApplyForce.h"
+11 -4
View File
@@ -139,6 +139,9 @@ bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e)
return false; return false;
} }
if(m_World->GetComponent<Components::Template>(shellEntity))
return false;
auto physicsComponents = m_World->GetComponentsOfType<Components::Physics>(); auto physicsComponents = m_World->GetComponentsOfType<Components::Physics>();
auto shellTransform = m_World->GetComponent<Components::Transform>(shellEntity); auto shellTransform = m_World->GetComponent<Components::Transform>(shellEntity);
//auto otherTransform = m_World->GetComponent<Components::Transform>(otherEntity); //auto otherTransform = m_World->GetComponent<Components::Transform>(otherEntity);
@@ -205,8 +208,6 @@ bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e)
EventBroker->Publish(d); EventBroker->Publish(d);
} }
m_World->RemoveEntity(shellEntity); m_World->RemoveEntity(shellEntity);
} }
} }
@@ -293,6 +294,12 @@ bool Systems::TankSteeringSystem::OnSpawnVehicle(const Events::SpawnVehicle &eve
return false; return false;
auto spawnPointComponents = m_World->GetComponentsOfType<Components::SpawnPoint>(); auto spawnPointComponents = m_World->GetComponentsOfType<Components::SpawnPoint>();
if (!spawnPointComponents)
{
LOG_ERROR("Found no spawn points!");
return false;
}
for (auto &spawnPointComponent : *spawnPointComponents) for (auto &spawnPointComponent : *spawnPointComponents)
{ {
auto spawnPoint = spawnPointComponent->Entity; auto spawnPoint = spawnPointComponent->Entity;
@@ -329,7 +336,7 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID)
//transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0)); //transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0));
auto physics = m_World->AddComponent<Components::Physics>(tank); auto physics = m_World->AddComponent<Components::Physics>(tank);
physics->Mass = 63000 - 16000; physics->Mass = 63000 - 16000;
physics->Static = false; physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic;
auto vehicle = m_World->AddComponent<Components::Vehicle>(tank); auto vehicle = m_World->AddComponent<Components::Vehicle>(tank);
vehicle->MaxTorque = 8000.f; vehicle->MaxTorque = 8000.f;
vehicle->MaxSteeringAngle = 90.f; vehicle->MaxSteeringAngle = 90.f;
@@ -397,7 +404,7 @@ EntityID Systems::TankSteeringSystem::CreateTank(int playerID)
m_World->AddComponent<Components::Template>(shot); m_World->AddComponent<Components::Template>(shot);
auto physics = m_World->AddComponent<Components::Physics>(shot); auto physics = m_World->AddComponent<Components::Physics>(shot);
physics->Mass = 25.f; physics->Mass = 25.f;
physics->Static = false; physics->MotionType = Components::Physics::MotionTypeEnum::Dynamic;
physics->CollisionEvent = true; physics->CollisionEvent = true;
auto modelComponent = m_World->AddComponent<Components::Model>(shot); auto modelComponent = m_World->AddComponent<Components::Model>(shot);
modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj"; modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj";
+56
View File
@@ -0,0 +1,56 @@
#include "PrecompiledHeader.h"
#include "WallSystem.h"
#include "World.h"
void Systems::WallSystem::RegisterComponents( ComponentFactory* cf )
{
cf->Register<Components::Wall>([]() { return new Components::Wall(); });
}
void Systems::WallSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_eDamage, &Systems::WallSystem::Damage);
}
bool Systems::WallSystem::Damage( const Events::Damage &event )
{
auto wallComponent = m_World->GetComponent<Components::Wall>(event.Entity);
if(!wallComponent)
{
return false;
}
LOG_INFO("WallSystem::Damage");
auto wallhealthcomponent = m_World->GetComponent<Components::Health>(event.Entity);
if(wallhealthcomponent->Amount > 0)
{
return false;
}
LOG_INFO("You are dead");
auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
for(auto d : wallComponent->Walldebris)
{
auto debris = m_World->CloneEntity(d);
auto transform = m_World->GetComponent<Components::Transform>(debris);
transform->Position += transformComponent->Position;
// DO STUFF! :D
float distance = glm::distance(transform->Position, transformComponent->Position);
float radius = 5.f;
float strength = (1.f - pow(distance / radius, 2)) * 500.f;
glm::vec3 direction = glm::normalize(transformComponent->Position - transform->Position);
Events::ApplyPointImpulse e;
e.Entity = debris;
e.Impulse = direction * strength;
e.Position = transformComponent->Position;
EventBroker->Publish(e);
}
m_World->RemoveEntity(event.Entity);
return true;
}
+42
View File
@@ -0,0 +1,42 @@
#ifndef WallSystem_h__
#define WallSystem_h__
#include "System.h"
#include "Events/OnDead.h"
#include "Events/Damage.h"
#include "Events/ApplyPointImpulse.h"
#include "Components/Model.h"
#include "Components/Wall.h"
#include "Components/Transform.h"
#include "Components/Physics.h"
#include "Components/MeshShape.h"
#include "Components/Tankshell.h"
#include "Components/Health.h"
namespace Systems
{
class WallSystem : public System
{
public:
WallSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
: System(world, eventBroker, resourceManager) { }
void Initialize() override;
void RegisterComponents(ComponentFactory* cf) override;
EventRelay<WallSystem, Events::Damage> m_eDamage;
bool Damage(const Events::Damage &event);
private:
};
}
#endif // WallSystem_h__
+4
View File
@@ -124,6 +124,7 @@
<ClCompile Include="..\..\src\Systems\TimerSystem.cpp" /> <ClCompile Include="..\..\src\Systems\TimerSystem.cpp" />
<ClCompile Include="..\..\src\Systems\TransformSystem.cpp" /> <ClCompile Include="..\..\src\Systems\TransformSystem.cpp" />
<ClCompile Include="..\..\src\Systems\TriggerSystem.cpp" /> <ClCompile Include="..\..\src\Systems\TriggerSystem.cpp" />
<ClCompile Include="..\..\src\Systems\WallSystem.cpp" />
<ClCompile Include="..\..\src\Systems\WheelPairSystem.cpp" /> <ClCompile Include="..\..\src\Systems\WheelPairSystem.cpp" />
<ClCompile Include="..\..\src\Texture.cpp" /> <ClCompile Include="..\..\src\Texture.cpp" />
<ClCompile Include="..\..\src\World.cpp" /> <ClCompile Include="..\..\src\World.cpp" />
@@ -173,6 +174,7 @@
<ClInclude Include="..\..\src\Components\Vehicle.h" /> <ClInclude Include="..\..\src\Components\Vehicle.h" />
<ClInclude Include="..\..\src\Components\SpawnPoint.h" /> <ClInclude Include="..\..\src\Components\SpawnPoint.h" />
<ClInclude Include="..\..\src\Components\Viewport.h" /> <ClInclude Include="..\..\src\Components\Viewport.h" />
<ClInclude Include="..\..\src\Components\Wall.h" />
<ClInclude Include="..\..\src\Components\Wheel.h" /> <ClInclude Include="..\..\src\Components\Wheel.h" />
<ClInclude Include="..\..\src\Components\WheelPair.h" /> <ClInclude Include="..\..\src\Components\WheelPair.h" />
<ClInclude Include="..\..\src\CubemapTexture.h" /> <ClInclude Include="..\..\src\CubemapTexture.h" />
@@ -200,6 +202,7 @@
<ClInclude Include="..\..\src\Events\MouseMove.h" /> <ClInclude Include="..\..\src\Events\MouseMove.h" />
<ClInclude Include="..\..\src\Events\MousePress.h" /> <ClInclude Include="..\..\src\Events\MousePress.h" />
<ClInclude Include="..\..\src\Events\MouseRelease.h" /> <ClInclude Include="..\..\src\Events\MouseRelease.h" />
<ClInclude Include="..\..\src\Events\OnDead.h" />
<ClInclude Include="..\..\src\Events\Move.h" /> <ClInclude Include="..\..\src\Events\Move.h" />
<ClInclude Include="..\..\src\Events\PlayBGM.h" /> <ClInclude Include="..\..\src\Events\PlayBGM.h" />
<ClInclude Include="..\..\src\Events\PlaySFX.h" /> <ClInclude Include="..\..\src\Events\PlaySFX.h" />
@@ -249,6 +252,7 @@
<ClInclude Include="..\..\src\Systems\TimerSystem.h" /> <ClInclude Include="..\..\src\Systems\TimerSystem.h" />
<ClInclude Include="..\..\src\Systems\TransformSystem.h" /> <ClInclude Include="..\..\src\Systems\TransformSystem.h" />
<ClInclude Include="..\..\src\Systems\TriggerSystem.h" /> <ClInclude Include="..\..\src\Systems\TriggerSystem.h" />
<ClInclude Include="..\..\src\Systems\WallSystem.h" />
<ClInclude Include="..\..\src\Systems\WheelPairSystem.h" /> <ClInclude Include="..\..\src\Systems\WheelPairSystem.h" />
<ClInclude Include="..\..\src\Texture.h" /> <ClInclude Include="..\..\src\Texture.h" />
<ClInclude Include="..\..\src\Util\GLError.h" /> <ClInclude Include="..\..\src\Util\GLError.h" />
+13 -2
View File
@@ -78,6 +78,9 @@
<ClCompile Include="..\..\src\Systems\FollowSystem.cpp"> <ClCompile Include="..\..\src\Systems\FollowSystem.cpp">
<Filter>Game\Systems</Filter> <Filter>Game\Systems</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\Systems\WallSystem.cpp">
<Filter>Gameplay\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\GarageSystem.cpp"> <ClCompile Include="..\..\src\Systems\GarageSystem.cpp">
<Filter>Game\Systems</Filter> <Filter>Game\Systems</Filter>
</ClCompile> </ClCompile>
@@ -516,11 +519,13 @@
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\Events\Move.h"> <ClInclude Include="..\..\src\Events\Move.h">
<Filter>Base\Events</Filter> <Filter>Base\Events</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\Components\BlendMap.h"> <ClInclude Include="..\..\src\Components\BlendMap.h">
<Filter>Rendering\Components</Filter> <Filter>Rendering\Components</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\Systems\WallSystem.h">
<Filter>Gameplay\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\LeaveTrigger.h"> <ClInclude Include="..\..\src\Events\LeaveTrigger.h">
<Filter>Physics\Events</Filter> <Filter>Physics\Events</Filter>
</ClInclude> </ClInclude>
@@ -554,9 +559,15 @@
<ClInclude Include="..\..\src\GUI\VehicleSelection.h"> <ClInclude Include="..\..\src\GUI\VehicleSelection.h">
<Filter>GUI</Filter> <Filter>GUI</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\Events\OnDead.h">
<Filter>Gameplay\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\SpawnVehicle.h"> <ClInclude Include="..\..\src\Events\SpawnVehicle.h">
<Filter>Game\Events</Filter> <Filter>Game\Events</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\Components\Wall.h">
<Filter>Game\Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\SpawnPoint.h"> <ClInclude Include="..\..\src\Components\SpawnPoint.h">
<Filter>Game\Components</Filter> <Filter>Game\Components</Filter>
</ClInclude> </ClInclude>