Fuckhack
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
#ifndef Events_Collision_h__
|
||||
#define Events_Collision_h__
|
||||
|
||||
#include "Entity.h"
|
||||
#include "EventBroker.h"
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
struct Collision : Event
|
||||
{
|
||||
EntityID Entity1;
|
||||
EntityID Entity2;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // Events_Collision_h__
|
||||
+2
-2
@@ -335,7 +335,7 @@ void GameWorld::Initialize()
|
||||
auto cameraTower = CreateEntity(tower);
|
||||
{
|
||||
auto transform = AddComponent<Components::Transform>(cameraTower);
|
||||
transform->Position.z = 11.f;
|
||||
transform->Position.z = 14.f;
|
||||
transform->Position.y = 4.f;
|
||||
//transform->Orientation = glm::quat(glm::vec3(glm::pi<float>() / 8.f, 0.f, 0.f));
|
||||
auto cameraComp = AddComponent<Components::Camera>(cameraTower);
|
||||
@@ -754,7 +754,7 @@ void GameWorld::Initialize()
|
||||
auto cameraTower = CreateEntity(tower);
|
||||
{
|
||||
auto transform = AddComponent<Components::Transform>(cameraTower);
|
||||
transform->Position.z = 11.f;
|
||||
transform->Position.z = 14.f;
|
||||
transform->Position.y = 4.f;
|
||||
//transform->Orientation = glm::quat(glm::vec3(glm::pi<float>() / 8.f, 0.f, 0.f));
|
||||
auto cameraComp = AddComponent<Components::Camera>(cameraTower);
|
||||
|
||||
+15
-14
@@ -357,18 +357,7 @@ void Renderer::AddTextureToDraw(Texture* texture, glm::vec3 position, glm::quat
|
||||
{
|
||||
glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
|
||||
|
||||
glm::vec3 camToParticle = glm::normalize(m_Camera->Position() - position);
|
||||
glm::vec3 up = glm::vec3(0,1,0);
|
||||
glm::vec3 rightVec = glm::normalize(glm::cross(up, camToParticle));
|
||||
glm::vec3 up2 = glm::normalize(glm::cross(camToParticle, rightVec));
|
||||
|
||||
glm::mat4 billboardMatrix;
|
||||
billboardMatrix[0] = glm::vec4(rightVec, 0);
|
||||
billboardMatrix[1] = glm::vec4(up2, 0);
|
||||
billboardMatrix[2] = glm::vec4(camToParticle, 0);
|
||||
//billboardMatrix[3] = glm::vec4(position, 0);
|
||||
|
||||
TexturesToRender.push_back(std::make_tuple(texture, modelMatrix, billboardMatrix));
|
||||
TexturesToRender.push_back(std::make_tuple(texture, modelMatrix, position));
|
||||
}
|
||||
|
||||
void Renderer::AddPointLightToDraw(
|
||||
@@ -770,10 +759,22 @@ void Renderer::DrawFBOScene(Viewport &viewport)
|
||||
{
|
||||
Texture* texture;
|
||||
glm::mat4 modelMatrix;
|
||||
glm::mat4 billboardMatrix;
|
||||
std::tie(texture, modelMatrix, billboardMatrix) = tuple;
|
||||
glm::vec3 position;
|
||||
std::tie(texture, modelMatrix, position) = tuple;
|
||||
|
||||
//MVP = cameraMatrix * glm::inverse(glm::toMat4(m_Camera->Orientation()) * modelMatrix );
|
||||
|
||||
glm::vec3 camToParticle = glm::normalize(viewport.Camera->Position() - position);
|
||||
glm::vec3 up = glm::vec3(0,1,0);
|
||||
glm::vec3 rightVec = glm::normalize(glm::cross(up, camToParticle));
|
||||
glm::vec3 up2 = glm::normalize(glm::cross(camToParticle, rightVec));
|
||||
|
||||
glm::mat4 billboardMatrix;
|
||||
billboardMatrix[0] = glm::vec4(rightVec, 0);
|
||||
billboardMatrix[1] = glm::vec4(up2, 0);
|
||||
billboardMatrix[2] = glm::vec4(camToParticle, 0);
|
||||
//billboardMatrix[3] = glm::vec4(position, 0);
|
||||
|
||||
MVP = cameraMatrix * modelMatrix * billboardMatrix;
|
||||
|
||||
depthMVP = depthCameraMatrix * modelMatrix;
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ public:
|
||||
int Height() const { return m_Height; }
|
||||
|
||||
std::list<std::tuple<Model*, glm::mat4, bool, bool>> ModelsToRender;
|
||||
std::list<std::tuple<Texture*, glm::mat4, glm::mat4>> TexturesToRender;
|
||||
std::list<std::tuple<Texture*, glm::mat4, glm::vec3>> TexturesToRender;
|
||||
std::list<std::tuple<glm::mat4, bool>> AABBsToRender;
|
||||
|
||||
Renderer();
|
||||
|
||||
@@ -40,7 +40,7 @@ void main()
|
||||
{
|
||||
|
||||
// Diffuse Texture
|
||||
frag_Diffuse = texture(DiffuseTexture, Input.TextureCoord) * Shadow(Input.ShadowCoord);
|
||||
frag_Diffuse = texture(DiffuseTexture, Input.TextureCoord); // * Shadow(Input.ShadowCoord);
|
||||
|
||||
// G-buffer Position
|
||||
frag_Position = vec4(Input.Position.xyz, 1.0);
|
||||
|
||||
@@ -33,6 +33,7 @@ public:
|
||||
virtual void OnComponentRemoved(std::string type, Component* component) { }
|
||||
// Called when components are committed to an entity
|
||||
virtual void OnEntityCommit(EntityID entity) { }
|
||||
virtual void OnEntityRemoved(EntityID entity) { }
|
||||
|
||||
protected:
|
||||
World* m_World;
|
||||
|
||||
@@ -78,7 +78,7 @@ void Systems::PhysicsSystem::Initialize()
|
||||
worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_DO_NOTHING;
|
||||
|
||||
// You must specify the size of the broad phase - objects should not be simulated outside this region
|
||||
worldInfo.setBroadPhaseWorldSize(1000.0f);
|
||||
worldInfo.setBroadPhaseWorldSize(1500.0f);
|
||||
m_PhysicsWorld = new hkpWorld(worldInfo);
|
||||
|
||||
// When the simulation type is SIMULATION_TYPE_MULTITHREADED, in the debug build, the sdk performs checks
|
||||
@@ -107,7 +107,7 @@ void Systems::PhysicsSystem::Initialize()
|
||||
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
|
||||
m_collisionResolution = new MyCollisionResolution;
|
||||
m_collisionResolution = new MyCollisionResolution(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -326,7 +326,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
rigidBody->addContactListener( m_collisionResolution );
|
||||
m_Vehicles[entity]->addToWorld(m_PhysicsWorld);
|
||||
m_RigidBodies[entity] = rigidBody;
|
||||
m_collisionResolution->m_RigidBodies[rigidBody] = entity;
|
||||
m_RigidBodyEntities[rigidBody] = entity;
|
||||
|
||||
|
||||
// The vehicle is an action
|
||||
@@ -344,7 +344,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
rigidBody->addContactListener( m_collisionResolution );
|
||||
m_PhysicsWorld->addEntity(rigidBody);
|
||||
m_RigidBodies[entity] = rigidBody;
|
||||
m_collisionResolution->m_RigidBodies[rigidBody] = entity;
|
||||
m_RigidBodyEntities[rigidBody] = entity;
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
|
||||
shape->removeReference();
|
||||
@@ -397,7 +397,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_PhysicsWorld->addEntity(rigidBody);
|
||||
m_RigidBodies[entity] = rigidBody;
|
||||
m_collisionResolution->m_RigidBodies[rigidBody] = entity;
|
||||
m_RigidBodyEntities[rigidBody] = entity;
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
|
||||
shape->removeReference();
|
||||
@@ -577,3 +577,17 @@ bool Systems::PhysicsSystem::OnApplyPointImpulse( const Events::ApplyPointImpuls
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::OnEntityRemoved( EntityID entity )
|
||||
{
|
||||
// TODO:
|
||||
/*auto rigidBodyIt = m_RigidBodies.find(entity);
|
||||
if (rigidBodyIt == m_RigidBodies.end())
|
||||
return;
|
||||
|
||||
auto rigidBody = rigidBodyIt->second;
|
||||
m_RigidBodies.erase(entity);
|
||||
m_RigidBodyEntities.erase(rigidBody);
|
||||
rigidBody->removeReference();*/
|
||||
|
||||
}
|
||||
|
||||
+38
-17
@@ -27,6 +27,7 @@
|
||||
#include "Events/SetVelocity.h"
|
||||
#include "Events/ApplyForce.h"
|
||||
#include "Events/ApplyPointImpulse.h"
|
||||
#include "Events/Collision.h"
|
||||
#include "OBJ.h"
|
||||
|
||||
// Math and base include
|
||||
@@ -75,27 +76,45 @@
|
||||
|
||||
#include <Physics2012/Dynamics/Collide/ContactListener/hkpContactListener.h>
|
||||
|
||||
class MyCollisionResolution: public hkReferencedObject, public hkpContactListener
|
||||
{
|
||||
public:
|
||||
std::unordered_map<hkpRigidBody*, EntityID> m_RigidBodies;
|
||||
|
||||
virtual void contactPointCallback( const hkpContactPointEvent& event )
|
||||
{
|
||||
|
||||
EntityID entity1 = m_RigidBodies[event.getBody(0)];
|
||||
EntityID entity2 = m_RigidBodies[event.getBody(1)];
|
||||
//LOG_INFO("Entities colliding: %i, %i ", entity1, entity2);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#include "Components/Model.h"
|
||||
namespace Systems
|
||||
{
|
||||
class PhysicsSystem : public System
|
||||
{
|
||||
public:
|
||||
class MyCollisionResolution: public hkReferencedObject, public hkpContactListener
|
||||
{
|
||||
public:
|
||||
|
||||
MyCollisionResolution(Systems::PhysicsSystem* physicsSystem)
|
||||
: m_PhysicsSystem(physicsSystem) { }
|
||||
|
||||
virtual void contactPointCallback( const hkpContactPointEvent& event )
|
||||
{
|
||||
EntityID entity1 = m_PhysicsSystem->m_RigidBodyEntities[event.getBody(0)];
|
||||
EntityID entity2 = m_PhysicsSystem->m_RigidBodyEntities[event.getBody(1)];
|
||||
|
||||
Events::Collision e;
|
||||
e.Entity1 = entity1;
|
||||
e.Entity2 = entity2;
|
||||
m_PhysicsSystem->EventBroker->Publish(e);
|
||||
|
||||
auto modelComponent = m_PhysicsSystem->m_World->GetComponent<Components::Model>(entity1);
|
||||
|
||||
if (modelComponent && modelComponent->ModelFile == "Models/Placeholders/rocket/Rocket.obj" && entity2 == 6)
|
||||
{
|
||||
m_PhysicsSystem->m_PhysicsWorld->markForWrite();
|
||||
m_PhysicsSystem->m_RigidBodies[entity1]->setPosition(hkVector4(2000, -2000, 2000));
|
||||
m_PhysicsSystem->m_PhysicsWorld->unmarkForWrite();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Systems::PhysicsSystem* m_PhysicsSystem;
|
||||
};
|
||||
|
||||
friend class MyCollisionResolution;
|
||||
|
||||
PhysicsSystem(World* world, std::shared_ptr<::EventBroker> eventBroker)
|
||||
: System(world, eventBroker) { }
|
||||
|
||||
@@ -107,7 +126,8 @@ public:
|
||||
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
|
||||
void OnComponentRemoved(std::string type, Component* component) override;
|
||||
void OnEntityCommit(EntityID entity) override;
|
||||
|
||||
void OnEntityRemoved(EntityID entity) override;
|
||||
|
||||
private:
|
||||
double m_Accumulator;
|
||||
hkpWorld* m_PhysicsWorld;
|
||||
@@ -132,6 +152,7 @@ private:
|
||||
void SetupPhysics(hkpWorld* physicsWorld);
|
||||
|
||||
std::unordered_map<EntityID, hkpRigidBody*> m_RigidBodies;
|
||||
std::unordered_map<hkpRigidBody*, EntityID> m_RigidBodyEntities;
|
||||
|
||||
hkJobThreadPool* m_ThreadPool;
|
||||
hkJobQueue* m_JobQueue;
|
||||
|
||||
@@ -11,6 +11,8 @@ void Systems::TankSteeringSystem::RegisterComponents( ComponentFactory* cf )
|
||||
|
||||
void Systems::TankSteeringSystem::Initialize()
|
||||
{
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ECollision, &Systems::TankSteeringSystem::OnCollision);
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
m_TankInputControllers[i] = std::shared_ptr<TankSteeringInputController>(new TankSteeringInputController(EventBroker, i + 1));
|
||||
@@ -93,6 +95,32 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
}
|
||||
}
|
||||
|
||||
bool Systems::TankSteeringSystem::OnCollision( const Events::Collision &e )
|
||||
{
|
||||
// TODO:
|
||||
auto modelComponent = m_World->GetComponent<Components::Model>(e.Entity1);
|
||||
|
||||
if (modelComponent && modelComponent->ModelFile == "Models/Placeholders/rocket/Rocket.obj")
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(e.Entity1);
|
||||
m_World->GetSystem<Systems::ParticleSystem>()->CreateExplosion(
|
||||
transform->Position,
|
||||
1,
|
||||
60,
|
||||
"Textures/Sprites/NewtonTreeDeleteASAPPlease.png",
|
||||
glm::angleAxis(glm::pi<float>()/2, glm::vec3(1,0,0)),
|
||||
40,
|
||||
glm::pi<float>(),
|
||||
0.5f
|
||||
);
|
||||
//m_World->RemoveEntity(e.Entity1);
|
||||
}
|
||||
|
||||
//LOG_INFO("Ent1 %i Ent2 %i", e.Entity1, e.Entity2);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Systems::TankSteeringSystem::TankSteeringInputController::Update( double dt )
|
||||
{
|
||||
PositionX = m_Horizontal;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "Events/SetVelocity.h"
|
||||
#include "Events/ApplyForce.h"
|
||||
#include "Events/ApplyPointImpulse.h"
|
||||
#include "Events/Collision.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/TankSteering.h"
|
||||
#include "Components/TowerSteering.h"
|
||||
@@ -12,7 +13,9 @@
|
||||
#include "Components/Physics.h"
|
||||
#include "Components/Vehicle.h"
|
||||
#include "Components/Player.h"
|
||||
#include "Components/Model.h"
|
||||
#include "Systems/TransformSystem.h"
|
||||
#include "Systems/ParticleSystem.h"
|
||||
#include "InputController.h"
|
||||
|
||||
namespace Systems
|
||||
@@ -31,6 +34,9 @@ namespace Systems
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
private:
|
||||
EventRelay<Events::Collision> m_ECollision;
|
||||
bool OnCollision(const Events::Collision &e);
|
||||
|
||||
class TankSteeringInputController;
|
||||
std::array<std::shared_ptr<TankSteeringInputController>, 4> m_TankInputControllers;
|
||||
|
||||
|
||||
@@ -83,6 +83,12 @@ void World::RemoveEntity(EntityID entity)
|
||||
m_EntitiesToRemove.push_back(pair.first);
|
||||
}
|
||||
}
|
||||
// Trigger events
|
||||
for (auto pair : m_Systems)
|
||||
{
|
||||
auto system = pair.second;
|
||||
system->OnEntityRemoved(entity);
|
||||
}
|
||||
}
|
||||
|
||||
void World::ProcessEntityRemovals()
|
||||
|
||||
@@ -163,6 +163,7 @@
|
||||
<ClInclude Include="..\..\src\Events\BindGamepadButton.h" />
|
||||
<ClInclude Include="..\..\src\Events\BindKey.h" />
|
||||
<ClInclude Include="..\..\src\Events\BindMouseButton.h" />
|
||||
<ClInclude Include="..\..\src\Events\Collision.h" />
|
||||
<ClInclude Include="..\..\src\Events\GamepadAxis.h" />
|
||||
<ClInclude Include="..\..\src\Events\GamepadButton.h" />
|
||||
<ClInclude Include="..\..\src\Events\InputCommand.h" />
|
||||
|
||||
@@ -397,6 +397,9 @@
|
||||
<ClInclude Include="..\..\src\Components\Player.h">
|
||||
<Filter>Gameplay\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Events\Collision.h">
|
||||
<Filter>Physics\Events</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\src\Shaders\Fragment2.glsl">
|
||||
|
||||
Reference in New Issue
Block a user