Implementing basic scene tree

This commit is contained in:
Dynamitos
2020-04-15 02:04:42 +02:00
parent 576747c369
commit 3ef8342247
34 changed files with 722 additions and 54 deletions
@@ -0,0 +1,6 @@
target_sources(SeeleEngine
PRIVATE
Component.h
Component.cpp
PrimitiveComponent.cpp
PrimitiveComponent.h)
+108
View File
@@ -0,0 +1,108 @@
#include "Component.h"
using namespace Seele;
Component::Component()
{
}
Component::~Component()
{
}
PComponent Component::getParent()
{
}
PActor Component::getOwner()
{
}
void Component::setWorldLocation(Vector location)
{
}
void Component::setWorldRotation(Vector rotation)
{
}
void Component::setWorldRotation(Quaternion rotation)
{
}
void Component::setWorldScale(Vector scale)
{
}
void Component::setRelativeLocation(Vector location)
{
}
void Component::setRelativeRotation(Vector rotation)
{
}
void Component::setRelativeRotation(Quaternion rotation)
{
}
void Component::setRelativeScale(Vector scale)
{
}
void Component::addWorldTranslation(Vector translation)
{
}
void Component::addWorldRotation(Vector rotation)
{
}
void Component::addWorldRotation(Quaternion rotation)
{
}
void Component::addWorldScale(Vector scale)
{
}
Transform Component::getTransform() const
{
return transform;
}
void Component::internalSetTransform(Vector newLocation, Quaternion newRotation)
{
if(parent != nullptr)
{
Transform parentTransform = parent->getTransform();
newLocation = parentTransform.inverseTransformPosition(newLocation);
newRotation = glm::inverse(parentTransform.getRotation()) * newRotation;
}
const Vector newRelRotation = toRotator(newRotation);
if(newLocation != relativeLocation || newRelRotation != relativeLocation)
{
relativeLocation = newLocation;
relativeRotation = newRelRotation;
updateComponentTransform(newRelRotation);
}
}
void Component::propagateTransformUpdate()
{
for(auto child : children)
{
if(child != nullptr)
{
child->updateComponentTransform(child->relativeRotation);
}
}
}
void Component::updateComponentTransform(Quaternion relativeRotationQuat)
{
if(parent != nullptr && !parent->bComponentTransformClean)
{
parent->updateComponentTransform(parent->relativeRotation);
if(bComponentTransformClean)
{
return;
}
}
bComponentTransformClean = true;
Transform newTransform;
const Transform relTransform(relativeLocation, relativeRotationQuat, relativeScale);
if(parent != nullptr)
{
newTransform = parent->getTransform() * relTransform;
}
}
+48
View File
@@ -0,0 +1,48 @@
#pragma once
#include "MinimalEngine.h"
#include "Transform.h"
namespace Seele
{
DECLARE_REF(Actor);
class Component
{
public:
Component();
virtual ~Component();
PComponent getParent();
void setParent(PComponent parent);
PActor getOwner();
void setOwner(PActor owner);
void setWorldLocation(Vector location);
void setWorldRotation(Vector rotation);
void setWorldRotation(Quaternion rotation);
void setWorldScale(Vector scale);
void setRelativeLocation(Vector location);
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 internalSetTransform(Vector newLocation, Quaternion newRotation);
void propagateTransformUpdate();
void updateComponentTransform(Quaternion relativeRotationQuat);
uint8 bComponentTransformClean:1;
Vector relativeLocation;
Vector relativeRotation;
Vector relativeScale;
Transform transform;
PActor owner;
PComponent parent;
Array<PComponent> children;
};
DEFINE_REF(Component)
}
@@ -0,0 +1,12 @@
#pragma once
#include "Component.h"
namespace Seele
{
class PrimitiveComponent : public Component
{
public:
private:
};
}