diff --git a/OpenGLEngine/OpenGLEngine/AddTorqueFromCameraComponent.h b/OpenGLEngine/OpenGLEngine/AddTorqueFromCameraComponent.h new file mode 100644 index 0000000..1da6028 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/AddTorqueFromCameraComponent.h @@ -0,0 +1,15 @@ +#pragma once +#include "ECSConfig.h" + +namespace Reality +{ + struct AddTorqueFromCameraComponent + { + AddTorqueFromCameraComponent(float _torqueScale = 10.0f) + : torqueScale(_torqueScale) + { + + } + float torqueScale; + }; +} diff --git a/OpenGLEngine/OpenGLEngine/AddTorqueFromCameraSystem.cpp b/OpenGLEngine/OpenGLEngine/AddTorqueFromCameraSystem.cpp new file mode 100644 index 0000000..be862b6 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/AddTorqueFromCameraSystem.cpp @@ -0,0 +1,35 @@ +#include "AddTorqueFromCameraSystem.h" +#include "LifeTimeComponent.h" + +namespace Reality +{ + AddTorqueFromCameraSystem::AddTorqueFromCameraSystem() + { + requireComponent(); + requireComponent(); + requireComponent(); + } + + void AddTorqueFromCameraSystem::Update(float deltaTime) + { + if (!pressed && glfwGetKey(getWorld().data.renderUtil->window->glfwWindow, GLFW_KEY_E) == GLFW_PRESS) + { + for (auto e : getEntities()) + { + auto& transform = e.getComponent(); + auto& forceAndTorqueAcc = e.getComponent(); + auto& addTorqueComp = e.getComponent(); + + Camera& cam = getWorld().data.renderUtil->camera; + + Vector3 torque = glm::cross(cam.Position - transform.GetPosition(), cam.Front * addTorqueComp.torqueScale); + forceAndTorqueAcc.AddTorque(torque); + } + pressed = true; + } + else if(glfwGetKey(getWorld().data.renderUtil->window->glfwWindow, GLFW_KEY_E) == GLFW_RELEASE) + { + pressed = false; + } + } +} diff --git a/OpenGLEngine/OpenGLEngine/AddTorqueFromCameraSystem.h b/OpenGLEngine/OpenGLEngine/AddTorqueFromCameraSystem.h new file mode 100644 index 0000000..b6a638f --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/AddTorqueFromCameraSystem.h @@ -0,0 +1,17 @@ +#pragma once +#include "ECSConfig.h" +#include "TransformComponentV2.h" +#include "ForceAndTorqueAccumulatorComponent.h" +#include "AddTorqueFromCameraComponent.h" + +namespace Reality +{ + class AddTorqueFromCameraSystem : public ECSSystem + { + public: + AddTorqueFromCameraSystem(); + void Update(float deltaTime); + private: + bool pressed = false; + }; +} diff --git a/OpenGLEngine/OpenGLEngine/AeroComponent.h b/OpenGLEngine/OpenGLEngine/AeroComponent.h deleted file mode 100644 index aa005a9..0000000 --- a/OpenGLEngine/OpenGLEngine/AeroComponent.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include "ECSConfig.h" - -namespace Reality -{ - struct AeroComponent - { - AeroComponent(ECSEntity _target = ECSEntity(), Mat3 _aerodynamicTensor = Mat3(1.0f), Vector3 _relativePoint = Vector3(0, 0, 0)) - :target(_target), aerodynamicTensor(_aerodynamicTensor), relativePoint(_relativePoint) - { - - } - Mat3 aerodynamicTensor; - ECSEntity target; - Vector3 relativePoint; - }; -} diff --git a/OpenGLEngine/OpenGLEngine/AeroControlComponent.h b/OpenGLEngine/OpenGLEngine/AeroControlComponent.h index a918690..4de2a53 100644 --- a/OpenGLEngine/OpenGLEngine/AeroControlComponent.h +++ b/OpenGLEngine/OpenGLEngine/AeroControlComponent.h @@ -1,19 +1,26 @@ #pragma once #include "ECSConfig.h" -#include namespace Reality { struct AeroControlComponent { - AeroControlComponent(std::vector _positiveKeys = { GLFW_KEY_UP }, std::vector _negetiveKeys = { GLFW_KEY_DOWN }, float _rate = 1) - :positiveKeys(_positiveKeys), negetiveKeys(_negetiveKeys), rate(_rate) + AeroControlComponent(Vector3 _aeroPlusOne = Vector3(0, 0, 0), Vector3 _aeroMinusOne = Vector3(0, 0, 0), + const std::vector& _positiveKeys = {}, const std::vector& _negetiveKeys = {}, + float _controlSpeed = 1) + :aeroPlusOne(_aeroPlusOne), + aeroMinusOne(_aeroMinusOne), + positiveKeys(_positiveKeys), + negetiveKeys(_negetiveKeys), + controlSpeed(_controlSpeed) { } - + Vector3 aeroPlusOne; + Vector3 aeroMinusOne; std::vector positiveKeys; std::vector negetiveKeys; - float rate; + float controlSetting = 0; + float controlSpeed; }; } diff --git a/OpenGLEngine/OpenGLEngine/AeroControlSystem.cpp b/OpenGLEngine/OpenGLEngine/AeroControlSystem.cpp index 98b7cab..85f643d 100644 --- a/OpenGLEngine/OpenGLEngine/AeroControlSystem.cpp +++ b/OpenGLEngine/OpenGLEngine/AeroControlSystem.cpp @@ -4,43 +4,54 @@ namespace Reality { AeroControlSystem::AeroControlSystem() { - requireComponent(); + requireComponent(); requireComponent(); } void AeroControlSystem::Update(float deltaTime) { - pKey = false; - nKey = false; for (auto e : getEntities()) { - auto& aero = e.getComponent(); + auto& surface = e.getComponent(); auto& control = e.getComponent(); - for (auto key : control.positiveKeys) + bool reset = true; + + for (int key : control.positiveKeys) { if (glfwGetKey(getWorld().data.renderUtil->window->glfwWindow, key) == GLFW_PRESS) { - aero.controlSetting += control.rate * deltaTime; - pKey = true; + control.controlSetting += control.controlSpeed * deltaTime; + reset = false; } } - - for (auto key : control.negetiveKeys) + + if (control.controlSetting > 1) + { + control.controlSetting = 1; + } + + for (int key : control.negetiveKeys) { if (glfwGetKey(getWorld().data.renderUtil->window->glfwWindow, key) == GLFW_PRESS) { - aero.controlSetting -= control.rate * deltaTime; - nKey = true; + control.controlSetting -= control.controlSpeed * deltaTime; + reset = false; } } - if (!pKey && !nKey) + if (control.controlSetting < -1) + { + control.controlSetting = -1; + } + + if (reset) { - aero.controlSetting = 0; + control.controlSetting = 0; } - aero.controlSetting = glm::clamp(aero.controlSetting, -1.0f, 1.0f); + float t = (control.controlSetting + 1) * 0.5f; + surface.aerodynamicForce = t * control.aeroMinusOne + (1 - t) * control.aeroPlusOne; } } } diff --git a/OpenGLEngine/OpenGLEngine/AeroControlSystem.h b/OpenGLEngine/OpenGLEngine/AeroControlSystem.h index 27b8ec1..1d2b69c 100644 --- a/OpenGLEngine/OpenGLEngine/AeroControlSystem.h +++ b/OpenGLEngine/OpenGLEngine/AeroControlSystem.h @@ -1,6 +1,6 @@ #pragma once #include "ECSConfig.h" -#include "AeroMinMaxComponent.h" +#include "AeroSurfaceComponent.h" #include "AeroControlComponent.h" namespace Reality @@ -10,8 +10,5 @@ namespace Reality public: AeroControlSystem(); void Update(float deltaTime); - private: - bool pKey = false; - bool nKey = false; }; } diff --git a/OpenGLEngine/OpenGLEngine/AeroMinMaxComponent.h b/OpenGLEngine/OpenGLEngine/AeroMinMaxComponent.h deleted file mode 100644 index 3d6abf6..0000000 --- a/OpenGLEngine/OpenGLEngine/AeroMinMaxComponent.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include "ECSConfig.h" - -namespace Reality -{ - struct AeroMinMaxComponent - { - AeroMinMaxComponent(Mat3 _minTensor = Mat3(1.0f), Mat3 _baseTensor = Mat3(1.0f), Mat3 _maxTensor = Mat3(1.0f), float _controlSetting = 0.0f) - :minTensor(_minTensor), baseTensor(_baseTensor), maxTensor(_maxTensor), controlSetting(_controlSetting) - { - - } - Mat3 minTensor; - Mat3 baseTensor; - Mat3 maxTensor; - float controlSetting; - }; -} diff --git a/OpenGLEngine/OpenGLEngine/AeroSurfaceComponent.h b/OpenGLEngine/OpenGLEngine/AeroSurfaceComponent.h new file mode 100644 index 0000000..d4b1c04 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/AeroSurfaceComponent.h @@ -0,0 +1,20 @@ +#pragma once +#include "ECSConfig.h" + +namespace Reality +{ + struct AeroSurfaceComponent + { + AeroSurfaceComponent(ECSEntity _targetEntity = ECSEntity(), Vector3 _aerodynamicForce = Vector3(0, 0, 0), + Vector3 _localOffset = Vector3(0, 0, 0)) + :targetEntity(_targetEntity), + aerodynamicForce(_aerodynamicForce), + localOffset(_localOffset) + { + + } + ECSEntity targetEntity; + Vector3 aerodynamicForce; + Vector3 localOffset; + }; +} diff --git a/OpenGLEngine/OpenGLEngine/AeroSurfaceSystem.cpp b/OpenGLEngine/OpenGLEngine/AeroSurfaceSystem.cpp new file mode 100644 index 0000000..326b028 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/AeroSurfaceSystem.cpp @@ -0,0 +1,48 @@ +#include "AeroSurfaceSystem.h" +#include "RigidbodyComponent.h" +#include "ForceAndTorqueAccumulatorComponent.h" + +namespace Reality +{ + AeroSurfaceSystem::AeroSurfaceSystem() + { + requireComponent(); + requireComponent(); + } + + void AeroSurfaceSystem::Update(float deltaTime) + { + for (auto e : getEntities()) + { + auto& surfaceTransform = e.getComponent(); + auto& aero = e.getComponent(); + + if (aero.targetEntity.hasComponent() && + aero.targetEntity.hasComponent() && + aero.targetEntity.hasComponent()) + { + auto& targetTransform = aero.targetEntity.getComponent(); + auto& rigidbody = aero.targetEntity.getComponent(); + auto& forceAndTorque = aero.targetEntity.getComponent(); + + // HACK: For lack of scene graph + Vector3 worldSurfacePosition = targetTransform.LocalToWorldPosition(aero.localOffset); + surfaceTransform.SetPosition(worldSurfacePosition); + surfaceTransform.SetOrientation(targetTransform.GetOrientation()); + getWorld().data.renderUtil->DrawCube(surfaceTransform.GetPosition(), + Vector3(1, 1, 1), + surfaceTransform.GetOrientation()); + + Vector3 force = CalculateWorldAerodynamicForce(aero.aerodynamicForce, targetTransform); + forceAndTorque.AddForceAtPoint(force, + surfaceTransform.GetPosition(), + targetTransform.GetPosition()); + } + } + } + + const Vector3 & AeroSurfaceSystem::CalculateWorldAerodynamicForce(const Vector3& localAeroForce, TransformComponentV2& transform) + { + return transform.LocalToWorldDirection(localAeroForce); + } +} diff --git a/OpenGLEngine/OpenGLEngine/AeroSurfaceSystem.h b/OpenGLEngine/OpenGLEngine/AeroSurfaceSystem.h new file mode 100644 index 0000000..b186ab1 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/AeroSurfaceSystem.h @@ -0,0 +1,18 @@ +#pragma once +#include "ECSConfig.h" +#include "TransformComponentV2.h" +#include "AeroSurfaceComponent.h" + +namespace Reality +{ + class AeroSurfaceSystem : public ECSSystem + { + public: + AeroSurfaceSystem(); + void Update(float deltaTime); + Vector3 windVelocity = Vector3(0, 0, 0); + private: + const Vector3& CalculateWorldAerodynamicForce(const Vector3& localAeroForce, + TransformComponentV2& transform); + }; +} diff --git a/OpenGLEngine/OpenGLEngine/AeroSystem.cpp b/OpenGLEngine/OpenGLEngine/AeroSystem.cpp deleted file mode 100644 index 8b68db7..0000000 --- a/OpenGLEngine/OpenGLEngine/AeroSystem.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "AeroSystem.h" -#include "RigidBodyComponent.h" -#include "TransformComponentV2.h" - -namespace Reality -{ - AeroSystem::AeroSystem() - { - requireComponent(); - } - - void AeroSystem::UpdateForceFromTensor(ECSWorld& world, AeroComponent& aero, RigidBodyComponent& body, TransformComponentV2& transform) - { - // Calculate total velocity (windspeed and body's velocity). - Vector3 velocity = body.velocity; - velocity += windspeed; - - // Calculate the velocity in body coordinates - Vector3 bodyVel = transform.WorldToLocalDirection(velocity); - - // Calculate the force in body coordinates - Vector3 bodyForce = aero.aerodynamicTensor * bodyVel / 1.0f; - Vector3 force = transform.LocalToWorldDirection(bodyForce); - - // Apply the force - Vector3 forcePoint = transform.LocalToWorldPosition(aero.relativePoint); - body.AddForceAtPoint(force, forcePoint, transform.GetPosition()); - - //world.data.renderUtil->DrawLine(transform.GetPosition(), forcePoint + force * 1000.0f, Color::Purple); - world.data.renderUtil->DrawLine(forcePoint, forcePoint + force * 1000.0f, Color::Purple); - } - - void AeroSystem::Update(float deltaTime) - { - for (auto e : getEntities()) - { - auto& aero = e.getComponent(); - if (aero.target.hasComponent() && aero.target.hasComponent()) - { - auto& rigidbody = aero.target.getComponent(); - auto& transform = aero.target.getComponent(); - UpdateForceFromTensor(getWorld(), aero, rigidbody, transform); - } - } - } -} diff --git a/OpenGLEngine/OpenGLEngine/AeroSystem.h b/OpenGLEngine/OpenGLEngine/AeroSystem.h deleted file mode 100644 index 63ccebd..0000000 --- a/OpenGLEngine/OpenGLEngine/AeroSystem.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include "ECSConfig.h" -#include "AeroComponent.h" - -namespace Reality -{ - struct RigidBodyComponent; - struct TransformComponentV2; - class AeroSystem : public ECSSystem - { - public: - AeroSystem(); - void Update(float deltaTime); - Vector3 windspeed = Vector3(0, 0, 0); - private: - void UpdateForceFromTensor(ECSWorld& world, AeroComponent& aero, RigidBodyComponent& body, TransformComponentV2& transform); - }; -} diff --git a/OpenGLEngine/OpenGLEngine/BoxColliderComponent.h b/OpenGLEngine/OpenGLEngine/BoxColliderComponent.h deleted file mode 100644 index 7ef0bf3..0000000 --- a/OpenGLEngine/OpenGLEngine/BoxColliderComponent.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once -#include "ECSConfig.h" -#include - -namespace Reality -{ - struct BoxColliderComponent - { - BoxColliderComponent(ECSEntity _body = ECSEntity(), Vector3 _size = Vector3(0, 0, 0), Vector3 _offset = Vector3(0, 0, 0), Vector3 _eulerAngles = Vector3(0, 0, 0)) - : body(_body), size(_size), offset(_offset), rp3dId(-1) - { - SetRotation(_eulerAngles); - } - ECSEntity body; - Vector3 offset; - Vector3 size; - Quaternion orientation; - // Euler angles in degrees - inline void SetRotation(Vector3 eulerAngles) - { - glm::vec3 rotationInRads = glm::vec3(glm::radians(eulerAngles.x), - glm::radians(eulerAngles.y), glm::radians(eulerAngles.z)); - orientation = glm::quat(rotationInRads); - } - int rp3dId; - }; -} diff --git a/OpenGLEngine/OpenGLEngine/BoxColliderSystem.cpp b/OpenGLEngine/OpenGLEngine/BoxColliderSystem.cpp deleted file mode 100644 index 898ccc4..0000000 --- a/OpenGLEngine/OpenGLEngine/BoxColliderSystem.cpp +++ /dev/null @@ -1,95 +0,0 @@ -#include "BoxColliderSystem.h" -#include "RigidBodyComponent.h" -#include "RigidBodySystem.h" - -namespace Reality -{ - BoxColliderSystem::BoxColliderSystem(rp3d::CollisionWorld& _rp3dWorld) - :rp3dWorld(_rp3dWorld) - { - requireComponent(); - } - - void BoxColliderSystem::Update(float deltaTime) - { - std::vector rp3dShapesTemp; - std::vector aliveIds; - aliveIds.resize(rp3dShapes.size()); - int id = 0; - - for (auto e : getEntities()) - { - auto &boxCollider = e.getComponent(); - - if (boxCollider.body.isAlive() && boxCollider.body.hasComponent()) - { - auto &body = boxCollider.body.getComponent(); - - // Update RP3D Ids - // Calculate local rp3d transform - rp3d::Vector3 initPosition(boxCollider.offset.x, - boxCollider.offset.y, - boxCollider.offset.z); - rp3d::Quaternion initOrientation = rp3d::Quaternion(boxCollider.orientation.x, boxCollider.orientation.y, boxCollider.orientation.z, boxCollider.orientation.w); - rp3d::Transform rp3dtransform(initPosition, initOrientation); - - auto rp3dBody = getWorld().getSystemManager().getSystem().rp3dBodies[body.rp3dId]; - // If new rigidbody, create an entry - if (boxCollider.rp3dId < 0) - { - rp3d::BoxShape* shape = new rp3d::BoxShape(rp3d::Vector3(boxCollider.size.x, boxCollider.size.y, boxCollider.size.z) * 0.5f); - // Add the collision shape to the rigid body - - rp3d::ProxyShape * proxyShape = rp3dBody->addCollisionShape(shape, rp3dtransform); - proxyShape->setUserData(&boxCollider); - rp3dShapesTemp.push_back(proxyShape); - body.inertiaTensor[0][0] += (1.0f / 12.0f) * (pow(2 * boxCollider.size.y, 2) + pow(2 * boxCollider.size.z, 2)) / body.inverseMass; - body.inertiaTensor[1][1] += (1.0f / 12.0f) * (pow(2 * boxCollider.size.z, 2) + pow(2 * boxCollider.size.x, 2)) / body.inverseMass; - body.inertiaTensor[2][2] += (1.0f / 12.0f) * (pow(2 * boxCollider.size.x, 2) + pow(2 * boxCollider.size.y, 2)) / body.inverseMass; - boxCollider.rp3dId = id; - } - else if (boxCollider.body.isAlive()) - { - rp3d::ProxyShape * shape = rp3dShapes[boxCollider.rp3dId]; - shape->setLocalToBodyTransform(rp3dtransform); - aliveIds[boxCollider.rp3dId] = 1; - rp3dShapesTemp.push_back(shape); - boxCollider.rp3dId = id; - } - id++; - - if (boxCollider.body.hasComponent()) - { - auto& bodyTransform = boxCollider.body.getComponent(); - getWorld().data.renderUtil->DrawCube(bodyTransform.GetUnScaledTransformationMatrix() * Vector4(boxCollider.offset, 1.0f), boxCollider.size, bodyTransform.GetOrientation() * boxCollider.orientation); - } - } - else - { - // No need to kill it, the death of RB already killed it - aliveIds[boxCollider.rp3dId] = 1; - e.kill(); - } - - } - - for (int i = 0; i < aliveIds.size(); i++) - { - if (aliveIds[i] == 0) - { - if (rp3dShapes[i]) - { - auto shape = rp3dShapes[i]->getCollisionShapePublic(); - - if (rp3dShapes[i]->getBody() && rp3dShapes[i]->getBody()->getProxyShapesList()) - { - rp3dShapes[i]->getBody()->removeCollisionShape(rp3dShapes[i]); - } - delete shape; - } - } - } - - rp3dShapes = rp3dShapesTemp; - } -} diff --git a/OpenGLEngine/OpenGLEngine/BoxColliderSystem.h b/OpenGLEngine/OpenGLEngine/BoxColliderSystem.h deleted file mode 100644 index 189e426..0000000 --- a/OpenGLEngine/OpenGLEngine/BoxColliderSystem.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include "ECSConfig.h" -#include "BoxColliderComponent.h" -#include "TransformComponentV2.h" -#include -namespace Reality -{ - class BoxColliderSystem : public ECSSystem - { - public: - BoxColliderSystem(rp3d::CollisionWorld& _rp3dWorld); - void Update(float deltaTime); - private: - rp3d::CollisionWorld& rp3dWorld; - std::vector rp3dShapes; - }; -} diff --git a/OpenGLEngine/OpenGLEngine/BuoyancyComponent.h b/OpenGLEngine/OpenGLEngine/BuoyancyComponent.h new file mode 100644 index 0000000..bb58b1d --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/BuoyancyComponent.h @@ -0,0 +1,20 @@ +#pragma once +#include "ECSConfig.h" + +namespace Reality +{ + struct BuoyancyComponent + { + BuoyancyComponent(ECSEntity _targetEntity = ECSEntity(), float _maxDepth = 5.f, float _volume = 10.f, Vector3 _localOffset = Vector3(0, 0, 0)) + :targetEntity(_targetEntity), maxDepth(_maxDepth), volume(_volume), localOffset(_localOffset) + { + + } + + ECSEntity targetEntity; + float maxDepth; + float volume; + Vector3 localOffset; + }; +} + diff --git a/OpenGLEngine/OpenGLEngine/BuoyancySystem.cpp b/OpenGLEngine/OpenGLEngine/BuoyancySystem.cpp new file mode 100644 index 0000000..3a25892 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/BuoyancySystem.cpp @@ -0,0 +1,88 @@ +#include "BuoyancySystem.h" +#include "RigidbodyComponent.h" +#include "ForceAndTorqueAccumulatorComponent.h" + +namespace Reality +{ + BuoyancySystem::BuoyancySystem() + { + requireComponent(); + requireComponent(); + } + + void BuoyancySystem::Update(float deltaTime) + { + //Draw water surface + getWorld().data.renderUtil->DrawLine(Vector3(-500, 0, -5), Vector3(500, 0, 5)); + + for (auto e : getEntities()) + { + //int i = 0; + //++i; + + auto& buoyancyTransform = e.getComponent(); + auto& buoyancy = e.getComponent(); + + if (buoyancy.targetEntity.hasComponent() && + buoyancy.targetEntity.hasComponent() && + buoyancy.targetEntity.hasComponent()) + { + auto& targetTransform = buoyancy.targetEntity.getComponent(); + auto& rigidbody = buoyancy.targetEntity.getComponent(); + auto& forceAndTorque = buoyancy.targetEntity.getComponent(); + + + // draw buoyancy + Vector3 worldBuoyancyPosition = targetTransform.LocalToWorldPosition(buoyancy.localOffset); + buoyancyTransform.SetPosition(worldBuoyancyPosition); + buoyancyTransform.SetOrientation(targetTransform.GetOrientation()); + getWorld().data.renderUtil->DrawCube(buoyancyTransform.GetPosition(), + Vector3(buoyancy.maxDepth * 2.f, buoyancy.maxDepth * 2.f, buoyancy.maxDepth * 2.f), + buoyancyTransform.GetOrientation()); + + + + //Get the Buoyancy's position + float depth = buoyancyTransform.GetPosition().y; + + //Draw cube + //getWorld().data.renderUtil->DrawCube( + // entityTransform.position/* - Vector3(0, 1, 0) * entityBuoyancy.maxDepth * 0.5f*/, + // Vector3(entityBuoyancy.maxDepth * 2.f, entityBuoyancy.maxDepth * 2.f, entityBuoyancy.maxDepth * 2.f), + // Vector3(0, 0, 0)); + + + Vector3 buoyancyForce = Vector3(0.f, 0.f, 0.f); + + //check if entity is out of water + if (depth >= waterHeight + buoyancy.maxDepth) + { + buoyancyForce.y = 0.f; + } + + //check if entity is at maximum depth + else if (depth <= waterHeight - buoyancy.maxDepth) + { + buoyancyForce.y = liquidDensity * buoyancy.volume; + } + + //otherwise entity is partly submerged + else + { + buoyancyForce.y = (liquidDensity * buoyancy.volume * (buoyancy.maxDepth - depth - waterHeight)) / (2 * buoyancy.maxDepth); + } + + + Vector3 force = CalculateWorldBuoyancyForce(buoyancyForce, targetTransform); + forceAndTorque.AddForceAtPoint(force, + buoyancyTransform.GetPosition(), + targetTransform.GetPosition()); + } + } + } + + const Vector3& BuoyancySystem::CalculateWorldBuoyancyForce(const Vector3& localBuoyancyForce, TransformComponentV2& transform) + { + return transform.LocalToWorldDirection(localBuoyancyForce); + } +} diff --git a/OpenGLEngine/OpenGLEngine/BuoyancySystem.h b/OpenGLEngine/OpenGLEngine/BuoyancySystem.h new file mode 100644 index 0000000..e50b395 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/BuoyancySystem.h @@ -0,0 +1,22 @@ +#pragma once +#include "ECSConfig.h" +#include "TransformComponentV2.h" +#include "BuoyancyComponent.h" + +namespace Reality +{ + class BuoyancySystem : public ECSSystem + { + public: + BuoyancySystem(); + void Update(float deltaTime); + + float waterHeight = 0.f; + float liquidDensity = 10.f; + + private: + const Vector3& CalculateWorldBuoyancyForce(const Vector3& localBuoyancyForce, + TransformComponentV2& transform); + }; +} + diff --git a/OpenGLEngine/OpenGLEngine/CableComponent.h b/OpenGLEngine/OpenGLEngine/CableComponent.h index 07d09c6..87972d5 100644 --- a/OpenGLEngine/OpenGLEngine/CableComponent.h +++ b/OpenGLEngine/OpenGLEngine/CableComponent.h @@ -1,11 +1,21 @@ #pragma once #include "ECSConfig.h" + namespace Reality { struct CableComponent { - CableComponent(ECSEntity a = ECSEntity(), ECSEntity b = ECSEntity(), float _maxLength = 10, float _restitution = 1.0f) - : entityA(a), entityB(b), maxLength(_maxLength), restitution(_restitution){} + CableComponent(ECSEntity a = ECSEntity(), + ECSEntity b = ECSEntity(), + float _maxLength = 10, + float _restitution = 1) + : entityA(a), + entityB(b), + maxLength(_maxLength), + restitution(_restitution) + { + + } ECSEntity entityA; ECSEntity entityB; float maxLength; diff --git a/OpenGLEngine/OpenGLEngine/CableSystem.cpp b/OpenGLEngine/OpenGLEngine/CableSystem.cpp new file mode 100644 index 0000000..4aa3143 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/CableSystem.cpp @@ -0,0 +1,49 @@ +#include "CableSystem.h" +#include "TransformComponent.h" +#include "ParticleContactEvent.h" + +namespace Reality +{ + CableSystem::CableSystem() + { + requireComponent(); + } + + void CableSystem::Update(float deltaTime) + { + for (auto e : getEntities()) + { + auto& cable = e.getComponent(); + + if (cable.entityA.hasComponent() && + cable.entityB.hasComponent()) + { + auto& transformA = cable.entityA.getComponent(); + auto& transformB = cable.entityB.getComponent(); + + Vector3 relativePos = transformA.position - transformB.position; + float length = glm::length(relativePos); + + if (length > cable.maxLength) + { + Vector3 normal = -glm::normalize(relativePos); + float penetration = length - cable.maxLength; + + getWorld().getEventManager().emitEvent( + cable.entityA, + cable.entityB, + cable.restitution, + normal, + penetration + ); + } + + getWorld().data.renderUtil->DrawLine( + transformA.position, + transformB.position, + Color::Magenta + ); + } + } + } +} diff --git a/OpenGLEngine/OpenGLEngine/CameraLookSystem.h b/OpenGLEngine/OpenGLEngine/CableSystem.h similarity index 52% rename from OpenGLEngine/OpenGLEngine/CameraLookSystem.h rename to OpenGLEngine/OpenGLEngine/CableSystem.h index 8d17a1c..a888363 100644 --- a/OpenGLEngine/OpenGLEngine/CameraLookSystem.h +++ b/OpenGLEngine/OpenGLEngine/CableSystem.h @@ -1,13 +1,13 @@ #pragma once #include "ECSConfig.h" -#include "CameraLookComponent.h" +#include "CableComponent.h" namespace Reality { - class CameraLookSystem : public ECSSystem + class CableSystem : public ECSSystem { public: - CameraLookSystem(); + CableSystem(); void Update(float deltaTime); }; } diff --git a/OpenGLEngine/OpenGLEngine/CameraLookComponent.h b/OpenGLEngine/OpenGLEngine/CameraLookComponent.h deleted file mode 100644 index 80c44a4..0000000 --- a/OpenGLEngine/OpenGLEngine/CameraLookComponent.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include "ECSConfig.h" - -namespace Reality -{ - struct CameraLookComponent - { - CameraLookComponent() - { - - } - }; -} diff --git a/OpenGLEngine/OpenGLEngine/CameraLookSystem.cpp b/OpenGLEngine/OpenGLEngine/CameraLookSystem.cpp deleted file mode 100644 index 420c611..0000000 --- a/OpenGLEngine/OpenGLEngine/CameraLookSystem.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "CameraLookSystem.h" -#include "MouseMoveEvent.h" - -namespace Reality -{ - CameraLookSystem::CameraLookSystem() - { - requireComponent(); - } - - void CameraLookSystem::Update(float deltaTime) - { - for (auto e : getEntities()) - { - Camera& camera = getWorld().data.renderUtil->camera; - auto mouseMoveEvents = getWorld().getEventManager().getEvents(); - for (auto event : mouseMoveEvents) - { - camera.ProcessMouseMovement(event.deltaX, event.deltaY); - } - } - } -} diff --git a/OpenGLEngine/OpenGLEngine/ContactEvent.h b/OpenGLEngine/OpenGLEngine/ContactEvent.h deleted file mode 100644 index c8ef717..0000000 --- a/OpenGLEngine/OpenGLEngine/ContactEvent.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once -#include "ECSConfig.h" -#include "RigidBodyComponent.h" - -namespace Reality -{ - struct ContactEvent - { - ContactEvent(ECSEntity _bodyA = ECSEntity(), ECSEntity _bodyB = ECSEntity(), Vector3 _normal = Vector3(0, 0 , 0), float _penetrationDepth = 0, Vector3 _localPointOnShape1 = Vector3(0, 0, 0), Vector3 _localPointOnShape2 = Vector3(0, 0, 0), Vector3 _worldPoint1 = Vector3(0, 0, 0), Vector3 _worldPoint2 = Vector3(0, 0, 0), float _restitution = 1.0f) - :entityA(_bodyA), entityB(_bodyB), normal(_normal), penetrationDepth(_penetrationDepth), localPointOnShape1(_localPointOnShape1), localPointOnShape2(_localPointOnShape2), worldPoint1(_worldPoint1), worldPoint2(_worldPoint2), restitution(_restitution) - { - - } - - ECSEntity entityA; - - ECSEntity entityB; - - /// Normalized normal vector of the contact (from body1 toward body2) in world space - Vector3 normal; - - /// Penetration depth - float penetrationDepth; - - /// Contact point on proxy shape 1 in local-space of proxy shape 1 - Vector3 localPointOnShape1; - - /// Contact point on proxy shape 2 in local-space of proxy shape 2 - Vector3 localPointOnShape2; - - /// Contact point on proxy shape 1 in world-space - Vector3 worldPoint1; - - /// Contact point on proxy shape 2 in world-space - Vector3 worldPoint2; - - /// Coefficient Of restitution - float restitution; - }; -} diff --git a/OpenGLEngine/OpenGLEngine/ContactGenerationSystem.cpp b/OpenGLEngine/OpenGLEngine/ContactGenerationSystem.cpp deleted file mode 100644 index 3ecb9f3..0000000 --- a/OpenGLEngine/OpenGLEngine/ContactGenerationSystem.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "ContactGenerationSystem.h" - -namespace Reality -{ - ContactGenerationSystem::ContactGenerationSystem(rp3d::CollisionWorld& _rp3dWorld) : rp3dWorld(_rp3dWorld) - { - - } - - void ContactGenerationSystem::Update(float deltaTime) - { - if (contactReciever == nullptr) - { - contactReciever = new ContactInfoReciever(getWorld()); - } - rp3dWorld.testCollision(contactReciever); - } - - ContactGenerationSystem::~ContactGenerationSystem() - { - delete contactReciever; - } -} diff --git a/OpenGLEngine/OpenGLEngine/ContactGenerationSystem.h b/OpenGLEngine/OpenGLEngine/ContactGenerationSystem.h deleted file mode 100644 index 14c2b24..0000000 --- a/OpenGLEngine/OpenGLEngine/ContactGenerationSystem.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include "ECSConfig.h" -#include "ContactInfoReciever.h" -#include - -namespace Reality -{ - class ContactGenerationSystem : public ECSSystem - { - public: - ContactGenerationSystem(rp3d::CollisionWorld& _rp3dWorld); - void Update(float deltaTime); - ~ContactGenerationSystem(); - private: - rp3d::CollisionWorld& rp3dWorld; - ContactInfoReciever* contactReciever = nullptr; - }; -} diff --git a/OpenGLEngine/OpenGLEngine/ContactInfoReciever.h b/OpenGLEngine/OpenGLEngine/ContactInfoReciever.h deleted file mode 100644 index f472fdd..0000000 --- a/OpenGLEngine/OpenGLEngine/ContactInfoReciever.h +++ /dev/null @@ -1,66 +0,0 @@ -#pragma once -#include "ECSConfig.h" -#include "ContactEvent.h" -#include "RigidBodyData.h" -#include -#include -#include -namespace Reality -{ - class ContactInfoReciever : public rp3d::CollisionCallback - { - public: - ContactInfoReciever(ECSWorld& _world) : world(_world) {} - ECSWorld& world; - void notifyContact(const CollisionCallbackInfo& collisionCallbackInfo) - { - rp3d::ContactManifoldListElement * listElem = collisionCallbackInfo.contactManifoldElements; - // For each contact manifold - for (; listElem != nullptr; listElem = listElem->getNext()) { - rp3d::ContactManifold * manifold = listElem->getContactManifold(); - // Get the contact point - rp3d::ContactPoint * point = manifold->getContactPoints(); - // For each contact point of the manifold - for (int i = 0; i < manifold->getNbContactPoints(); i++) { - // Get the world - space contact point on body 1 - rp3d::Vector3 pos1 = point->getLocalPointOnShape1(); - // Get the world - space contact point on body 1 - rp3d::Vector3 pos2 = point->getLocalPointOnShape2(); - // Get the world - space contact normal - rp3d::Vector3 normal = point->getNormal(); - normal.normalize(); - // Get the penetration - rp3d::decimal penetration = point->getPenetrationDepth(); - // Get Body 1 - rp3d::CollisionBody* body1 = manifold->getBody1(); - assert(body1); - RigidBodyData* bodyA = (RigidBodyData*)(manifold->getBody1()->getUserData()); - // Get Body 2 - rp3d::CollisionBody* body2 = manifold->getBody2(); - assert(body2); - RigidBodyData* bodyB = (RigidBodyData*)(manifold->getBody2()->getUserData()); - // Get Collider 1 - rp3d::ProxyShape* shape1 = manifold->getShape1(); - assert(shape1); - // Get Collider 2 - rp3d::ProxyShape* shape2 = manifold->getShape2(); - assert(shape2); - // Get World Point 1 - rp3d::Vector3 worldPos1 = shape1->getLocalToWorldTransform() * pos1; - // Get World Point 2 - rp3d::Vector3 worldPos2 = shape2->getLocalToWorldTransform() * pos2; - // Create a contact event - world.getEventManager().emitEvent(bodyA->entity, bodyB->entity, - Vector3(normal.x, normal.y, normal.z), - penetration, - Vector3(pos1.x, pos1.y, pos1.z), - Vector3(pos2.x, pos2.y, pos2.z), - Vector3(worldPos1.x, worldPos1.y, worldPos1.z), - Vector3(worldPos2.x, worldPos2.y, worldPos2.z)); - // Go to the next point in the list - point = point->getNext(); - } - } - } - }; -} diff --git a/OpenGLEngine/OpenGLEngine/ContactResolutionSystem.cpp b/OpenGLEngine/OpenGLEngine/ContactResolutionSystem.cpp deleted file mode 100644 index 5999763..0000000 --- a/OpenGLEngine/OpenGLEngine/ContactResolutionSystem.cpp +++ /dev/null @@ -1,225 +0,0 @@ -#include "ContactResolutionSystem.h" -#include "TransformComponentV2.h" -#include "RigidBodyComponent.h" -#include - -namespace Reality -{ - - ContactResolutionSystem::ContactResolutionSystem(rp3d::CollisionWorld& _rp3dWorld) : rp3dWorld(_rp3dWorld) - { - } - - void ContactResolutionSystem::Update(float deltaTime) - { - auto contactEvents = getWorld().getEventManager().getEvents(); - for (auto& contact : contactEvents) - { - ResolvePenetration(contact); - ResolveVelocity(contact); - } - getWorld().data.renderUtil->RenderText("Num Contacts = " + to_string(contactEvents.size()), 1920 * 0.5f - 100, 1080 * 0.5f, 0.5f, Color::Red); - } - void ContactResolutionSystem::ResolvePenetration(ContactEvent & contact) - { - // Get Rigidbodies involved - auto& rbA = contact.entityA.getComponent(); - auto& rbB = contact.entityB.getComponent(); - auto& transformA = contact.entityA.getComponent(); - auto& transformB = contact.entityB.getComponent(); - - // Calculate contact point as avg - Vector3 contactPoint = (contact.worldPoint1 + contact.worldPoint2) * 0.5f; - - // Relative Positions - Vector3 relativePositionA = contact.worldPoint1 - transformA.GetPosition(); - Vector3 relativePositionB = contact.worldPoint2 - transformB.GetPosition(); - contact.normal *= -1; - // World Inertia Tensors - Mat3 worldInvInertiaTensorA = rbA.worldInverseInertiaTensor(transformA.GetRotationMatrix()); - Mat3 worldInvInertiaTensorB = rbB.worldInverseInertiaTensor(transformB.GetRotationMatrix()); - - float totalInertia = 0; - - Vector3 angularInertiaWorldA = glm::cross(relativePositionA, contact.normal); - angularInertiaWorldA = worldInvInertiaTensorA * angularInertiaWorldA; - angularInertiaWorldA = glm::cross(angularInertiaWorldA, relativePositionA); - - float angularInertiaA = glm::dot(angularInertiaWorldA, contact.normal); - float linearInertiaA = rbA.inverseMass; - totalInertia += angularInertiaA + linearInertiaA; - - Vector3 angularInertiaWorldB = glm::cross(relativePositionB, contact.normal); - angularInertiaWorldB = worldInvInertiaTensorB * angularInertiaWorldB; - angularInertiaWorldB = glm::cross(angularInertiaWorldB, relativePositionB); - - float angularInertiaB = glm::dot(angularInertiaWorldB, contact.normal); - float linearInertiaB = rbB.inverseMass; - totalInertia += angularInertiaB + linearInertiaB; - - // Total Moves - float inverseInertia = 1 / totalInertia; - float linearMoveA = contact.penetrationDepth * linearInertiaA * inverseInertia; - float linearMoveB = -contact.penetrationDepth * linearInertiaB * inverseInertia; - float angularMoveA = contact.penetrationDepth * angularInertiaA * inverseInertia; - float angularMoveB = -contact.penetrationDepth * angularInertiaB * inverseInertia; - - float limitA = angularLimitConstant * glm::length(relativePositionA); - if (abs(angularMoveA) > limitA) - { - float totalMoveA = linearMoveA + angularMoveA; - // Set the new angular move, with the same sign as before. - if (angularMoveA >= 0) - { - angularMoveA = limitA; - } else - { - angularMoveA = -limitA; - } - // Make the linear move take the extra slack. - linearMoveA = totalMoveA - angularMoveA; - } - - float limitB = angularLimitConstant * glm::length(relativePositionB); - if (abs(angularMoveB) > limitB) - { - float totalMoveB = linearMoveB + angularMoveB; - // Set the new angular move, with the same sign as before. - if (angularMoveB >= 0) - { - angularMoveB = limitB; - } - else - { - angularMoveB = -limitB; - } - // Make the linear move take the extra slack. - linearMoveB = totalMoveB - angularMoveB; - } - - // Update Linear Moves - transformA.SetPosition(transformA.GetPosition() + contact.normal * linearMoveA); - transformB.SetPosition(transformB.GetPosition() + contact.normal * linearMoveB); - - // Update Rotational Moves - // A - Vector3 impulsiveTorqueA = glm::cross(relativePositionA, contact.normal); - Vector3 impulsePerMoveA = worldInvInertiaTensorA * impulsiveTorqueA; - - Vector3 rotationPerMoveA = impulsePerMoveA * (1 / angularInertiaA); - Vector3 rotationA = rotationPerMoveA * angularMoveA; - - glm::quat rotationQuatA = glm::quat(0, rotationA.x, rotationA.y, rotationA.z); - transformA.SetOrientation(glm::normalize(transformA.GetOrientation() + 0.5f * rotationQuatA * transformA.GetOrientation())); - - // B - Vector3 impulsiveTorqueB = glm::cross(relativePositionB, contact.normal); - Vector3 impulsePerMoveB = worldInvInertiaTensorB * impulsiveTorqueB; - - Vector3 rotationPerMoveB = impulsePerMoveB * (1 / angularInertiaB); - Vector3 rotationB = rotationPerMoveB * angularMoveB; - - glm::quat rotationQuatB = glm::quat(0, rotationB.x, rotationB.y, rotationB.z); - transformB.SetOrientation(glm::normalize(transformB.GetOrientation() + 0.5f * rotationQuatB * transformB.GetOrientation())); - contact.normal *= -1; - - } - void ContactResolutionSystem::ResolveVelocity(ContactEvent & contact) - { - // Get Rigidbodies involved - auto& rbA = contact.entityA.getComponent(); - auto& rbB = contact.entityB.getComponent(); - auto& transformA = contact.entityA.getComponent(); - auto& transformB = contact.entityB.getComponent(); - - // Calculate contact point as avg - Vector3 contactPoint = (contact.worldPoint1 + contact.worldPoint2) * 0.5f; - - // Calculate contact point basis - Vector3 contactY; - Vector3 contactZ; - Mat3 contactLocalToWorld = Mat3(1.0f); - CalculateContactBasis(contact.normal, contactLocalToWorld, contactY, contactZ); - getWorld().data.renderUtil->DrawLine(contactPoint, contactPoint + 5.0f * contact.normal, Color::Red); - getWorld().data.renderUtil->DrawLine(contactPoint, contactPoint + 5.0f * contactY, Color::Green); - getWorld().data.renderUtil->DrawLine(contactPoint, contactPoint + 5.0f * contactZ, Color::Blue); - - // Relative Positions - Vector3 relativePositionA = contact.worldPoint1 - transformA.GetPosition(); - Vector3 relativePositionB = contact.worldPoint2 - transformB.GetPosition(); - - // World Inertia Tensors - Mat3 worldInvInertiaTensorA = rbA.worldInverseInertiaTensor(transformA.GetRotationMatrix()); - Mat3 worldInvInertiaTensorB = rbB.worldInverseInertiaTensor(transformB.GetRotationMatrix()); - - // Calculate velocity Per Unit Impulse - // Body A - Vector3 torquePerUnitImpulseA = glm::cross(relativePositionA, contact.normal); - Vector3 rotationPerUnitImpulseA = worldInvInertiaTensorA * torquePerUnitImpulseA; - Vector3 deltaVelWorldA = glm::cross(rotationPerUnitImpulseA, relativePositionA); - - float deltaVel = glm::dot(deltaVelWorldA, contact.normal); - deltaVel += rbA.inverseMass; - - // Body B - Vector3 torquePerUnitImpulseB = glm::cross(relativePositionB, contact.normal); - Vector3 rotationPerUnitImpulseB = worldInvInertiaTensorB * torquePerUnitImpulseB; - Vector3 deltaVelWorldB = glm::cross(rotationPerUnitImpulseB, relativePositionB); - - deltaVel += glm::dot(deltaVelWorldB, contact.normal); - deltaVel += rbB.inverseMass; - - // Closing Velocity - Vector3 velocityA = glm::cross(rbA.angularVelocity, relativePositionA); - velocityA += rbA.velocity; - - Vector3 velocityB = glm::cross(rbB.angularVelocity, relativePositionB); - velocityB += rbB.velocity; - - Vector3 closingVelocityWorld = velocityA - velocityB; - Vector3 closingVelocityLocal = glm::transpose(contactLocalToWorld) * closingVelocityWorld; - - if (closingVelocityLocal.x < 0) - { - return; - } - // Delta Velocity and impulse - float desiredDeltaVelocityLocal = -closingVelocityLocal.x * (1 + 0.4f); - Vector3 impulseContact = Vector3(desiredDeltaVelocityLocal / deltaVel, 0, 0); - Vector3 impulseA = contactLocalToWorld * impulseContact; - Vector3 impulseB = -impulseA; - - // Calculate Velocity Change - // A - Vector3 velocityChangeA = impulseA * rbA.inverseMass; - Vector3 rotationalTorqueA = glm::cross(relativePositionA, impulseA); - Vector3 angularVelocityChangeA = worldInvInertiaTensorA * rotationalTorqueA; - rbA.velocity += velocityChangeA; - rbA.angularVelocity += angularVelocityChangeA; - // B - Vector3 velocityChangeB = impulseB * rbB.inverseMass; - Vector3 rotationalTorqueB = glm::cross(relativePositionB, impulseB); - Vector3 angularVelocityChangeB = worldInvInertiaTensorB * rotationalTorqueB; - rbB.velocity += velocityChangeB; - rbB.angularVelocity += angularVelocityChangeB; - - // Debug Drawing - getWorld().data.renderUtil->DrawSphere(contact.worldPoint1, 0.4f, Color::Red); - getWorld().data.renderUtil->DrawSphere(contact.worldPoint2, 0.4f, Color::Blue); - getWorld().data.renderUtil->DrawLine(contact.worldPoint1, contact.worldPoint2, Color::Beige); - } - void ContactResolutionSystem::CalculateContactBasis(Vector3 contactNormal, Mat3 & transformationMat, Vector3 & y, Vector3 & z) - { - Vector3 possibleYAxis = Vector3(0, 1.0f, 0); - if (glm::length(glm::cross(possibleYAxis, contactNormal)) <= 0.01f) - { - possibleYAxis = Vector3(0, 0, 1.0f); - } - z = glm::normalize(glm::cross(contactNormal, possibleYAxis)); - y = glm::normalize(glm::cross(z, contactNormal)); - - transformationMat = Mat3(contactNormal.x, contactNormal.y, contactNormal.z, - y.x, y.y, y.z, - z.x, z.y, z.z); - } -} diff --git a/OpenGLEngine/OpenGLEngine/ContactResolutionSystem.h b/OpenGLEngine/OpenGLEngine/ContactResolutionSystem.h deleted file mode 100644 index 2b70f08..0000000 --- a/OpenGLEngine/OpenGLEngine/ContactResolutionSystem.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#include "ECSConfig.h" -#include "ContactEvent.h" -#include - -namespace Reality -{ - class ContactResolutionSystem : public ECSSystem - { - public: - ContactResolutionSystem(rp3d::CollisionWorld& _rp3dWorld); - void Update(float deltaTime); - rp3d::CollisionWorld& rp3dWorld; - float angularLimitConstant = 0.2f; - private: - void ResolvePenetration(ContactEvent& contact); - void ResolveVelocity(ContactEvent& contact); - void CalculateContactBasis(Vector3 contactNormal, Mat3& transformationMat, Vector3& y, Vector3& z); - }; -} \ No newline at end of file diff --git a/OpenGLEngine/OpenGLEngine/DragComponent.h b/OpenGLEngine/OpenGLEngine/DragComponent.h new file mode 100644 index 0000000..c802f1f --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/DragComponent.h @@ -0,0 +1,16 @@ +#pragma once +#include "ECSConfig.h" + +namespace Reality +{ + struct DragComponent + { + DragComponent(float _linearDrag = 0.3f, float _angularDrag = 0.3f) + :linearDrag(_linearDrag), angularDrag(_angularDrag) + { + + } + float linearDrag; + float angularDrag; + }; +} diff --git a/OpenGLEngine/OpenGLEngine/DragForceComponent.h b/OpenGLEngine/OpenGLEngine/DragForceComponent.h new file mode 100644 index 0000000..dec367f --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/DragForceComponent.h @@ -0,0 +1,16 @@ +#pragma once +#include "ECSConfig.h" + +namespace Reality +{ + struct DragForceComponent + { + DragForceComponent(float _k1 = 0.0f, float _k2 = 0.0f) + : k1(_k1), k2(_k2) + { + + } + float k1; + float k2; + }; +} diff --git a/OpenGLEngine/OpenGLEngine/DragForceSystem.cpp b/OpenGLEngine/OpenGLEngine/DragForceSystem.cpp new file mode 100644 index 0000000..591e326 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/DragForceSystem.cpp @@ -0,0 +1,29 @@ +#include "DragForceSystem.h" + +namespace Reality +{ + DragForceSystem::DragForceSystem() + { + requireComponent(); + requireComponent(); + requireComponent(); + } + + void DragForceSystem::Update(float deltaTime) + { + for (auto e : getEntities()) + { + auto& particle = e.getComponent(); + auto& forceAcc = e.getComponent(); + auto& drag = e.getComponent(); + + float speed = glm::length(particle.velocity); + if (speed > 0) + { + Vector3 force = -glm::normalize(particle.velocity); + force *= drag.k1 * speed + drag.k2 * pow(speed, 2); + forceAcc.AddForce(force); + } + } + } +} diff --git a/OpenGLEngine/OpenGLEngine/GravityForceGeneratorSystem.h b/OpenGLEngine/OpenGLEngine/DragForceSystem.h similarity index 50% rename from OpenGLEngine/OpenGLEngine/GravityForceGeneratorSystem.h rename to OpenGLEngine/OpenGLEngine/DragForceSystem.h index c9a720f..d3f21e8 100644 --- a/OpenGLEngine/OpenGLEngine/GravityForceGeneratorSystem.h +++ b/OpenGLEngine/OpenGLEngine/DragForceSystem.h @@ -1,15 +1,15 @@ #pragma once #include "ECSConfig.h" #include "ParticleComponent.h" +#include "ForceAccumulatorComponent.h" +#include "DragForceComponent.h" namespace Reality { - class GravityForceGeneratorSystem : public ECSSystem + class DragForceSystem : public ECSSystem { public: - Vector3 gravity = Vector3(0, -9.8f, 0); - GravityForceGeneratorSystem(); + DragForceSystem(); void Update(float deltaTime); }; } - diff --git a/OpenGLEngine/OpenGLEngine/DragSystem.cpp b/OpenGLEngine/OpenGLEngine/DragSystem.cpp new file mode 100644 index 0000000..8b51198 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/DragSystem.cpp @@ -0,0 +1,22 @@ +#include "DragSystem.h" + +namespace Reality +{ + DragSystem::DragSystem() + { + requireComponent(); + requireComponent(); + } + + void DragSystem::Update(float deltaTime) + { + for (auto e : getEntities()) + { + auto& rigidbody = e.getComponent(); + auto& drag = e.getComponent(); + + rigidbody.velocity *= pow(1.0f - drag.linearDrag, deltaTime); + rigidbody.angularVelocity *= pow(1.0f - drag.angularDrag, deltaTime); + } + } +} diff --git a/OpenGLEngine/OpenGLEngine/DragSystem.h b/OpenGLEngine/OpenGLEngine/DragSystem.h new file mode 100644 index 0000000..5636485 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/DragSystem.h @@ -0,0 +1,14 @@ +#pragma once +#include "ECSConfig.h" +#include "RigidbodyComponent.h" +#include "DragComponent.h" + +namespace Reality +{ + class DragSystem : public ECSSystem + { + public: + DragSystem(); + void Update(float deltaTime); + }; +} diff --git a/OpenGLEngine/OpenGLEngine/ECSConfig.h b/OpenGLEngine/OpenGLEngine/ECSConfig.h index dee62f8..08fdbcd 100644 --- a/OpenGLEngine/OpenGLEngine/ECSConfig.h +++ b/OpenGLEngine/OpenGLEngine/ECSConfig.h @@ -4,6 +4,7 @@ #include #include #define RANDOM_FLOAT(LO, HI) LO + static_cast (rand()) / (static_cast (RAND_MAX / (HI - LO))) +#define DEBUG_LOG_LEVEL 3 namespace Reality { diff --git a/OpenGLEngine/OpenGLEngine/FireworksComponent.h b/OpenGLEngine/OpenGLEngine/FireworksComponent.h new file mode 100644 index 0000000..f988802 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/FireworksComponent.h @@ -0,0 +1,20 @@ +#pragma once +#include "ECSConfig.h" + +namespace Reality +{ + struct FireworksComponent + { + FireworksComponent(int _numberOfParticles = 6, int _generation = 3, float _spawnTime = 3, float _velocityScale = 10.0f, Color _color = Color::Green) + :numberOfParticles(_numberOfParticles), generation(_generation), spawnTime(_spawnTime), velocityScale(_velocityScale),color(_color), timer(0.0f) + { + + } + int numberOfParticles; + int generation; + float spawnTime; + float timer; + float velocityScale; + Color color; + }; +} diff --git a/OpenGLEngine/OpenGLEngine/FireworksSystem.cpp b/OpenGLEngine/OpenGLEngine/FireworksSystem.cpp new file mode 100644 index 0000000..3d24430 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/FireworksSystem.cpp @@ -0,0 +1,60 @@ +#include "FireworksSystem.h" +#include "ParticleComponent.h" +#include "ForceAccumulatorComponent.h" +#include "GravityForceComponent.h" + +namespace Reality +{ + FireworksSystem::FireworksSystem() + { + requireComponent(); + requireComponent(); + } + + void FireworksSystem::Update(float deltaTime) + { + for (auto e : getEntities()) + { + auto& transform = e.getComponent(); + auto& fireworks = e.getComponent(); + + fireworks.timer += deltaTime; + if (fireworks.timer > fireworks.spawnTime) + { + if (fireworks.generation > 0) + { + float deltaAngle = 2 * AI_MATH_PI / fireworks.numberOfParticles; + for (int i = 0; i < fireworks.numberOfParticles; i++) + { + auto particle = getWorld().createEntity(); + particle.addComponent(transform.position); + float angle = i * deltaAngle; + Vector3 velocity = Vector3(0, 1, 0); + velocity.x = cos(angle); + velocity.z = sin(angle); + velocity *= fireworks.velocityScale; + particle.addComponent(velocity); + particle.addComponent(); + particle.addComponent(); + float colorAlpha = (float)i / (float)fireworks.numberOfParticles; + particle.addComponent( + fireworks.numberOfParticles, + fireworks.generation - 1, + fireworks.spawnTime + RANDOM_FLOAT(-0.3f, 0.3f), + fireworks.velocityScale, + Color(colorAlpha, 0, 1 - colorAlpha) + ); + + } + } + e.kill(); + } + + + if (DEBUG_LOG_LEVEL > 0) + { + getWorld().data.renderUtil->DrawSphere(transform.position, 1.0f, fireworks.color); + } + } + } +} diff --git a/OpenGLEngine/OpenGLEngine/FireworksSystem.h b/OpenGLEngine/OpenGLEngine/FireworksSystem.h new file mode 100644 index 0000000..c8bdc7f --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/FireworksSystem.h @@ -0,0 +1,14 @@ +#pragma once +#include "ECSConfig.h" +#include "TransformComponent.h" +#include "FireworksComponent.h" + +namespace Reality +{ + class FireworksSystem : public ECSSystem + { + public: + FireworksSystem(); + void Update(float deltaTime); + }; +} diff --git a/OpenGLEngine/OpenGLEngine/FixedSpringComponent.h b/OpenGLEngine/OpenGLEngine/FixedSpringComponent.h index b8b312b..dabd2d8 100644 --- a/OpenGLEngine/OpenGLEngine/FixedSpringComponent.h +++ b/OpenGLEngine/OpenGLEngine/FixedSpringComponent.h @@ -5,10 +5,17 @@ namespace Reality { struct FixedSpringComponent { - FixedSpringComponent(float _springConstant = 10, float _restLength = 10, ECSEntity e = ECSEntity()) - :springConstant(_springConstant), restLength(_restLength), entity(e){} + FixedSpringComponent(float _springConstant = 10.0f, + float _restLength = 10.0f, + ECSEntity _connectedEntity = ECSEntity()) + : springConstant(_springConstant), + restLength(_restLength), + connectedEntity(_connectedEntity) + { + + } float springConstant; float restLength; - ECSEntity entity; + ECSEntity connectedEntity; }; } diff --git a/OpenGLEngine/OpenGLEngine/FixedSpringSystem.cpp b/OpenGLEngine/OpenGLEngine/FixedSpringSystem.cpp new file mode 100644 index 0000000..ae5a0f6 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/FixedSpringSystem.cpp @@ -0,0 +1,55 @@ +#include "FixedSpringSystem.h" +#include "ForceAccumulatorComponent.h" + +namespace Reality +{ + FixedSpringSystem::FixedSpringSystem() + { + requireComponent(); + requireComponent(); + } + + void FixedSpringSystem::Update(float deltaTime) + { + for (auto e : getEntities()) + { + auto& springTransform = e.getComponent(); + auto& spring = e.getComponent(); + + if (spring.connectedEntity.hasComponent() + && spring.connectedEntity.hasComponent()) + { + auto& forceAcc = spring.connectedEntity.getComponent(); + auto& transform = spring.connectedEntity.getComponent(); + + Vector3 relativePosition = transform.position - springTransform.position; + float length = glm::length(relativePosition); + if (length > 0) + { + float deltaL = length - spring.restLength; + Vector3 force = -glm::normalize(relativePosition); + force *= spring.springConstant * deltaL; + forceAcc.AddForce(force); + + float g = 1.0f / (1.0f + pow(abs(deltaL), 0.5f)); + float r = 1 - g; + + Color col = Color(r, g, 0, 1); + + float deltaLength = length / 10.0f; + Vector3 direction = -glm::normalize(relativePosition); + for (int i = 0; i < 10; i++) + { + getWorld().data.renderUtil->DrawCube( + transform.position + (float)i * deltaLength * direction, + Vector3(1.0f, 1.0f, 1.0f) * min((spring.restLength / 20.0f), 100.0f), Vector3(0, 0, 0), col); + } + + getWorld().data.renderUtil->DrawLine(springTransform.position, transform.position, + col); + } + + } + } + } +} diff --git a/OpenGLEngine/OpenGLEngine/FixedSpringSystem.h b/OpenGLEngine/OpenGLEngine/FixedSpringSystem.h new file mode 100644 index 0000000..89968b1 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/FixedSpringSystem.h @@ -0,0 +1,14 @@ +#pragma once +#include "ECSConfig.h" +#include "TransformComponent.h" +#include "FixedSpringComponent.h" + +namespace Reality +{ + class FixedSpringSystem : public ECSSystem + { + public: + FixedSpringSystem(); + void Update(float deltaTime); + }; +} diff --git a/OpenGLEngine/OpenGLEngine/FlighSimulatorComponent.h b/OpenGLEngine/OpenGLEngine/FlighSimulatorComponent.h deleted file mode 100644 index 6d4420c..0000000 --- a/OpenGLEngine/OpenGLEngine/FlighSimulatorComponent.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include "ECSConfig.h" - -namespace Reality -{ - struct FlighSimulatorComponent - { - FlighSimulatorComponent(Vector3 _propulsion = Vector3(0.0f ,0.0f, 1000.0f)) - :propulsion(_propulsion) - { - - } - Vector3 propulsion; - }; -} diff --git a/OpenGLEngine/OpenGLEngine/FlightSimulatorSystem.cpp b/OpenGLEngine/OpenGLEngine/FlightSimulatorSystem.cpp deleted file mode 100644 index a2ff9d5..0000000 --- a/OpenGLEngine/OpenGLEngine/FlightSimulatorSystem.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "FlightSimulatorSystem.h" -#include "LifeTimeComponent.h" - -namespace Reality -{ - FlightSimulatorSystem::FlightSimulatorSystem() - { - requireComponent(); - requireComponent(); - requireComponent(); - } - - void FlightSimulatorSystem::Update(float deltaTime) - { - timer += deltaTime; - for (auto e : getEntities()) - { - auto& rigidbody = e.getComponent(); - auto& transform = e.getComponent(); - auto& flight = e.getComponent(); - - rigidbody.AddForce(transform.LocalToWorldDirection(flight.propulsion)); - //rigidbody.AddForce(Vector3(0, -10, 0)); - - // smoke - if (timer > 0.1f) - { - /*for (int i = 0; i < 3; i++) - { - auto e = getWorld().createEntity(); - e.addComponent(transform.GetPosition() + Vector3(RANDOM_FLOAT(-5.0f, 5.0f), RANDOM_FLOAT(-5.0f, 5.0f), RANDOM_FLOAT(-5.0f, 5.0f)) - transform.Forward() * 15.0f); - e.addComponent(7.0f); - }*/ - auto e = getWorld().createEntity(); - e.addComponent(transform.GetPosition() - transform.Forward() * 15.0f); - e.addComponent(7.0f); - timer = 0; - } - } - - if (getEntities().size() > 0) - { - float width = getWorld().data.renderUtil->window->width; - float height = getWorld().data.renderUtil->window->height; - - getWorld().data.renderUtil->RenderText("W , S - Pitch Controls", width / 2 - 100.0f, 60.0f, 0.4f, Color::Orange); - getWorld().data.renderUtil->RenderText("A , D - Yaw Controls", width / 2 - 100.0f, 35.0f, 0.4f, Color::Orange); - getWorld().data.renderUtil->RenderText("Q , E - Roll Controls", width / 2 - 100.0f, 10.0f, 0.4f, Color::Orange); - } - - } -} diff --git a/OpenGLEngine/OpenGLEngine/ForceAccumulatorComponent.h b/OpenGLEngine/OpenGLEngine/ForceAccumulatorComponent.h new file mode 100644 index 0000000..62ca949 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/ForceAccumulatorComponent.h @@ -0,0 +1,30 @@ +#pragma once +#include "ECSConfig.h" + +namespace Reality +{ + struct ForceAccumulatorComponent + { + ForceAccumulatorComponent(float _mass = 1.0f) + : inverseMass(1.0f / _mass), forceAccumulator(Vector3(0, 0, 0)) + { + + } + float inverseMass; + + inline void AddForce(Vector3 force) + { + forceAccumulator += force; + } + inline void ResetAccumulator() + { + forceAccumulator = Vector3(0, 0, 0); + } + inline Vector3 GetAccumulatedForce() + { + return forceAccumulator; + } + private: + Vector3 forceAccumulator; + }; +} diff --git a/OpenGLEngine/OpenGLEngine/ForceAccumulatorSystem.cpp b/OpenGLEngine/OpenGLEngine/ForceAccumulatorSystem.cpp index d1bbb3d..b4f7c21 100644 --- a/OpenGLEngine/OpenGLEngine/ForceAccumulatorSystem.cpp +++ b/OpenGLEngine/OpenGLEngine/ForceAccumulatorSystem.cpp @@ -1,21 +1,22 @@ #include "ForceAccumulatorSystem.h" - namespace Reality { ForceAccumulatorSystem::ForceAccumulatorSystem() { requireComponent(); + requireComponent(); } - void ForceAccumulatorSystem::Update(float deltaTime) { for (auto e : getEntities()) { - auto &particle = e.getComponent(); - particle.accelaration = particle.GetForce() * particle.inverseMass; - particle.ResetForceAccumulator(); + auto& particle = e.getComponent(); + auto& forceAcc = e.getComponent(); + + particle.acceleration = forceAcc.GetAccumulatedForce() * forceAcc.inverseMass; + forceAcc.ResetAccumulator(); } } } diff --git a/OpenGLEngine/OpenGLEngine/ForceAccumulatorSystem.h b/OpenGLEngine/OpenGLEngine/ForceAccumulatorSystem.h index ff375ad..ce612ed 100644 --- a/OpenGLEngine/OpenGLEngine/ForceAccumulatorSystem.h +++ b/OpenGLEngine/OpenGLEngine/ForceAccumulatorSystem.h @@ -1,6 +1,7 @@ #pragma once #include "ECSConfig.h" #include "ParticleComponent.h" +#include "ForceAccumulatorComponent.h" namespace Reality { @@ -11,4 +12,3 @@ namespace Reality void Update(float deltaTime); }; } - diff --git a/OpenGLEngine/OpenGLEngine/ForceAndTorqueAccumulatorComponent.h b/OpenGLEngine/OpenGLEngine/ForceAndTorqueAccumulatorComponent.h new file mode 100644 index 0000000..7d9f67b --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/ForceAndTorqueAccumulatorComponent.h @@ -0,0 +1,58 @@ +#pragma once +#include "ECSConfig.h" + +namespace Reality +{ + struct ForceAndTorqueAccumulatorComponent + { + ForceAndTorqueAccumulatorComponent(float _mass = 1.0f, float _inertia = 1.0f) + : inverseMass(1.0f / _mass), forceAccumulator(Vector3(0, 0, 0)), + inertiaTensor(Mat3(_inertia)), torqueAccumulator(Vector3(0, 0, 0)) + { + + } + float inverseMass; + Mat3 inertiaTensor; + + inline void AddForce(const Vector3& force) + { + forceAccumulator += force; + } + inline void ResetForceAccumulator() + { + forceAccumulator = Vector3(0, 0, 0); + } + inline const Vector3& GetAccumulatedForce() + { + return forceAccumulator; + } + + inline void AddTorque(const Vector3& torque) + { + torqueAccumulator += torque; + } + inline void ResetTorqueAccumulator() + { + torqueAccumulator = Vector3(0, 0, 0); + } + inline const Vector3& GetAccumulatedTorque() + { + return torqueAccumulator; + } + + inline void AddForceAtPoint(const Vector3& force, const Vector3& point, const Vector3& origin) + { + AddForce(force); + AddTorque(glm::cross(point - origin, force)); + } + + inline const Mat3& GetWorldInverseInertiaTensor(const Mat3& localToWorldRotation) + { + return localToWorldRotation * inertiaTensor * glm::inverse(localToWorldRotation); + } + + private: + Vector3 forceAccumulator; + Vector3 torqueAccumulator; + }; +} diff --git a/OpenGLEngine/OpenGLEngine/ForceAndTorqueAccumulatorSystem.cpp b/OpenGLEngine/OpenGLEngine/ForceAndTorqueAccumulatorSystem.cpp index 3b91bdb..8f1cf94 100644 --- a/OpenGLEngine/OpenGLEngine/ForceAndTorqueAccumulatorSystem.cpp +++ b/OpenGLEngine/OpenGLEngine/ForceAndTorqueAccumulatorSystem.cpp @@ -5,23 +5,24 @@ namespace Reality ForceAndTorqueAccumulatorSystem::ForceAndTorqueAccumulatorSystem() { requireComponent(); - requireComponent(); + requireComponent(); + requireComponent(); } void ForceAndTorqueAccumulatorSystem::Update(float deltaTime) { for (auto e : getEntities()) { - auto &rigidbody = e.getComponent(); - auto &transform = e.getComponent(); + auto& transform = e.getComponent(); + auto& rigidbody = e.getComponent(); + auto& forceAndTorqueAcc = e.getComponent(); - rigidbody.accelaration = rigidbody.GetForce() * rigidbody.inverseMass; - rigidbody.ResetForceAccumulator(); + rigidbody.acceleration = forceAndTorqueAcc.GetAccumulatedForce() * forceAndTorqueAcc.inverseMass; + forceAndTorqueAcc.ResetForceAccumulator(); - Mat3 rotMat = transform.GetRotationMatrix(); - rigidbody.angularAccelaration = rigidbody.worldInverseInertiaTensor(rotMat) - * rigidbody.GetTorque(); - rigidbody.ResetTorqueAccumulator(); + Mat3 worldInvInertia = forceAndTorqueAcc.GetWorldInverseInertiaTensor(transform.GetRotationMatrix()); + rigidbody.angularAcceleration = worldInvInertia * forceAndTorqueAcc.GetAccumulatedTorque(); + forceAndTorqueAcc.ResetTorqueAccumulator(); } } } diff --git a/OpenGLEngine/OpenGLEngine/ForceAndTorqueAccumulatorSystem.h b/OpenGLEngine/OpenGLEngine/ForceAndTorqueAccumulatorSystem.h index d4f0221..cea9f11 100644 --- a/OpenGLEngine/OpenGLEngine/ForceAndTorqueAccumulatorSystem.h +++ b/OpenGLEngine/OpenGLEngine/ForceAndTorqueAccumulatorSystem.h @@ -1,6 +1,7 @@ #pragma once #include "ECSConfig.h" -#include "RigidBodyComponent.h" +#include "RigidbodyComponent.h" +#include "ForceAndTorqueAccumulatorComponent.h" #include "TransformComponentV2.h" namespace Reality diff --git a/OpenGLEngine/OpenGLEngine/GravityForceComponent.h b/OpenGLEngine/OpenGLEngine/GravityForceComponent.h new file mode 100644 index 0000000..09ad65b --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/GravityForceComponent.h @@ -0,0 +1,15 @@ +#pragma once +#include "ECSConfig.h" + +namespace Reality +{ + struct GravityForceComponent + { + GravityForceComponent(float _gravityScale = 1.0f) + : gravityScale(_gravityScale) + { + + } + float gravityScale; + }; +} diff --git a/OpenGLEngine/OpenGLEngine/GravityForceGeneratorSystem.cpp b/OpenGLEngine/OpenGLEngine/GravityForceGeneratorSystem.cpp deleted file mode 100644 index c1df543..0000000 --- a/OpenGLEngine/OpenGLEngine/GravityForceGeneratorSystem.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "GravityForceGeneratorSystem.h" - - -namespace Reality -{ - GravityForceGeneratorSystem::GravityForceGeneratorSystem() - { - requireComponent(); - } - - - void GravityForceGeneratorSystem::Update(float deltaTime) - { - for (auto e : getEntities()) - { - auto &particle = e.getComponent(); - particle.AddForce(gravity * particle.gravityScale / particle.inverseMass); - } - - } -} diff --git a/OpenGLEngine/OpenGLEngine/GravityForceSystem.cpp b/OpenGLEngine/OpenGLEngine/GravityForceSystem.cpp new file mode 100644 index 0000000..142c144 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/GravityForceSystem.cpp @@ -0,0 +1,24 @@ +#include "GravityForceSystem.h" + +namespace Reality +{ + GravityForceSystem::GravityForceSystem() + { + requireComponent(); + requireComponent(); + } + + void GravityForceSystem::Update(float deltaTime) + { + for (auto e : getEntities()) + { + auto& forceAcc = e.getComponent(); + auto& gravity = e.getComponent(); + + if (forceAcc.inverseMass > 0) + { + forceAcc.AddForce(worldGravity * gravity.gravityScale / forceAcc.inverseMass); + } + } + } +} diff --git a/OpenGLEngine/OpenGLEngine/GravityForceSystem.h b/OpenGLEngine/OpenGLEngine/GravityForceSystem.h new file mode 100644 index 0000000..ab42edf --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/GravityForceSystem.h @@ -0,0 +1,15 @@ +#pragma once +#include "ECSConfig.h" +#include "ForceAndTorqueAccumulatorComponent.h" +#include "GravityForceComponent.h" + +namespace Reality +{ + class GravityForceSystem : public ECSSystem + { + public: + GravityForceSystem(); + void Update(float deltaTime); + Vector3 worldGravity = Vector3(0.0f, -9.8f, 0.0f); + }; +} diff --git a/OpenGLEngine/OpenGLEngine/InfiniteSpawnComponent.h b/OpenGLEngine/OpenGLEngine/InfiniteSpawnComponent.h deleted file mode 100644 index 8a81892..0000000 --- a/OpenGLEngine/OpenGLEngine/InfiniteSpawnComponent.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include "ECSConfig.h" - -namespace Reality -{ - struct InfiniteSpawnComponent - { - InfiniteSpawnComponent(float _height = 0) - : height(_height) - { - - } - float height; - }; -} diff --git a/OpenGLEngine/OpenGLEngine/InfiniteSpawnSystem.cpp b/OpenGLEngine/OpenGLEngine/InfiniteSpawnSystem.cpp deleted file mode 100644 index ae10ce8..0000000 --- a/OpenGLEngine/OpenGLEngine/InfiniteSpawnSystem.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "InfiniteSpawnSystem.h" -#include "SpawnTargetEvent.h" - -namespace Reality -{ - InfiniteSpawnSystem::InfiniteSpawnSystem() - { - requireComponent(); - requireComponent(); - } - - void InfiniteSpawnSystem::Update(float deltaTime) - { - auto targetEvents = getWorld().getEventManager().getEvents(); - - if (targetEvents.size() > 0) - { - Vector3 target = targetEvents[0].targetPos; - - for (auto e : getEntities()) - { - auto& spawn = e.getComponent(); - auto& transform = e.getComponent(); - - if (abs(target.z - transform.GetPosition().z) > 2050.0f) - { - transform.SetPosition(transform.GetPosition() + (target.z > transform.GetPosition().z ? 4050.0f : -4050.0f) * Vector3(0, 0, 1)); - spawn.height = RANDOM_FLOAT(100.0f, 500.0f); - } - getWorld().data.renderUtil->DrawCube(transform.GetPosition() + spawn.height * 0.5f * Vector3(0, 1, 0), Vector3(50.0f, spawn.height, 50.0f)); - } - } - } -} diff --git a/OpenGLEngine/OpenGLEngine/InfiniteSpawnSystem.h b/OpenGLEngine/OpenGLEngine/InfiniteSpawnSystem.h deleted file mode 100644 index cb95b34..0000000 --- a/OpenGLEngine/OpenGLEngine/InfiniteSpawnSystem.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include "ECSConfig.h" -#include "InfiniteSpawnComponent.h" -#include "TransformComponentV2.h" - -namespace Reality -{ - class InfiniteSpawnSystem : public ECSSystem - { - public: - InfiniteSpawnSystem(); - void Update(float deltaTime); - }; -} diff --git a/OpenGLEngine/OpenGLEngine/InfiniteSpawnTargetComponent.h b/OpenGLEngine/OpenGLEngine/InfiniteSpawnTargetComponent.h deleted file mode 100644 index 317a9ad..0000000 --- a/OpenGLEngine/OpenGLEngine/InfiniteSpawnTargetComponent.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include "ECSConfig.h" - -namespace Reality -{ - struct InfiniteSpawnTargetComponent - { - InfiniteSpawnTargetComponent() - { - - } - }; -} diff --git a/OpenGLEngine/OpenGLEngine/InfiniteSpawnTargetSystem.cpp b/OpenGLEngine/OpenGLEngine/InfiniteSpawnTargetSystem.cpp deleted file mode 100644 index 5434839..0000000 --- a/OpenGLEngine/OpenGLEngine/InfiniteSpawnTargetSystem.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "InfiniteSpawnTargetSystem.h" -#include "SpawnTargetEvent.h" - -namespace Reality -{ - InfiniteSpawnTargetSystem::InfiniteSpawnTargetSystem() - { - requireComponent(); - requireComponent(); - } - - void InfiniteSpawnTargetSystem::Update(float deltaTime) - { - for (auto e : getEntities()) - { - auto& transform = e.getComponent(); - getWorld().getEventManager().emitEvent(transform.GetPosition()); - } - } -} diff --git a/OpenGLEngine/OpenGLEngine/InfiniteSpawnTargetSystem.h b/OpenGLEngine/OpenGLEngine/InfiniteSpawnTargetSystem.h deleted file mode 100644 index 7694392..0000000 --- a/OpenGLEngine/OpenGLEngine/InfiniteSpawnTargetSystem.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include "ECSConfig.h" -#include "InfiniteSpawnTargetComponent.h" -#include "TransformComponentV2.h" - -namespace Reality -{ - class InfiniteSpawnTargetSystem : public ECSSystem - { - public: - InfiniteSpawnTargetSystem(); - void Update(float deltaTime); - }; -} diff --git a/OpenGLEngine/OpenGLEngine/LifeTimeComponent.h b/OpenGLEngine/OpenGLEngine/LifeTimeComponent.h index 0173690..94ed8c2 100644 --- a/OpenGLEngine/OpenGLEngine/LifeTimeComponent.h +++ b/OpenGLEngine/OpenGLEngine/LifeTimeComponent.h @@ -5,14 +5,13 @@ namespace Reality { struct LifeTimeComponent { - LifeTimeComponent(float _maxTime = 10) - :maxTime(_maxTime), timer(0), startSize(RANDOM_FLOAT(1.0f, 3.0f)), size(0) + LifeTimeComponent(float _maxTime = 5, Color _color = Color::Green) + :maxTime(_maxTime), timer(0), color(_color) { } float maxTime; float timer; - float startSize; - float size; + Color color; }; } diff --git a/OpenGLEngine/OpenGLEngine/LifeTimeSystem.cpp b/OpenGLEngine/OpenGLEngine/LifeTimeSystem.cpp index b188084..afe6b1a 100644 --- a/OpenGLEngine/OpenGLEngine/LifeTimeSystem.cpp +++ b/OpenGLEngine/OpenGLEngine/LifeTimeSystem.cpp @@ -4,21 +4,21 @@ namespace Reality { LifeTimeSystem::LifeTimeSystem() { - requireComponent(); requireComponent(); + requireComponent(); } void LifeTimeSystem::Update(float deltaTime) { for (auto e : getEntities()) { - auto& life = e.getComponent(); auto& transform = e.getComponent(); + auto& lifeTime = e.getComponent(); + + getWorld().data.renderUtil->DrawSphere(transform.GetPosition(), 1.0f, lifeTime.color); - life.timer += deltaTime; - life.size = life.startSize + 10.0f * pow(life.timer, 0.5f); - getWorld().data.renderUtil->DrawSphere(transform.GetPosition(), life.size, Color::Yellow); - if (life.timer > life.maxTime) + lifeTime.timer += deltaTime; + if (lifeTime.timer >= lifeTime.maxTime) { e.kill(); } diff --git a/OpenGLEngine/OpenGLEngine/LifeTimeSystem.h b/OpenGLEngine/OpenGLEngine/LifeTimeSystem.h index 17b76fb..db8725c 100644 --- a/OpenGLEngine/OpenGLEngine/LifeTimeSystem.h +++ b/OpenGLEngine/OpenGLEngine/LifeTimeSystem.h @@ -1,7 +1,7 @@ #pragma once #include "ECSConfig.h" -#include "LifeTimeComponent.h" #include "TransformComponentV2.h" +#include "LifeTimeComponent.h" namespace Reality { diff --git a/OpenGLEngine/OpenGLEngine/Main.cpp b/OpenGLEngine/OpenGLEngine/Main.cpp index 91a5161..e1e60d5 100644 --- a/OpenGLEngine/OpenGLEngine/Main.cpp +++ b/OpenGLEngine/OpenGLEngine/Main.cpp @@ -1,59 +1,55 @@ //#define STB_IMAGE_IMPLEMENTATION -#include "UpdateTransformMatricesSystem.h" #include "RenderingSystem.h" #include "RenderingSystemV2.h" #include "InputEventSystem.h" +#include "FPSControlSystem.h" +#include "FollowCameraSystem.h" #include "RotateSystem.h" -#include "ParticleSystem.h" -#include "ParticleSpawnerSystem.h" -#include "GravityForceGeneratorSystem.h" -#include "FixedSpringForceGeneratorSystem.h" -#include "ForceAccumulatorSystem.h" -#include "PairedSpringForceGeneratorSystem.h" -#include "SphereContactGeneratorSystem.h" -#include "ParticleContactResolutionSystem.h" -#include "CableComponentSystem.h" +#include "RotateSystemV2.h" +#include "LifeTimeSystem.h" +#include "FireworksSystem.h" +#include "GravityForceSystem.h" +#include "DragForceSystem.h" +#include "FixedSpringSystem.h" +#include "PairedSpringSystem.h" +#include "ParticleSphereSystem.h" +#include "BuoyancySystem.h" +#include "CableSystem.h" #include "RodSystem.h" +#include "ParticleContactResolutionSystem.h" +#include "ResetPenetrationDeltaMoveSystem.h" +#include "ForceAccumulatorSystem.h" +#include "ParticleSystem.h" +#include "RigidbodySystem.h" #include "ForceAndTorqueAccumulatorSystem.h" -#include "RigidBodySystem.h" -#include "RigidbodyGravityForceGeneratorSystem.h" -#include "ContactGenerationSystem.h" -#include "ContactResolutionSystem.h" -#include "SphereColliderSystem.h" -#include "BoxColliderSystem.h" -#include "MoveInBoundsSystem.h" -#include "FPSControlSystem.h" +#include "DragSystem.h" +#include "AddTorqueFromCameraSystem.h" +#include "AeroControlSystem.h" +#include "AeroSurfaceSystem.h" +#include "ThrusterSystem.h" #include "DynamicDirectionalLightSystem.h" #include "DynamicPointLightSystem.h" #include "DynamicSpotLightSystem.h" -#include "FlightSimulatorSystem.h" -#include "FollowCameraSystem.h" -#include "InfiniteSpawnSystem.h" -#include "InfiniteSpawnTargetSystem.h" -#include "AeroControlSystem.h" -#include "SetAerodynamicTensorSystem.h" -#include "AeroSystem.h" -#include "CameraLookSystem.h" -#include "LifeTimeSystem.h" #include #include #include -#define DEBUG_LOG_LEVEL 3 - using namespace Reality; void LoadShaders(ECSWorld& world); void LoadModels(ECSWorld& world); +void SetupLights(ECSWorld& world); void MakeABunchaObjects(ECSWorld& world); +void MakeFireworks(ECSWorld& world); +void Make3Particles(ECSWorld& world); void MakeABunchaSprings(ECSWorld& world); void MakeABunchaSpheres(ECSWorld& world); -void MakeACable(ECSWorld& world); -void MakeCablesAndRods(ECSWorld& world); -void MakeFlight(ECSWorld& world); -void TestContacts(ECSWorld& world); -void TestCollision(ECSWorld& world); -void SetupLights(ECSWorld& world); +void MakeABunchaCablesAndRods(ECSWorld& world); +void MakeARopeBridge(ECSWorld& world); +void MakeABunchaObjectsV2(ECSWorld& world); +void MakeRigidBodyTest(ECSWorld& world); +void MakeAFlightSimulator(ECSWorld& world); +void MakeABoatSImulator(ECSWorld& world); int main() { @@ -63,7 +59,7 @@ int main() world.data.InitRendering(); //LoadAssets(world); - world.data.renderUtil->camera.Position = Vector3(0, 15.0f, 100.0f); + world.data.renderUtil->camera.Position = Vector3(0, 0.0f, 50.0f); world.data.renderUtil->SetFOV(60); // Create entities @@ -71,63 +67,52 @@ int main() auto e = world.createEntity(); e.addComponent(); - //auto wall = world.createEntity(); - //wall.addComponent(Vector3(0, -3.0f, 0.0f), Vector3(0.1f, 0.1f, 0.1f), Vector3(0, 270, 0)); - //// Add mesh - //wall.addComponent("Resources/Models/Sponza-master/sponza.obj"); - SetupLights(world); //MakeABunchaObjects(world); - //MakeABunchaSpheres(world); + //MakeFireworks(world); + //Make3Particles(world); //MakeABunchaSprings(world); - //MakeACable(world); - //akeCablesAndRods(world); - //MakeFlight(world); - //TestContacts(world); - TestCollision(world); + //MakeABunchaSpheres(world); + //MakeABunchaCablesAndRods(world); + //MakeARopeBridge(world); + //MakeABunchaObjectsV2(world); + //MakeRigidBodyTest(world); + //MakeAFlightSimulator(world); + MakeABoatSImulator(world); // Create Systems - world.getSystemManager().addSystem(); world.getSystemManager().addSystem(); world.getSystemManager().addSystem(); world.getSystemManager().addSystem(); + world.getSystemManager().addSystem(); + world.getSystemManager().addSystem(); world.getSystemManager().addSystem(); - world.getSystemManager().addSystem(); - world.getSystemManager().addSystem(); - world.getSystemManager().addSystem(); - world.getSystemManager().addSystem(); - world.getSystemManager().addSystem(); - world.getSystemManager().addSystem(); - world.getSystemManager().addSystem(); + world.getSystemManager().addSystem(); + world.getSystemManager().addSystem(); + world.getSystemManager().addSystem(); + world.getSystemManager().addSystem(); + world.getSystemManager().addSystem(); + world.getSystemManager().addSystem(); + world.getSystemManager().addSystem(); + world.getSystemManager().addSystem(); + world.getSystemManager().addSystem(); world.getSystemManager().addSystem(); world.getSystemManager().addSystem(); + world.getSystemManager().addSystem(); world.getSystemManager().addSystem(); + world.getSystemManager().addSystem(); + world.getSystemManager().addSystem(); + world.getSystemManager().addSystem(); world.getSystemManager().addSystem(); - world.getSystemManager().addSystem(); - world.getSystemManager().addSystem(); - world.getSystemManager().addSystem(); - world.getSystemManager().addSystem(); - world.getSystemManager().addSystem(); - world.getSystemManager().addSystem(); + world.getSystemManager().addSystem(); + world.getSystemManager().addSystem(); world.getSystemManager().addSystem(); - world.getSystemManager().addSystem(); - world.getSystemManager().addSystem(); - world.getSystemManager().addSystem(); - world.getSystemManager().addSystem(); + world.getSystemManager().addSystem(); + world.getSystemManager().addSystem(); world.getSystemManager().addSystem(); world.getSystemManager().addSystem(); world.getSystemManager().addSystem(); - // Rigidbody Physics - rp3d::CollisionWorld rp3dWorld; - world.getSystemManager().addSystem(rp3dWorld); - world.getSystemManager().addSystem(rp3dWorld); - world.getSystemManager().addSystem(rp3dWorld); - world.getSystemManager().addSystem(rp3dWorld); - world.getSystemManager().addSystem(rp3dWorld); - world.getSystemManager().addSystem(); - - float time = glfwGetTime(); float stepTime = glfwGetTime(); float deltaTime = 0; @@ -171,49 +156,54 @@ int main() // Game Logic Update world.getSystemManager().getSystem().Update(deltaTime); - world.getSystemManager().getSystem().Update(deltaTime); - world.getSystemManager().getSystem().Update(deltaTime); - world.getSystemManager().getSystem().Update(deltaTime); - - //Flight Sim - world.getSystemManager().getSystem().Update(deltaTime); world.getSystemManager().getSystem().Update(deltaTime); - world.getSystemManager().getSystem().Update(deltaTime); - world.getSystemManager().getSystem().Update(deltaTime); - world.getSystemManager().getSystem().Update(deltaTime); - world.getSystemManager().getSystem().Update(deltaTime); - world.getSystemManager().getSystem().Update(deltaTime); + world.getSystemManager().getSystem().Update(deltaTime); + world.getSystemManager().getSystem().Update(deltaTime); world.getSystemManager().getSystem().Update(deltaTime); + world.getSystemManager().getSystem().Update(deltaTime); + world.getSystemManager().getSystem().Update(deltaTime); + world.getSystemManager().getSystem().Update(deltaTime); + world.getSystemManager().getSystem().Update(deltaTime); + world.getSystemManager().getSystem().Update(deltaTime); + world.getSystemManager().getSystem().Update(deltaTime); // Update Transform - world.getSystemManager().getSystem().Update(deltaTime); + // Physics - float fixedDeltaTime = glfwGetKey(world.data.renderUtil->window->glfwWindow, GLFW_KEY_SPACE) == GLFW_PRESS ? 1 / 60.0f : 0; - //float fixedDeltaTime = 1 / 60.0f; - world.getSystemManager().getSystem().Update(fixedDeltaTime); - world.getSystemManager().getSystem().Update(fixedDeltaTime); - // Particle Force Generators - world.getSystemManager().getSystem().Update(fixedDeltaTime); - world.getSystemManager().getSystem().Update(fixedDeltaTime); - world.getSystemManager().getSystem().Update(fixedDeltaTime); + //float fixedDeltaTime = glfwGetKey(world.data.renderUtil->window->glfwWindow, GLFW_KEY_SPACE) == GLFW_PRESS ? 1 / 60.0f : 0; + float fixedDeltaTime = 1 / 60.0f; + // Force Generator + /// Particle + world.getSystemManager().getSystem().Update(fixedDeltaTime); + world.getSystemManager().getSystem().Update(fixedDeltaTime); + world.getSystemManager().getSystem().Update(fixedDeltaTime); + world.getSystemManager().getSystem().Update(fixedDeltaTime); + world.getSystemManager().getSystem().Update(fixedDeltaTime); + /// Rigidbody + world.getSystemManager().getSystem().Update(fixedDeltaTime); + world.getSystemManager().getSystem().Update(fixedDeltaTime); + world.getSystemManager().getSystem().Update(fixedDeltaTime); + + // Force Accumulator + /// Particle world.getSystemManager().getSystem().Update(fixedDeltaTime); - world.getSystemManager().getSystem().Update(fixedDeltaTime); - // Rigiidbody Force Generators and collisions - world.getSystemManager().getSystem().Update(fixedDeltaTime); + /// Rigidbody world.getSystemManager().getSystem().Update(fixedDeltaTime); - world.getSystemManager().getSystem().Update(fixedDeltaTime); - world.getSystemManager().getSystem().Update(fixedDeltaTime); - world.getSystemManager().getSystem().Update(fixedDeltaTime); - // Physics Solvers - world.getSystemManager().getSystem().Update(fixedDeltaTime); - world.getSystemManager().getSystem().Update(fixedDeltaTime); - world.getSystemManager().getSystem().Update(fixedDeltaTime); + + // Contact Resolution world.getSystemManager().getSystem().Update(fixedDeltaTime); + world.getSystemManager().getSystem().Update(fixedDeltaTime); - world.getSystemManager().getSystem().Update(fixedDeltaTime); - world.getSystemManager().getSystem().Update(fixedDeltaTime); + // Integrator + /// Particle + world.getSystemManager().getSystem().Update(fixedDeltaTime); + /// Rigidbody + world.getSystemManager().getSystem().Update(fixedDeltaTime); // Rendering Update + ///*** HACK: For the last DrawCall not working on some systems + world.data.renderUtil->DrawCube(Vector3(0, 0, 0), Vector3(0, 0, 0)); + ///*** HACK: For the last DrawCall not working on some systems world.getSystemManager().getSystem().Update(deltaTime); world.getSystemManager().getSystem().Update(deltaTime); world.getSystemManager().getSystem().Update(deltaTime); @@ -276,365 +266,480 @@ void LoadShaders(ECSWorld& world) void LoadModels(ECSWorld& world) { world.data.assetLoader->StartModelLoading({ - //ModelData("Resources/Models/snowy-mountain-terrain/SnowyMountainMesh.obj"), //ModelData("Resources/Models/Sponza-master/sponza.obj"), - //ModelData("Resources/Models/nanosuit/nanosuit.obj"),*/ + //ModelData("Resources/Models/nanosuit/nanosuit.obj"), ModelData("Resources/Models/supermarine-spitfire/spitfire.fbx", - {{"spitfire_d.png"}}) + {{"spitfire_d.png"}}), + ModelData("Resources/Models/Boat/boat.obj", {{"wood1.jpg"}}) }); } void MakeABunchaObjects(ECSWorld& world) { - auto e = world.createEntity(); - e.addComponent(Vector3(4, 10.0f, 48), Vector3(0.10f, 0.1f, 0.1f), Vector3(-90, 180, 0)); + auto castle = world.createEntity(); + castle.addComponent(Vector3(0, -3.0f, 0.0f), Vector3(0.1f, 0.1f, 0.1f), Vector3(0, 270, 0)); // Add mesh - e.addComponent("Resources/Models/supermarine-spitfire/spitfire.fbx"); - e.addComponent(0, 40, 0); + castle.addComponent("Resources/Models/Sponza-master/sponza.obj"); + + //auto flight = world.createEntity(); + //flight.addComponent(Vector3(0, 30, -50), Vector3(0.1f, 0.1f, 0.1f), Vector3(270, 0, 0)); + //// Add mesh + //flight.addComponent("Resources/Models/supermarine-spitfire/spitfire.fbx"); + //flight.addComponent(Vector3(0, 90, 0)); + //flight.addComponent(Vector3(0, 30, 0)); + //flight.addComponent(); + //flight.addComponent(); - e = world.createEntity(); - e.addComponent(Vector3(4, 10.0f, -62), Vector3(0.1f, 0.1f, 0.1f), Vector3(-90, 0, 0)); - // Add mesh - e.addComponent("Resources/Models/supermarine-spitfire/spitfire.fbx"); - e.addComponent(0, 40, 0); } -void MakeABunchaSprings(ECSWorld& world) +void MakeFireworks(ECSWorld & world) { - auto e = world.createEntity(); - float yOffset = 30; - e.addComponent(Vector3(-2.5f, -5 + yOffset, -3), Vector3(1.0f, 1.0f, 1.0f)); - e.addComponent(); - // Add mesh - e.addComponent("Resources/Models/nanosuit/nanosuit.obj"); - - auto springEntinty = world.createEntity(); - springEntinty.addComponent(Vector3(-2.5f, 0 + yOffset, 3)); - springEntinty.addComponent(8, 2, e); + for (int i = 0; i < 3; i++) + { + auto fireworks = world.createEntity(); + fireworks.addComponent(Vector3(-100 + 100 * i, 30 + RANDOM_FLOAT(-10, 10), -50)); + fireworks.addComponent(Vector3(0, 100, 0)); + fireworks.addComponent(); + fireworks.addComponent(); + fireworks.addComponent(6, 3, 3 + RANDOM_FLOAT(-1, 1)); + } + +} - auto e2 = world.createEntity(); - e2.addComponent(Vector3(2.5f, -5 + yOffset, -1), Vector3(1.0f, 1.0f, 1.0f)); - e2.addComponent(); - // Add mesh - e2.addComponent("Resources/Models/nanosuit/nanosuit.obj"); +void Make3Particles(ECSWorld & world) +{ + auto particle1 = world.createEntity(); + particle1.addComponent(Vector3(-10, 60, -50)); + particle1.addComponent(Vector3(0, 0, 0)); + particle1.addComponent(); + particle1.addComponent(); + particle1.addComponent(0, 0); + + auto particle2 = world.createEntity(); + particle2.addComponent(Vector3(0, 60, -50)); + particle2.addComponent(Vector3(0, 0, 0)); + particle2.addComponent(); + particle2.addComponent(); + particle2.addComponent(1, 0); + + auto particle3 = world.createEntity(); + particle3.addComponent(Vector3(10, 60, -50)); + particle3.addComponent(Vector3(0, 0, 0)); + particle3.addComponent(); + particle3.addComponent(); + particle3.addComponent(1, 1); +} - auto springEntinty2 = world.createEntity(); - springEntinty2.addComponent(Vector3(2.5f, 0 + yOffset, 1)); - springEntinty2.addComponent(5, 5, e2); +void MakeABunchaSprings(ECSWorld & world) +{ + auto particle1 = world.createEntity(); + particle1.addComponent(Vector3(0, 20, -50)); + particle1.addComponent(Vector3(0, 0, 0)); + particle1.addComponent(); + particle1.addComponent(); + + auto particle2= world.createEntity(); + particle2.addComponent(Vector3(-10, 0, -50)); + particle2.addComponent(Vector3(0, 0, 0)); + particle2.addComponent(); + particle2.addComponent(); + + auto spring1 = world.createEntity(); + spring1.addComponent(Vector3(10, 60, -50)); + spring1.addComponent(20.0f, 20.0f, particle1); + + auto spring2 = world.createEntity(); + spring2.addComponent(Vector3(-10, 60, -50)); + spring2.addComponent(20.0f, 15.0f, particle1); auto pairedSpring = world.createEntity(); - pairedSpring.addComponent(100, 5.0f, e, e2); - - auto e3 = world.createEntity(); - e3.addComponent(Vector3(-7.5f, -7.5f + yOffset, 1), Vector3(1.0f, 1.0f, 1.0f)); - e3.addComponent(); - // Add mesh - e3.addComponent("Resources/Models/nanosuit/nanosuit.obj"); - - auto springEntinty3 = world.createEntity(); - springEntinty3.addComponent(Vector3(-7.5f, -10 + yOffset, -1)); - springEntinty3.addComponent(7, 7, e3); - - auto e4 = world.createEntity(); - e4.addComponent(Vector3(7.5f, -7.5f + yOffset, 3), Vector3(1.0f, 1.0f, 1.0f)); - e4.addComponent(); - // Add mesh - e4.addComponent("Resources/Models/nanosuit/nanosuit.obj"); + pairedSpring.addComponent(20.0f, 20.0f, particle1, particle2); - auto springEntinty4 = world.createEntity(); - springEntinty4.addComponent(Vector3(7.5f, -10 + yOffset, -3)); - springEntinty4.addComponent(5, 0, e4); - - auto pairedSpring2 = world.createEntity(); - pairedSpring2.addComponent(100, 5.2f, e, e3); - - auto pairedSpring3 = world.createEntity(); - pairedSpring3.addComponent(100, 5.2f, e2, e4); - - auto pairedSpring4 = world.createEntity(); - pairedSpring4.addComponent(100, 10.0f, e3, e4); } -void MakeABunchaSpheres(ECSWorld& world) +void MakeABunchaSpheres(ECSWorld & world) { - for (int i = 0; i < 30; i++) + for (int i = 0; i < 40; i++) { - auto e = world.createEntity(); - //e.addComponent(Vector3(RANDOM_FLOAT(-1, 1), 20,0)); - - e.addComponent(Vector3(RANDOM_FLOAT(-15.0f, 15.0f), RANDOM_FLOAT(6.0f, 34.0f), RANDOM_FLOAT(-15.0f, 15.0f))); - e.addComponent(1, Vector3(RANDOM_FLOAT(-5, 5), RANDOM_FLOAT(-5, 5), RANDOM_FLOAT(-5, 5))); - e.addComponent(1); - Color col = Color(0, RANDOM_FLOAT(0.0f, 1.0f), RANDOM_FLOAT(0.0f, 1.0f)); - //e.addComponent(20.0f, col, col, col); + auto sphere = world.createEntity(); + sphere.addComponent(Vector3(RANDOM_FLOAT(-10, 10), RANDOM_FLOAT(-10, 10), RANDOM_FLOAT(-10, 10))); + sphere.addComponent(Vector3(RANDOM_FLOAT(-40, 40), RANDOM_FLOAT(-40, 40), RANDOM_FLOAT(-40, 40))); + sphere.addComponent(1.0f); + sphere.addComponent(); + sphere.addComponent(RANDOM_FLOAT(1, 3)); } +} - auto ref = world.createEntity(); - ref.addComponent(Vector3(0, 20, 0), Vector3(0.3f, 0.3f, 0.3f), Vector3(0, 180, 0)); - // Add mesh - ref.addComponent("Resources/Models/nanosuit/nanosuit.obj"); - ref.addComponent(0, 40, 0); +void CreateParticleArchetype(ECSEntity e) +{ + e.addComponent(); + e.addComponent(); + e.addComponent(); + //e.addComponent(); + e.addComponent(); } -void MakeACable(ECSWorld& world) +void MakeARopeBridge(ECSWorld & world) { + auto ePivot1 = world.createEntity(); + ePivot1.addComponent(Vector3(3, 10, 5)); + auto e1 = world.createEntity(); - e1.addComponent(Vector3(0, 40, 0)); - //e1.addComponent(1, Vector3(0,0,0), 0); + e1.addComponent(Vector3(0, 3, 5)); + CreateParticleArchetype(e1); + + auto ePivot2 = world.createEntity(); + ePivot2.addComponent(Vector3(3, 10, -5)); auto e2 = world.createEntity(); - e2.addComponent(Vector3(0, 30, 0)); - e2.addComponent(1); - - auto e = world.createEntity(); - e.addComponent(e1, e2, 20); -} + e2.addComponent(Vector3(0, 2, -5)); + CreateParticleArchetype(e2); -void MakeCablesAndRods(ECSWorld& world) -{ - auto eFixed = world.createEntity(); - eFixed.addComponent(Vector3(10, 40, 0)); - //e1.addComponent(1, Vector3(0,0,0), 0); + auto rod1 = world.createEntity(); + rod1.addComponent(e1, e2, 10); - auto eFixed2 = world.createEntity(); - eFixed2.addComponent(Vector3(20, 10, 0)); + auto cable1 = world.createEntity(); + cable1.addComponent(ePivot1, e1, 20, 1); - auto eFixed3 = world.createEntity(); - eFixed3.addComponent(Vector3(-20, 10, 0)); + auto cable2 = world.createEntity(); + cable2.addComponent(ePivot2, e2, 20, 1); - auto e1 = world.createEntity(); - e1.addComponent(Vector3(0, 30, 0)); - e1.addComponent(10); - - auto e2 = world.createEntity(); - e2.addComponent(Vector3(-10, 20, 0)); - e2.addComponent(10); + // 2 + auto ePivot3 = world.createEntity(); + ePivot3.addComponent(Vector3(3 + 10, 10, 5)); auto e3 = world.createEntity(); - e3.addComponent(Vector3(0, 10, 0)); - e3.addComponent(10); + e3.addComponent(Vector3(0 + 10, -2, 5)); + CreateParticleArchetype(e3); + + auto ePivot4 = world.createEntity(); + ePivot4.addComponent(Vector3(3 + 10, 10, -5)); auto e4 = world.createEntity(); - e4.addComponent(Vector3(10, 20, 0)); - e4.addComponent(10); - - auto eCable = world.createEntity(); - eCable.addComponent(eFixed, e1, 20); - - auto eCable2 = world.createEntity(); - eCable2.addComponent(1000, 20, eFixed2, e4); - - auto eCable3 = world.createEntity(); - eCable3.addComponent(1000, 20, eFixed3, e2); - - auto eRod1 = world.createEntity(); - eRod1.addComponent(e1, e2, 10 * sqrt(2)); - auto eRod2 = world.createEntity(); - eRod2.addComponent(e2, e3, 10 * sqrt(2)); - auto eRod3 = world.createEntity(); - eRod3.addComponent(e3, e4, 10 * sqrt(2)); - auto eRod4 = world.createEntity(); - eRod4.addComponent(e4, e1, 10 * sqrt(2)); - - auto eRodDiagonal1 = world.createEntity(); - eRodDiagonal1.addComponent(e1, e3, 20); - auto eRodDiagonal2 = world.createEntity(); - eRodDiagonal2.addComponent(e2, e4, 20); + e4.addComponent(Vector3(0 + 10, 0, -5)); + CreateParticleArchetype(e4); + + auto rod2 = world.createEntity(); + rod2.addComponent(e3, e4, 10); + + auto cable3 = world.createEntity(); + cable3.addComponent(ePivot3, e3, 15, 1); + + auto cable4 = world.createEntity(); + cable4.addComponent(ePivot4, e4, 15, 1); + + // 3 + auto ePivot5 = world.createEntity(); + ePivot5.addComponent(Vector3(3 - 10, 10, 5)); + + auto e5 = world.createEntity(); + e5.addComponent(Vector3(0 - 10, 1, 5)); + CreateParticleArchetype(e5); + + auto ePivot6 = world.createEntity(); + ePivot6.addComponent(Vector3(3 - 10, 10, -5)); + + auto e6 = world.createEntity(); + e6.addComponent(Vector3(0 - 10, -1, -5)); + CreateParticleArchetype(e6); + + auto rod3 = world.createEntity(); + rod3.addComponent(e5, e6, 10); + + auto cable5 = world.createEntity(); + cable5.addComponent(ePivot5, e5, 15, 1); + + auto cable6 = world.createEntity(); + cable6.addComponent(ePivot6, e6, 15, 1); + + // rods + auto rod4 = world.createEntity(); + rod4.addComponent(e1, e3, 10); + auto rod5 = world.createEntity(); + rod5.addComponent(e2, e4, 10); + auto rod6 = world.createEntity(); + rod6.addComponent(e5, e1, 10); + auto rod7 = world.createEntity(); + rod7.addComponent(e6, e2, 10); + + // diagonal rods + auto rod8 = world.createEntity(); + rod8.addComponent(e1, e4, 10 * pow(2.0f, 0.5f)); + auto rod9 = world.createEntity(); + rod9.addComponent(e2, e3, 10 * pow(2.0f, 0.5f)); + auto rod10 = world.createEntity(); + rod10.addComponent(e6, e1, 10 * pow(2.0f, 0.5f)); + auto rod11 = world.createEntity(); + rod11.addComponent(e5, e2, 10 * pow(2.0f, 0.5f)); } -void MakeFlight(ECSWorld& world) +void MakeABunchaObjectsV2(ECSWorld & world) { - auto e = world.createEntity(); - glm::vec3 rotationInRads = glm::vec3(glm::radians(-90.0f), - glm::radians(180.0f), glm::radians(0.0f)); - Quaternion orientation = glm::quat(rotationInRads); - e.addComponent(Vector3(0, 350.0f, 0), Vector3(0.10f, 0.1f, 0.1f)); + auto flightV1 = world.createEntity(); + flightV1.addComponent(Vector3(-50, 0, -50), Vector3(0.1f, 0.1f, 0.1f), Vector3(270, 0, 0)); // Add mesh - e.addComponent("Resources/Models/supermarine-spitfire/spitfire.fbx", Vector3(0, -50, 20), Vector3(-90, 0, 0)); - e.addComponent(10.0f ,0.3f, 0.5f); - e.addComponent(); - e.addComponent(Vector3(0.0f, 15.0f, 40.0f)); - e.addComponent(); - e.addComponent(); - - std::vector p1 { GLFW_KEY_E }; - std::vector n1 { GLFW_KEY_Q }; - //Right Wing - auto RW = world.createEntity(); - RW.addComponent(p1, n1); - RW.addComponent(Mat3(0, 0, 0, 0, 0.000f, 0, 0, -0.0005f, 0), - Mat3(0, 0, 0, 0, 0, 0, 0, 0, 0), - Mat3(0, 0, 0, 0, -0.000f, 0, 0, 0.0005f, 0)); - RW.addComponent(e, Mat3(1.0f), Vector3(100.0f, 0, 50.0f)); - - //Left Wing - auto LW = world.createEntity(); - LW.addComponent(n1, p1); - LW.addComponent(Mat3(0, 0, 0, 0, 0.000f, 0, 0, -0.0005f, 0), - Mat3(0, 0, 0, 0, 0, 0, 0, 0, 0), - Mat3(0, 0, 0, 0, -0.000f, 0, 0, 0.0005f, 0)); - LW.addComponent(e, Mat3(1.0f), Vector3(-100.0f, 0, 50.0f)); - - //Rudder - std::vector pR = { GLFW_KEY_A }; - std::vector nR = { GLFW_KEY_D }; - auto R = world.createEntity(); - R.addComponent(pR, nR); - R.addComponent(Mat3(0, 0, 0, 0, 0, 0, 0.002f, 0, 0), - Mat3(0, 0, 0, 0, 0, 0, 0.00f, 0, 0), - Mat3(0, 0, 0, 0, 0, 0, -0.002f, 0, 0)); - R.addComponent(e, Mat3(1.0f), Vector3(0, 0, -200.0f)); - - //Back Wing - std::vector p2{ GLFW_KEY_W }; - std::vector n2{ GLFW_KEY_S }; - auto RW2 = world.createEntity(); - RW2.addComponent(p2, n2); - RW2.addComponent(Mat3(0, 0, 0, 0, 0, 0, 0, -0.0015f, 0), - Mat3(0, 0, 0, 0, 0, 0, 0, 0, 0), - Mat3(0, 0, 0, 0, 0, 0, 0, 0.0015f, 0)); - RW2.addComponent(e, Mat3(1.0f), Vector3(0.0f, 0, -200.0f)); - - for (int i = -40; i <= 40; i++) - { - auto buildingR = world.createEntity(); - buildingR.addComponent(Vector3(100.0f, 0.0f, 50.0f * i)); - buildingR.addComponent(RANDOM_FLOAT(100.0f, 500.0f)); + flightV1.addComponent("Resources/Models/supermarine-spitfire/spitfire.fbx"); + flightV1.addComponent(Vector3(45, 70, -20)); - auto buildingL = world.createEntity(); - buildingL.addComponent(Vector3(-100.0f, 0.0f, 50.0f * i)); - buildingL.addComponent(RANDOM_FLOAT(100.0f, 500.0f)); - } + auto flightV2 = world.createEntity(); + flightV2.addComponent(Vector3(50, 0, -50), Vector3(0.1f, 0.1f, 0.1f), Vector3(270, 0, 0)); + // Add mesh + flightV2.addComponent("Resources/Models/supermarine-spitfire/spitfire.fbx"); + flightV2.addComponent(Vector3(45, 70, -20)); } -void TestContacts(ECSWorld& world) +void MakeRigidBodyTest(ECSWorld & world) { - for (int i = 0; i < 30; i++) - { - auto e = world.createEntity(); - e.addComponent(Vector3(RANDOM_FLOAT(-200.0f, 200.0f), RANDOM_FLOAT(-200.0f, 200.0f), RANDOM_FLOAT(-200.0f, 200.0f)), - Vector3(1, 1, 1), - Vector3(RANDOM_FLOAT(-180.0f, 180.0f), RANDOM_FLOAT(-180.0f, 180.0f), RANDOM_FLOAT(-180.0f, 180.0f))); - e.addComponent(); - e.addComponent(Vector3(RANDOM_FLOAT(-10.0f, 10.0f), RANDOM_FLOAT(-10.0f, 10.0f), RANDOM_FLOAT(-10.0f, 10.0f)), - Vector3(200, 200, 200)); - auto col = world.createEntity(); - if ((RANDOM_FLOAT(0.0f, 1.0f) >= 0.5f)) - { - col.addComponent(e, RANDOM_FLOAT(10.0f, 50.0f)); - } - else - { - col.addComponent(e, Vector3(RANDOM_FLOAT(30.0f, 70.0f), RANDOM_FLOAT(30.0f, 70.0f), RANDOM_FLOAT(30.0f, 70.0f))); - } - } - /*for (int i = 0; i < 2; i++) - { - auto e = world.createEntity(); - e.addComponent(Vector3(50 * ( i % 2 == 0 ? -1 : 1), 0, 0)); - e.addComponent(); - e.addComponent(Vector3(10 * (i % 2 == 0 ? 1 : -1), 0, 0), Vector3(100, 100, 100)); - auto col = world.createEntity(); - col.addComponent(e, 30); - }*/ + auto flight = world.createEntity(); + flight.addComponent(Vector3(0, 0, -50), Vector3(0.1f, 0.1f, 0.1f)); + flight.addComponent("Resources/Models/supermarine-spitfire/spitfire.fbx", Vector3(-90, 0, 0), Vector3(0, -50, 0)); + flight.addComponent(); + flight.addComponent(); + flight.addComponent(); + flight.addComponent(); } -void TestCollision(ECSWorld& world) +void MakeAFlightSimulator(ECSWorld & world) { - // Floor 1 - auto floor1 = world.createEntity(); - floor1.addComponent(Vector3(0, -50, 0), Vector3(1, 1, 1), Vector3(0, 0, 0)); - floor1.addComponent(100000.0f, 0.4f, 0.3f, Vector3(0, 0, 0), Vector3(0, 0, 0), 0); - auto floorCol1 = world.createEntity(); - floorCol1.addComponent(floor1, Vector3(1000, 10, 1000)); - - // Floor 2 - /*auto floor2 = world.createEntity(); - floor2.addComponent(Vector3(80, -50, 0), Vector3(1, 1, 1), Vector3(0, 0, 30)); - floor2.addComponent(10000.0f, 0.0f, 0.0f, Vector3(0, 0, 0), Vector3(0, 0, 0), 0); - auto floorCol2 = world.createEntity(); - floorCol2.addComponent(floor2, Vector3(300, 10, 300));*/ - - //// Object 1 - //auto object1 = world.createEntity(); - //object1.addComponent(Vector3(-30, 50, 0)); - //object1.addComponent(); - //auto objectCol1 = world.createEntity(); - //objectCol1.addComponent(object1, 10); - - // Object 2 - for (int i = 0; i < 40; i++) - { - auto object2 = world.createEntity(); - object2.addComponent(Vector3(RANDOM_FLOAT(-50.0f, 50.0f), 50, RANDOM_FLOAT(-50.0f, 50.0f)), Vector3(1, 1, 1), Vector3(RANDOM_FLOAT(0, 180), RANDOM_FLOAT(0, 180), RANDOM_FLOAT(0, 180))); - object2.addComponent(10.0f, 0.1f, 0.1f, Vector3(0, 0, 0), Vector3(0, 0, 0), 5); - auto objectCol2 = world.createEntity(); - objectCol2.addComponent(object2, Vector3(10, 10, 10)); - } + //auto ground = world.createEntity(); + //ground.addComponent(Vector3(0, -1000, 0), Vector3(10, 10, 10), Vector3(0, 90, 0)); + //ground.addComponent("Resources/Models/Sponza-master/sponza.obj"); + + auto flight = world.createEntity(); + flight.addComponent(Vector3(0, 0, -50), Vector3(0.1f, 0.1f, 0.1f), Vector3(0, 180, 0)); + flight.addComponent("Resources/Models/supermarine-spitfire/spitfire.fbx", Vector3(-90, 0, 0), Vector3(0, -50, 0)); + flight.addComponent(); + flight.addComponent(); + flight.addComponent(0.3, 0.5); + flight.addComponent(); + + auto engine = world.createEntity(); + engine.addComponent(flight); + + auto leftWing = world.createEntity(); + leftWing.addComponent(); + leftWing.addComponent(flight, Vector3(0, 0, 0), Vector3(100, 50, -50)); + std::vector leftWingPositiveKeys = { GLFW_KEY_S, GLFW_KEY_Q }; + std::vector leftWingNegetiveKeys = { GLFW_KEY_W, GLFW_KEY_E }; + leftWing.addComponent( + Vector3(0, 0.1f, 0), + Vector3(0, -0.1f, 0), + leftWingPositiveKeys, leftWingNegetiveKeys); + + auto rightWing = world.createEntity(); + rightWing.addComponent(); + rightWing.addComponent(flight, Vector3(0, 0, 0), Vector3(-100, 50, -50)); + std::vector rightWingPositiveKeys = { GLFW_KEY_S, GLFW_KEY_E }; + std::vector rightWingNegetiveKeys = { GLFW_KEY_W, GLFW_KEY_Q }; + rightWing.addComponent( + Vector3(0, 0.1f, 0), + Vector3(0, -0.1f, 0), + rightWingPositiveKeys, rightWingNegetiveKeys); + + auto rudder = world.createEntity(); + rudder.addComponent(); + rudder.addComponent(flight, Vector3(0, 0, 0), Vector3(0, 0, -150)); + std::vector rudderWingPositiveKeys = { GLFW_KEY_D }; + std::vector rudderWingNegetiveKeys = { GLFW_KEY_A }; + rudder.addComponent( + Vector3(-0.04f, 0, 0), + Vector3(0.04f, 0, 0), + rudderWingPositiveKeys, rudderWingNegetiveKeys); + +} + +void MakeABoatSImulator(ECSWorld& world) +{ + auto boat = world.createEntity(); + boat.addComponent(Vector3(0, 10, 0), Vector3(5.f, 5.f, 5.f), Vector3(0, 0, 0)); + boat.addComponent("Resources/Models/Boat/boat.obj", Vector3(0, 180, 0), Vector3(-2, 0, 1)); + //boat.addComponent("Resources/Models/supermarine-spitfire/spitfire.fbx", Vector3(-90, 0, 0), Vector3(0, -50, 0)); + boat.addComponent(); + boat.addComponent(); + boat.addComponent(0.3, 0.5); + boat.addComponent(); + boat.addComponent(); + + auto engine = world.createEntity(); + engine.addComponent(boat); + + auto buoyancyFront = world.createEntity(); + buoyancyFront.addComponent(); + buoyancyFront.addComponent(boat, 4.f, 2.f, Vector3(-2, 0, 0)); + + auto buoyancyRear = world.createEntity(); + buoyancyRear.addComponent(); + buoyancyRear.addComponent(boat, 4.f, 2.f, Vector3(2, 0, 0)); + + + auto leftRotating = world.createEntity(); + leftRotating.addComponent(); + leftRotating.addComponent(boat, Vector3(0, 0, 0), Vector3(-5, 0, 0)); + std::vector leftRotatingPositiveKeys = { GLFW_KEY_Q}; + std::vector leftRotatingNegetiveKeys = { GLFW_KEY_E}; + leftRotating.addComponent( + Vector3(0, 5.f, 0), + Vector3(0, -5.f, 0), + leftRotatingPositiveKeys, leftRotatingNegetiveKeys); + + auto rightRotating = world.createEntity(); + rightRotating.addComponent(); + rightRotating.addComponent(boat, Vector3(0, 0, 0), Vector3(5, 0, 0)); + std::vector rightRotatingPositiveKeys = { GLFW_KEY_E }; + std::vector rightRotatingNegetiveKeys = { GLFW_KEY_Q }; + rightRotating.addComponent( + Vector3(0, 5.f, 0), + Vector3(0, -5.f, 0), + rightRotatingPositiveKeys, rightRotatingNegetiveKeys); + + + auto rudder = world.createEntity(); + rudder.addComponent(); + rudder.addComponent(boat, Vector3(0, 0, 0), Vector3(0, 0, 5)); + std::vector rudderWingPositiveKeys = { GLFW_KEY_A }; + std::vector rudderWingNegetiveKeys = { GLFW_KEY_D }; + rudder.addComponent( + Vector3(-0.04f, 0, 0), + Vector3(0.04f, 0, 0), + rudderWingPositiveKeys, rudderWingNegetiveKeys); +} + +void MakeABunchaCablesAndRods(ECSWorld & world) +{ + auto ePivot = world.createEntity(); + ePivot.addComponent(Vector3(3, 10, 0)); + + auto e1 = world.createEntity(); + e1.addComponent(Vector3(0, 10, 0)); + e1.addComponent(); + e1.addComponent(); + e1.addComponent(); + e1.addComponent(); + e1.addComponent(); + + auto e2 = world.createEntity(); + e2.addComponent(Vector3(5, 5, 0)); + e2.addComponent(); + e2.addComponent(); + e2.addComponent(); + e2.addComponent(); + e2.addComponent(); + + auto e3 = world.createEntity(); + e3.addComponent(Vector3(0, 0, 0)); + e3.addComponent(); + e3.addComponent(); + e3.addComponent(); + e3.addComponent(); + e3.addComponent(); + + auto e4 = world.createEntity(); + e4.addComponent(Vector3(-5, 5, 0)); + e4.addComponent(); + e4.addComponent(); + e4.addComponent(); + e4.addComponent(); + e4.addComponent(); + + auto cable1 = world.createEntity(); + //cable.addComponent(ePivot, e1, 5, 1); + cable1.addComponent(50, 2, ePivot, e1); + + auto cable2 = world.createEntity(); + //cable.addComponent(ePivot, e1, 5, 1); + cable2.addComponent(50, 25, ePivot, e2); + + auto cable3 = world.createEntity(); + cable3.addComponent(ePivot, e3, 15, 1); + //cable3.addComponent(50, 20, ePivot, e3); + + auto rod1 = world.createEntity(); + rod1.addComponent(e1, e2, 5 * pow(2, 0.5f)); + + auto rod2 = world.createEntity(); + rod2.addComponent(e2, e3, 5 * pow(2, 0.5f)); + + auto rod3 = world.createEntity(); + rod3.addComponent(e3, e4, 5 * pow(2, 0.5f)); + + auto rod4 = world.createEntity(); + rod4.addComponent(e4, e1, 5 * pow(2, 0.5f)); + + auto rod5 = world.createEntity(); + rod5.addComponent(e1, e3, 10); + + auto rod6 = world.createEntity(); + rod6.addComponent(e2, e4, 10); + + //for (int i = 0; i < 20; i++) + //{ + // auto e1 = world.createEntity(); + // e1.addComponent(Vector3(RANDOM_FLOAT(-5, 5), RANDOM_FLOAT(-5, 5), RANDOM_FLOAT(-5, 5))); + // e1.addComponent(); + // e1.addComponent(); + // e1.addComponent(); + // e1.addComponent(RANDOM_FLOAT(0.5, 1.5)); + // e1.addComponent(); + + // auto e2 = world.createEntity(); + // e2.addComponent(Vector3(RANDOM_FLOAT(-5, 5), RANDOM_FLOAT(-5, 5), RANDOM_FLOAT(-5, 5))); + // e2.addComponent(); + // e2.addComponent(); + // e2.addComponent(); + // e2.addComponent(RANDOM_FLOAT(0.5, 1.5)); + // e2.addComponent(); + + // auto rod = world.createEntity(); + // rod.addComponent(e1, e2, RANDOM_FLOAT(6, 10)); + //} } void SetupLights(ECSWorld& world) { auto l = world.createEntity(); l.addComponent(Vector3(0, 0, 0), Vector3(0, 0, 0), Vector3(90, 0, 0)); - l.addComponent(Color(0.00, 0.0, 0), Color::White, Color::Orange); + l.addComponent(Color(1, 1, 1), Color(0.0, 0.1, 0.1), Color(0.0, 0.1, 0.1)); // Lanterns auto pl1 = world.createEntity(); pl1.addComponent(Vector3(22, 14, 48.5f)); pl1.addComponent(100.0f, Color(0.1, 0, 0), Color(1.0f, 0.0f, 0.0f), Color(1.0f, 0.0f, 0.0f)); - pl1.addComponent(); auto hook = world.createEntity(); hook.addComponent(Vector3(23, 15, 48.0f)); - hook.addComponent(5, 1, pl1); hook = world.createEntity(); hook.addComponent(Vector3(22, 13.5f, 50.5f)); - hook.addComponent(5, 1, pl1); hook = world.createEntity(); hook.addComponent(Vector3(21, 12.5f, 47.5f)); - hook.addComponent(5, 1, pl1); auto pl2 = world.createEntity(); pl2.addComponent(Vector3(-14.5f, 14, 49.0f)); pl2.addComponent(100.0f, Color(0, 0, 0.1f), Color(0.0f, 0.0f, 1.0f), Color(0.0f, 0.0f, 1.0f)); - pl2.addComponent(); hook = world.createEntity(); hook.addComponent(Vector3(-14.5f + 1, 14 - 1, 49.0f - 1)); - hook.addComponent(5, 1, pl2); hook = world.createEntity(); hook.addComponent(Vector3(-14.5f - 0.5f, 14 + 1, 49.0f)); - hook.addComponent(5, 1, pl2); hook = world.createEntity(); hook.addComponent(Vector3(-14.5f, 14 - 1, 49.0f + 1)); - hook.addComponent(5, 1, pl2); auto pl3 = world.createEntity(); pl3.addComponent(Vector3(22, 14, -62.0f)); pl3.addComponent(100.0f, Color(0, 0.1f, 0), Color(0.0f, 1.0f, 0.0f), Color(0.0f, 1.0f, 0.0f)); - pl3.addComponent(); hook = world.createEntity(); hook.addComponent(Vector3(22 - 1, 14 - 1, -62.0f)); - hook.addComponent(5, 1, pl3); hook = world.createEntity(); hook.addComponent(Vector3(22, 14 + 0.5f, -62.0f - 1)); - hook.addComponent(5, 1, pl3); hook = world.createEntity(); hook.addComponent(Vector3(22 + 1, 14, -62.0f + 0.5f)); - hook.addComponent(5, 1, pl3); auto pl4 = world.createEntity(); pl4.addComponent(Vector3(-14.5f, 14, -61.5f)); pl4.addComponent(100.0f, Color(0.1, 0.05, 0), Color(1.0f, 0.55f, 0.0f), Color(1.0f, 0.55f, 0.0f)); - pl4.addComponent(); hook = world.createEntity(); hook.addComponent(Vector3(-14.5f - 1, 14, -61.5f -1)); - hook.addComponent(5, 1, pl4); hook = world.createEntity(); hook.addComponent(Vector3(-14.5f - 0.25f, 14 - 0.5f, -61.5f + 1)); - hook.addComponent(5, 1, pl4); hook = world.createEntity(); hook.addComponent(Vector3(-14.5f + 0.5f, 14+ 1, -61.5f + 1)); - hook.addComponent(5, 1, pl4); // Spears std::vector cols = { Color(1,0,0), Color(0,1,0), Color(0,0,1), Color(0.7f,0.55f,0) }; @@ -645,7 +750,6 @@ void SetupLights(ECSWorld& world) pl1 = world.createEntity(); pl1.addComponent(Vector3((i % 2 == 0 ? 8 : -1), 85, 49.5f - 37 * j), Vector3(1, 1, 1), Vector3(180, 0, 0)); pl1.addComponent(10.0f, 100, Color(0, 0, 0), cols[3 - j], cols[3 - j], 5); - pl1.addComponent((i % 2 == 0 ? 1 : -1) * 100,100,100); } } } \ No newline at end of file diff --git a/OpenGLEngine/OpenGLEngine/MeshComponent.h b/OpenGLEngine/OpenGLEngine/MeshComponent.h index f76b4e7..b473b9e 100644 --- a/OpenGLEngine/OpenGLEngine/MeshComponent.h +++ b/OpenGLEngine/OpenGLEngine/MeshComponent.h @@ -11,9 +11,20 @@ namespace Reality Vector3 offset; Vector3 rotation; // Constructor - ModelComponent(std::string const _model = "", Vector3 _offset = Vector3(0, 0, 0), Vector3 _rotation = Vector3(0, 0, 0)) : mesh(_model), offset(_offset), rotation(_rotation) + ModelComponent(std::string const _model = "", Vector3 _rotation = Vector3(0, 0, 0), Vector3 _offset = Vector3(0, 0, 0)) : mesh(_model), offset(_offset), rotation(_rotation) { modelId = -1; + Vector3 rotInRads = Vector3(glm::radians(_rotation.x), glm::radians(_rotation.y), glm::radians(_rotation.z)); + modelOffsetTransformation = Mat4(Quaternion(rotInRads)); + modelOffsetTransformation = glm::translate(Mat4(1.0f), _offset) * modelOffsetTransformation; } + + const Mat4& GetModelOffsetTransformation() + { + return modelOffsetTransformation; + } + + private: + Mat4 modelOffsetTransformation; }; } diff --git a/OpenGLEngine/OpenGLEngine/OpenGLEngine.vcxproj b/OpenGLEngine/OpenGLEngine/OpenGLEngine.vcxproj index dbb8b45..791a5ca 100644 --- a/OpenGLEngine/OpenGLEngine/OpenGLEngine.vcxproj +++ b/OpenGLEngine/OpenGLEngine/OpenGLEngine.vcxproj @@ -28,7 +28,7 @@ Application true - v141 + v142 MultiByte @@ -121,30 +121,30 @@ - + - + - - + - - + + + - + - + @@ -160,25 +160,26 @@ - - + - + + + + + + - - - - + @@ -196,25 +197,33 @@ - + + + + + + + + + + + + + - - - - - + - + @@ -222,26 +231,28 @@ - - + - - + - + - + - + + + + + @@ -253,52 +264,44 @@ - + - + - + + + - + - - - - - - - - - - - + + - + - + - + - @@ -320,42 +323,47 @@ - - - + - + - + - - + - - - + + + + + + + - - + - - + - + + + + + + + @@ -379,41 +387,58 @@ - + - + - - - - - - - - - - + - - + + + + + + + + + - + - + - + + + + + + + + + + + + + + + + + + + + @@ -425,37 +450,36 @@ - - - - + - - - + - + - + - - + + - - + - + + + + + + diff --git a/OpenGLEngine/OpenGLEngine/OpenGLEngine.vcxproj.filters b/OpenGLEngine/OpenGLEngine/OpenGLEngine.vcxproj.filters index 0199877..5ca5d61 100644 --- a/OpenGLEngine/OpenGLEngine/OpenGLEngine.vcxproj.filters +++ b/OpenGLEngine/OpenGLEngine/OpenGLEngine.vcxproj.filters @@ -43,12 +43,39 @@ {09a9940b-c17f-43c0-becf-d8da8efa3d30} - - {1a9d715c-69e4-4d0c-b881-159070a97fa6} - {3f5a8043-c367-47f5-bbe1-005323d21b00} + + {3b57134f-d90e-46bd-8888-c0777df6a173} + + + {2a1ab3ed-c9b4-469a-8efb-a6ad96814ca1} + + + {a47e3b81-90db-42eb-a5f1-e5a072f9b973} + + + {05f83a53-3654-4ae0-99f7-3b5b0131942b} + + + {4c54bdb5-bf1a-46eb-97aa-4ad2f029416e} + + + {26df7371-0611-42cd-b6e5-2556995c23d7} + + + {8f440b87-7f9c-4d7f-993c-ec5fa08dde39} + + + {8d7d692e-fedf-4e75-9661-f2eb1dd346c1} + + + {fee04adf-2290-4e0b-9dd6-1b2c67f5a98f} + + + {4c10d8d6-d9d5-4e1f-883c-ae1bd9e9443b} + @@ -81,27 +108,9 @@ ECSCore - - TestCS - - - Physics\Particles - - - Physics\Particles - - - Physics\Particles - - - Physics\Particles - Input - - TestCS - Rendering @@ -126,86 +135,89 @@ Rendering - - TestCS + + Rendering + + + Rendering - + TestCS - + TestCS - - Rendering + + Physics\Particles - - ComponentsCore + + Physics\Particles - - Rendering + + TestCS\FireWorksDemo - - TestCS\FlightSim + + Physics\Particles\ForceGenerators\Gravity - - TestCS\FlightSim + + Physics\Particles\ForceGenerators\Drag - - TestCS\FlightSim + + Physics\Particles\ForceGenerators\FixedSpring - - TestCS\FlightSim + + Physics\Particles\PairedSpring - - TestCS + + Physics\Particles - - TestCS + + TestCS\ParticleSphereDemo - - TestCS\FlightSim + + TestCS\CablesAndRods - - TestCS\FlightSim + + TestCS\CablesAndRods - - TestCS\FlightSim + + Physics\Particles - + Rendering - - Physics\Rigidbody + + TestCS - - Physics\Rigidbody + + TestCS - - Physics\Particles + + Physics\Rigidbody Physics\Rigidbody - + Physics\Rigidbody - - Physics\Rigidbody + + TestCS - - Physics\Particles + + TestCS\FlightSimulator - - Physics\Particles + + TestCS\FlightSimulator - - Physics\Rigidbody + + TestCS\FlightSimulator - - TestCS + + TestCS\FlightSimulator - - Physics\Rigidbody + + Physics\Particles\ForceGenerators\Buoyancy @@ -272,42 +284,12 @@ ECSCore - - TestCS - - - TestCS - - - Physics\Particles - - - Physics\Particles - - - Physics\Particles - - - Physics\Particles - - - Physics\Particles - - - Physics\Particles - Input Input - - TestCS - - - TestCS - Rendering @@ -332,155 +314,164 @@ Rendering - - TestCS + + Rendering - + TestCS - + TestCS - + TestCS - + TestCS - - TestCS + + Physics\Particles - - ComponentsCore + + Physics\Particles - - ComponentsCore + + Physics\Particles - - Rendering + + Physics\Particles - - TestCS\FlightSim + + TestCS\FireWorksDemo - - TestCS\FlightSim + + TestCS\FireWorksDemo - - TestCS\FlightSim + + Physics\Particles\ForceGenerators\Gravity - - TestCS\FlightSim + + Physics\Particles\ForceGenerators\Gravity - - TestCS\FlightSim + + Physics\Particles\ForceGenerators\Drag - - TestCS\FlightSim + + Physics\Particles\ForceGenerators\Drag - - TestCS\FlightSim + + Physics\Particles\ForceGenerators\FixedSpring - - TestCS\FlightSim + + Physics\Particles\ForceGenerators\FixedSpring - - TestCS + + Physics\Particles\PairedSpring - - TestCS + + Physics\Particles\PairedSpring - - TestCS + + Physics\Particles - - TestCS + + Physics\Particles + + + TestCS\ParticleSphereDemo + + + TestCS\ParticleSphereDemo - - TestCS\FlightSim + + TestCS\CablesAndRods - - TestCS\FlightSim + + TestCS\CablesAndRods - - TestCS\FlightSim + + TestCS\CablesAndRods - - TestCS\FlightSim + + TestCS\CablesAndRods - - TestCS\FlightSim + + Physics\Particles - - TestCS\FlightSim + + Physics\Particles - - TestCS\FlightSim + + ComponentsCore - + Rendering - - Physics\Rigidbody + + TestCS - - Physics\Rigidbody + + TestCS - - Physics\Rigidbody + + TestCS - + + TestCS + + Physics\Rigidbody - - Physics\Particles + + Physics\Rigidbody - - Physics\Particles + + Physics\Rigidbody Physics\Rigidbody - + Physics\Rigidbody - + Physics\Rigidbody - - Physics\Rigidbody + + TestCS - - Physics\Rigidbody + + TestCS - - Physics\Rigidbody + + TestCS\FlightSimulator - - Physics\Particles + + TestCS\FlightSimulator - - Physics\Particles + + TestCS\FlightSimulator - - Physics\Particles + + TestCS\FlightSimulator - - Physics\Particles + + TestCS\FlightSimulator - - Physics\Rigidbody + + TestCS\FlightSimulator - - Physics\Rigidbody + + TestCS\FlightSimulator - - TestCS + + TestCS\FlightSimulator - - TestCS + + Physics\Particles\ForceGenerators\Buoyancy - - Physics\Rigidbody + + Physics\Particles\ForceGenerators\Buoyancy diff --git a/OpenGLEngine/OpenGLEngine/PairedSpringComponent.h b/OpenGLEngine/OpenGLEngine/PairedSpringComponent.h index 88bf9a9..0511892 100644 --- a/OpenGLEngine/OpenGLEngine/PairedSpringComponent.h +++ b/OpenGLEngine/OpenGLEngine/PairedSpringComponent.h @@ -5,11 +5,20 @@ namespace Reality { struct PairedSpringComponent { - PairedSpringComponent(float _springConstant = 10, float _restLength = 10, ECSEntity a = ECSEntity(), ECSEntity b = ECSEntity()) - :springConstant(_springConstant), restLength(_restLength), entityA(a), entityB(b) {} + PairedSpringComponent(float _springConstant = 10.0f, + float _restLength = 10.0f, + ECSEntity _connectedEntityA = ECSEntity(), + ECSEntity _connectedEntityB = ECSEntity()) + : springConstant(_springConstant), + restLength(_restLength), + connectedEntityA(_connectedEntityA), + connectedEntityB(_connectedEntityB) + { + + } float springConstant; float restLength; - ECSEntity entityA; - ECSEntity entityB; + ECSEntity connectedEntityA; + ECSEntity connectedEntityB; }; -} \ No newline at end of file +} diff --git a/OpenGLEngine/OpenGLEngine/PairedSpringForceGeneratorSystem.cpp b/OpenGLEngine/OpenGLEngine/PairedSpringForceGeneratorSystem.cpp deleted file mode 100644 index 532d8eb..0000000 --- a/OpenGLEngine/OpenGLEngine/PairedSpringForceGeneratorSystem.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "PairedSpringForceGeneratorSystem.h" -#include "TransformComponent.h" -#include "ParticleComponent.h" - -namespace Reality -{ - PairedSpringForceGeneratorSystem::PairedSpringForceGeneratorSystem() - { - requireComponent(); - } - - - void PairedSpringForceGeneratorSystem::Update(float deltaTime) - { - for (auto e : getEntities()) - { - auto &spring = e.getComponent(); - - if (spring.entityA.hasComponent() && - spring.entityB.hasComponent()) - { - //auto &particle = spring.entity.getComponent(); - auto &entityTransformA = spring.entityA.getComponent(); - auto &entityTransformB = spring.entityB.getComponent(); - - Vector3 relativePosition = entityTransformA.position - entityTransformB.position; - float length = glm::length(relativePosition); - float x = length - spring.restLength; - Vector3 direction = glm::normalize(relativePosition); - - if (spring.entityA.hasComponent()) - { - spring.entityA.getComponent().AddForce(-spring.springConstant * x * direction); - } - - if (spring.entityB.hasComponent()) - { - spring.entityB.getComponent().AddForce(spring.springConstant * x * direction); - } - - float g = 1.0f / (1.0f + pow(abs(x), 0.5f)); - float r = (1 - g); - Color color = Color(r, g, 0, 1); - - float deltaLength = length / 10.0f; - for (int i = 0; i < 10; i++) - { - getWorld().data.renderUtil->DrawCube( - entityTransformB.position + (float)i * deltaLength * direction, - Vector3(0.1f, 0.1f, 0.1f) * min((spring.springConstant / 10.0f), 5.0f), Vector3(0,0,0), color); - } - - getWorld().data.renderUtil->DrawLine( - entityTransformB.position, entityTransformB.position + length * direction, color); - } - } - - } -} - diff --git a/OpenGLEngine/OpenGLEngine/PairedSpringSystem.cpp b/OpenGLEngine/OpenGLEngine/PairedSpringSystem.cpp new file mode 100644 index 0000000..70e7b38 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/PairedSpringSystem.cpp @@ -0,0 +1,61 @@ +#include "PairedSpringSystem.h" +#include "TransformComponent.h" +#include "ForceAccumulatorComponent.h" + +namespace Reality +{ + PairedSpringSystem::PairedSpringSystem() + { + requireComponent(); + } + + void PairedSpringSystem::Update(float deltaTime) + { + for (auto e : getEntities()) + { + auto& spring = e.getComponent(); + + if (spring.connectedEntityA.hasComponent() + && spring.connectedEntityB.hasComponent()) + { + auto& transformA = spring.connectedEntityA.getComponent(); + auto& transformB = spring.connectedEntityB.getComponent(); + + Vector3 relativePosition = transformA.position - transformB.position; + float length = glm::length(relativePosition); + if (length > 0) + { + float deltaL = length - spring.restLength; + Vector3 force = -glm::normalize(relativePosition); + force *= spring.springConstant * deltaL; + + if (spring.connectedEntityA.hasComponent()) + { + spring.connectedEntityA.getComponent().AddForce(force); + } + if (spring.connectedEntityB.hasComponent()) + { + spring.connectedEntityB.getComponent().AddForce(-force); + } + + float g = 1.0f / (1.0f + pow(abs(deltaL), 0.5f)); + float r = 1 - g; + + Color col = Color(r, g, 0, 1); + + float deltaLength = length / 10.0f; + Vector3 direction = glm::normalize(relativePosition); + for (int i = 0; i < 10; i++) + { + getWorld().data.renderUtil->DrawCube( + transformB.position + (float)i * deltaLength * direction, + Vector3(1.0f, 1.0f, 1.0f) * min((spring.restLength / 20.0f), 100.0f), Vector3(0, 0, 0), col); + } + getWorld().data.renderUtil->DrawLine(transformA.position, transformB.position, + col); + } + + } + } + } +} diff --git a/OpenGLEngine/OpenGLEngine/PairedSpringForceGeneratorSystem.h b/OpenGLEngine/OpenGLEngine/PairedSpringSystem.h similarity index 59% rename from OpenGLEngine/OpenGLEngine/PairedSpringForceGeneratorSystem.h rename to OpenGLEngine/OpenGLEngine/PairedSpringSystem.h index 5adbcab..5cf0204 100644 --- a/OpenGLEngine/OpenGLEngine/PairedSpringForceGeneratorSystem.h +++ b/OpenGLEngine/OpenGLEngine/PairedSpringSystem.h @@ -4,11 +4,10 @@ namespace Reality { - class PairedSpringForceGeneratorSystem : public ECSSystem + class PairedSpringSystem : public ECSSystem { public: - PairedSpringForceGeneratorSystem(); + PairedSpringSystem(); void Update(float deltaTime); }; } - diff --git a/OpenGLEngine/OpenGLEngine/ParticleComponent.h b/OpenGLEngine/OpenGLEngine/ParticleComponent.h index 3c7e057..2580c48 100644 --- a/OpenGLEngine/OpenGLEngine/ParticleComponent.h +++ b/OpenGLEngine/OpenGLEngine/ParticleComponent.h @@ -5,30 +5,12 @@ namespace Reality { struct ParticleComponent { - ParticleComponent(float mass = 1.0f, Vector3 _velocity = Vector3(0,0,0), float _gravityScale = 1) : - velocity(_velocity), gravityScale(_gravityScale) + ParticleComponent(Vector3 _velocity = Vector3(0, 0, 0)) + :velocity(_velocity), acceleration(Vector3(0, 0, 0)) { - inverseMass = 1 / mass; - accelaration = Vector3(0, 0, 0); - forceAccumulator = Vector3(0, 0, 0); + } + Vector3 acceleration; Vector3 velocity; - Vector3 accelaration; - float inverseMass; - float gravityScale; - inline void AddForce(Vector3 force) - { - forceAccumulator += force; - } - inline Vector3 GetForce() - { - return forceAccumulator; - } - inline void ResetForceAccumulator() - { - forceAccumulator = Vector3(0, 0, 0); - } - private: - Vector3 forceAccumulator; }; } diff --git a/OpenGLEngine/OpenGLEngine/ParticleContactEvent.h b/OpenGLEngine/OpenGLEngine/ParticleContactEvent.h new file mode 100644 index 0000000..0d7074e --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/ParticleContactEvent.h @@ -0,0 +1,27 @@ +#pragma once +#include "ECSConfig.h" + +namespace Reality +{ + struct ParticleContactEvent + { + ParticleContactEvent(ECSEntity _entityA = ECSEntity(), + ECSEntity _entityB = ECSEntity(), + float _restitution = 1.0f, + Vector3 _normal = Vector3(0, 1.0f, 0), + float _penetration = 0.0f) + : entityA(_entityA), + entityB(_entityB), + restitution(_restitution), + normal(_normal), + penetration(_penetration) + { + + } + ECSEntity entityA; + ECSEntity entityB; + float restitution; + Vector3 normal; + float penetration; + }; +} diff --git a/OpenGLEngine/OpenGLEngine/ParticleContactResolutionSystem.cpp b/OpenGLEngine/OpenGLEngine/ParticleContactResolutionSystem.cpp index 42c892a..0b53901 100644 --- a/OpenGLEngine/OpenGLEngine/ParticleContactResolutionSystem.cpp +++ b/OpenGLEngine/OpenGLEngine/ParticleContactResolutionSystem.cpp @@ -1,186 +1,185 @@ #include "ParticleContactResolutionSystem.h" #include "ParticleComponent.h" +#include "ForceAccumulatorSystem.h" #include "TransformComponent.h" +#include "PenetrationDeltaMoveComponent.h" namespace Reality { ParticleContactResolutionSystem::ParticleContactResolutionSystem() { - requireComponent(); + } - float ParticleContactResolutionSystem::CalculateSeparatingVelocity(ParticleContactComponent& contact) + void ParticleContactResolutionSystem::Update(float deltaTime) { - Vector3 velocityA = contact.entityA.hasComponent() ? contact.entityA.getComponent().velocity : Vector3(0, 0, 0); - Vector3 velocityB = contact.entityB.hasComponent() ? contact.entityB.getComponent().velocity : Vector3(0, 0, 0); - Vector3 relativeVel = velocityA - velocityB; - return glm::dot(relativeVel, contact.normal); + auto contactEvents = getWorld().getEventManager().getEvents(); + if (contactEvents.size() > 0) + { + for (int i = 0; i < velocityIterations; i++) + { + // Sort from highest incoming OR most negetive separting velocity to least + std::sort(contactEvents.begin(), contactEvents.end(), + [this](auto a, auto b) + { + return CalculateSeparationVelocity(a) < CalculateSeparationVelocity(b); + }); + ResolveVelocity(contactEvents[0], deltaTime); + } + for (int i = 0; i < positionIterations; i++) + { + // Sort from highest penetration to the least + std::sort(contactEvents.begin(), contactEvents.end(), + [this](auto a, auto b) + { + return CalculateActualPenetration(a) > CalculateActualPenetration(b); + }); + ResolveInterPenetration(contactEvents[0]); + } + } + //for (auto& contact : contactEvents) + //{ + // ResolveVelocity(contact, deltaTime); + // ResolveInterPenetration(contact); + //} } - void ParticleContactResolutionSystem::ResolveVelocity(ParticleContactComponent& contact, float deltaTime) + float ParticleContactResolutionSystem::CalculateSeparationVelocity(ParticleContactEvent & contact) { - float separatingVelocity = CalculateSeparatingVelocity(contact); + Vector3 velocityA = contact.entityA.hasComponent() ? + contact.entityA.getComponent().velocity : Vector3(0, 0, 0); - if (separatingVelocity > 0) - { - return; - } + Vector3 velocityB = contact.entityB.hasComponent() ? + contact.entityB.getComponent().velocity : Vector3(0, 0, 0); - bool isAvalid = contact.entityA.hasComponent(); - bool isBvalid = contact.entityB.hasComponent(); - float invM1 = isAvalid ? contact.entityA.getComponent().inverseMass : 0; - float invM2 = isBvalid ? contact.entityB.getComponent().inverseMass : 0; + Vector3 separationVelocity = velocityA - velocityB; + return glm::dot(separationVelocity, contact.normal); + } - float newSeparatingVelocity = -separatingVelocity * contact.restitution; + float ParticleContactResolutionSystem::CalculateActualPenetration(ParticleContactEvent & contact) + { + float actualPenetration = contact.penetration; - // Check the velocity build up due to accelaration only - Vector3 accCausedVelocity = Vector3(0, 0, 0); - if (isAvalid) - { - accCausedVelocity += contact.entityA.getComponent().accelaration; - } - if (isBvalid) + if (contact.entityA.hasComponent()) { - accCausedVelocity -= contact.entityB.getComponent().accelaration; + Vector3 deltaMove = contact.entityA.getComponent().deltaMove; + actualPenetration -= glm::dot(deltaMove, contact.normal); } - float accCausedSepVelocity = glm::dot(accCausedVelocity, contact.normal) * deltaTime; - // If we have a closing velocity due to accelaration build up, - // remove it from new separating velocity - if (accCausedSepVelocity < 0) + if (contact.entityB.hasComponent()) { - newSeparatingVelocity += contact.restitution * accCausedSepVelocity; - if (newSeparatingVelocity < 0) - { - newSeparatingVelocity = 0; - } + Vector3 deltaMove = contact.entityB.getComponent().deltaMove; + actualPenetration += glm::dot(deltaMove, contact.normal); } - float deltaVelocity = newSeparatingVelocity - separatingVelocity; + return actualPenetration; + } - float totalInverseMass = invM1 + invM2; + void ParticleContactResolutionSystem::ResolveVelocity(ParticleContactEvent & contact, float deltaTime) + { + float initialVelocity = CalculateSeparationVelocity(contact); - if (totalInverseMass <= 0) + if (initialVelocity > 0) { return; } - float impulse = deltaVelocity / totalInverseMass; - - Vector3 impulsePerIMass = contact.normal * impulse; + float finalVelocity = -initialVelocity * contact.restitution; - if (isAvalid) + Vector3 relativeAccelaration = Vector3(0, 0, 0); + if (contact.entityA.hasComponent()) { - contact.entityA.getComponent().velocity += impulsePerIMass * invM1; + relativeAccelaration += contact.entityA.getComponent().acceleration; } - if (isBvalid) + if (contact.entityB.hasComponent()) { - contact.entityB.getComponent().velocity -= impulsePerIMass * invM2; + relativeAccelaration -= contact.entityB.getComponent().acceleration; } - } - void ParticleContactResolutionSystem::ResolveInterpenetration(ParticleContactComponent& contact) - { - if (contact.penetration <= 0) + float accCausedSepVelocity = glm::dot(relativeAccelaration, contact.normal) * deltaTime; + + if (accCausedSepVelocity < 0) { - return; + finalVelocity += contact.restitution * accCausedSepVelocity; + + if (finalVelocity < 0) + { + finalVelocity = 0; + } } - bool isAvalid = contact.entityA.hasComponent(); - bool isBvalid = contact.entityB.hasComponent(); - float invM1 = isAvalid ? contact.entityA.getComponent().inverseMass : 0; - float invM2 = isBvalid ? contact.entityB.getComponent().inverseMass : 0; + float deltaVelocity = finalVelocity - initialVelocity; + + float invMA = contact.entityA.hasComponent() ? + contact.entityA.getComponent().inverseMass : 0; + + float invMB = contact.entityB.hasComponent() ? + contact.entityB.getComponent().inverseMass : 0; - float totalInverseMass = invM1 + invM2; + float totalInverseMass = invMA + invMB; if (totalInverseMass <= 0) { return; } - Vector3 movePerMass = contact.normal * (-contact.penetration / totalInverseMass); - contact.deltaMovePerMass = movePerMass; - if (isAvalid) + float impulse = deltaVelocity / totalInverseMass; + Vector3 impulsePerIMass = impulse * contact.normal; + + if (contact.entityA.hasComponent()) { - contact.entityA.getComponent().position -= movePerMass * invM1; + contact.entityA.getComponent().velocity += impulsePerIMass * invMA; } - if (isBvalid) + if (contact.entityB.hasComponent()) { - contact.entityB.getComponent().position += movePerMass * invM2; + contact.entityB.getComponent().velocity -= impulsePerIMass * invMB; } - //contact.penetration = 0; } - - void ParticleContactResolutionSystem::UpdateInterpenetration(ParticleContactComponent & bestContact, ParticleContactComponent & contact) + void ParticleContactResolutionSystem::ResolveInterPenetration(ParticleContactEvent & contact) { - bool isAvalid = contact.entityA.hasComponent(); - bool isBvalid = contact.entityB.hasComponent(); - float invM1 = isAvalid ? contact.entityA.getComponent().inverseMass : 0; - float invM2 = isBvalid ? contact.entityB.getComponent().inverseMass : 0; - if (bestContact.entityA == contact.entityA || bestContact.entityB == contact.entityA) + float actualPenetration = CalculateActualPenetration(contact); + + if (actualPenetration < 0) { - float mult = bestContact.entityA == contact.entityA ? -1 : 1; - Vector3 deltaMove = mult * bestContact.deltaMovePerMass * invM1; - float deltaPenetration = glm::dot(deltaMove, contact.normal); - contact.penetration -= deltaPenetration; + return; } - if (bestContact.entityB == contact.entityB || bestContact.entityA == contact.entityB) + + float invMassA = contact.entityA.hasComponent() ? + contact.entityA.getComponent().inverseMass : 0; + + float invMassB = contact.entityB.hasComponent() ? + contact.entityB.getComponent().inverseMass : 0; + + float totalInverseMass = invMassA + invMassB; + + if (totalInverseMass <= 0) { - float mult = bestContact.entityA == contact.entityB ? -1 : 1; - Vector3 deltaMove = mult * bestContact.deltaMovePerMass * invM2; - float deltaPenetration = glm::dot(deltaMove, contact.normal); - contact.penetration += deltaPenetration; + return; } - } - void ParticleContactResolutionSystem::Update(float deltaTime) - { - iterationsUsed = 0; - iterations = getEntities().size() * 2; + Vector3 movePerUnitIMass = contact.normal * (actualPenetration / totalInverseMass); - if (getEntities().size() > 0) + if (contact.entityA.hasComponent()) { - unsigned int bestContactIndex = 0; - unsigned int lastBest = 0; - while (iterationsUsed < iterations) + Vector3 deltaMove = movePerUnitIMass * invMassA; + contact.entityA.getComponent().position += deltaMove; + if (contact.entityA.hasComponent()) { - // Find the contact with the largest closing velocity - float max = 0; - for (int i = 0; i < getEntities().size(); i++) - { - auto e = getEntities()[i]; - auto &contact = e.getComponent(); - if (iterationsUsed > 0) - { - UpdateInterpenetration(getEntities()[lastBest].getComponent(), contact); - } - float sepVel = CalculateSeparatingVelocity(contact); - if (sepVel < max) - { - max = sepVel; - bestContactIndex = i; - } - } - if (max >= 0) - { - break; - } - auto& bestContact = getEntities()[bestContactIndex].getComponent(); - ResolveVelocity(bestContact, deltaTime); - ResolveInterpenetration(bestContact); - lastBest = bestContactIndex; - iterationsUsed++; + contact.entityA.getComponent().deltaMove += deltaMove; } + } - for (auto e : getEntities()) + if (contact.entityB.hasComponent()) + { + Vector3 deltaMove = movePerUnitIMass * invMassB; + contact.entityB.getComponent().position -= movePerUnitIMass * invMassB; + if (contact.entityB.hasComponent()) { - e.kill(); + contact.entityB.getComponent().deltaMove -= deltaMove; } } - - } } diff --git a/OpenGLEngine/OpenGLEngine/ParticleContactResolutionSystem.h b/OpenGLEngine/OpenGLEngine/ParticleContactResolutionSystem.h index ff0daa1..a203f9b 100644 --- a/OpenGLEngine/OpenGLEngine/ParticleContactResolutionSystem.h +++ b/OpenGLEngine/OpenGLEngine/ParticleContactResolutionSystem.h @@ -1,6 +1,6 @@ #pragma once #include "ECSConfig.h" -#include "ParticleContactComponent.h" +#include "ParticleContactEvent.h" namespace Reality { @@ -9,13 +9,12 @@ namespace Reality public: ParticleContactResolutionSystem(); void Update(float deltaTime); - unsigned int iterations = 1; private: - float CalculateSeparatingVelocity(ParticleContactComponent& contact); - void ResolveVelocity(ParticleContactComponent& contact, float deltaTime); - void ResolveInterpenetration(ParticleContactComponent& contact); - void UpdateInterpenetration(ParticleContactComponent& bestContact, ParticleContactComponent& contact); - unsigned int iterationsUsed = 0; + float CalculateSeparationVelocity(ParticleContactEvent& contact); + float CalculateActualPenetration(ParticleContactEvent& contact); + void ResolveVelocity(ParticleContactEvent& contact, float deltaTime); + void ResolveInterPenetration(ParticleContactEvent& contact); + int velocityIterations = 4; + int positionIterations = 8; }; } - diff --git a/OpenGLEngine/OpenGLEngine/ParticleSphereComponent.h b/OpenGLEngine/OpenGLEngine/ParticleSphereComponent.h new file mode 100644 index 0000000..4954332 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/ParticleSphereComponent.h @@ -0,0 +1,15 @@ +#pragma once +#include "ECSConfig.h" + +namespace Reality +{ + struct ParticleSphereComponent + { + ParticleSphereComponent(float _radius = 1.0f) + : radius(_radius) + { + + } + float radius; + }; +} diff --git a/OpenGLEngine/OpenGLEngine/ParticleSphereSystem.cpp b/OpenGLEngine/OpenGLEngine/ParticleSphereSystem.cpp new file mode 100644 index 0000000..bd2cc30 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/ParticleSphereSystem.cpp @@ -0,0 +1,145 @@ +#include "ParticleSphereSystem.h" +#include "ParticleContactEvent.h" + +namespace Reality +{ + ParticleSphereSystem::ParticleSphereSystem() + { + requireComponent(); + requireComponent(); + } + + void ParticleSphereSystem::Update(float deltaTime) + { + if (!createBox) + { + boundingBox = getWorld().createEntity(); + createBox = true; + } + + // Draw Bounding Box + if (getEntities().size() > 0) + { + getWorld().data.renderUtil->DrawCube( + Vector3(0, 0, 0), + Vector3(20, 20, 20), + Vector3(0, 0, 0), + Color::Purple + ); + } + + for (int i = 0; i < getEntities().size(); i++) + { + auto e = getEntities()[i]; + auto& transform = e.getComponent(); + auto& sphere = e.getComponent(); + + // Draw Debug Sphere + if (DEBUG_LOG_LEVEL > 0) + { + getWorld().data.renderUtil->DrawSphere( + transform.position, + sphere.radius, + Color::Orange + ); + } + + // Collision Check with X + if (abs(transform.position.x) + sphere.radius >= 10) + { + Vector3 normal = Vector3(transform.position.x > 0 ? -1 : 1, 0, 0); + float penetration = abs(transform.position.x) + sphere.radius - 10; + + getWorld().getEventManager().emitEvent( + e, + boundingBox, + 0.8f, + normal, + penetration); + + getWorld().data.renderUtil->DrawLine( + transform.position - normal * sphere.radius, + transform.position - normal * (sphere.radius - penetration), + Color::Red); + } + + // Collision Check with Y + if (abs(transform.position.y) + sphere.radius >= 10) + { + Vector3 normal = Vector3(0, transform.position.y > 0 ? -1 : 1, 0); + float penetration = abs(transform.position.y) + sphere.radius - 10; + + getWorld().getEventManager().emitEvent( + e, + boundingBox, + 0.8f, + normal, + penetration); + + getWorld().data.renderUtil->DrawLine( + transform.position - normal * sphere.radius, + transform.position - normal * (sphere.radius - penetration), + Color::Red); + } + + // Collision Check with Z + if (abs(transform.position.z) + sphere.radius >= 10) + { + Vector3 normal = Vector3(0, 0, transform.position.z > 0 ? -1 : 1); + float penetration = abs(transform.position.z) + sphere.radius - 10; + + getWorld().getEventManager().emitEvent( + e, + boundingBox, + 0.8f, + normal, + penetration); + + getWorld().data.renderUtil->DrawLine( + transform.position - normal * sphere.radius, + transform.position - normal * (sphere.radius - penetration), + Color::Red); + } + + // Collision with other spheres + if (i < getEntities().size() - 1) + { + for (int j = i + 1; j < getEntities().size(); j++) + { + CheckCollision(e, getEntities()[j]); + } + } + } + } + void ParticleSphereSystem::CheckCollision(ECSEntity sphereEntityA, ECSEntity sphereEntityB) + { + auto& transformA = sphereEntityA.getComponent(); + auto& sphereA = sphereEntityA.getComponent(); + + auto& transformB = sphereEntityB.getComponent(); + auto& sphereB = sphereEntityB.getComponent(); + + Vector3 relativePos = transformA.position - transformB.position; + float distance = glm::length(relativePos); + + if (distance < sphereA.radius + sphereB.radius) + { + Vector3 normal = glm::normalize(relativePos); + float penetration = sphereA.radius + sphereB.radius - distance; + + getWorld().getEventManager().emitEvent( + sphereEntityA, + sphereEntityB, + 0.8f, + normal, + penetration + ); + + getWorld().data.renderUtil->DrawLine( + transformA.position - normal * sphereA.radius, + transformB.position + normal * sphereB.radius, + Color::Red + ); + } + } +} diff --git a/OpenGLEngine/OpenGLEngine/ParticleSphereSystem.h b/OpenGLEngine/OpenGLEngine/ParticleSphereSystem.h new file mode 100644 index 0000000..0bda2db --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/ParticleSphereSystem.h @@ -0,0 +1,18 @@ +#pragma once +#include "ECSConfig.h" +#include "ParticleSphereComponent.h" +#include "TransformComponent.h" + +namespace Reality +{ + class ParticleSphereSystem : public ECSSystem + { + public: + ParticleSphereSystem(); + void Update(float deltaTime); + private: + bool createBox = false; + ECSEntity boundingBox; + void CheckCollision(ECSEntity sphereEntityA, ECSEntity sphereEntityB); + }; +} diff --git a/OpenGLEngine/OpenGLEngine/ParticleSystem.cpp b/OpenGLEngine/OpenGLEngine/ParticleSystem.cpp index 41744a2..c9b3b97 100644 --- a/OpenGLEngine/OpenGLEngine/ParticleSystem.cpp +++ b/OpenGLEngine/OpenGLEngine/ParticleSystem.cpp @@ -1,6 +1,5 @@ #include "ParticleSystem.h" - namespace Reality { ParticleSystem::ParticleSystem() @@ -13,21 +12,16 @@ namespace Reality { for (auto e : getEntities()) { - auto &particle = e.getComponent(); - auto &transform = e.getComponent(); + auto& transform = e.getComponent(); + auto& particle = e.getComponent(); + + particle.velocity += particle.acceleration * deltaTime; + transform.position += particle.velocity * deltaTime; - // HACK for bounce - if (transform.position.y <= -10) + if (DEBUG_LOG_LEVEL > 0) { - //particle.velocity.y = -particle.velocity.y; - //e.kill(); + getWorld().data.renderUtil->DrawSphere(transform.position); } - - // Update velocity from accelarartion - particle.velocity += particle.accelaration * deltaTime; - - // Update position from velocity - transform.position += particle.velocity * deltaTime; } } } diff --git a/OpenGLEngine/OpenGLEngine/ParticleSystem.h b/OpenGLEngine/OpenGLEngine/ParticleSystem.h index 4c69212..2c926e8 100644 --- a/OpenGLEngine/OpenGLEngine/ParticleSystem.h +++ b/OpenGLEngine/OpenGLEngine/ParticleSystem.h @@ -12,4 +12,3 @@ namespace Reality void Update(float deltaTime); }; } - diff --git a/OpenGLEngine/OpenGLEngine/PenetrationDeltaMoveComponent.h b/OpenGLEngine/OpenGLEngine/PenetrationDeltaMoveComponent.h new file mode 100644 index 0000000..fb50100 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/PenetrationDeltaMoveComponent.h @@ -0,0 +1,14 @@ +#pragma once +#include "ECSConfig.h" + +namespace Reality +{ + struct PenetrationDeltaMoveComponent + { + PenetrationDeltaMoveComponent() : deltaMove(Vector3(0, 0, 0)) + { + + } + Vector3 deltaMove; + }; +} diff --git a/OpenGLEngine/OpenGLEngine/RenderUtil.cpp b/OpenGLEngine/OpenGLEngine/RenderUtil.cpp index cfadec7..2bd8400 100644 --- a/OpenGLEngine/OpenGLEngine/RenderUtil.cpp +++ b/OpenGLEngine/OpenGLEngine/RenderUtil.cpp @@ -576,6 +576,10 @@ namespace Reality glm::vec3 position = (start + end) * 0.5f; float scale = glm::length(start - end); glm::vec3 axis = glm::cross(glm::vec3(1, 0, 0), end - start); + if (glm::length(axis) < 0.001f) + { + axis = glm::vec3(1, 0, 0); + } axis = glm::normalize(axis); float proj = glm::dot(end - start, glm::vec3(1, 0, 0)); glm::mat4 model = glm::mat4(1.0f); diff --git a/OpenGLEngine/OpenGLEngine/RenderingSystem.cpp b/OpenGLEngine/OpenGLEngine/RenderingSystem.cpp index b11bd6d..0f4663a 100644 --- a/OpenGLEngine/OpenGLEngine/RenderingSystem.cpp +++ b/OpenGLEngine/OpenGLEngine/RenderingSystem.cpp @@ -25,7 +25,7 @@ namespace Reality } for (auto e : getEntities()) { - const auto transform = e.getComponent(); + auto &transform = e.getComponent(); auto &mesh = e.getComponent(); if (getWorld().data.assetLoader->ModelsLoaded()) @@ -41,10 +41,18 @@ namespace Reality getWorld().data.renderUtil->DrawModel(mesh.modelId, transform.position, transform.scale, transform.eulerAngles, drawModes[drawMode]); } - // Draw - //getWorld().data.renderUtil->DrawCube(transform.position, Vector3(10,10,10), transform.eulerAngles); - //getWorld().data.renderUtil->DrawCube(transform.position + Vector3(0, transform.scale.y , 0) * 7.5f, transform.scale * 15.0f, transform.eulerAngles); - //getWorld().data.renderUtil->DrawLine(transform.position - Vector3(1, 1, 1), transform.position + Vector3(1, 1, 1)); + if (DEBUG_LOG_LEVEL > 0) + { + // X + getWorld().data.renderUtil->DrawLine(transform.position, + transform.position + transform.Right() * 10.0f, Color::Red); + // Y + getWorld().data.renderUtil->DrawLine(transform.position, + transform.position + transform.Up() * 10.0f, Color::Green); + // Z + getWorld().data.renderUtil->DrawLine(transform.position, + transform.position + transform.Forward() * 10.0f, Color::Blue); + } } } } diff --git a/OpenGLEngine/OpenGLEngine/RenderingSystemV2.cpp b/OpenGLEngine/OpenGLEngine/RenderingSystemV2.cpp index aa2dbef..a31ab95 100644 --- a/OpenGLEngine/OpenGLEngine/RenderingSystemV2.cpp +++ b/OpenGLEngine/OpenGLEngine/RenderingSystemV2.cpp @@ -1,4 +1,7 @@ #include "RenderingSystemV2.h" +#include "Shader.h" +#include "Camera.h" +#include namespace Reality { @@ -10,31 +13,46 @@ namespace Reality void RenderingSystemV2::Update(float deltaTime) { + if (glfwGetKey(getWorld().data.renderUtil->window->glfwWindow, GLFW_KEY_F1) == GLFW_PRESS && !drawModeChanged) + { + drawMode++; + drawMode = drawMode % 2; + drawModeChanged = true; + } + else if (glfwGetKey(getWorld().data.renderUtil->window->glfwWindow, GLFW_KEY_F1) == GLFW_RELEASE) + { + drawModeChanged = false; + } for (auto e : getEntities()) { - auto& transform = e.getComponent(); - auto &model = e.getComponent(); + auto &transform = e.getComponent(); + auto &mesh = e.getComponent(); if (getWorld().data.assetLoader->ModelsLoaded()) { getWorld().data.assetLoader->SetLight(getWorld().data.renderUtil->camera.Position); } - if (model.modelId < 0) + if (mesh.modelId < 0) { - model.modelId = getWorld().data.assetLoader->GetModelId(model.mesh); + mesh.modelId = getWorld().data.assetLoader->GetModelId(mesh.mesh); } - if (model.modelId >= 0) + if (mesh.modelId >= 0) + { + getWorld().data.renderUtil->DrawModel(mesh.modelId, transform.GetTransformationMatrix() * mesh.GetModelOffsetTransformation(), drawModes[drawMode]); + } + + if (DEBUG_LOG_LEVEL > 0) { - //Mat4 modelMat = glm::translate(glm::mat4(1.0f), model.offset.x * transform.Right() + model.offset.y * transform.Up() + model.offset.z * transform.Forward()) * transform.transformationMatrix; - //Mat4 modelMat = glm::translate(transform.transformationMatrix, model.offset.x * transform.Right() + model.offset.y * transform.Up() + model.offset.z * transform.Forward()); - glm::vec3 rotationOffsetInRads = glm::vec3(glm::radians(model.rotation.x), glm::radians(model.rotation.y), glm::radians(model.rotation.z)); - glm::mat4 rotationOffsetMat = glm::toMat4(glm::quat(rotationOffsetInRads)); - Mat4 modelMat = transform.GetTransformationMatrix() * glm::translate(glm::mat4(1.0f), model.offset) * rotationOffsetMat; - getWorld().data.renderUtil->DrawModel(model.modelId, modelMat); + // X + getWorld().data.renderUtil->DrawLine(transform.GetPosition(), + transform.GetPosition() + transform.Right() * 10.0f, Color::Red); + // Y + getWorld().data.renderUtil->DrawLine(transform.GetPosition(), + transform.GetPosition() + transform.Up() * 10.0f, Color::Green); + // Z + getWorld().data.renderUtil->DrawLine(transform.GetPosition(), + transform.GetPosition() + transform.Forward() * 10.0f, Color::Blue); } - getWorld().data.renderUtil->DrawLine(transform.GetPosition(), transform.GetPosition() + transform.Right() * 10.0f, Color::Red); - getWorld().data.renderUtil->DrawLine(transform.GetPosition(), transform.GetPosition() + transform.Up() * 10.0f, Color::Green); - getWorld().data.renderUtil->DrawLine(transform.GetPosition(), transform.GetPosition() + transform.Forward() * 10.0f, Color::Blue); } } } diff --git a/OpenGLEngine/OpenGLEngine/RenderingSystemV2.h b/OpenGLEngine/OpenGLEngine/RenderingSystemV2.h index b2a18e5..610bfbe 100644 --- a/OpenGLEngine/OpenGLEngine/RenderingSystemV2.h +++ b/OpenGLEngine/OpenGLEngine/RenderingSystemV2.h @@ -2,6 +2,10 @@ #include "ECSConfig.h" #include "TransformComponentV2.h" #include "MeshComponent.h" + +class Shader; +class Camera; + namespace Reality { class RenderingSystemV2 : public ECSSystem @@ -9,5 +13,9 @@ namespace Reality public: RenderingSystemV2(); void Update(float deltaTime); + private: + unsigned int drawMode = 0; + unsigned int drawModes[2] = { GL_FILL, GL_LINE }; + bool drawModeChanged = false; }; } diff --git a/OpenGLEngine/OpenGLEngine/ResetPenetrationDeltaMoveSystem.cpp b/OpenGLEngine/OpenGLEngine/ResetPenetrationDeltaMoveSystem.cpp new file mode 100644 index 0000000..8b1d203 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/ResetPenetrationDeltaMoveSystem.cpp @@ -0,0 +1,18 @@ +#include "ResetPenetrationDeltaMoveSystem.h" + +namespace Reality +{ + ResetPenetrationDeltaMoveSystem::ResetPenetrationDeltaMoveSystem() + { + requireComponent(); + } + + void ResetPenetrationDeltaMoveSystem::Update(float deltaTime) + { + for (auto e : getEntities()) + { + auto& penetration = e.getComponent(); + penetration.deltaMove = Vector3(0, 0, 0); + } + } +} diff --git a/OpenGLEngine/OpenGLEngine/ResetPenetrationDeltaMoveSystem.h b/OpenGLEngine/OpenGLEngine/ResetPenetrationDeltaMoveSystem.h new file mode 100644 index 0000000..958dfed --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/ResetPenetrationDeltaMoveSystem.h @@ -0,0 +1,13 @@ +#pragma once +#include "ECSConfig.h" +#include "PenetrationDeltaMoveComponent.h" + +namespace Reality +{ + class ResetPenetrationDeltaMoveSystem : public ECSSystem + { + public: + ResetPenetrationDeltaMoveSystem(); + void Update(float deltaTime); + }; +} diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood1_BUMPS/wood1_COLOR.jpg b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood1_BUMPS/wood1_COLOR.jpg new file mode 100644 index 0000000..f44707c Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood1_BUMPS/wood1_COLOR.jpg differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood1_BUMPS/wood1_DISP.jpg b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood1_BUMPS/wood1_DISP.jpg new file mode 100644 index 0000000..31187f4 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood1_BUMPS/wood1_DISP.jpg differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood1_BUMPS/wood1_NRM.jpg b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood1_BUMPS/wood1_NRM.jpg new file mode 100644 index 0000000..7740320 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood1_BUMPS/wood1_NRM.jpg differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood1_BUMPS/wood1_OCC.jpg b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood1_BUMPS/wood1_OCC.jpg new file mode 100644 index 0000000..82b64e9 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood1_BUMPS/wood1_OCC.jpg differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood1_BUMPS/wood1_SPEC.jpg b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood1_BUMPS/wood1_SPEC.jpg new file mode 100644 index 0000000..c12e25b Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood1_BUMPS/wood1_SPEC.jpg differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood2_BUMPS/wood2_COLOR.jpg b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood2_BUMPS/wood2_COLOR.jpg new file mode 100644 index 0000000..1fe853d Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood2_BUMPS/wood2_COLOR.jpg differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood2_BUMPS/wood2_DISP.jpg b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood2_BUMPS/wood2_DISP.jpg new file mode 100644 index 0000000..2f4d1b4 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood2_BUMPS/wood2_DISP.jpg differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood2_BUMPS/wood2_NRM.jpg b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood2_BUMPS/wood2_NRM.jpg new file mode 100644 index 0000000..16f23bd Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood2_BUMPS/wood2_NRM.jpg differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood2_BUMPS/wood2_OCC.jpg b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood2_BUMPS/wood2_OCC.jpg new file mode 100644 index 0000000..b7a7dd5 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood2_BUMPS/wood2_OCC.jpg differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood2_BUMPS/wood2_SPEC.jpg b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood2_BUMPS/wood2_SPEC.jpg new file mode 100644 index 0000000..7072cec Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood2_BUMPS/wood2_SPEC.jpg differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood3_BUMPS/Bump_DISP.jpg b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood3_BUMPS/Bump_DISP.jpg new file mode 100644 index 0000000..52e1108 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood3_BUMPS/Bump_DISP.jpg differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood3_BUMPS/Bump_NORMAL.jpg b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood3_BUMPS/Bump_NORMAL.jpg new file mode 100644 index 0000000..ba1fb7a Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood3_BUMPS/Bump_NORMAL.jpg differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood3_BUMPS/Bump_SPECULAR.jpg b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood3_BUMPS/Bump_SPECULAR.jpg new file mode 100644 index 0000000..52e1108 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/Texture/bumps/wood3_BUMPS/Bump_SPECULAR.jpg differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/boat.3ds b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/boat.3ds new file mode 100644 index 0000000..1425e4e Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/boat.3ds differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/boat.blend b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/boat.blend new file mode 100644 index 0000000..ef98fd2 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/boat.blend differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/boat.dae b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/boat.dae new file mode 100644 index 0000000..85dd7f7 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/boat.dae @@ -0,0 +1,328 @@ + + + + + Blender User + Blender 2.73.0 commit date:2015-01-20, commit time:18:16, hash:bbf09d9 + + 2015-02-26T22:51:09 + 2015-02-26T22:51:09 + + Z_UP + + + + + + + 61.56293 + 1.777778 + 0.1 + 100 + + + + + + 0 + 0 + 0 + + + + + + + + + 1 1 1 + + + + + 0.000999987 + 1 + 0.1 + 0.1 + 1 + 1 + 1 + 2 + 0 + 1 + 1 + 1 + 1 + 1 + 0 + 2880 + 2 + 30.002 + 1.000799 + 0.04999995 + 29.99998 + 1 + 2 + 0 + 0 + 1 + 1 + 1 + 1 + 8192 + 1 + 1 + 0 + 1 + 1 + 1 + 3 + 0 + 0 + 0 + 0 + 0 + 1 + 1 + 1 + 3 + 0.15 + 75 + 1 + 1 + 0 + 1 + 1 + 1 + + + + + + + + + + + + 0 0 0 1 + + + 0 0 0 1 + + + 0.64 0.64 0.64 1 + + + 0.5 0.5 0.5 1 + + + 50 + + + 1 + + + + + + + + + + + 0 0 0 1 + + + 0 0 0 1 + + + 0.64 0.64 0.64 1 + + + 0.5 0.5 0.5 1 + + + 50 + + + 1 + + + + + + + + + + + 0 0 0 1 + + + 0 0 0 1 + + + 0.64 0.64 0.64 1 + + + 0.5 0.5 0.5 1 + + + 50 + + + 1 + + + + + + + + + + + + + + + + + + + + + + 1.007646 -0.05424559 -0.8827474 -1.007646 -0.4819458 -1.015587 1.174247 -0.06321448 1.206953 -1.174248 -0.5616297 1.002589 0.6717638 -0.4351164 -1.106287 0.3358819 -0.7451021 -1.131107 0 -0.85812 -1.140304 -0.335882 -0.85812 -1.114486 -0.6717639 -0.7415367 -1.06645 0.7828311 -0.5070579 1.058492 0.3914152 -0.8682962 0.9090516 -6.21755e-7 -1 0.8974201 -0.3914164 -1 0.9254782 -0.7828323 -0.8641409 0.9734094 1.007646 0.05424559 -0.8827474 -1.007646 0.4819458 -1.015587 1.174247 0.06321448 1.206953 -1.174248 0.5616297 1.002589 0.6717638 0.4351164 -1.106287 0.3358819 0.7451021 -1.131107 0 0.85812 -1.140304 -0.335882 0.85812 -1.114486 -0.6717639 0.7415367 -1.06645 0.7828311 0.5070579 1.058492 0.3914152 0.8682962 0.9090516 -6.21755e-7 1 0.8974201 -0.3914164 1 0.9254782 -0.7828323 0.8641409 0.9734094 1.007646 0 -0.8827388 -1.112828 0 -1.015908 1.174248 0 1.208777 -1.228127 0 1.003045 0.6717639 0 -1.662178 0.335882 0 -1.8003 0 0 -1.821671 -0.3358818 0 -1.790873 -0.6717638 0 -1.728952 0.9738362 -0.04124248 -0.8616384 -0.9747318 -0.4657751 -0.9884755 1.128929 -0.04637187 1.203304 -1.130892 -0.540357 1.010178 0.6476582 -0.4115287 -1.095687 0.3178981 -0.7148227 -1.102791 -0.005652666 -0.8238458 -1.108637 -0.3301686 -0.8238887 -1.083231 -0.6553772 -0.7111079 -1.036172 0.7482104 -0.4732394 1.049938 0.3667871 -0.8266418 0.9056544 -0.007761001 -0.9522461 0.8979274 -0.3832979 -0.9523214 0.925719 -0.7597405 -0.8216695 0.9731251 0.9738362 0.04124248 -0.8616384 -0.9747318 0.4657751 -0.9884755 1.128929 0.04637187 1.203304 -1.130892 0.540357 1.010178 0.6476582 0.4115287 -1.095687 0.3178981 0.7148227 -1.102791 -0.005652666 0.8238458 -1.108637 -0.3301686 0.8238887 -1.083231 -0.6553772 0.7111079 -1.036172 0.7482104 0.4732394 1.049938 0.3667871 0.8266418 0.9056544 -0.007761001 0.9522461 0.8979274 -0.3832979 0.9523214 0.925719 -0.7597405 0.8216695 0.9731251 0.9748057 0 -0.8577298 -1.079988 0 -0.9863697 1.125916 0 1.204341 -1.179796 0 1.009828 -0.6717638 0 -1.139361 -0.3358818 0 -1.201236 0 0 -1.231965 0.335882 0 -1.210489 0.6717639 0 -1.072129 -0.9748056 0 -0.9863697 0.9748057 0 -0.8577298 -0.6553772 0.7111079 -1.036172 -0.3301686 0.8238887 -1.083231 -0.005652666 0.8238458 -1.108637 0.3178981 0.7148227 -1.102791 0.6476582 0.4115287 -1.095687 -0.9747318 0.4657751 -0.9884755 0.9738362 0.04124248 -0.8616384 -0.6553772 -0.7111079 -1.036172 -0.3301686 -0.8238887 -1.083231 0.9738362 -0.04124248 -0.8616384 -0.9747318 -0.4657751 -0.9884755 0.6476582 -0.4115287 -1.095687 0.3178981 -0.7148227 -1.102791 -0.005652666 -0.8238458 -1.108637 + + + + + + + + + + -0.1796543 -0.03986275 -0.9829218 0.9968399 0.002280473 -0.07940435 -0.613277 -0.7856369 -0.08164596 0.5539417 1.31732e-4 -0.8325554 0.5575623 -0.5546903 -0.6176108 0.2247776 -0.6059241 -0.7631061 -0.06025725 -0.6179122 -0.7839347 -0.3109624 -0.5883466 -0.7464254 0.7589173 -0.6481044 -0.0632863 0.689159 -0.7221749 -0.05935811 0.3199761 -0.9451392 -0.06578153 -0.004983663 -0.9975684 -0.06951671 -0.335141 -0.9392021 -0.07469809 -0.9917806 -0.09507471 -0.08562624 -0.1796539 0.03986269 -0.9829219 0.9968371 -1.25747e-5 -0.07947272 -0.613277 0.7856369 -0.08164596 0.8195641 0.4512024 -0.3531728 0.5575623 0.5546903 -0.6176108 0.2247776 0.6059241 -0.7631061 -0.06025725 0.6179122 -0.7839347 -0.136196 0.6600401 -0.7387812 0.7660051 0.6399747 -0.0605691 0.6793742 0.7311135 -0.06264054 0.3198385 0.9451838 -0.06580996 -0.004983663 0.9975684 -0.06951671 -0.335141 0.9392021 -0.07469809 -0.9754781 0.2129296 -0.05570793 -0.9951322 -0.06628715 0.07292431 0.6071218 0.7908742 0.07694828 -0.7553474 0.6527214 0.05835378 -0.689422 0.7224121 0.0530864 -0.3184866 0.9459998 0.06042051 0.004530251 0.9979448 0.06391865 0.3348548 0.9397326 0.06910121 0.9926594 0.08989101 0.08091336 -0.9970552 -0.01633787 0.07492715 0.6071218 -0.7908742 0.07694828 -0.7660586 -0.6404713 0.05432116 -0.6765086 -0.7341989 0.05734342 -0.3197151 -0.9456011 0.06017321 0.004530251 -0.9979448 0.06391865 0.3348548 -0.9397326 0.06910121 0.9742939 -0.2199509 0.04871368 -0.09136062 -0.02819871 0.9954185 0.07404547 -0.03358525 0.9966892 -0.1496102 -0.19246 0.969833 -0.2992916 -0.06561154 0.9519032 -0.04755282 0.05323386 0.9974491 0.073803 0.001400709 0.9972718 0.1132007 -0.02429211 0.9932752 -0.1644877 -0.01658004 0.9862398 -0.09082138 0.02872973 0.9954528 -0.07640963 0.1932183 0.9781759 -0.3036714 0.07053554 0.9501622 -0.2824414 0.08909493 0.9551382 -0.0161826 0.01324927 0.9997813 0.07148957 0.01720994 0.9972928 0.1071298 0.0515986 0.9929053 -0.1389793 0.01193732 0.9902234 0.2539385 0.1446263 0.9563465 -0.5728871 -0.01335662 0.8195255 -0.1598947 0.1509983 0.9755168 -0.06775236 0.1481618 0.9866396 0.07724219 0.1418831 0.9868651 0.1893495 0.1405035 0.9718053 0.4506712 0.003964304 0.8926811 -0.5728871 0.01335662 0.8195255 -0.1598947 -0.1509983 0.9755168 -0.06775236 -0.1481618 0.9866396 0.07724219 -0.1418831 0.9868651 0.1792451 -0.1453234 0.973012 -0.7696797 -0.4253529 -0.4760967 0.996837 1.25747e-5 -0.07947272 -0.6171402 -0.7827095 -0.08064681 0.8195641 -0.4512025 -0.3531728 0.2456961 -0.763318 -0.5974773 0.04728567 -0.6674453 -0.743156 -0.07162576 -0.6202399 -0.7811354 -0.1361961 -0.66004 -0.7387813 0.7660051 -0.6399747 -0.0605691 0.6793742 -0.7311134 -0.06264054 0.3198385 -0.9451838 -0.06580996 -0.005338847 -0.9975707 -0.06945759 -0.3364812 -0.9387426 -0.07444983 -0.9754782 -0.2129296 -0.05570793 -0.7696797 0.425353 -0.4760967 0.9968399 -0.002280414 -0.07940435 -0.6171402 0.7827095 -0.08064681 0.5539417 -1.31732e-4 -0.8325554 0.2456961 0.763318 -0.5974773 0.04728573 0.6674452 -0.743156 -0.07162588 0.6202398 -0.7811353 -0.3109627 0.5883466 -0.7464253 0.7589174 0.6481044 -0.0632863 0.689159 0.7221748 -0.05935811 0.3199761 0.9451392 -0.06578153 -0.005338847 0.9975707 -0.06945759 -0.3364812 0.9387426 -0.07444983 -0.9917807 0.09507471 -0.0856263 -0.9970552 0.01633816 0.07492715 0.6145148 0.7853198 0.07513022 -0.7660586 0.6404713 0.05432116 -0.6765086 0.7341989 0.05734348 -0.3197152 0.9456011 0.06017321 0.004867851 0.9979467 0.06386387 0.3357621 0.9394208 0.06893706 0.9742939 0.2199509 0.04871368 -0.9951322 0.06628715 0.07292431 0.6145147 -0.7853198 0.07513022 -0.7553474 -0.6527214 0.05835378 -0.6894219 -0.722412 0.05308634 -0.3184866 -0.9459998 0.06042051 0.004867911 -0.9979467 0.06386387 0.3357621 -0.9394208 0.06893706 0.9926594 -0.08989101 0.08091336 -0.09082138 -0.02872973 0.9954527 -0.07640963 -0.1932183 0.9781759 -0.3036714 -0.07053554 0.9501622 -0.2824414 -0.08909493 0.9551382 -0.0161826 -0.01324927 0.9997813 0.07148957 -0.01720994 0.9972929 0.1071298 -0.0515986 0.9929052 -0.1389793 -0.01193732 0.9902234 -0.09136062 0.02819871 0.9954185 0.07404547 0.03358525 0.9966892 -0.14961 0.19246 0.9698329 -0.2992916 0.0656116 0.9519032 -0.04755282 -0.05323386 0.9974492 0.073803 -0.001400709 0.9972719 0.1132007 0.02429211 0.9932751 -0.1644877 0.01658004 0.9862398 0.4506712 -0.003964364 0.8926811 -0.5763877 -0.06365901 0.8146931 -0.3807034 -0.03060555 0.9241907 -0.06308257 0.1502379 0.9866353 0.09011888 0.1468402 0.9850465 0.1792451 0.1453234 0.973012 0.2539387 -0.1446263 0.9563463 -0.5763877 0.06365919 0.814693 -0.3807034 0.03060555 0.9241907 -0.06308257 -0.1502378 0.9866353 0.09011888 -0.1468402 0.9850465 0.1893495 -0.1405035 0.9718052 + + + + + + + + + + 0.2936738 0.08745861 0.2049739 0.1206793 0.204974 0.1823557 0.9536204 0.3169239 0.9536204 0.4386782 0.94197 0.4386782 -0.1660379 0.5451037 -0.4240978 0.5451037 -0.3142571 0.3340348 0.7371733 0.1823556 0.7371733 0.1754136 0.6484734 0.1266723 0.6484734 0.1266723 0.5597735 0.08700227 0.5597736 0.1823556 0.5597735 0.08700227 0.4710736 0.07253903 0.4710736 0.1823556 0.4710736 0.07253903 0.3823737 0.07253903 0.3823738 0.1823556 0.3823738 0.1823556 0.3823737 0.07253903 0.2936738 0.08745861 1.014421 0.3340348 1.124261 0.5451037 0.8662012 0.5451037 0.7929748 0.3340348 0.8662012 0.5451037 0.6081414 0.5451037 0.5715284 0.3340348 0.6081414 0.5451037 0.3500816 0.5451037 0.3500816 0.5451037 0.09202182 0.5451037 0.1286357 0.3340348 0.09202182 0.5451037 -0.1660379 0.5451037 -0.09281075 0.3340348 1.074048 0.3436214 1.109922 0.6410389 0.8570751 0.6410389 0.204974 0.7967886 0.2049739 0.7351123 0.2936738 0.7018916 0.9536204 0.3169239 0.963618 0.3169239 0.9652709 0.4386782 -0.2153792 0.414336 -0.3231895 0.6215035 -0.06989979 0.6215035 0.7371733 0.7967886 0.6484734 0.7967886 0.6484734 0.7411052 0.5597736 0.7967886 0.5597735 0.7014352 0.6484734 0.7411052 0.4710736 0.7967886 0.4710736 0.686972 0.5597735 0.7014352 0.3823738 0.7967886 0.3823737 0.686972 0.4710736 0.686972 0.3823738 0.7967886 0.2936738 0.7967886 0.2936738 0.7018916 1.088739 0.414336 0.8713861 0.414336 0.943259 0.6215035 0.8713861 0.414336 0.6540331 0.414336 0.6899693 0.6215035 0.6540331 0.414336 0.4366799 0.414336 0.4366796 0.6215035 0.2193269 0.414336 0.1833899 0.6215035 0.4366796 0.6215035 0.001973748 0.414336 -0.06989979 0.6215035 0.1833899 0.6215035 0.6401022 0.3436214 0.8570751 0.3436214 0.8570751 0.6410389 0.94197 0.4386782 0.9536204 0.4386782 0.9536204 0.3169239 -0.3142571 0.3340348 -0.4240978 0.5451037 -0.1660379 0.5451037 0.8662012 0.5451037 1.124261 0.5451037 1.014421 0.3340348 0.6081414 0.5451037 0.8662012 0.5451037 0.7929748 0.3340348 0.3500816 0.5451037 0.6081414 0.5451037 0.5715284 0.3340348 0.1286357 0.3340348 0.09202182 0.5451037 0.3500816 0.5451037 -0.09281075 0.3340348 -0.1660379 0.5451037 0.09202182 0.5451037 0.8570751 0.5430634 0.943336 0.5430634 0.9310973 0.4415969 0.9652709 0.4386782 0.963618 0.3169239 0.9536204 0.3169239 0.006651639 0.8811129 -0.246638 0.8811129 -0.1388277 0.6739454 1.01981 0.8811129 0.9479376 0.6739454 1.165291 0.6739454 0.7665207 0.8811129 0.7305846 0.6739454 0.9479376 0.6739454 0.5132311 0.8811129 0.5132315 0.6739454 0.7305846 0.6739454 0.5132311 0.8811129 0.2599413 0.8811129 0.2958784 0.6739454 0.2599413 0.8811129 0.006651639 0.8811129 0.0785253 0.6739454 0.8570751 0.5430634 0.8570751 0.4415969 0.783053 0.4415969 1.05129 0.1507245 1.017275 0.1490373 1.020123 0.1333665 -0.3028976 -0.2070539 -0.2876847 -0.1920534 -0.5503943 -0.1102724 0.7815139 -0.03396093 1.052278 0.1292179 1.020123 0.1333665 0.7815139 -0.03396093 0.7566943 -0.02368903 0.4948011 -0.1543194 0.2431122 -0.2253679 0.5125675 -0.16744 0.4948011 -0.1543194 0.2431122 -0.2253679 0.2369282 -0.2096687 -0.02388823 -0.2228504 -0.3028976 -0.2070539 -0.02867293 -0.2390757 -0.02388823 -0.2228504 -0.5892584 0.07024854 -0.5797374 -0.1187492 -0.5503943 -0.1102724 1.05129 0.1507245 1.050131 0.172249 1.018548 0.1649311 -0.3319366 0.3746804 -0.5986079 0.2592816 -0.5685599 0.253635 0.7643864 0.3091515 0.7407119 0.2964942 1.018548 0.1649311 0.7643864 0.3091515 0.4834107 0.4166587 0.46704 0.4018108 0.2095276 0.4474268 0.2049407 0.4311364 0.46704 0.4018108 0.2095276 0.4474268 -0.06226766 0.4339248 -0.05588823 0.4182018 -0.3319366 0.3746804 -0.3153026 0.3612139 -0.05588823 0.4182018 -0.5892584 0.07024854 -0.556105 0.07183575 -0.5685599 0.253635 1.618602 0.9702224 1.237842 1.240017 1.25738 0.4580035 -0.34448 0.4580033 -0.3157394 0.9105669 -0.7046349 0.5033581 0.05598473 0.4580033 0.07742655 1.244103 -0.3157394 0.9105669 0.4564498 0.4580033 0.4631894 1.363997 0.07742655 1.244103 0.8569145 0.4580033 0.8501027 1.364044 0.4631894 1.363997 1.237842 1.240017 0.8501027 1.364044 0.8569145 0.4580033 1.618602 -0.05421501 1.61869 0.4580035 1.25738 0.4580035 -0.7046349 0.4126485 -0.3157394 0.005440354 -0.34448 0.4580033 -0.3157394 0.005440354 0.07742655 -0.3280951 0.05598473 0.4580033 0.07742655 -0.3280951 0.4631894 -0.4479901 0.4564498 0.4580033 0.4631894 -0.4479901 0.8501027 -0.448037 0.8569145 0.4580033 1.237842 -0.3240106 1.25738 0.4580035 0.8569145 0.4580033 0.2936738 0.1823556 0.2936738 0.08745861 0.204974 0.1823557 0.943623 0.3169239 0.9536204 0.3169239 0.94197 0.4386782 -0.09281075 0.3340348 -0.1660379 0.5451037 -0.3142571 0.3340348 0.6484734 0.1823556 0.7371733 0.1823556 0.6484734 0.1266723 0.6484734 0.1823556 0.6484734 0.1266723 0.5597736 0.1823556 0.5597736 0.1823556 0.5597735 0.08700227 0.4710736 0.1823556 0.4710736 0.1823556 0.4710736 0.07253903 0.3823738 0.1823556 0.2936738 0.1823556 0.3823738 0.1823556 0.2936738 0.08745861 0.7929748 0.3340348 1.014421 0.3340348 0.8662012 0.5451037 0.5715284 0.3340348 0.7929748 0.3340348 0.6081414 0.5451037 0.350082 0.3340348 0.5715284 0.3340348 0.3500816 0.5451037 0.350082 0.3340348 0.3500816 0.5451037 0.1286357 0.3340348 0.1286357 0.3340348 0.09202182 0.5451037 -0.09281075 0.3340348 0.8570751 0.3436214 1.074048 0.3436214 0.8570751 0.6410389 0.2936738 0.7967886 0.204974 0.7967886 0.2936738 0.7018916 0.9536204 0.4386782 0.9536204 0.3169239 0.9652709 0.4386782 0.001973748 0.414336 -0.2153792 0.414336 -0.06989979 0.6215035 0.7371733 0.7898465 0.7371733 0.7967886 0.6484734 0.7411052 0.6484734 0.7967886 0.5597736 0.7967886 0.6484734 0.7411052 0.5597736 0.7967886 0.4710736 0.7967886 0.5597735 0.7014352 0.4710736 0.7967886 0.3823738 0.7967886 0.4710736 0.686972 0.3823737 0.686972 0.3823738 0.7967886 0.2936738 0.7018916 1.196548 0.6215035 1.088739 0.414336 0.943259 0.6215035 0.943259 0.6215035 0.8713861 0.414336 0.6899693 0.6215035 0.6899693 0.6215035 0.6540331 0.414336 0.4366796 0.6215035 0.4366799 0.414336 0.2193269 0.414336 0.4366796 0.6215035 0.2193269 0.414336 0.001973748 0.414336 0.1833899 0.6215035 0.6042283 0.6410389 0.6401022 0.3436214 0.8570751 0.6410389 0.943623 0.3169239 0.94197 0.4386782 0.9536204 0.3169239 -0.09281075 0.3340348 -0.3142571 0.3340348 -0.1660379 0.5451037 0.7929748 0.3340348 0.8662012 0.5451037 1.014421 0.3340348 0.5715284 0.3340348 0.6081414 0.5451037 0.7929748 0.3340348 0.350082 0.3340348 0.3500816 0.5451037 0.5715284 0.3340348 0.350082 0.3340348 0.1286357 0.3340348 0.3500816 0.5451037 0.1286357 0.3340348 -0.09281075 0.3340348 0.09202182 0.5451037 0.8570751 0.4415969 0.8570751 0.5430634 0.9310973 0.4415969 0.9536204 0.4386782 0.9652709 0.4386782 0.9536204 0.3169239 0.0785253 0.6739454 0.006651639 0.8811129 -0.1388277 0.6739454 1.2731 0.8811129 1.01981 0.8811129 1.165291 0.6739454 1.01981 0.8811129 0.7665207 0.8811129 0.9479376 0.6739454 0.7665207 0.8811129 0.5132311 0.8811129 0.7305846 0.6739454 0.5132315 0.6739454 0.5132311 0.8811129 0.2958784 0.6739454 0.2958784 0.6739454 0.2599413 0.8811129 0.0785253 0.6739454 0.7708143 0.5430634 0.8570751 0.5430634 0.783053 0.4415969 1.052278 0.1292179 1.05129 0.1507245 1.020123 0.1333665 -0.5797374 -0.1187492 -0.3028976 -0.2070539 -0.5503943 -0.1102724 0.7566943 -0.02368903 0.7815139 -0.03396093 1.020123 0.1333665 0.5125675 -0.16744 0.7815139 -0.03396093 0.4948011 -0.1543194 0.2369282 -0.2096687 0.2431122 -0.2253679 0.4948011 -0.1543194 -0.02867293 -0.2390757 0.2431122 -0.2253679 -0.02388823 -0.2228504 -0.2876847 -0.1920534 -0.3028976 -0.2070539 -0.02388823 -0.2228504 -0.556105 0.07183575 -0.5892584 0.07024854 -0.5503943 -0.1102724 1.017275 0.1490373 1.05129 0.1507245 1.018548 0.1649311 -0.3153026 0.3612139 -0.3319366 0.3746804 -0.5685599 0.253635 1.050131 0.172249 0.7643864 0.3091515 1.018548 0.1649311 0.7407119 0.2964942 0.7643864 0.3091515 0.46704 0.4018108 0.4834107 0.4166587 0.2095276 0.4474268 0.46704 0.4018108 0.2049407 0.4311364 0.2095276 0.4474268 -0.05588823 0.4182018 -0.06226766 0.4339248 -0.3319366 0.3746804 -0.05588823 0.4182018 -0.5986079 0.2592816 -0.5892584 0.07024854 -0.5685599 0.253635 1.61869 0.4580035 1.618602 0.9702224 1.25738 0.4580035 -0.7057904 0.4580035 -0.34448 0.4580033 -0.7046349 0.5033581 -0.34448 0.4580033 0.05598473 0.4580033 -0.3157394 0.9105669 0.05598473 0.4580033 0.4564498 0.4580033 0.07742655 1.244103 0.4564498 0.4580033 0.8569145 0.4580033 0.4631894 1.363997 1.25738 0.4580035 1.237842 1.240017 0.8569145 0.4580033 1.237842 -0.3240106 1.618602 -0.05421501 1.25738 0.4580035 -0.7057904 0.4580035 -0.7046349 0.4126485 -0.34448 0.4580033 -0.34448 0.4580033 -0.3157394 0.005440354 0.05598473 0.4580033 0.05598473 0.4580033 0.07742655 -0.3280951 0.4564498 0.4580033 0.4564498 0.4580033 0.4631894 -0.4479901 0.8569145 0.4580033 0.8501027 -0.448037 1.237842 -0.3240106 0.8569145 0.4580033 + + + + + + + + + + + + + + + 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 +

