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
+69
View File
@@ -0,0 +1,69 @@
#include "Actor.h"
#include "Component.h"
using namespace Seele;
Actor::Actor()
{
}
Actor::~Actor()
{
}
void Actor::setParent(PActor newParent)
{
parent = newParent;
}
void Actor::addChild(PActor child)
{
children.add(child);
}
void Actor::detachChild(PActor child)
{
children.remove(children.find(child), false);
}
void Actor::setWorldLocation(Vector location)
{
rootComponent->setWorldLocation(location);
}
void Actor::setWorldRotation(Vector4 rotation)
{
rootComponent->setWorldRotation(rotation);
}
void Actor::setWorldScale(Vector scale)
{
rootComponent->setWorldScale(scale);
}
void Actor::setRelativeLocation(Vector location)
{
rootComponent->setRelativeLocation(location);
}
void Actor::setRelativeRotation(Vector4 rotation)
{
rootComponent->setRelativeRotation(rotation);
}
void Actor::setRelativeScale(Vector scale)
{
rootComponent->setRelativeScale(scale);
}
void Actor::addWorldTranslation(Vector translation)
{
rootComponent->addWorldTranslation(translation);
}
void Actor::addWorldRotation(Vector4 rotation)
{
rootComponent->addWorldRotation(rotation);
}
void Actor::addWorldScale(Vector scale)
{
rootComponent->addWorldScale(scale);
}
PComponent Actor::getRootComponent()
{
return rootComponent;
}
void Actor::setRootComponent(PComponent newRoot)
{
rootComponent = newRoot;
}
+40
View File
@@ -0,0 +1,40 @@
#pragma once
#include "MinimalEngine.h"
#include "Transform.h"
namespace Seele
{
DECLARE_REF(Actor);
DECLARE_REF(Component);
class Actor
{
public:
Actor();
virtual ~Actor();
void setParent(PActor parent);
PActor getParent();
void addChild(PActor child);
void detachChild(PActor child);
Array<PActor> getChildren();
void setWorldLocation(Vector location);
void setWorldRotation(Vector4 rotation);
void setWorldScale(Vector scale);
void setRelativeLocation(Vector location);
void setRelativeRotation(Vector4 rotation);
void setRelativeScale(Vector scale);
void addWorldTranslation(Vector translation);
void addWorldRotation(Vector4 rotation);
void addWorldScale(Vector scale);
PComponent getRootComponent();
void setRootComponent(PComponent newRoot);
private:
PActor parent;
Array<PActor> children;
PComponent rootComponent;
Transform transform;
};
DEFINE_REF(Actor);
}
+4
View File
@@ -0,0 +1,4 @@
target_sources(SeeleEngine
PRIVATE
Actor.cpp
Actor.h)
+7
View File
@@ -0,0 +1,7 @@
target_sources(SeeleEngine
PRIVATE
Scene.cpp
Scene.h)
add_subdirectory(Actor/)
add_subdirectory(Components/)
@@ -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:
};
}
View File
+14
View File
@@ -0,0 +1,14 @@
#include "MinimalEngine.h"
#include "Actor/Actor.h"
namespace Seele
{
class Scene
{
public:
Scene();
~Scene();
private:
Array<PActor> rootActors;
};
}