Now uses now sorts and renders sprites by depth.
Merge remote-tracking branch 'origin/deffered_rendering' into particles Conflicts: assets src/GameWorld.cpp
This commit is contained in:
@@ -138,6 +138,7 @@ void Systems::PhysicsSystem::Initialize()
|
||||
e.Layer2 = EXPLOSION_LAYER;
|
||||
EventBroker->Publish(e);
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
|
||||
@@ -155,6 +156,8 @@ void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
|
||||
|
||||
void Systems::PhysicsSystem::Update(double dt)
|
||||
{
|
||||
|
||||
|
||||
for (auto pair : *m_World->GetEntities())
|
||||
{
|
||||
EntityID entity = pair.first;
|
||||
@@ -171,23 +174,36 @@ void Systems::PhysicsSystem::Update(double dt)
|
||||
{
|
||||
hkVector4 position;
|
||||
hkQuaternion rotation;
|
||||
hkVector4 velocity;
|
||||
|
||||
if (parent)
|
||||
{
|
||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
|
||||
position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position);
|
||||
rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation);
|
||||
velocity = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Velocity);
|
||||
}
|
||||
else
|
||||
{
|
||||
position = GLMVEC3_TO_HKVECTOR4(transformComponent->Position);
|
||||
rotation = GLMQUAT_TO_HKQUATERNION(transformComponent->Orientation);
|
||||
velocity = GLMVEC3_TO_HKVECTOR4(transformComponent->Velocity);
|
||||
}
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_RigidBodies[entity]->setPositionAndRotation(position, rotation);
|
||||
m_RigidBodies[entity]->setLinearVelocity(velocity);
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
|
||||
}
|
||||
/*
|
||||
|
||||
glm::vec3 pos1 = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[m_World->m_Terrain]->getPosition());
|
||||
pos1 += glm::vec3(1, 1, 1)*(float)dt;
|
||||
hkVector4 pos = GLMVEC3_TO_HKVECTOR4(pos1);
|
||||
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_RigidBodies[m_World->m_Terrain]->setPositionAndRotation(pos, GLMQUAT_TO_HKQUATERNION(glm::quat()));
|
||||
m_PhysicsWorld->unmarkForWrite();*/
|
||||
}
|
||||
|
||||
static const double timestep = 1 / 60.0;
|
||||
@@ -240,11 +256,12 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
||||
else if(m_RigidBodies.find(entity) != m_RigidBodies.end())
|
||||
{
|
||||
auto transformComponentParent = m_World->GetComponent<Components::Transform>(parent);
|
||||
|
||||
transformComponent->Position = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getPosition());
|
||||
transformComponent->Orientation = HKQUATERNION_TO_GLMQUAT(m_RigidBodies[entity]->getRotation());
|
||||
transformComponent->Velocity = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getLinearVelocity());
|
||||
// TODO: No support for Scale, MIGHT be possible
|
||||
|
||||
// HACK: WTF IS THIS?
|
||||
if (transformComponentParent)
|
||||
{
|
||||
transformComponent->Position -= transformComponentParent->Position;
|
||||
@@ -319,7 +336,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Create a hkpListShape* of all the childEntities collected in m_ShapeArrays
|
||||
hkpListShape* listShape = new hkpListShape(shapeArray.begin(), shapeArray.getSize(), hkpShapeContainer::REFERENCE_POLICY_INCREMENT);
|
||||
// Save the listShape for further use
|
||||
@@ -377,6 +393,8 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
}
|
||||
// Create RigidBody
|
||||
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
|
||||
m_RigidBodies[entity] = rigidBody;
|
||||
m_RigidBodyEntities[rigidBody] = entity;
|
||||
|
||||
auto vehicleComponent = m_World->GetComponent<Components::Vehicle >(entity);
|
||||
if (vehicleComponent && m_Vehicles.find(entity) == m_Vehicles.end())
|
||||
@@ -393,7 +411,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
|
||||
VehicleSetup vehicleSetup;
|
||||
// Create the basic vehicle.
|
||||
m_Vehicles[entity] = new hkpVehicleInstance(rigidBody);
|
||||
m_Vehicles[entity] = new hkpVehicleInstance(m_RigidBodies[entity]);
|
||||
m_PhysicsWorld->markForWrite();
|
||||
vehicleSetup.buildVehicle(m_World, m_PhysicsWorld, *m_Vehicles[entity], entity, m_Wheels);
|
||||
// Add the vehicle's entities and phantoms to the world
|
||||
@@ -402,8 +420,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
rigidBody->addContactListener( m_collisionResolution );
|
||||
}
|
||||
m_Vehicles[entity]->addToWorld(m_PhysicsWorld);
|
||||
m_RigidBodies[entity] = rigidBody;
|
||||
m_RigidBodyEntities[rigidBody] = entity;
|
||||
|
||||
|
||||
// The vehicle is an action
|
||||
@@ -423,8 +439,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
rigidBody->addContactListener( m_collisionResolution );
|
||||
}
|
||||
m_PhysicsWorld->addEntity(rigidBody);
|
||||
m_RigidBodies[entity] = rigidBody;
|
||||
m_RigidBodyEntities[rigidBody] = entity;
|
||||
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
|
||||
shape->removeReference();
|
||||
@@ -576,7 +591,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
||||
if(triggerComponent)
|
||||
{
|
||||
auto parentTransformComponent = m_World->GetComponent<Components::Transform >(entityParent);
|
||||
|
||||
PhantomCallbackShape* phantom = new PhantomCallbackShape(this);
|
||||
hkpBvShape* phantomShape = new hkpBvShape(boxShape, phantom);
|
||||
|
||||
@@ -707,11 +721,40 @@ void HK_CALL Systems::PhysicsSystem::HavokErrorReport(const char* msg, void*)
|
||||
bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event)
|
||||
{
|
||||
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(event.Entity);
|
||||
|
||||
if (vehicleComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
|
||||
{
|
||||
hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[event.Entity]->m_deviceStatus;
|
||||
deviceStatus->m_positionX = event.PositionX;
|
||||
deviceStatus->m_positionY = event.PositionY;
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
|
||||
|
||||
float steeringX = event.PositionX;
|
||||
|
||||
glm::vec3 velocityNormalized = glm::normalize(HKVECTOR4_TO_GLMVEC3(m_RigidBodies[event.Entity]->getLinearVelocity()));
|
||||
glm::vec3 forward = glm::normalize(transformComponent->Orientation * glm::vec3(0, 0, -1));
|
||||
float dotProduct = glm::dot(forward, velocityNormalized);
|
||||
|
||||
if(dotProduct < 0)
|
||||
{
|
||||
steeringX = (1 - (glm::clamp(abs(m_Vehicles[event.Entity]->calcKMPH() /vehicleComponent->TopSpeed), 0.f, 0.7f))) * steeringX;
|
||||
}
|
||||
|
||||
|
||||
if(abs(m_Vehicles[event.Entity]->calcKMPH()) < 2 && abs(m_Vehicles[event.Entity]->m_mainSteeringAngle) > 80.f * (HK_REAL_PI / 180))
|
||||
{
|
||||
deviceStatus->m_positionY = -0.4f;
|
||||
deviceStatus->m_positionX = steeringX;
|
||||
}
|
||||
// else if(m_Vehicles[event.Entity]->calcKMPH() > -2 && abs(m_Vehicles[event.Entity]->m_mainSteeringAngle) > 80.f * (HK_REAL_PI / 180))
|
||||
// {
|
||||
// deviceStatus->m_positionY = 0.4f;;
|
||||
// deviceStatus->m_positionX = -steeringX;
|
||||
// }
|
||||
else
|
||||
{
|
||||
deviceStatus->m_positionX = steeringX;
|
||||
deviceStatus->m_positionY = event.PositionY;
|
||||
}
|
||||
|
||||
if(event.PositionY > 0)
|
||||
{
|
||||
deviceStatus->m_reverseButtonPressed = true;
|
||||
@@ -728,6 +771,9 @@ bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event )
|
||||
{
|
||||
m_PhysicsWorld->markForWrite();
|
||||
m_RigidBodies[event.Entity]->setLinearVelocity(GLMVEC3_TO_HKVECTOR4(event.Velocity));
|
||||
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
|
||||
transformComponent->Velocity = event.Velocity;
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
}
|
||||
return true;
|
||||
@@ -813,4 +859,4 @@ bool Systems::PhysicsSystem::OnDisableCollisions( const Events::DisableCollision
|
||||
m_PhysicsWorld->setCollisionFilter(m_CollisionFilter);
|
||||
m_PhysicsWorld->unmarkForWrite();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf)
|
||||
cf->Register<Components::PointLight>([]() { return new Components::PointLight(); });
|
||||
cf->Register<Components::DirectionalLight>([]() { return new Components::DirectionalLight(); });
|
||||
cf->Register<Components::Viewport>([]() { return new Components::Viewport(); });
|
||||
cf->Register<Components::BlendMap>([]() { return new Components::BlendMap(); });
|
||||
}
|
||||
|
||||
void Systems::RenderSystem::OnEntityCommit(EntityID entity)
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "Renderer.h"
|
||||
#include "RenderQueue.h"
|
||||
#include "Events/SetViewportCamera.h"
|
||||
#include "Components/BlendMap.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
@@ -33,7 +33,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
if(!tankSteeringComponent)
|
||||
return;
|
||||
|
||||
auto playerComponent = m_World->GetComponent<Components::Player>(tankSteeringComponent->Player);
|
||||
auto playerComponent = m_World->GetComponent<Components::Player>(entity);
|
||||
if (!playerComponent)
|
||||
return;
|
||||
|
||||
@@ -62,6 +62,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
|
||||
if(barrelSteeringComponent)
|
||||
{
|
||||
auto tankTransform = m_World->GetComponent<Components::Transform>(entity);
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(tankSteeringComponent->Barrel);
|
||||
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(tankSteeringComponent->Barrel);
|
||||
glm::quat orientation = glm::angleAxis(barrelSteeringComponent->TurnSpeed * inputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis);
|
||||
@@ -76,7 +77,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
cloneTransform->Orientation = absoluteTransform.Orientation * cloneTransform->Orientation;
|
||||
Events::SetVelocity eSetVelocity;
|
||||
eSetVelocity.Entity = clone;
|
||||
eSetVelocity.Velocity = absoluteTransform.Orientation * (glm::vec3(0.f, 0.f, -1.f) * barrelSteeringComponent->ShotSpeed);
|
||||
eSetVelocity.Velocity = tankTransform->Velocity + absoluteTransform.Orientation * (glm::vec3(0.f, 0.f, -1.f) * barrelSteeringComponent->ShotSpeed);
|
||||
EventBroker->Publish(eSetVelocity);
|
||||
m_TimeSinceLastShot[tankSteeringComponent->Barrel] = 0;
|
||||
|
||||
@@ -87,7 +88,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
Events::ApplyPointImpulse ePointImpulse ;
|
||||
ePointImpulse.Entity = entity;
|
||||
ePointImpulse.Position = absoluteTransform.Position;
|
||||
ePointImpulse.Impulse = glm::normalize(absoluteTransform.Orientation * glm::vec3(0, 0, 1)) * clonePhysicsComponent->Mass * 1670.f;
|
||||
ePointImpulse.Impulse = glm::normalize(absoluteTransform.Orientation * glm::vec3(0, 0, 1)) * clonePhysicsComponent->Mass * 6.f * 1670.f;
|
||||
EventBroker->Publish(ePointImpulse);
|
||||
}
|
||||
|
||||
@@ -280,13 +281,12 @@ bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const E
|
||||
if (event.Command == "horizontal")
|
||||
{
|
||||
m_Horizontal = val;
|
||||
m_Vertical = -0.4f;
|
||||
}
|
||||
else if (event.Command == "vertical")
|
||||
{
|
||||
m_Vertical = -val;
|
||||
}
|
||||
|
||||
|
||||
else if (event.Command == "handbrake")
|
||||
{
|
||||
Handbrake = val > 0;
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
#include "Components/FrameTimer.h"
|
||||
|
||||
#include "Events/Damage.h"
|
||||
#include "Components/Vehicle.h"
|
||||
#include "Components/Player.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
@@ -82,7 +82,7 @@ void Systems::TriggerSystem::Flag( EntityID entity, EntityID phantomEntity )
|
||||
m_World->RemoveComponent<Components::Trigger>(phantomEntity);
|
||||
m_World->SetEntityParent(phantomEntity, entity);
|
||||
auto phantomTransform = m_World->GetComponent<Components::Transform>(phantomEntity);
|
||||
phantomTransform->Position = glm::vec3(1.f, 0.1f, 2.f);
|
||||
phantomTransform->Position = glm::vec3(-1.5f, 0.1f, 2.f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "WheelPairSystem.h"
|
||||
#include "World.h"
|
||||
|
||||
void Systems::WheelPairSystem::RegisterComponents(ComponentFactory* cf)
|
||||
{
|
||||
cf->Register<Components::WheelPair>([]() { return new Components::WheelPair(); });
|
||||
}
|
||||
|
||||
void Systems::WheelPairSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
auto wheelPair = m_World->GetComponent<Components::WheelPair>(entity);
|
||||
if (!wheelPair)
|
||||
return;
|
||||
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity);
|
||||
if (!transform)
|
||||
return;
|
||||
auto transformFakeFront = m_World->GetComponent<Components::Transform>(wheelPair->FakeWheelFront);
|
||||
if (!transformFakeFront)
|
||||
return;
|
||||
auto transformFakeBack = m_World->GetComponent<Components::Transform>(wheelPair->FakeWheelBack);
|
||||
if (!transformFakeBack)
|
||||
return;
|
||||
|
||||
glm::vec3 thing = transformFakeBack->Position - transformFakeFront->Position;
|
||||
|
||||
float height = ((transformFakeFront->Position + transformFakeBack->Position) / 2.f).y;
|
||||
float angle = std::atan2f(thing.y, thing.z);
|
||||
|
||||
transform->Position.y = height;
|
||||
transform->Orientation = glm::quat(glm::eulerAngles(transform->Orientation) * glm::vec3(0, 1, 1) + glm::vec3(-angle, 0, 0));
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef Systems_WheelPairSystem_h__
|
||||
#define Systems_WheelPairSystem_h__
|
||||
|
||||
#include "World.h"
|
||||
#include "System.h"
|
||||
#include "Components/Transform.h"
|
||||
#include "Components/WheelPair.h"
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
class WheelPairSystem : public System
|
||||
{
|
||||
public:
|
||||
|
||||
WheelPairSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
|
||||
: System(world, eventBroker, resourceManager) { }
|
||||
|
||||
void RegisterComponents(ComponentFactory* cf) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
};
|
||||
}
|
||||
#endif // Systems_WheelPairSystem_h__
|
||||
Reference in New Issue
Block a user