8 0 0 1 0 1 29 0 2 28 1 3 30 1 4 2 1 5 13 2 6 3 2 7 1 2 8 28 3 9 0 3 10 4 3 11 4 4 12 5 4 13 33 4 14 5 5 15 6 5 16 34 5 17 6 6 18 7 6 19 35 6 20 35 7 21 7 7 22 8 7 23 0 8 24 2 8 25 9 8 26 4 9 27 9 9 28 10 9 29 5 10 30 10 10 31 11 10 32 11 11 33 12 11 34 7 11 35 12 12 36 13 12 37 8 12 38 1 13 39 3 13 40 31 13 41 29 14 42 15 14 43 22 14 44 28 15 45 14 15 46 16 15 47 15 16 48 17 16 49 27 16 50 28 17 51 32 17 52 18 17 53 33 18 54 19 18 55 18 18 56 34 19 57 20 19 58 19 19 59 35 20 60 21 20 61 20 20 62 35 21 63 36 21 64 22 21 65 14 22 66 18 22 67 23 22 68 18 23 69 19 23 70 24 23 71 19 24 72 20 24 73 25 24 74 21 25 75 26 25 76 25 25 77 22 26 78 27 26 79 26 26 80 15 27 81 29 27 82 31 27 83 39 28 84 67 28 85 65 28 86 38 29 87 40 29 88 50 29 89 46 30 90 39 30 91 37 30 92 47 31 93 46 31 94 41 31 95 48 32 96 47 32 97 42 32 98 44 33 99 49 33 100 48 33 101 45 34 102 50 34 103 49 34 104 68 35 105 40 35 106 38 35 107 53 36 108 51 36 109 65 36 110 64 37 111 54 37 112 52 37 113 60 38 114 55 38 115 51 38 116 61 39 117 56 39 118 55 39 119 62 40 120 57 40 121 56 40 122 62 41 123 63 41 124 58 41 125 63 42 126 64 42 127 59 42 128 68 43 129 66 43 130 52 43 131 30 44 132 67 44 133 39 44 134 13 45 135 50 45 136 40 45 137 9 46 138 2 46 139 39 46 140 9 47 141 46 47 142 47 47 143 11 48 144 10 48 145 47 48 146 11 49 147 48 49 148 49 49 149 13 50 150 12 50 151 49 50 152 31 51 153 3 51 154 40 51 155 30 52 156 16 52 157 53 52 158 27 53 159 17 53 160 54 53 161 23 54 162 60 54 163 53 54 164 23 55 165 24 55 166 61 55 167 25 56 168 62 56 169 61 56 170 25 57 171 26 57 172 63 57 173 27 58 174 64 58 175 63 58 176 31 59 177 68 59 178 54 59 179 36 72 216 8 72 217 29 72 218 0 73 219 28 73 220 2 73 221 8 74 222 13 74 223 1 74 224 32 75 225 28 75 226 4 75 227 32 76 228 4 76 229 33 76 230 33 77 231 5 77 232 34 77 233 34 78 234 6 78 235 35 78 236 36 79 237 35 79 238 8 79 239 4 80 240 0 80 241 9 80 242 5 81 243 4 81 244 10 81 245 6 82 246 5 82 247 11 82 248 6 83 249 11 83 250 7 83 251 7 84 252 12 84 253 8 84 254 29 85 255 1 85 256 31 85 257 36 86 258 29 86 259 22 86 260 30 87 261 28 87 262 16 87 263 22 88 264 15 88 265 27 88 266 14 89 267 28 89 268 18 89 269 32 90 270 33 90 271 18 90 272 33 91 273 34 91 274 19 91 275 34 92 276 35 92 277 20 92 278 21 93 279 35 93 280 22 93 281 16 94 282 14 94 283 23 94 284 23 95 285 18 95 286 24 95 287 24 96 288 19 96 289 25 96 290 20 97 291 21 97 292 25 97 293 21 98 294 22 98 295 26 98 296 17 99 297 15 99 298 31 99 299 37 100 300 39 100 301 65 100 302 45 101 303 38 101 304 50 101 305 41 102 306 46 102 307 37 102 308 42 103 309 47 103 310 41 103 311 43 104 312 48 104 313 42 104 314 43 105 315 44 105 316 48 105 317 44 106 318 45 106 319 49 106 320 66 107 321 68 107 322 38 107 323 67 108 324 53 108 325 65 108 326 59 109 327 64 109 328 52 109 329 53 110 330 60 110 331 51 110 332 60 111 333 61 111 334 55 111 335 61 112 336 62 112 337 56 112 338 57 113 339 62 113 340 58 113 341 58 114 342 63 114 343 59 114 344 54 115 345 68 115 346 52 115 347 2 116 348 30 116 349 39 116 350 3 117 351 13 117 352 40 117 353 46 118 354 9 118 355 39 118 356 10 119 357 9 119 358 47 119 359 48 120 360 11 120 361 47 120 362 12 121 363 11 121 364 49 121 365 50 122 366 13 122 367 49 122 368 68 123 369 31 123 370 40 123 371 67 124 372 30 124 373 53 124 374 64 125 375 27 125 376 54 125 377 16 126 378 23 126 379 53 126 380 60 127 381 23 127 382 61 127 383 24 128 384 25 128 385 61 128 386 62 129 387 25 129 388 63 129 389 26 130 390 27 130 391 63 130 392 17 131 393 31 131 394 54 131 395

