Adding nlohmanns json library

This commit is contained in:
Dynamitos
2020-05-05 01:52:07 +02:00
parent 3ef8342247
commit bb5b48698a
83 changed files with 2426 additions and 646 deletions
+113 -17
View File
@@ -1,4 +1,6 @@
#include "Component.h"
#include "Scene/Actor/Actor.h"
#include "Scene/Scene.h"
using namespace Seele;
@@ -8,58 +10,123 @@ Component::Component()
Component::~Component()
{
}
void Component::tick(float deltaTime)
{
for (auto child : children)
{
child->tick(deltaTime);
}
}
PComponent Component::getParent()
{
return parent;
}
PActor Component::getOwner()
{
if (owner != nullptr)
{
return owner;
}
if (parent != nullptr)
{
return parent->getOwner();
}
return nullptr;
}
void Component::notifySceneAttach(PScene scene)
{
owningScene = scene;
for (auto child : children)
{
child->notifySceneAttach(scene);
}
}
void Component::setWorldLocation(Vector location)
{
Vector newRelLocation = location;
if (parent != nullptr)
{
Transform parentToWorld = getParent()->getTransform();
newRelLocation = parentToWorld.inverseTransformPosition(location);
}
setRelativeLocation(newRelLocation);
}
void Component::setWorldRotation(Vector rotation)
{
Vector newRelRotator = rotation;
if (parent == nullptr)
{
setRelativeRotation(rotation);
}
else
{
setWorldRotation(toQuaternion(newRelRotator));
}
}
void Component::setWorldRotation(Quaternion rotation)
{
Quaternion newRelRotation = getRelativeWorldRotation(rotation);
setRelativeRotation(newRelRotation);
}
void Component::setWorldScale(Vector scale)
{
Vector newRelScale = scale;
if (parent != nullptr)
{
Transform parentToWorld = parent->getTransform();
newRelScale = scale * parentToWorld.getSafeScaleReciprocal(Vector4(parentToWorld.getScale(), 0));
}
setRelativeScale(newRelScale);
}
void Component::setRelativeLocation(Vector location)
{
setRelativeLocationAndRotation(location, relativeRotation);
}
void Component::setRelativeRotation(Vector rotation)
{
setRelativeLocationAndRotation(relativeLocation, toQuaternion(rotation));
}
void Component::setRelativeRotation(Quaternion rotation)
{
setRelativeLocationAndRotation(relativeLocation, rotation);
}
void Component::setRelativeScale(Vector scale)
{
if (scale != relativeScale)
{
relativeScale = scale;
updateComponentTransform(relativeRotation);
}
}
void Component::addWorldTranslation(Vector translation)
{
const Vector newWorldLocation = translation + transform.getPosition();
setWorldLocation(newWorldLocation);
}
void Component::addWorldRotation(Vector rotation)
{
const Quaternion newWorldRotation = toQuaternion(rotation) * transform.getRotation();
setWorldRotation(newWorldRotation);
}
void Component::addWorldRotation(Quaternion rotation)
{
}
void Component::addWorldScale(Vector scale)
{
const Quaternion newWorldRotation = rotation * transform.getRotation();
setWorldRotation(newWorldRotation);
}
Transform Component::getTransform() const
{
return transform;
}
void Component::setParent(PComponent newParent)
{
parent = newParent;
}
void Component::internalSetTransform(Vector newLocation, Quaternion newRotation)
{
if(parent != nullptr)
if (parent != nullptr)
{
Transform parentTransform = parent->getTransform();
newLocation = parentTransform.inverseTransformPosition(newLocation);
@@ -67,7 +134,7 @@ void Component::internalSetTransform(Vector newLocation, Quaternion newRotation)
}
const Vector newRelRotation = toRotator(newRotation);
if(newLocation != relativeLocation || newRelRotation != relativeLocation)
if (newLocation != relativeLocation || newRelRotation != relativeLocation)
{
relativeLocation = newLocation;
relativeRotation = newRelRotation;
@@ -75,24 +142,21 @@ void Component::internalSetTransform(Vector newLocation, Quaternion newRotation)
}
}
void Component::propagateTransformUpdate()
void Component::propagateTransformUpdate()
{
for(auto child : children)
for (auto child : children)
{
if(child != nullptr)
{
child->updateComponentTransform(child->relativeRotation);
}
child->updateComponentTransform(child->relativeRotation);
}
}
void Component::updateComponentTransform(Quaternion relativeRotationQuat)
void Component::updateComponentTransform(Quaternion relativeRotationQuat)
{
if(parent != nullptr && !parent->bComponentTransformClean)
if (parent != nullptr && !parent->bComponentTransformClean)
{
parent->updateComponentTransform(parent->relativeRotation);
if(bComponentTransformClean)
if (bComponentTransformClean)
{
return;
}
@@ -100,9 +164,41 @@ void Component::updateComponentTransform(Quaternion relativeRotationQuat)
bComponentTransformClean = true;
Transform newTransform;
const Transform relTransform(relativeLocation, relativeRotationQuat, relativeScale);
if(parent != nullptr)
if (parent != nullptr)
{
newTransform = parent->getTransform() * relTransform;
}
bool bHasChanged = !getTransform().equals(newTransform);
if (bHasChanged)
{
transform = newTransform;
propagateTransformUpdate();
}
}
Quaternion Component::getRelativeWorldRotation(Quaternion worldRotation)
{
Quaternion newRelRotation = worldRotation;
if (parent != nullptr)
{
const Transform parentToWorld = parent->getTransform();
const Quaternion parentToWorldQuat = parentToWorld.getRotation();
const Quaternion newRelQuat = glm::inverse(parentToWorldQuat) * worldRotation;
newRelRotation = newRelQuat;
}
return newRelRotation;
}
void Component::setRelativeLocationAndRotation(Vector newLocation, Quaternion newRotation)
{
if (!bComponentTransformClean)
{
updateComponentTransform(toQuaternion(relativeRotation));
}
const Transform desiredRelTransform(newLocation, newRotation);
const Transform desiredWorldTransform = parent->getTransform() * desiredRelTransform;
internalSetTransform(desiredWorldTransform.getPosition(), desiredWorldTransform.getRotation());
}
+14 -7
View File
@@ -1,19 +1,21 @@
#pragma once
#include "MinimalEngine.h"
#include "Transform.h"
#include "Math/Transform.h"
namespace Seele
{
DECLARE_REF(Actor);
DECLARE_REF(Scene);
DECLARE_REF(Component);
class Component
{
public:
Component();
virtual ~Component();
void tick(float deltaTime);
PComponent getParent();
void setParent(PComponent parent);
PActor getOwner();
void setOwner(PActor owner);
virtual void notifySceneAttach(PScene scene);
void setWorldLocation(Vector location);
void setWorldRotation(Vector rotation);
@@ -24,25 +26,30 @@ public:
void setRelativeRotation(Vector rotation);
void setRelativeRotation(Quaternion rotation);
void setRelativeScale(Vector scale);
void addWorldTranslation(Vector translation);
void addWorldRotation(Vector rotation);
void addWorldRotation(Quaternion rotation);
void addWorldScale(Vector scale);
Transform getTransform() const;
private:
void setParent(PComponent parent);
void internalSetTransform(Vector newLocation, Quaternion newRotation);
void propagateTransformUpdate();
void updateComponentTransform(Quaternion relativeRotationQuat);
uint8 bComponentTransformClean:1;
Quaternion getRelativeWorldRotation(Quaternion worldRotation);
void setRelativeLocationAndRotation(Vector newLocation, Quaternion newRotation);
uint8 bComponentTransformClean : 1;
Vector relativeLocation;
Vector relativeRotation;
Vector relativeScale;
Transform transform;
PScene owningScene;
PActor owner;
PComponent parent;
Array<PComponent> children;
friend class Actor;
};
DEFINE_REF(Component)
}
} // namespace Seele
@@ -0,0 +1,23 @@
#include "PrimitiveComponent.h"
#include "Scene/Scene.h"
#include "Material/MaterialInstance.h"
using namespace Seele;
PrimitiveComponent::PrimitiveComponent()
{
}
PrimitiveComponent::~PrimitiveComponent()
{
}
void PrimitiveComponent::notifySceneAttach(PScene scene)
{
scene->addPrimitiveComponent(this);
}
Matrix4 PrimitiveComponent::getRenderMatrix()
{
return getTransform().toMatrix();
}
@@ -1,12 +1,23 @@
#pragma once
#include "Component.h"
#include "Graphics/GraphicsResources.h"
#include "Material/MaterialInstance.h"
namespace Seele
{
class PrimitiveComponent : public Component
{
public:
private:
PrimitiveComponent();
~PrimitiveComponent();
virtual void notifySceneAttach(PScene scene) override;
Matrix4 getRenderMatrix();
private:
PMaterialInstance instance;
Gfx::PVertexBuffer vertexBuffer;
Gfx::PIndexBuffer indexBuffer;
friend class Scene;
};
}
DEFINE_REF(PrimitiveComponent);
} // namespace Seele