Indentation style changed to Allman
Using Artistic Style (http://astyle.sourceforge.net/) Options: --style=allman --indent=tab --keep-one-line-blocks --align-pointer=type --align-reference=name
This commit is contained in:
@@ -7,15 +7,15 @@
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
class DebugSystem : public System
|
||||
{
|
||||
public:
|
||||
DebugSystem(World* world)
|
||||
: System(world) { }
|
||||
class DebugSystem : public System
|
||||
{
|
||||
public:
|
||||
DebugSystem(World* world)
|
||||
: System(world) { }
|
||||
|
||||
void Update(double dt) override;
|
||||
//void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
};
|
||||
void Update(double dt) override;
|
||||
//void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
};
|
||||
|
||||
}
|
||||
#endif // DebugSystem_h__
|
||||
@@ -16,39 +16,49 @@ void Systems::FreeSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
|
||||
{
|
||||
auto steering = m_World->GetComponent<Components::FreeSteering>(entity, "FreeSteering");
|
||||
auto input = m_World->GetComponent<Components::Input>(entity, "Input");
|
||||
if (steering && input) {
|
||||
if (steering && input)
|
||||
{
|
||||
auto transform = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
|
||||
glm::vec3 Camera_Right = glm::vec3(glm::vec4(1, 0, 0, 0) * transform->Orientation);
|
||||
glm::vec3 Camera_Forward = glm::vec3(glm::vec4(0, 0, 1, 0) * transform->Orientation);
|
||||
|
||||
float speed = steering->Speed;
|
||||
if (input->KeyState[GLFW_KEY_LEFT_SHIFT]) {
|
||||
if (input->KeyState[GLFW_KEY_LEFT_SHIFT])
|
||||
{
|
||||
speed *= 4.0f;
|
||||
}
|
||||
if (input->KeyState[GLFW_KEY_LEFT_ALT]) {
|
||||
if (input->KeyState[GLFW_KEY_LEFT_ALT])
|
||||
{
|
||||
speed /= 4.0f;
|
||||
}
|
||||
if (input->KeyState[GLFW_KEY_A]) {
|
||||
if (input->KeyState[GLFW_KEY_A])
|
||||
{
|
||||
transform->Position -= Camera_Right * (float)dt * speed;
|
||||
}
|
||||
else if (input->KeyState[GLFW_KEY_D]) {
|
||||
else if (input->KeyState[GLFW_KEY_D])
|
||||
{
|
||||
transform->Position += Camera_Right * (float)dt * speed;
|
||||
}
|
||||
if (input->KeyState[GLFW_KEY_W]) {
|
||||
if (input->KeyState[GLFW_KEY_W])
|
||||
{
|
||||
transform->Position -= Camera_Forward * (float)dt * speed;
|
||||
}
|
||||
if (input->KeyState[GLFW_KEY_S]) {
|
||||
if (input->KeyState[GLFW_KEY_S])
|
||||
{
|
||||
transform->Position += Camera_Forward * (float)dt * speed;
|
||||
}
|
||||
if (input->KeyState[GLFW_KEY_SPACE]) {
|
||||
if (input->KeyState[GLFW_KEY_SPACE])
|
||||
{
|
||||
transform->Position += glm::vec3(0, 1, 0) * (float)dt * speed;
|
||||
}
|
||||
if (input->KeyState[GLFW_KEY_LEFT_CONTROL]) {
|
||||
if (input->KeyState[GLFW_KEY_LEFT_CONTROL])
|
||||
{
|
||||
transform->Position -= glm::vec3(0, 1, 0) * (float)dt * speed;
|
||||
}
|
||||
|
||||
if (input->MouseState[GLFW_MOUSE_BUTTON_LEFT]) {
|
||||
if (input->MouseState[GLFW_MOUSE_BUTTON_LEFT])
|
||||
{
|
||||
// TOUCHING THIS CODE MIGHT CAUSE THE UNIVERSE TO IMPLODE, ALSO DRAGONS // spelling tobias :3
|
||||
//---------------------------------------------------------------------
|
||||
transform->Orientation = glm::angleAxis<float>(input->dY / 300.f, glm::vec3(1, 0, 0)) * transform->Orientation;
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
namespace Systems
|
||||
{
|
||||
class FreeSteeringSystem : public System
|
||||
{
|
||||
public:
|
||||
FreeSteeringSystem(World* world);
|
||||
class FreeSteeringSystem : public System
|
||||
{
|
||||
public:
|
||||
FreeSteeringSystem(World* world);
|
||||
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
};
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
};
|
||||
}
|
||||
@@ -8,12 +8,14 @@ void Systems::InputSystem::Update(double dt)
|
||||
m_LastMouseState = m_CurrentMouseState;
|
||||
|
||||
// Keyboard input
|
||||
for (int i = 0; i <= GLFW_KEY_LAST; ++i) {
|
||||
for (int i = 0; i <= GLFW_KEY_LAST; ++i)
|
||||
{
|
||||
m_CurrentKeyState[i] = glfwGetKey(m_Renderer->GetWindow(), i);
|
||||
}
|
||||
|
||||
// Mouse buttons
|
||||
for (int i = 0; i <= GLFW_MOUSE_BUTTON_LAST; ++i) {
|
||||
for (int i = 0; i <= GLFW_MOUSE_BUTTON_LAST; ++i)
|
||||
{
|
||||
m_CurrentMouseState[i] = glfwGetMouseButton(m_Renderer->GetWindow(), i);
|
||||
}
|
||||
|
||||
@@ -26,30 +28,36 @@ void Systems::InputSystem::Update(double dt)
|
||||
m_LastMouseY = ypos;
|
||||
|
||||
// Lock mouse while holding LMB
|
||||
if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT]) {
|
||||
if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT])
|
||||
{
|
||||
m_LastMouseX = m_Renderer->WIDTH / 2.f; // xpos;
|
||||
m_LastMouseY = m_Renderer->HEIGHT / 2.f; // ypos;
|
||||
glfwSetCursorPos(m_Renderer->GetWindow(), m_LastMouseX, m_LastMouseY);
|
||||
}
|
||||
// Hide/show cursor with LMB
|
||||
if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT] && !m_LastMouseState[GLFW_MOUSE_BUTTON_LEFT]) {
|
||||
if (m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT] && !m_LastMouseState[GLFW_MOUSE_BUTTON_LEFT])
|
||||
{
|
||||
glfwSetInputMode(m_Renderer->GetWindow(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
}
|
||||
if (!m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT] && m_LastMouseState[GLFW_MOUSE_BUTTON_LEFT]) {
|
||||
if (!m_CurrentMouseState[GLFW_MOUSE_BUTTON_LEFT] && m_LastMouseState[GLFW_MOUSE_BUTTON_LEFT])
|
||||
{
|
||||
glfwSetInputMode(m_Renderer->GetWindow(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
// Wireframe
|
||||
if (m_CurrentKeyState[GLFW_KEY_F1] && !m_LastKeyState[GLFW_KEY_F1]) {
|
||||
if (m_CurrentKeyState[GLFW_KEY_F1] && !m_LastKeyState[GLFW_KEY_F1])
|
||||
{
|
||||
m_Renderer->DrawWireframe(!m_Renderer->DrawWireframe());
|
||||
}
|
||||
// Normals
|
||||
if (m_CurrentKeyState[GLFW_KEY_F2] && !m_LastKeyState[GLFW_KEY_F2]) {
|
||||
if (m_CurrentKeyState[GLFW_KEY_F2] && !m_LastKeyState[GLFW_KEY_F2])
|
||||
{
|
||||
m_Renderer->DrawNormals(!m_Renderer->DrawNormals());
|
||||
}
|
||||
// Bounds
|
||||
if (m_CurrentKeyState[GLFW_KEY_F3] && !m_LastKeyState[GLFW_KEY_F3]) {
|
||||
if (m_CurrentKeyState[GLFW_KEY_F3] && !m_LastKeyState[GLFW_KEY_F3])
|
||||
{
|
||||
m_Renderer->DrawBounds(!m_Renderer->DrawBounds());
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -10,7 +10,7 @@ Systems::PhysicsSystem::PhysicsSystem(World* world) : System(world)
|
||||
m_CollisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
m_Dispatcher = new btCollisionDispatcher(m_CollisionConfiguration);
|
||||
m_Solver = new btSequentialImpulseConstraintSolver();
|
||||
|
||||
|
||||
m_DynamicsWorld = new btDiscreteDynamicsWorld(m_Dispatcher, m_Broadphase, m_Solver, m_CollisionConfiguration);
|
||||
|
||||
m_DynamicsWorld->setGravity(btVector3(0, -9.82f, 0));
|
||||
@@ -20,14 +20,16 @@ Systems::PhysicsSystem::PhysicsSystem(World* world) : System(world)
|
||||
void Systems::PhysicsSystem::Update(double dt)
|
||||
{
|
||||
// Update entity transform in physics world
|
||||
for (auto pair : *m_World->GetEntities()) {
|
||||
for (auto pair : *m_World->GetEntities())
|
||||
{
|
||||
EntityID entity = pair.first;
|
||||
EntityID parent = pair.second;
|
||||
|
||||
if (parent != 0)
|
||||
continue;
|
||||
|
||||
if (m_PhysicsData.find(entity) != m_PhysicsData.end()) {
|
||||
if (m_PhysicsData.find(entity) != m_PhysicsData.end())
|
||||
{
|
||||
PhysicsData* physicsData = &m_PhysicsData[entity];
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
|
||||
@@ -63,7 +65,8 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
||||
|
||||
if (physicsComponent || sphereShapeComponent || boxShapeComponent || meshShapeComponent || staticMeshShapeComponent)
|
||||
{
|
||||
if (m_PhysicsData.find(entity) == m_PhysicsData.end()) {
|
||||
if (m_PhysicsData.find(entity) == m_PhysicsData.end())
|
||||
{
|
||||
SetUpPhysicsState(entity, parent);
|
||||
}
|
||||
|
||||
@@ -84,10 +87,11 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_PhysicsData.find(entity) != m_PhysicsData.end()) {
|
||||
if (m_PhysicsData.find(entity) != m_PhysicsData.end())
|
||||
{
|
||||
TearDownPhysicsState(entity, parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto ballSocketComponent = m_World->GetComponent<Components::BallSocketConstraint>(entity, "BallSocketConstraint");
|
||||
auto sliderComponent = m_World->GetComponent<Components::SliderConstraint>(entity, "SliderConstraint");
|
||||
@@ -145,7 +149,7 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
||||
btVector3 AxisB = btVector3(hingeComponent->AxisB.x, hingeComponent->AxisB.y, hingeComponent->AxisB.z);
|
||||
|
||||
|
||||
btHingeConstraint *hingeConstraint = new btHingeConstraint(*m_PhysicsData[entityA].RigidBody, *m_PhysicsData[entityB].RigidBody, PivotA, PivotB, AxisA, AxisB, true);
|
||||
btHingeConstraint* hingeConstraint = new btHingeConstraint(*m_PhysicsData[entityA].RigidBody, *m_PhysicsData[entityB].RigidBody, PivotA, PivotB, AxisA, AxisB, true);
|
||||
hingeConstraint->setLimit(hingeComponent->LowLimit, hingeComponent->HighLimit, hingeComponent->Softness, hingeComponent->BiasFactor, hingeComponent->RelaxationFactor);
|
||||
|
||||
|
||||
@@ -159,7 +163,7 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
|
||||
|
||||
void Systems::PhysicsSystem::OnComponentCreated(std::string type, std::shared_ptr<Component> component)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::OnComponentRemoved(std::string type, Component* component)
|
||||
@@ -170,7 +174,8 @@ void Systems::PhysicsSystem::OnComponentRemoved(std::string type, Component* com
|
||||
void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent)
|
||||
{
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||
if (!transformComponent) {
|
||||
if (!transformComponent)
|
||||
{
|
||||
LOG_WARNING("Physics component missing transform component on entity %i", entity);
|
||||
return;
|
||||
}
|
||||
@@ -182,7 +187,8 @@ void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent)
|
||||
auto meshShapeComponent = m_World->GetComponent<Components::MeshShape>(entity, "MeshShape");
|
||||
auto staticMeshShapeComponent = m_World->GetComponent<Components::StaticMeshShape>(entity, "StaticMeshShape");
|
||||
|
||||
if (compoundShapeComponent && (sphereShapeComponent || boxShapeComponent || meshShapeComponent || staticMeshShapeComponent)) {
|
||||
if (compoundShapeComponent && (sphereShapeComponent || boxShapeComponent || meshShapeComponent || staticMeshShapeComponent))
|
||||
{
|
||||
LOG_WARNING("Entity %i has both compound shape and normal shape! Normal shapes must be children to entity with compound shape.", entity);
|
||||
}
|
||||
|
||||
@@ -192,7 +198,8 @@ void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent)
|
||||
auto baseCompoundShape = m_World->GetComponent<Components::CompoundShape>(baseParent, "CompoundShape");*/
|
||||
|
||||
// Set-up compound shape
|
||||
if (compoundShapeComponent) {
|
||||
if (compoundShapeComponent)
|
||||
{
|
||||
btCompoundShape* compoundShape = new btCompoundShape();
|
||||
physicsData->CollisionShape = compoundShape;
|
||||
|
||||
@@ -201,7 +208,8 @@ void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent)
|
||||
physicsData->MotionState = new btDefaultMotionState(transform);
|
||||
|
||||
btVector3 inertia;
|
||||
if (physicsComponent->Mass != 0) {
|
||||
if (physicsComponent->Mass != 0)
|
||||
{
|
||||
physicsData->CollisionShape->calculateLocalInertia(physicsComponent->Mass, inertia);
|
||||
}
|
||||
|
||||
@@ -210,26 +218,34 @@ void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent)
|
||||
|
||||
m_DynamicsWorld->addRigidBody(physicsData->RigidBody);
|
||||
}
|
||||
|
||||
|
||||
// Set-up normal shapes
|
||||
else if (boxShapeComponent) {
|
||||
else if (boxShapeComponent)
|
||||
{
|
||||
physicsData->CollisionShape = new btBoxShape(btVector3(boxShapeComponent->Width, boxShapeComponent->Height, boxShapeComponent->Depth));
|
||||
} else if (sphereShapeComponent) {
|
||||
}
|
||||
else if (sphereShapeComponent)
|
||||
{
|
||||
physicsData->CollisionShape = new btSphereShape(sphereShapeComponent->Radius);
|
||||
} else if (meshShapeComponent) {
|
||||
}
|
||||
else if (meshShapeComponent)
|
||||
{
|
||||
// TODO: Collision mesh things go here
|
||||
//new btConvexTriangleMeshShape()
|
||||
}
|
||||
if (boxShapeComponent || sphereShapeComponent || meshShapeComponent || staticMeshShapeComponent) {
|
||||
if (boxShapeComponent || sphereShapeComponent || meshShapeComponent || staticMeshShapeComponent)
|
||||
{
|
||||
btTransform transform;
|
||||
transform.setFromOpenGLMatrix(glm::value_ptr(glm::translate(glm::mat4(), transformComponent->Position) * glm::toMat4(transformComponent->Orientation)));
|
||||
|
||||
// If there's a local physics component
|
||||
if (physicsComponent) {
|
||||
if (physicsComponent)
|
||||
{
|
||||
physicsData->MotionState = new btDefaultMotionState(transform);
|
||||
|
||||
btVector3 inertia;
|
||||
if (physicsComponent->Mass != 0) {
|
||||
if (physicsComponent->Mass != 0)
|
||||
{
|
||||
physicsData->CollisionShape->calculateLocalInertia(physicsComponent->Mass, inertia);
|
||||
}
|
||||
|
||||
@@ -237,16 +253,20 @@ void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent)
|
||||
physicsData->RigidBody = new btRigidBody(rigidBodyCI);
|
||||
|
||||
m_DynamicsWorld->addRigidBody(physicsData->RigidBody);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, find our base parent and attach to compound shape
|
||||
EntityID baseParent = m_World->GetEntityBaseParent(entity);
|
||||
auto basePhysicsComponent = m_World->GetComponent<Components::Physics>(baseParent, "Physics");
|
||||
if (!basePhysicsComponent) {
|
||||
if (!basePhysicsComponent)
|
||||
{
|
||||
LOG_WARNING("Failed to attach orphan collision shape on entity %i: missing physics component on base parent entity %i", entity, baseParent);
|
||||
return;
|
||||
}
|
||||
auto baseCompoundShapeComponent = m_World->GetComponent<Components::CompoundShape>(baseParent, "CompoundShape");
|
||||
if (!baseCompoundShapeComponent) {
|
||||
if (!baseCompoundShapeComponent)
|
||||
{
|
||||
LOG_WARNING("Failed to attach orphan collision shape on entity %i: missing compound shape on base parent entity %i", entity, baseParent);
|
||||
return;
|
||||
}
|
||||
@@ -267,7 +287,7 @@ void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent)
|
||||
void Systems::PhysicsSystem::TearDownPhysicsState(EntityID entity, EntityID parent)
|
||||
{
|
||||
PhysicsData* physicsData = &m_PhysicsData[entity];
|
||||
|
||||
|
||||
delete physicsData->RigidBody;
|
||||
delete physicsData->MotionState;
|
||||
delete physicsData->CollisionShape;
|
||||
|
||||
+26
-26
@@ -19,34 +19,34 @@
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
class PhysicsSystem : public System
|
||||
class PhysicsSystem : public System
|
||||
{
|
||||
public:
|
||||
PhysicsSystem(World* world);
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
|
||||
void OnComponentRemoved(std::string type, Component* component) override;
|
||||
|
||||
private:
|
||||
btBroadphaseInterface* m_Broadphase;
|
||||
btDefaultCollisionConfiguration* m_CollisionConfiguration;
|
||||
btCollisionDispatcher* m_Dispatcher;
|
||||
btSequentialImpulseConstraintSolver* m_Solver;
|
||||
btDiscreteDynamicsWorld* m_DynamicsWorld;
|
||||
|
||||
struct PhysicsData
|
||||
{
|
||||
public:
|
||||
PhysicsSystem(World* world);
|
||||
void Update(double dt) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
|
||||
void OnComponentRemoved(std::string type, Component* component) override;
|
||||
|
||||
private:
|
||||
btBroadphaseInterface* m_Broadphase;
|
||||
btDefaultCollisionConfiguration* m_CollisionConfiguration;
|
||||
btCollisionDispatcher* m_Dispatcher;
|
||||
btSequentialImpulseConstraintSolver* m_Solver;
|
||||
btDiscreteDynamicsWorld* m_DynamicsWorld;
|
||||
|
||||
struct PhysicsData
|
||||
{
|
||||
btRigidBody* RigidBody;
|
||||
btMotionState* MotionState;
|
||||
btCollisionShape* CollisionShape;
|
||||
};
|
||||
std::map<EntityID, PhysicsData> m_PhysicsData;
|
||||
std::map<std::pair<EntityID, EntityID>, btTypedConstraint*> m_Constraints;
|
||||
|
||||
void SetUpPhysicsState(EntityID entity, EntityID parent);
|
||||
void TearDownPhysicsState(EntityID entity, EntityID parent);
|
||||
btRigidBody* RigidBody;
|
||||
btMotionState* MotionState;
|
||||
btCollisionShape* CollisionShape;
|
||||
};
|
||||
std::map<EntityID, PhysicsData> m_PhysicsData;
|
||||
std::map<std::pair<EntityID, EntityID>, btTypedConstraint*> m_Constraints;
|
||||
|
||||
void SetUpPhysicsState(EntityID entity, EntityID parent);
|
||||
void TearDownPhysicsState(EntityID entity, EntityID parent);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // PhysicsSystem_h__
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
|
||||
void Systems::RenderSystem::OnComponentCreated(std::string type, std::shared_ptr<Component> component)
|
||||
{
|
||||
if(type == "Model") {
|
||||
if(type == "Model")
|
||||
{
|
||||
auto modelComponent = std::static_pointer_cast<Components::Model>(component);
|
||||
}
|
||||
}
|
||||
@@ -17,8 +18,10 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
|
||||
// Draw models
|
||||
auto modelComponent = m_World->GetComponent<Components::Model>(entity, "Model");
|
||||
if (modelComponent != nullptr) {
|
||||
if (m_CachedModels.find(modelComponent->ModelFile) == m_CachedModels.end()){
|
||||
if (modelComponent != nullptr)
|
||||
{
|
||||
if (m_CachedModels.find(modelComponent->ModelFile) == m_CachedModels.end())
|
||||
{
|
||||
m_CachedModels[modelComponent->ModelFile] = std::make_shared<Model>(OBJ(modelComponent->ModelFile));
|
||||
}
|
||||
|
||||
@@ -33,7 +36,8 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
#ifdef DEBUG
|
||||
auto collision = m_World->GetComponent<Components::Collision>(entity, "Collision");
|
||||
auto bounds = m_World->GetComponent<Components::Bounds>(entity, "Bounds");
|
||||
if (bounds != nullptr) {
|
||||
if (bounds != nullptr)
|
||||
{
|
||||
glm::vec3 origin = m_TransformSystem->AbsolutePosition(entity) + (transformComponent->Scale * bounds->Origin);
|
||||
glm::vec3 volumeVector = transformComponent->Scale * bounds->VolumeVector;
|
||||
m_Renderer->AddAABBToDraw(origin, volumeVector, (collision != nullptr && collision->CollidingEntities.size() > 0));
|
||||
@@ -41,20 +45,22 @@ void Systems::RenderSystem::UpdateEntity(double dt, EntityID entity, EntityID pa
|
||||
#endif
|
||||
|
||||
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity, "PointLight");
|
||||
if (pointLightComponent != nullptr) {
|
||||
if (pointLightComponent != nullptr)
|
||||
{
|
||||
glm::vec3 position = m_TransformSystem->AbsolutePosition(entity);
|
||||
m_Renderer->AddPointLightToDraw(
|
||||
position,
|
||||
pointLightComponent->Specular,
|
||||
pointLightComponent->Diffuse,
|
||||
pointLightComponent->constantAttenuation,
|
||||
pointLightComponent->linearAttenuation,
|
||||
pointLightComponent->quadraticAttenuation,
|
||||
pointLightComponent->spotExponent);
|
||||
position,
|
||||
pointLightComponent->Specular,
|
||||
pointLightComponent->Diffuse,
|
||||
pointLightComponent->constantAttenuation,
|
||||
pointLightComponent->linearAttenuation,
|
||||
pointLightComponent->quadraticAttenuation,
|
||||
pointLightComponent->spotExponent);
|
||||
}
|
||||
|
||||
auto cameraComponent = m_World->GetComponent<Components::Camera>(entity, "Camera");
|
||||
if (cameraComponent != nullptr) {
|
||||
if (cameraComponent != nullptr)
|
||||
{
|
||||
m_Renderer->GetCamera()->Position(transformComponent->Position);
|
||||
m_Renderer->GetCamera()->Orientation(transformComponent->Orientation);
|
||||
|
||||
|
||||
+13
-13
@@ -17,23 +17,23 @@
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
class RenderSystem : public System
|
||||
{
|
||||
public:
|
||||
RenderSystem(World* world, std::shared_ptr<Renderer> renderer)
|
||||
: System(world), m_Renderer(renderer){ }
|
||||
class RenderSystem : public System
|
||||
{
|
||||
public:
|
||||
RenderSystem(World* world, std::shared_ptr<Renderer> renderer)
|
||||
: System(world), m_Renderer(renderer) { }
|
||||
|
||||
void Initialize() override;
|
||||
void Initialize() override;
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<Model>> m_CachedModels;
|
||||
std::unordered_map<std::string, std::shared_ptr<Model>> m_CachedModels;
|
||||
|
||||
void OnComponentCreated(std::string type, std:: shared_ptr<Component> component) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
void OnComponentCreated(std::string type, std:: shared_ptr<Component> component) override;
|
||||
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Renderer> m_Renderer;
|
||||
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
|
||||
};
|
||||
private:
|
||||
std::shared_ptr<Renderer> m_Renderer;
|
||||
std::shared_ptr<Systems::TransformSystem> m_TransformSystem;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
+19
-12
@@ -3,7 +3,7 @@
|
||||
#include "World.h"
|
||||
|
||||
Systems::SoundSystem::SoundSystem(World* world)
|
||||
: System(world)
|
||||
: System(world)
|
||||
{
|
||||
//initialize OpenAL
|
||||
ALCdevice* Device = alcOpenDevice(NULL);
|
||||
@@ -26,7 +26,7 @@ Systems::SoundSystem::SoundSystem(World* world)
|
||||
|
||||
void Systems::SoundSystem::Update(double dt)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
@@ -62,7 +62,7 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par
|
||||
alSourcef(source, AL_GAIN, soundEmitter->Gain);
|
||||
//alSourcef(source, AL_MAX_DISTANCE, soundEmitter->MaxDistance);
|
||||
alSourcef(source, AL_REFERENCE_DISTANCE, soundEmitter->ReferenceDistance);
|
||||
alSourcef(source, AL_PITCH, soundEmitter->Pitch);
|
||||
alSourcef(source, AL_PITCH, soundEmitter->Pitch);
|
||||
alSourcei(source, AL_LOOPING, soundEmitter->Loop);
|
||||
|
||||
glm::vec3 emitterPos = transformComponent->Position;
|
||||
@@ -104,7 +104,8 @@ void Systems::SoundSystem::StopSound(std::shared_ptr<Components::SoundEmitter> e
|
||||
|
||||
void Systems::SoundSystem::OnComponentCreated(std::string type, std::shared_ptr<Component> component)
|
||||
{
|
||||
if(type == "SoundEmitter") {
|
||||
if(type == "SoundEmitter")
|
||||
{
|
||||
ALuint source = CreateSource();
|
||||
m_Sources[component.get()] = source;
|
||||
}
|
||||
@@ -112,8 +113,10 @@ void Systems::SoundSystem::OnComponentCreated(std::string type, std::shared_ptr<
|
||||
|
||||
void Systems::SoundSystem::OnComponentRemoved(std::string type, Component* component)
|
||||
{
|
||||
if(type == "SoundEmitter") {
|
||||
if (m_Sources.find(component) != m_Sources.end()) {
|
||||
if(type == "SoundEmitter")
|
||||
{
|
||||
if (m_Sources.find(component) != m_Sources.end())
|
||||
{
|
||||
ALuint source = m_Sources[component];
|
||||
alDeleteSources(1, &source);
|
||||
}
|
||||
@@ -125,30 +128,34 @@ ALuint Systems::SoundSystem::LoadFile(std::string path)
|
||||
if (m_BufferCache.find(path) != m_BufferCache.end())
|
||||
return m_BufferCache[path];
|
||||
|
||||
FILE *fp = NULL;
|
||||
FILE* fp = NULL;
|
||||
fp = fopen(path.c_str(), "rb");
|
||||
|
||||
if (fp == NULL) {
|
||||
if (fp == NULL)
|
||||
{
|
||||
LOG_ERROR("Failed to load sound file \"%s\"", path.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
//CHECK FOR VALID WAVE-FILE
|
||||
fread(type, sizeof(char), 4, fp);
|
||||
if(type[0]!='R' || type[1]!='I' || type[2]!='F' || type[3]!='F') {
|
||||
if(type[0]!='R' || type[1]!='I' || type[2]!='F' || type[3]!='F')
|
||||
{
|
||||
LOG_ERROR("ERROR: No RIFF in WAVE-file");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fread(&size, sizeof(unsigned long), 1, fp);
|
||||
fread(type, sizeof(char), 4, fp);
|
||||
if(type[0]!='W' || type[1]!='A' || type[2]!='V' || type[3]!='E') {
|
||||
if(type[0]!='W' || type[1]!='A' || type[2]!='V' || type[3]!='E')
|
||||
{
|
||||
LOG_ERROR("ERROR: Not WAVE-file");
|
||||
return 0;
|
||||
}
|
||||
|
||||
fread(type, sizeof(char), 4, fp);
|
||||
if(type[0]!='f' || type[1]!='m' || type[2]!='t' || type[3]!=' ') {
|
||||
if(type[0]!='f' || type[1]!='m' || type[2]!='t' || type[3]!=' ')
|
||||
{
|
||||
LOG_ERROR("ERROR: No fmt in WAVE-file");
|
||||
return 0;
|
||||
}
|
||||
@@ -206,7 +213,7 @@ ALuint Systems::SoundSystem::CreateSource()
|
||||
ALuint source;
|
||||
alGenSources((ALuint)1, &source);
|
||||
|
||||
alDopplerFactor(1); // Numbers greater than 1 will increase Doppler effect, numbers lower than 1 will decrease the Doppler effect
|
||||
alDopplerFactor(1); // Numbers greater than 1 will increase Doppler effect, numbers lower than 1 will decrease the Doppler effect
|
||||
alDopplerVelocity(350.f); // Defines the velocity of the sound
|
||||
|
||||
return source;
|
||||
|
||||
@@ -35,9 +35,9 @@ private:
|
||||
unsigned long sampleRate, avgBytesPerSec;
|
||||
short bytesPerSample, bitsPerSample;
|
||||
unsigned long dataSize;
|
||||
|
||||
|
||||
std::map<Component*, ALuint> m_Sources;
|
||||
|
||||
|
||||
std::map<Component*, ALuint> m_Sources;
|
||||
std::map<std::string, ALuint> m_BufferCache; // string = fileName
|
||||
};
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ glm::vec3 Systems::TransformSystem::AbsolutePosition(EntityID entity)
|
||||
return absPosition * accumulativeOrientation;
|
||||
}
|
||||
|
||||
glm::quat Systems::TransformSystem::AbsoluteOrientation(EntityID entity)
|
||||
glm::quat Systems::TransformSystem::AbsoluteOrientation(EntityID entity)
|
||||
{
|
||||
glm::quat absOrientation;
|
||||
|
||||
|
||||
@@ -7,19 +7,19 @@
|
||||
namespace Systems
|
||||
{
|
||||
|
||||
class TransformSystem : public System
|
||||
{
|
||||
public:
|
||||
TransformSystem(World* world)
|
||||
: System(world) { }
|
||||
class TransformSystem : public System
|
||||
{
|
||||
public:
|
||||
TransformSystem(World* world)
|
||||
: System(world) { }
|
||||
|
||||
//void Update(double dt) override;
|
||||
//void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
//void Update(double dt) override;
|
||||
//void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||
|
||||
glm::vec3 AbsolutePosition(EntityID entity);
|
||||
glm::quat AbsoluteOrientation(EntityID entity);
|
||||
glm::vec3 AbsoluteScale(EntityID entity);
|
||||
};
|
||||
glm::vec3 AbsolutePosition(EntityID entity);
|
||||
glm::quat AbsoluteOrientation(EntityID entity);
|
||||
glm::vec3 AbsoluteScale(EntityID entity);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user