+
+ + + + + 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 +

86 60 180 83 60 181 69 60 182 73 61 183 87 61 184 85 61 185 72 62 186 88 62 187 87 62 188 71 63 189 89 63 190 88 63 191 70 64 192 84 64 193 89 64 194 83 65 195 84 65 196 70 65 197 81 66 198 74 66 199 69 66 200 82 67 201 80 67 202 73 67 203 80 68 204 79 68 205 72 68 206 79 69 207 78 69 208 71 69 209 78 70 210 77 70 211 70 70 212 76 71 213 69 71 214 70 71 215 74 132 396 86 132 397 69 132 398 75 133 399 73 133 400 85 133 401 73 134 402 72 134 403 87 134 404 72 135 405 71 135 406 88 135 407 71 136 408 70 136 409 89 136 410 69 137 411 83 137 412 70 137 413 76 138 414 81 138 415 69 138 416 75 139 417 82 139 418 73 139 419 73 140 420 80 140 421 72 140 422 72 141 423 79 141 424 71 141 425 71 142 426 78 142 427 70 142 428 77 143 429 76 143 430 70 143 431

+
+
+
+ + + + 1.006081 -10.04286 -0.9863719 0.930742 -11.98221 -0.9863719 -0.9258825 -11.98293 -0.9863719 -0.9996094 -10.04214 -0.9863719 1.006081 -10.04286 0.9863719 0.930742 -11.98221 0.9863719 -0.9258825 -11.98293 0.9863719 -0.9996094 -10.04214 0.9863719 -0.9934141 -0.9916546 -1 -0.9396619 0.9916546 -1 0.9170902 0.9928237 -1 0.9669505 -0.9928237 -1 -0.9934141 -0.9916546 1 -0.9396619 0.9916546 1 0.9170902 0.9928237 1 0.9669505 -0.9928237 1 + + + + + + + + + + 0.9992463 -0.03881806 0 3.83191e-4 -1 0 -0.9992792 -0.03796082 0 3.55662e-4 1 0 0 0 -1 0 0 1 -0.999633 0.02709227 0 -6.29608e-4 0.9999998 0 0.9996849 0.02510243 0 -5.96331e-4 -0.9999999 0 0 0 -1 0 0 1 0.9992463 -0.03881806 0 3.83191e-4 -1 0 -0.9992792 -0.03796082 0 3.55662e-4 1 0 0 0 -1 0 0 1 -0.999633 0.02709227 0 -6.29608e-4 0.9999998 0 0.9996849 0.02510243 0 -5.96331e-4 -0.9999999 0 0 0 -1 0 0 1 + + + + + + + + + + 0.7455023 0.3447239 0.7455023 0.2786964 0.1982113 0.2786964 0.853459 0.6796768 0.853459 0.6618066 0.1429265 0.6618066 0.1982113 0.3447239 0.1982113 0.2786964 0.7455023 0.2786964 0.1429265 0.6796768 0.1429265 0.6618066 0.853459 0.6618066 0.216936 0.8846961 0.6880179 0.8846961 0.6880179 0.7968402 0.8316063 0.3986082 0.8316063 0.5172151 0.1647791 0.5172151 0.7455023 0.3447239 0.7455023 0.2786964 0.1982113 0.2786964 0.853459 0.6796768 0.853459 0.6618066 0.1429265 0.6618066 0.1982113 0.3447239 0.1982113 0.2786964 0.7455023 0.2786964 0.1429265 0.6796768 0.1429265 0.6618066 0.853459 0.6618066 0.216936 0.8846961 0.6880179 0.8846961 0.6880179 0.7968402 0.8316063 0.3986082 0.8316063 0.5172151 0.1647791 0.5172151 0.1982113 0.3447239 0.7455023 0.3447239 0.1982113 0.2786964 0.1429265 0.6796768 0.853459 0.6796768 0.1429265 0.6618066 0.7455023 0.3447239 0.1982113 0.3447239 0.7455023 0.2786964 0.853459 0.6796768 0.1429265 0.6796768 0.853459 0.6618066 0.216936 0.7968402 0.216936 0.8846961 0.6880179 0.7968402 0.1647791 0.3986082 0.8316063 0.3986082 0.1647791 0.5172151 0.1982113 0.3447239 0.7455023 0.3447239 0.1982113 0.2786964 0.1429265 0.6796768 0.853459 0.6796768 0.1429265 0.6618066 0.7455023 0.3447239 0.1982113 0.3447239 0.7455023 0.2786964 0.853459 0.6796768 0.1429265 0.6796768 0.853459 0.6618066 0.216936 0.7968402 0.216936 0.8846961 0.6880179 0.7968402 0.1647791 0.3986082 0.8316063 0.3986082 0.1647791 0.5172151 + + + + + + + + + + + + + + + 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 +

5 0 0 1 0 1 0 0 2 6 1 3 2 1 4 1 1 5 7 2 6 3 2 7 2 2 8 4 3 9 0 3 10 3 3 11 1 4 12 2 4 13 3 4 14 7 5 15 6 5 16 5 5 17 13 6 18 9 6 19 8 6 20 14 7 21 10 7 22 9 7 23 15 8 24 11 8 25 10 8 26 12 9 27 8 9 28 11 9 29 9 10 30 10 10 31 11 10 32 15 11 33 14 11 34 13 11 35 4 12 36 5 12 37 0 12 38 5 13 39 6 13 40 1 13 41 6 14 42 7 14 43 2 14 44 7 15 45 4 15 46 3 15 47 0 16 48 1 16 49 3 16 50 4 17 51 7 17 52 5 17 53 12 18 54 13 18 55 8 18 56 13 19 57 14 19 58 9 19 59 14 20 60 15 20 61 10 20 62 15 21 63 12 21 64 11 21 65 8 22 66 9 22 67 11 22 68 12 23 69 15 23 70 13 23 71

+
+
+
+
+ + + + + 0.7092186 0.3024773 -0.6368017 -9.955311 -0.7049885 0.304292 -0.6406228 -11.11552 -1.56016e-7 0.9032794 0.4290527 6.706635 0 0 0 1 + + + + -0.3115562 -1.555061 1.657013 16.8838 1.402011 -1.447789 -1.0951 -13.54151 1.788371 0.8640976 1.147186 13.02748 0 0 0 1 + + + + 1.458011 -0.03194912 -0.03465635 2.213996 0.02980422 1.455799 -0.0881978 1.004593 0.03651736 0.08744368 1.455691 1.57316 0 0 0 1 + + -1.80211e-7 1.682623 1.86265e-9 -3.006195 -4.188159 -1.73459e-7 0 -2.163969 -2.98023e-8 -6.33299e-8 0.6704022 -5.96046e-8 0 0 0 1 + + + + + + + + + + + 1.524567 -8.73115e-11 5.82077e-11 -2.992699 -8.91741e-8 0.3178238 0 0.3725368 -5.96046e-8 0 0.03794027 0.3840501 0 0 0 1 + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/boat.fbx b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/boat.fbx new file mode 100644 index 0000000..1762d64 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/boat.fbx differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/boat.mtl b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/boat.mtl new file mode 100644 index 0000000..7e4e70d --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/boat.mtl @@ -0,0 +1,29 @@ +# Blender MTL File: 'SANDAL.blend' +# Material Count: 3 + +newmtl Material +Ns 96.078431 +Ka 0.000000 0.000000 0.000000 +Kd 0.640000 0.640000 0.640000 +Ks 0.500000 0.500000 0.500000 +Ni 1.000000 +d 1.000000 +illum 2 + +newmtl Material.001 +Ns 96.078431 +Ka 0.000000 0.000000 0.000000 +Kd 0.640000 0.640000 0.640000 +Ks 0.500000 0.500000 0.500000 +Ni 1.000000 +d 1.000000 +illum 2 + +newmtl Material.002 +Ns 96.078431 +Ka 0.000000 0.000000 0.000000 +Kd 0.640000 0.640000 0.640000 +Ks 0.500000 0.500000 0.500000 +Ni 1.000000 +d 1.000000 +illum 2 diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/spitfire_d.png b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/spitfire_d.png new file mode 100644 index 0000000..247d496 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/spitfire_d.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/wood1.jpg b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/wood1.jpg new file mode 100644 index 0000000..93a8ac4 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/wood1.jpg differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/wood2.jpg b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/wood2.jpg new file mode 100644 index 0000000..3601738 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/wood2.jpg differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/wood3.jpg b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/wood3.jpg new file mode 100644 index 0000000..212bea3 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/Boat/wood3.jpg differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/source/Unity2Skfb.fbx b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/source/Unity2Skfb.fbx new file mode 100644 index 0000000..4449b50 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/source/Unity2Skfb.fbx differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CH2_LOD2_S3a.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CH2_LOD2_S3a.png new file mode 100644 index 0000000..a16384f Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CH2_LOD2_S3a.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CH2_LOD3_slod3.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CH2_LOD3_slod3.png new file mode 100644 index 0000000..84eb3bd Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CH2_LOD3_slod3.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CH3_SLOD3_1_B.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CH3_SLOD3_1_B.png new file mode 100644 index 0000000..4d14898 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CH3_SLOD3_1_B.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CH3_SLOD3_2.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CH3_SLOD3_2.png new file mode 100644 index 0000000..0c5cd2d Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CH3_SLOD3_2.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS1_13_LAND_SLOD3_D.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS1_13_LAND_SLOD3_D.png new file mode 100644 index 0000000..6a93d0e Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS1_13_LAND_SLOD3_D.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS1_15_SLOD3new.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS1_15_SLOD3new.png new file mode 100644 index 0000000..d3f1000 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS1_15_SLOD3new.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS1_15b_SLOD3.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS1_15b_SLOD3.png new file mode 100644 index 0000000..0d84331 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS1_15b_SLOD3.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS1_15c_SLOD3.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS1_15c_SLOD3.png new file mode 100644 index 0000000..8e6160c Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS1_15c_SLOD3.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS1_LOD2_SLOD3_A.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS1_LOD2_SLOD3_A.png new file mode 100644 index 0000000..498ee97 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS1_LOD2_SLOD3_A.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS2_10_SLOD3a.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS2_10_SLOD3a.png new file mode 100644 index 0000000..d920a71 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS2_10_SLOD3a.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS2_LOD_1234_S3new.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS2_LOD_1234_S3new.png new file mode 100644 index 0000000..5fd8814 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS2_LOD_1234_S3new.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS3_02_SLOD3.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS3_02_SLOD3.png new file mode 100644 index 0000000..f69fec7 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS3_02_SLOD3.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS3_05_SLOD3.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS3_05_SLOD3.png new file mode 100644 index 0000000..e8bad86 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS3_05_SLOD3.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS4_LOD_SLOD3.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS4_LOD_SLOD3.png new file mode 100644 index 0000000..1af8d07 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS4_LOD_SLOD3.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS5_LOD_01_04_SLOD3.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS5_LOD_01_04_SLOD3.png new file mode 100644 index 0000000..b819a5d Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS5_LOD_01_04_SLOD3.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS5_LOD_2_3_SLOD3.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS5_LOD_2_3_SLOD3.png new file mode 100644 index 0000000..7fccc60 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS5_LOD_2_3_SLOD3.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS6_LOD_SLOD3_01.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS6_LOD_SLOD3_01.png new file mode 100644 index 0000000..5eeb41c Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS6_LOD_SLOD3_01.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS6_LOD_SLOD3_02.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS6_LOD_SLOD3_02.png new file mode 100644 index 0000000..2dcc16d Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS6_LOD_SLOD3_02.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS6_LOD_SLOD3_03.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS6_LOD_SLOD3_03.png new file mode 100644 index 0000000..e578e1e Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS6_LOD_SLOD3_03.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS6_LOD_SLOD3_04.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS6_LOD_SLOD3_04.png new file mode 100644 index 0000000..33325b2 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/CS6_LOD_SLOD3_04.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/Ch3_slod3_08_09.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/Ch3_slod3_08_09.png new file mode 100644 index 0000000..06af2da Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/Ch3_slod3_08_09.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/DT1_SLOD4.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/DT1_SLOD4.png new file mode 100644 index 0000000..819d045 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/DT1_SLOD4.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/supermarine-spitfire.zip b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/GTAV-HD-MAP-satellite.jpeg similarity index 57% rename from OpenGLEngine/OpenGLEngine/Resources/Models/supermarine-spitfire.zip rename to OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/GTAV-HD-MAP-satellite.jpeg index ca156c4..7732073 100644 Binary files a/OpenGLEngine/OpenGLEngine/Resources/Models/supermarine-spitfire.zip and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/GTAV-HD-MAP-satellite.jpeg differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/HW1_SLOD4.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/HW1_SLOD4.png new file mode 100644 index 0000000..44e13a9 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/HW1_SLOD4.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ID1_SLOD4.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ID1_SLOD4.png new file mode 100644 index 0000000..b76d58d Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ID1_SLOD4.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/KT1_SLOD4.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/KT1_SLOD4.png new file mode 100644 index 0000000..66f32db Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/KT1_SLOD4.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/PO1_SLOD4.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/PO1_SLOD4.png new file mode 100644 index 0000000..2a3ca4f Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/PO1_SLOD4.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/SC1_SLOD4.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/SC1_SLOD4.png new file mode 100644 index 0000000..3408640 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/SC1_SLOD4.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/SM1_SLOD4.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/SM1_SLOD4.png new file mode 100644 index 0000000..16fbd08 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/SM1_SLOD4.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/SP1_SLOD4.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/SP1_SLOD4.png new file mode 100644 index 0000000..252085b Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/SP1_SLOD4.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/VB_LOD_SLOD4.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/VB_LOD_SLOD4.png new file mode 100644 index 0000000..f53db56 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/VB_LOD_SLOD4.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ap1_slod4b_B.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ap1_slod4b_B.png new file mode 100644 index 0000000..8977102 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ap1_slod4b_B.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/bh_lod_slod3.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/bh_lod_slod3.png new file mode 100644 index 0000000..1d59116 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/bh_lod_slod3.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ch1_lod_slod3a.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ch1_lod_slod3a.png new file mode 100644 index 0000000..71cd076 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ch1_lod_slod3a.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ch1_lod_slod3c.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ch1_lod_slod3c.png new file mode 100644 index 0000000..0004aee Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ch1_lod_slod3c.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ch3_01_02_slod3_B.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ch3_01_02_slod3_B.png new file mode 100644 index 0000000..46b08de Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ch3_01_02_slod3_B.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ch3_03_04_slod3_B.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ch3_03_04_slod3_B.png new file mode 100644 index 0000000..787399e Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ch3_03_04_slod3_B.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/cs1_16_slod3.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/cs1_16_slod3.png new file mode 100644 index 0000000..bed8e37 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/cs1_16_slod3.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/cs2_08_slod3.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/cs2_08_slod3.png new file mode 100644 index 0000000..701dd5b Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/cs2_08_slod3.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/cs3_01_slod3_00.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/cs3_01_slod3_00.png new file mode 100644 index 0000000..753d533 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/cs3_01_slod3_00.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/cs3_08_slod3aa.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/cs3_08_slod3aa.png new file mode 100644 index 0000000..6e39a1d Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/cs3_08_slod3aa.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/cs4_lod_MR1_slod3.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/cs4_lod_MR1_slod3.png new file mode 100644 index 0000000..3c0626a Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/cs4_lod_MR1_slod3.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/gradient_circle.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/gradient_circle.png new file mode 100644 index 0000000..3e6e08f Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/gradient_circle.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/id2_slod4_tg.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/id2_slod4_tg.png new file mode 100644 index 0000000..d1d28b5 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/id2_slod4_tg.png differ diff --git a/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ss1_lod_slod3.png b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ss1_lod_slod3.png new file mode 100644 index 0000000..92cbe66 Binary files /dev/null and b/OpenGLEngine/OpenGLEngine/Resources/Models/map-gta5/textures/ss1_lod_slod3.png differ diff --git a/OpenGLEngine/OpenGLEngine/RigidBodyComponent.h b/OpenGLEngine/OpenGLEngine/RigidBodyComponent.h index f391a16..b2b56d5 100644 --- a/OpenGLEngine/OpenGLEngine/RigidBodyComponent.h +++ b/OpenGLEngine/OpenGLEngine/RigidBodyComponent.h @@ -3,74 +3,17 @@ namespace Reality { - struct RigidBodyComponent + struct RigidbodyComponent { - RigidBodyComponent(float mass = 1.0f, float _linearDamping = 0.4f, float _angularDamping = 0.3f, Vector3 _velocity = Vector3(0, 0, 0), Vector3 _angularVelocity = Vector3(0, 0, 0), float _gravityScale = 1) - : inverseMass(1.0f / mass), velocity(_velocity), angularVelocity(_angularVelocity), linearDamping(_linearDamping), angularDamping(_angularDamping), gravityScale(_gravityScale), rp3dId(-1) + RigidbodyComponent(Vector3 _velocity = Vector3(0, 0, 0), Vector3 _angularVelocity = Vector3(0, 0, 0)) + :velocity(_velocity), acceleration(Vector3(0, 0, 0)), + angularVelocity(_angularVelocity), angularAcceleration(Vector3(0, 0, 0)) { - inertiaTensor = glm::mat3(0.0f); - inertiaTensor[0][0] = 0.001f; - inertiaTensor[1][1] = 0.001f; - inertiaTensor[2][2] = 0.001f; - accelaration = Vector3(0, 0, 0); - angularAccelaration = Vector3(0, 0, 0); - forceAccumulator = Vector3(0, 0, 0); - torqueAccumulator = Vector3(0, 0, 0); + } - float inverseMass; + Vector3 acceleration; Vector3 velocity; + Vector3 angularAcceleration; Vector3 angularVelocity; - Vector3 accelaration; - Vector3 angularAccelaration; - Mat3 inertiaTensor; - float gravityScale; - float linearDamping; - float angularDamping; - int rp3dId; - - Mat3 worldInverseInertiaTensor(Mat3 localToWorld) - { - Mat3 worldInertiaTensor = localToWorld * inertiaTensor * glm::inverse(localToWorld); - return glm::inverse(worldInertiaTensor); - } - - - // Forces - inline void AddForce(Vector3 force) - { - forceAccumulator += force; - } - inline Vector3 GetForce() - { - return forceAccumulator; - } - inline void ResetForceAccumulator() - { - forceAccumulator = Vector3(0, 0, 0); - } - - // Torque and force - inline void AddForceAtPoint(Vector3 force, Vector3 point, Vector3 origin) - { - AddForce(force); - AddTorque(glm::cross(point - origin, force)); - } - - // Torque - inline void AddTorque(Vector3 torque) - { - torqueAccumulator += torque; - } - inline Vector3 GetTorque() - { - return torqueAccumulator; - } - inline void ResetTorqueAccumulator() - { - torqueAccumulator = Vector3(0, 0, 0); - } - private: - Vector3 forceAccumulator; - Vector3 torqueAccumulator; }; } diff --git a/OpenGLEngine/OpenGLEngine/RigidBodyData.h b/OpenGLEngine/OpenGLEngine/RigidBodyData.h deleted file mode 100644 index d02cd64..0000000 --- a/OpenGLEngine/OpenGLEngine/RigidBodyData.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include "ECSConfig.h" - -namespace Reality -{ - struct RigidBodyData - { - RigidBodyData(ECSEntity _entity) - :entity(_entity) - { - - } - ECSEntity entity; - }; -} diff --git a/OpenGLEngine/OpenGLEngine/RigidBodySystem.cpp b/OpenGLEngine/OpenGLEngine/RigidBodySystem.cpp index aa20197..b8b36d3 100644 --- a/OpenGLEngine/OpenGLEngine/RigidBodySystem.cpp +++ b/OpenGLEngine/OpenGLEngine/RigidBodySystem.cpp @@ -1,77 +1,26 @@ -#include "RigidBodySystem.h" -#include "RigidBodyData.h" +#include "RigidbodySystem.h" namespace Reality { - RigidBodySystem::RigidBodySystem(rp3d::CollisionWorld& _rp3dWorld) - :rp3dWorld(_rp3dWorld) + RigidbodySystem::RigidbodySystem() { requireComponent(); - requireComponent(); + requireComponent(); } - void RigidBodySystem::Update(float deltaTime) + void RigidbodySystem::Update(float deltaTime) { - std::vector rp3dBodiesTemp; - std::vector aliveIds; - aliveIds.resize(rp3dBodies.size()); - int id = 0; - for (auto e : getEntities()) { - auto &rigidbody = e.getComponent(); - auto &transform = e.getComponent(); - - // Update RP3D Ids - // Calculate rp3d transform - rp3d::Vector3 initPosition(transform.GetPosition().x, - transform.GetPosition().y, - transform.GetPosition().z); - Quaternion quat = transform.GetOrientation(); - rp3d::Quaternion initOrientation = rp3d::Quaternion( - quat.x, quat.y, quat.z, quat.w); - rp3d::Transform rp3dtransform(initPosition, initOrientation); - // If new rigidbody, create an entry - if (rigidbody.rp3dId < 0) - { - rp3d::CollisionBody * body = rp3dWorld.createCollisionBody(rp3dtransform); - RigidBodyData* data = new RigidBodyData(e); - body->setUserData(data); - rp3dBodiesTemp.push_back(body); - rigidbody.rp3dId = id; - } - else - { - rp3d::CollisionBody * body = rp3dBodies[rigidbody.rp3dId]; - body->setTransform(rp3dtransform); - aliveIds[rigidbody.rp3dId] = 1; - rp3dBodiesTemp.push_back(body); - rigidbody.rp3dId = id; - } - id++; - - // Update velocity from accelarartion - rigidbody.velocity += rigidbody.accelaration * deltaTime; - rigidbody.angularVelocity += rigidbody.angularAccelaration * deltaTime; + auto& transform = e.getComponent(); + auto& rigidbody = e.getComponent(); - // Damping - rigidbody.velocity *= pow(1.0f - rigidbody.linearDamping, deltaTime); - rigidbody.angularVelocity *= pow(1.0f - rigidbody.angularDamping, deltaTime); - + rigidbody.velocity += rigidbody.acceleration * deltaTime; transform.SetPosition(transform.GetPosition() + rigidbody.velocity * deltaTime); - glm::quat angularVelocityQuat = glm::quat(0, rigidbody.angularVelocity.x, rigidbody.angularVelocity.y, rigidbody.angularVelocity.z); - getWorld().data.renderUtil->DrawLine(transform.GetPosition(), transform.GetPosition() + rigidbody.angularVelocity, Color::Blue); - transform.SetOrientation(glm::normalize(transform.GetOrientation() + 0.5f * angularVelocityQuat * transform.GetOrientation() * deltaTime)); - } - for (int i = 0; i < aliveIds.size(); i++) - { - if (aliveIds[i] == 0) - { - rp3dWorld.destroyCollisionBody(rp3dBodies[i]); - } + rigidbody.angularVelocity += rigidbody.angularAcceleration * deltaTime; + Quaternion deltaRot = Quaternion(0, rigidbody.angularVelocity * deltaTime); + transform.SetOrientation(glm::normalize(transform.GetOrientation() + 0.5f * deltaRot * transform.GetOrientation())); } - - rp3dBodies = rp3dBodiesTemp; } } diff --git a/OpenGLEngine/OpenGLEngine/RigidBodySystem.h b/OpenGLEngine/OpenGLEngine/RigidBodySystem.h index 88b8e03..7d3800c 100644 --- a/OpenGLEngine/OpenGLEngine/RigidBodySystem.h +++ b/OpenGLEngine/OpenGLEngine/RigidBodySystem.h @@ -1,17 +1,14 @@ #pragma once #include "ECSConfig.h" -#include "RigidBodyComponent.h" #include "TransformComponentV2.h" -#include +#include "RigidbodyComponent.h" namespace Reality { - class RigidBodySystem : public ECSSystem + class RigidbodySystem : public ECSSystem { public: - RigidBodySystem(rp3d::CollisionWorld& _rp3dWorld); + RigidbodySystem(); void Update(float deltaTime); - rp3d::CollisionWorld& rp3dWorld; - std::vector rp3dBodies; }; } diff --git a/OpenGLEngine/OpenGLEngine/RigidbodyGravityForceGeneratorSystem.cpp b/OpenGLEngine/OpenGLEngine/RigidbodyGravityForceGeneratorSystem.cpp deleted file mode 100644 index bf6fcef..0000000 --- a/OpenGLEngine/OpenGLEngine/RigidbodyGravityForceGeneratorSystem.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "RigidbodyGravityForceGeneratorSystem.h" - -namespace Reality -{ - RigidbodyGravityForceGeneratorSystem::RigidbodyGravityForceGeneratorSystem() - { - requireComponent(); - } - - void RigidbodyGravityForceGeneratorSystem::Update(float deltaTime) - { - for (auto e : getEntities()) - { - auto &body = e.getComponent(); - if (body.inverseMass > 0) - { - body.AddForce(gravity * body.gravityScale / body.inverseMass); - } - } - } -} diff --git a/OpenGLEngine/OpenGLEngine/RigidbodyGravityForceGeneratorSystem.h b/OpenGLEngine/OpenGLEngine/RigidbodyGravityForceGeneratorSystem.h deleted file mode 100644 index e1ea768..0000000 --- a/OpenGLEngine/OpenGLEngine/RigidbodyGravityForceGeneratorSystem.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include "ECSConfig.h" -#include "RigidBodyComponent.h" - -namespace Reality -{ - class RigidbodyGravityForceGeneratorSystem : public ECSSystem - { - public: - Vector3 gravity = Vector3(0.0f, -9.8f, 0.0f); - RigidbodyGravityForceGeneratorSystem(); - void Update(float deltaTime); - }; -} diff --git a/OpenGLEngine/OpenGLEngine/RodComponent.h b/OpenGLEngine/OpenGLEngine/RodComponent.h index 33583ad..5c5b3ef 100644 --- a/OpenGLEngine/OpenGLEngine/RodComponent.h +++ b/OpenGLEngine/OpenGLEngine/RodComponent.h @@ -5,11 +5,17 @@ namespace Reality { struct RodComponent { - RodComponent(ECSEntity a = ECSEntity(), ECSEntity b = ECSEntity(), float _length = 10) - : entityA(a), entityB(b), length(_length) - {} + RodComponent(ECSEntity a = ECSEntity(), + ECSEntity b = ECSEntity(), + float _rodLength = 10) + : entityA(a), + entityB(b), + rodLength(_rodLength) + { + + } ECSEntity entityA; ECSEntity entityB; - float length; + float rodLength; }; } diff --git a/OpenGLEngine/OpenGLEngine/RodSystem.cpp b/OpenGLEngine/OpenGLEngine/RodSystem.cpp index f1da27e..c3f6bb7 100644 --- a/OpenGLEngine/OpenGLEngine/RodSystem.cpp +++ b/OpenGLEngine/OpenGLEngine/RodSystem.cpp @@ -1,6 +1,6 @@ #include "RodSystem.h" #include "TransformComponent.h" -#include "ParticleContactComponent.h" +#include "ParticleContactEvent.h" namespace Reality { @@ -14,49 +14,50 @@ namespace Reality for (auto e : getEntities()) { auto& rod = e.getComponent(); - float currentLength = glm::length(rod.entityA.getComponent().position - - rod.entityB.getComponent().position); - getWorld().data.renderUtil->DrawSphere(rod.entityA.getComponent().position, 1, Color::Purple); - getWorld().data.renderUtil->DrawSphere(rod.entityB.getComponent().position, 1, Color::Purple); - - if (currentLength == rod.length) + if (rod.entityA.hasComponent() && + rod.entityB.hasComponent()) { - continue; + auto& transformA = rod.entityA.getComponent(); + auto& transformB = rod.entityB.getComponent(); + + Vector3 relativePos = transformA.position - transformB.position; + float length = glm::length(relativePos); + + if (length > rod.rodLength) + { + Vector3 normal = -glm::normalize(relativePos); + float penetration = length - rod.rodLength; + + getWorld().getEventManager().emitEvent( + rod.entityA, + rod.entityB, + 0, + normal, + penetration + ); + } + + if (length < rod.rodLength) + { + Vector3 normal = glm::normalize(relativePos); + float penetration = rod.rodLength - length; + + getWorld().getEventManager().emitEvent( + rod.entityA, + rod.entityB, + 0, + normal, + penetration + ); + } + + getWorld().data.renderUtil->DrawLine( + transformA.position, + transformB.position, + Color::Beige + ); } - - Vector3 normal = glm::normalize(rod.entityB.getComponent().position - - rod.entityA.getComponent().position); - - - if (currentLength > rod.length) - { - auto contactEntity = getWorld().createEntity(); - contactEntity.addComponent( - rod.entityA, - rod.entityB, - 0, - normal, - currentLength - rod.length); - getWorld().data.renderUtil->DrawLine(rod.entityA.getComponent().position, - rod.entityB.getComponent().position, - Color::Yellow); - } - else - { - auto contactEntity = getWorld().createEntity(); - contactEntity.addComponent( - rod.entityA, - rod.entityB, - 0, - -normal, - rod.length - currentLength); - getWorld().data.renderUtil->DrawLine(rod.entityA.getComponent().position, - rod.entityB.getComponent().position, - Color::Yellow); - } - - } } } diff --git a/OpenGLEngine/OpenGLEngine/RotateComponent.h b/OpenGLEngine/OpenGLEngine/RotateComponent.h index ecc5968..bde45b6 100644 --- a/OpenGLEngine/OpenGLEngine/RotateComponent.h +++ b/OpenGLEngine/OpenGLEngine/RotateComponent.h @@ -1,9 +1,15 @@ #pragma once -struct RotateComponent +#include "ECSConfig.h" + +namespace Reality { - float xRot; - float yRot; - float zRot; - RotateComponent(float x = 0, float y = 0, float z = 0) - : xRot(x), yRot(y), zRot(z) {} -}; + struct RotateComponent + { + RotateComponent(Vector3 _rotationVelocity = Vector3(0, 0, 0)) + : rotationVelocity(_rotationVelocity) + { + + } + Vector3 rotationVelocity; + }; +} diff --git a/OpenGLEngine/OpenGLEngine/RotateComponentV2.h b/OpenGLEngine/OpenGLEngine/RotateComponentV2.h new file mode 100644 index 0000000..b5f34d8 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/RotateComponentV2.h @@ -0,0 +1,15 @@ +#pragma once +#include "ECSConfig.h" + +namespace Reality +{ + struct RotateComponentV2 + { + RotateComponentV2(Vector3 _rotationVelocity = Vector3(0, 0, 0)) + : rotationVelocity(_rotationVelocity) + { + + } + Vector3 rotationVelocity; + }; +} diff --git a/OpenGLEngine/OpenGLEngine/RotateSystem.cpp b/OpenGLEngine/OpenGLEngine/RotateSystem.cpp index 6bd16a0..2fa5ae1 100644 --- a/OpenGLEngine/OpenGLEngine/RotateSystem.cpp +++ b/OpenGLEngine/OpenGLEngine/RotateSystem.cpp @@ -1,20 +1,45 @@ #include "RotateSystem.h" +#include "LifeTimeComponent.h" +#include "TransformComponentV2.h" -RotateSystem::RotateSystem() +namespace Reality { - requireComponent(); - requireComponent(); -} + RotateSystem::RotateSystem() + { + requireComponent(); + requireComponent(); + } -void RotateSystem::Update(float deltaTime) -{ - for (auto e : getEntities()) + void RotateSystem::Update(float deltaTime) { - auto &rotate = e.getComponent(); - auto &transform = e.getComponent(); + timer += deltaTime; + for (auto e : getEntities()) + { + auto& transform = e.getComponent(); + auto& rotate = e.getComponent(); + + transform.eulerAngles += rotate.rotationVelocity * deltaTime; + + if (timer >= 0.1f) + { + auto e1 = getWorld().createEntity(); + e1.addComponent(transform.position + transform.Up() * 10.0f); + e1.addComponent(); + + auto e2 = getWorld().createEntity(); + e2.addComponent(transform.position + transform.Right() * 10.0f); + e2.addComponent(5, Color::Red); + + auto e3 = getWorld().createEntity(); + e3.addComponent(transform.position + transform.Forward() * 10.0f); + e3.addComponent(5, Color::Blue); + } + } + if (timer >= 0.1f) + { + timer = 0; + } - transform.eulerAngles.x += rotate.xRot * deltaTime; - transform.eulerAngles.y += rotate.yRot * deltaTime; - transform.eulerAngles.z += rotate.zRot * deltaTime; + //getWorld().data.renderUtil->RenderText("Euler Angles", 350, 200, 1, Color::Orange); } } diff --git a/OpenGLEngine/OpenGLEngine/RotateSystem.h b/OpenGLEngine/OpenGLEngine/RotateSystem.h index 1a9cc29..c76bcef 100644 --- a/OpenGLEngine/OpenGLEngine/RotateSystem.h +++ b/OpenGLEngine/OpenGLEngine/RotateSystem.h @@ -3,11 +3,14 @@ #include "TransformComponent.h" #include "RotateComponent.h" -using namespace Reality; -class RotateSystem : public ECSSystem +namespace Reality { -public: - RotateSystem(); - void Update(float deltaTime); -}; - + class RotateSystem : public ECSSystem + { + public: + RotateSystem(); + void Update(float deltaTime); + private: + float timer = 0; + }; +} diff --git a/OpenGLEngine/OpenGLEngine/RotateSystemV2.cpp b/OpenGLEngine/OpenGLEngine/RotateSystemV2.cpp new file mode 100644 index 0000000..b3d64fe --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/RotateSystemV2.cpp @@ -0,0 +1,51 @@ +#include "RotateSystemV2.h" +#include +#include "LifeTimeComponent.h" + +namespace Reality +{ + RotateSystemV2::RotateSystemV2() + { + requireComponent(); + requireComponent(); + } + + void RotateSystemV2::Update(float deltaTime) + { + timer += deltaTime; + for (auto e : getEntities()) + { + auto& transform = e.getComponent(); + auto& rotate = e.getComponent(); + + Vector3 axis = glm::normalize(rotate.rotationVelocity); + float angle = glm::radians(glm::length(rotate.rotationVelocity)) * deltaTime; + + Quaternion deltaQuat = glm::angleAxis(angle, axis); + Quaternion newRot = glm::normalize(deltaQuat * transform.GetOrientation()); + + transform.SetOrientation(newRot); + + if (timer >= 0.1f) + { + auto e1 = getWorld().createEntity(); + e1.addComponent(transform.GetPosition() + transform.Up() * 10.0f); + e1.addComponent(); + + auto e2 = getWorld().createEntity(); + e2.addComponent(transform.GetPosition() + transform.Right() * 10.0f); + e2.addComponent(5, Color::Red); + + auto e3 = getWorld().createEntity(); + e3.addComponent(transform.GetPosition() + transform.Forward() * 10.0f); + e3.addComponent(5, Color::Blue); + } + } + if (timer >= 0.1f) + { + timer = 0; + } + + //getWorld().data.renderUtil->RenderText("Quaternions", 1300, 200, 1, Color::Orange); + } +} diff --git a/OpenGLEngine/OpenGLEngine/FlightSimulatorSystem.h b/OpenGLEngine/OpenGLEngine/RotateSystemV2.h similarity index 54% rename from OpenGLEngine/OpenGLEngine/FlightSimulatorSystem.h rename to OpenGLEngine/OpenGLEngine/RotateSystemV2.h index 67dcc5c..9b594bf 100644 --- a/OpenGLEngine/OpenGLEngine/FlightSimulatorSystem.h +++ b/OpenGLEngine/OpenGLEngine/RotateSystemV2.h @@ -1,15 +1,14 @@ #pragma once #include "ECSConfig.h" -#include "FlighSimulatorComponent.h" -#include "RigidBodyComponent.h" #include "TransformComponentV2.h" +#include "RotateComponentV2.h" namespace Reality { - class FlightSimulatorSystem : public ECSSystem + class RotateSystemV2 : public ECSSystem { public: - FlightSimulatorSystem(); + RotateSystemV2(); void Update(float deltaTime); private: float timer = 0; diff --git a/OpenGLEngine/OpenGLEngine/SetAerodynamicTensorSystem.cpp b/OpenGLEngine/OpenGLEngine/SetAerodynamicTensorSystem.cpp deleted file mode 100644 index 6ba18d7..0000000 --- a/OpenGLEngine/OpenGLEngine/SetAerodynamicTensorSystem.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "SetAerodynamicTensorSystem.h" - -namespace Reality -{ - SetAerodynamicTensorSystem::SetAerodynamicTensorSystem() - { - requireComponent(); - requireComponent(); - } - - void SetAerodynamicTensorSystem::Update(float deltaTime) - { - for (auto e : getEntities()) - { - auto& aero = e.getComponent(); - auto& minMax = e.getComponent(); - - /*if (minMax.controlSetting <= -1.0f) - { - aero.aerodynamicTensor = minMax.minTensor; - } - else if (minMax.controlSetting >= 1.0f) - { - aero.aerodynamicTensor = minMax.maxTensor; - }*/ - if (minMax.controlSetting <= 0) - { - aero.aerodynamicTensor = -minMax.controlSetting * minMax.minTensor + (minMax.controlSetting + 1) * minMax.baseTensor; - } - else if (minMax.controlSetting > 0) - { - aero.aerodynamicTensor = (1-minMax.controlSetting) * minMax.baseTensor + minMax.controlSetting * minMax.maxTensor; - } - /*else - { - aero.aerodynamicTensor = minMax.baseTensor; - }*/ - - - } - } -} diff --git a/OpenGLEngine/OpenGLEngine/SetAerodynamicTensorSystem.h b/OpenGLEngine/OpenGLEngine/SetAerodynamicTensorSystem.h deleted file mode 100644 index ad467f0..0000000 --- a/OpenGLEngine/OpenGLEngine/SetAerodynamicTensorSystem.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include "ECSConfig.h" -#include "AeroComponent.h" -#include "AeroMinMaxComponent.h" - -namespace Reality -{ - class SetAerodynamicTensorSystem : public ECSSystem - { - public: - SetAerodynamicTensorSystem(); - void Update(float deltaTime); - }; -} diff --git a/OpenGLEngine/OpenGLEngine/Shaders/Lighting_Maps.fs b/OpenGLEngine/OpenGLEngine/Shaders/Lighting_Maps.fs index e2b8430..1361fad 100644 --- a/OpenGLEngine/OpenGLEngine/Shaders/Lighting_Maps.fs +++ b/OpenGLEngine/OpenGLEngine/Shaders/Lighting_Maps.fs @@ -111,7 +111,9 @@ void main() { result += CalcSpotLight(spotLights[i], norm, FragPos, viewDir); } - FragColor = vec4(result, texture(material.diffuse, TexCoords).a); + //FragColor = vec4(result, texture(material.diffuse, TexCoords).a); + + FragColor = vec4(0.f, 0.f, 1.f, 1.f); } // calculates the color when using a directional light. diff --git a/OpenGLEngine/OpenGLEngine/SphereColliderComponent.h b/OpenGLEngine/OpenGLEngine/SphereColliderComponent.h deleted file mode 100644 index 3d5e9cd..0000000 --- a/OpenGLEngine/OpenGLEngine/SphereColliderComponent.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once -#include "ECSConfig.h" - -namespace Reality -{ - struct SphereColliderComponent - { - SphereColliderComponent(ECSEntity _body = ECSEntity(), float _radius = 1.0f, Vector3 _offset = Vector3(0, 0, 0)) - : body(_body), offset(_offset), radius(_radius), rp3dId(-1) - {} - ECSEntity body; - Vector3 offset; - float radius; - int rp3dId; - }; -} diff --git a/OpenGLEngine/OpenGLEngine/SphereColliderSystem.cpp b/OpenGLEngine/OpenGLEngine/SphereColliderSystem.cpp deleted file mode 100644 index 46c752f..0000000 --- a/OpenGLEngine/OpenGLEngine/SphereColliderSystem.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include "SphereColliderSystem.h" -#include "RigidBodyComponent.h" -#include "RigidBodySystem.h" - -namespace Reality -{ - SphereColliderSystem::SphereColliderSystem(rp3d::CollisionWorld& _rp3dWorld) - :rp3dWorld(_rp3dWorld) - { - requireComponent(); - } - - void SphereColliderSystem::Update(float deltaTime) - { - std::vector rp3dShapesTemp; - std::vector aliveIds; - aliveIds.resize(rp3dShapes.size()); - int id = 0; - - for (auto e : getEntities()) - { - auto &sphereCollider = e.getComponent(); - - if (sphereCollider.body.isAlive() && sphereCollider.body.hasComponent()) - { - auto &body = sphereCollider.body.getComponent(); - - // Update RP3D Ids - // Calculate local rp3d transform - rp3d::Vector3 initPosition(sphereCollider.offset.x, - sphereCollider.offset.y, - sphereCollider.offset.z); - rp3d::Quaternion initOrientation = rp3d::Quaternion::identity(); - rp3d::Transform rp3dtransform(initPosition, initOrientation); - - auto rp3dBody = getWorld().getSystemManager().getSystem().rp3dBodies[body.rp3dId]; - // If new rigidbody, create an entry - if (sphereCollider.rp3dId < 0) - { - rp3d::decimal radius = rp3d::decimal(sphereCollider.radius); - rp3d::SphereShape* shape = new rp3d::SphereShape(radius); - // Add the collision shape to the rigid body - - rp3d::ProxyShape * proxyShape = rp3dBody->addCollisionShape(shape, rp3dtransform); - proxyShape->setUserData(&sphereCollider); - rp3dShapesTemp.push_back(proxyShape); - sphereCollider.rp3dId = id; - } - else if (sphereCollider.body.isAlive()) - { - rp3d::ProxyShape * shape = rp3dShapes[sphereCollider.rp3dId]; - shape->setLocalToBodyTransform(rp3dtransform); - aliveIds[sphereCollider.rp3dId] = 1; - rp3dShapesTemp.push_back(shape); - sphereCollider.rp3dId = id; - } - id++; - - if (sphereCollider.body.hasComponent()) - { - getWorld().data.renderUtil->DrawSphere(sphereCollider.body.getComponent().GetUnScaledTransformationMatrix() * Vector4(sphereCollider.offset, 1.0f), sphereCollider.radius); - } - } - else - { - // No need to kill it, the death of RB already killed it - aliveIds[sphereCollider.rp3dId] = 1; - e.kill(); - } - } - - for (int i = 0; i < aliveIds.size(); i++) - { - if (aliveIds[i] == 0) - { - if (rp3dShapes[i]) - { - auto shape = rp3dShapes[i]->getCollisionShapePublic(); - - if (rp3dShapes[i]->getBody() && rp3dShapes[i]->getBody()->getProxyShapesList()) - { - rp3dShapes[i]->getBody()->removeCollisionShape(rp3dShapes[i]); - } - delete shape; - } - } - } - - rp3dShapes = rp3dShapesTemp; - } -} diff --git a/OpenGLEngine/OpenGLEngine/SphereColliderSystem.h b/OpenGLEngine/OpenGLEngine/SphereColliderSystem.h deleted file mode 100644 index 9be8223..0000000 --- a/OpenGLEngine/OpenGLEngine/SphereColliderSystem.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include "ECSConfig.h" -#include "SphereColliderComponent.h" -#include "TransformComponentV2.h" -#include - -namespace Reality -{ - class SphereColliderSystem : public ECSSystem - { - public: - SphereColliderSystem(rp3d::CollisionWorld& _rp3dWorld); - void Update(float deltaTime); - private: - rp3d::CollisionWorld& rp3dWorld; - std::vector rp3dShapes; - }; -} diff --git a/OpenGLEngine/OpenGLEngine/ThrusterComponent.h b/OpenGLEngine/OpenGLEngine/ThrusterComponent.h new file mode 100644 index 0000000..991bac2 --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/ThrusterComponent.h @@ -0,0 +1,22 @@ +#pragma once +#include "ECSConfig.h" + +namespace Reality +{ + struct ThrusterComponent + { + ThrusterComponent(ECSEntity _targetEntity = ECSEntity(), + Vector3 _localThrustDirection = Vector3(0, 0, -1), + float _thrust = 50) + :targetEntity(_targetEntity), + localThrustDirection(_localThrustDirection), + thrust(_thrust) + { + + } + ECSEntity targetEntity; + Vector3 localThrustDirection; + float thrust; + float timer = 0; + }; +} diff --git a/OpenGLEngine/OpenGLEngine/ThrusterSystem.cpp b/OpenGLEngine/OpenGLEngine/ThrusterSystem.cpp new file mode 100644 index 0000000..a871bec --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/ThrusterSystem.cpp @@ -0,0 +1,49 @@ +#include "ThrusterSystem.h" +#include "TransformComponentV2.h" +#include "ForceAndTorqueAccumulatorComponent.h" +#include "LifeTimeComponent.h" + +namespace Reality +{ + ThrusterSystem::ThrusterSystem() + { + requireComponent(); + } + + void ThrusterSystem::Update(float deltaTime) + { + for (auto e : getEntities()) + { + auto& thruster = e.getComponent(); + + if (thruster.targetEntity.hasComponent() && + thruster.targetEntity.hasComponent()) + { + auto& transform = thruster.targetEntity.getComponent(); + auto& forceAndTorque = thruster.targetEntity.getComponent(); + + Vector3 worldThrustDirection = transform.LocalToWorldDirection(thruster.localThrustDirection); + + if (glfwGetKey(getWorld().data.renderUtil->window->glfwWindow, GLFW_KEY_W) == GLFW_PRESS) + { + forceAndTorque.AddForce(worldThrustDirection * thruster.thrust); + } + + if (glfwGetKey(getWorld().data.renderUtil->window->glfwWindow, GLFW_KEY_S) == GLFW_PRESS) + { + forceAndTorque.AddForce(-worldThrustDirection * thruster.thrust); + } + + thruster.timer += deltaTime; + + if (thruster.timer > 0.3f) + { + auto smokeTrail = getWorld().createEntity(); + smokeTrail.addComponent(transform.GetPosition() - worldThrustDirection * 30.0f); + smokeTrail.addComponent(); + thruster.timer = 0; + } + } + } + } +} diff --git a/OpenGLEngine/OpenGLEngine/ThrusterSystem.h b/OpenGLEngine/OpenGLEngine/ThrusterSystem.h new file mode 100644 index 0000000..d32164d --- /dev/null +++ b/OpenGLEngine/OpenGLEngine/ThrusterSystem.h @@ -0,0 +1,13 @@ +#pragma once +#include "ECSConfig.h" +#include "ThrusterComponent.h" + +namespace Reality +{ + class ThrusterSystem : public ECSSystem + { + public: + ThrusterSystem(); + void Update(float deltaTime); + }; +} diff --git a/OpenGLEngine/OpenGLEngine/TransformComponent.h b/OpenGLEngine/OpenGLEngine/TransformComponent.h index cfa71b5..a5bb70f 100644 --- a/OpenGLEngine/OpenGLEngine/TransformComponent.h +++ b/OpenGLEngine/OpenGLEngine/TransformComponent.h @@ -12,11 +12,26 @@ namespace Reality Vector3 position; Vector3 scale; Vector3 eulerAngles; - Quaternion orientation; - Mat4 scaleMatrix; - Mat4 rotationMatrix; - Mat4 translationMatrix; - Mat4 unScaledTransformationMatrix; - Mat4 transformationMatrix; + + inline const Vector3& Right() + { + Vector3 radAngle = Vector3(glm::radians(eulerAngles.x), + glm::radians(eulerAngles.y), glm::radians(eulerAngles.z)); + return glm::quat(radAngle) * Vector3(1, 0, 0); + } + + inline const Vector3& Up() + { + Vector3 radAngle = Vector3(glm::radians(eulerAngles.x), + glm::radians(eulerAngles.y), glm::radians(eulerAngles.z)); + return glm::quat(radAngle) * Vector3(0, 1, 0); + } + + inline const Vector3& Forward() + { + Vector3 radAngle = Vector3(glm::radians(eulerAngles.x), + glm::radians(eulerAngles.y), glm::radians(eulerAngles.z)); + return glm::quat(radAngle) * Vector3(0, 0, 1); + } }; } \ No newline at end of file diff --git a/OpenGLEngine/OpenGLEngine/TransformComponentV2.h b/OpenGLEngine/OpenGLEngine/TransformComponentV2.h index 27575d5..b3bfc0e 100644 --- a/OpenGLEngine/OpenGLEngine/TransformComponentV2.h +++ b/OpenGLEngine/OpenGLEngine/TransformComponentV2.h @@ -6,10 +6,10 @@ namespace Reality { struct TransformComponentV2 { - TransformComponentV2(Vector3 _position = Vector3(0, 0, 0), Vector3 _scale = Vector3(1, 1, 1), Vector3 _eulerAngles = Vector3(0.0f, 0.0f, 0.0f)) : + TransformComponentV2(Vector3 _position = Vector3(0, 0, 0), Vector3 _scale = Vector3(1, 1, 1), Vector3 _eulerAngles = Vector3(0, 0, 0)) : position(_position), scale(_scale) { - SetRotation(_eulerAngles); + SetEulerAngles(_eulerAngles); } private: Vector3 position; @@ -24,22 +24,25 @@ namespace Reality inline void UpdateMatrices() { - scaleMatrix = glm::scale(glm::mat4(1.0f), scale); - translationMatrix = glm::translate(glm::mat4(1.0f), position); + scaleMatrix = glm::scale(Mat4(1.0f), scale); rotationMatrix = glm::toMat4(orientation); + translationMatrix = glm::translate(Mat4(1.0f), position); unScaledTransformationMatrix = translationMatrix * rotationMatrix; transformationMatrix = unScaledTransformationMatrix * scaleMatrix; dirty = false; } + public: - public: inline void SetPosition(const Vector3& _position) { position = _position; dirty = true; } - inline Vector3 GetPosition() { return position; } + inline const Vector3& GetPosition() + { + return position; + } inline void SetScale(const Vector3& _scale) { @@ -47,43 +50,36 @@ namespace Reality dirty = true; } - inline Vector3 GetScale() { return scale; } - - inline void SetOrientation(const Quaternion& _orientation) + inline const Vector3& GetScale() { - orientation = _orientation; - dirty = true; + return scale; } - inline Quaternion GetOrientation() { return orientation; } - - // Euler angles in degrees - inline void SetRotation(Vector3 eulerAngles) + inline void SetOrientation(const Quaternion& _orientation) { - glm::vec3 rotationInRads = glm::vec3(glm::radians(eulerAngles.x), - glm::radians(eulerAngles.y), glm::radians(eulerAngles.z)); - orientation = glm::quat(rotationInRads); + orientation = _orientation; dirty = true; } - inline Vector3 GetRotation() { return glm::eulerAngles(orientation); } - - inline Vector3 Up() + inline const Quaternion& GetOrientation() { - return orientation * Vector3(0.0f, 1.0f, 0.0f); + return orientation; } - inline Vector3 Right() + inline void SetEulerAngles(const Vector3& _eulerAngles) { - return orientation * Vector3(1.0f, 0.0f, 0.0f); + Vector3 radAngle = Vector3(glm::radians(_eulerAngles.x), + glm::radians(_eulerAngles.y), glm::radians(_eulerAngles.z)); + orientation = glm::quat(radAngle); + dirty = true; } - inline Vector3 Forward() + inline const Vector3& GetEulerAngles() { - return orientation * Vector3(0.0f, 0.0f, 1.0f); + return glm::eulerAngles(orientation); } - inline Mat4 GetScaleMatrix() + inline const Mat4& GetScaleMatrix() { if (dirty) { @@ -92,7 +88,7 @@ namespace Reality return scaleMatrix; } - inline Mat4 GetRotationMatrix() + inline const Mat4& GetRotationMatrix() { if (dirty) { @@ -101,16 +97,16 @@ namespace Reality return rotationMatrix; } - inline Mat4 GetTranslationMatrix() + inline const Mat4& GetTranslationMatrix() { if (dirty) { UpdateMatrices(); } - return transformationMatrix; + return translationMatrix; } - inline Mat4 GetUnScaledTransformationMatrix() + inline const Mat4& GetUnScaledTransformationMatrix() { if (dirty) { @@ -119,7 +115,7 @@ namespace Reality return unScaledTransformationMatrix; } - inline Mat4 GetTransformationMatrix() + inline const Mat4& GetTransformationMatrix() { if (dirty) { @@ -128,30 +124,48 @@ namespace Reality return transformationMatrix; } - inline Vector3 WorldToLocalPosition(Vector3 _position) + inline const Vector3& Right() { - return glm::inverse(GetTransformationMatrix()) * Vector4(_position, 1); + return orientation * Vector3(1, 0, 0); + } + + inline const Vector3& Up() + { + return orientation * Vector3(0, 1, 0); + } + inline const Vector3& Forward() + { + return orientation * Vector3(0, 0, 1); } - inline Vector3 LocalToWorldPosition(Vector3 _position) + inline const Vector3& LocalToWorldDirection(const Vector3& _localDirection) { - return GetTransformationMatrix() * Vector4(_position, 1); + return orientation * _localDirection; } - //TODO : Check - inline Vector3 WorldToLocalDirection(Vector3 direction) + inline const Vector3& WorldToLocalDirection(const Vector3& _worldDirection) { if (glm::length(orientation) > 0) { - return glm::inverse(orientation) * direction; + return glm::inverse(orientation) * _worldDirection; } return Vector3(0, 0, 0); } - inline Vector3 LocalToWorldDirection(Vector3 direction) + + inline const Vector3& LocalToWorldPosition(const Vector3& _localPosition) + { + return GetTransformationMatrix() * Vector4(_localPosition, 1.0f); + } + + inline const Vector3& WorldToLocalPosition(const Vector3& _worldPosition) { - return orientation * direction; + if (abs(glm::determinant(GetTransformationMatrix())) > 0) + { + return glm::inverse(GetTransformationMatrix()) * Vector4(_worldPosition, 1.0f); + } + return Vector3(0, 0, 0); } }; } diff --git a/OpenGLEngine/OpenGLEngine/UpdateTransformMatricesSystem.cpp b/OpenGLEngine/OpenGLEngine/UpdateTransformMatricesSystem.cpp deleted file mode 100644 index a17a6ce..0000000 --- a/OpenGLEngine/OpenGLEngine/UpdateTransformMatricesSystem.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "UpdateTransformMatricesSystem.h" - -namespace Reality -{ - UpdateTransformMatricesSystem::UpdateTransformMatricesSystem() - { - requireComponent(); - } - - void UpdateTransformMatricesSystem::Update(float deltaTime) - { - for (auto e : getEntities()) - { - auto& transform = e.getComponent(); - //transform.scaleMatrix = glm::scale(glm::mat4(1.0f), transform.scale); - //transform.translationMatrix = glm::translate(glm::mat4(1.0f), transform.position); - //transform.rotationMatrix = glm::toMat4(transform.orientation); - //transform.unScaledTransformationMatrix = transform.translationMatrix * transform.rotationMatrix; - //transform.transformationMatrix = transform.unScaledTransformationMatrix * transform.scaleMatrix; - } - } -} diff --git a/OpenGLEngine/OpenGLEngine/UpdateTransformMatricesSystem.h b/OpenGLEngine/OpenGLEngine/UpdateTransformMatricesSystem.h deleted file mode 100644 index bcda6dc..0000000 --- a/OpenGLEngine/OpenGLEngine/UpdateTransformMatricesSystem.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include "ECSConfig.h" -#include "TransformComponentV2.h" - -namespace Reality -{ - class UpdateTransformMatricesSystem : public ECSSystem - { - public: - UpdateTransformMatricesSystem(); - void Update(float deltaTime); - }; -}