Implementing basic scene tree
This commit is contained in:
@@ -1,21 +1,27 @@
|
||||
target_sources(SeeleEngine
|
||||
PRIVATE
|
||||
ForwardPlusRenderPath.h
|
||||
ForwardPlusRenderPath.cpp
|
||||
GraphicsResources.h
|
||||
GraphicsResources.cpp
|
||||
GraphicsEnums.h
|
||||
Graphics.h
|
||||
Graphics.cpp
|
||||
Mesh.h
|
||||
Mesh.cpp
|
||||
RenderCore.h
|
||||
RenderCore.cpp
|
||||
RenderPath.h
|
||||
RenderPath.cpp
|
||||
SceneView.h
|
||||
SceneView.cpp
|
||||
SceneRenderPath.h
|
||||
SceneRenderPath.cpp
|
||||
View.h
|
||||
View.cpp
|
||||
SceneView.h
|
||||
SceneView.cpp
|
||||
Window.cpp
|
||||
Window.h
|
||||
WindowManager.h
|
||||
WindowManager.cpp
|
||||
GraphicsResources.h
|
||||
GraphicsResources.cpp
|
||||
GraphicsEnums.h)
|
||||
WindowManager.cpp)
|
||||
|
||||
add_subdirectory(Vulkan/)
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "ForwardPlusRenderPath.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
Seele::ForwardPlusRenderPath::ForwardPlusRenderPath(Gfx::PGraphics graphics, Gfx::PViewport viewport)
|
||||
: SceneRenderPath(graphics, viewport)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Seele::ForwardPlusRenderPath::~ForwardPlusRenderPath()
|
||||
{}
|
||||
|
||||
void Seele::ForwardPlusRenderPath::beginFrame()
|
||||
{
|
||||
}
|
||||
|
||||
void Seele::ForwardPlusRenderPath::render()
|
||||
{
|
||||
}
|
||||
|
||||
void Seele::ForwardPlusRenderPath::endFrame()
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
#include "SceneRenderPath.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class ForwardPlusRenderPath : public SceneRenderPath
|
||||
{
|
||||
public:
|
||||
ForwardPlusRenderPath(Gfx::PGraphics graphics, Gfx::PViewport target);
|
||||
virtual ~ForwardPlusRenderPath();
|
||||
virtual void beginFrame() override;
|
||||
virtual void render() override;
|
||||
virtual void endFrame() override;
|
||||
private:
|
||||
};
|
||||
}
|
||||
@@ -283,7 +283,8 @@ class Viewport
|
||||
public:
|
||||
Viewport(PWindow owner, const ViewportCreateInfo &createInfo);
|
||||
virtual ~Viewport();
|
||||
|
||||
virtual void resize(uint32 newX, uint32 newY) = 0;
|
||||
virtual void move(uint32 newOffsetX, uint32 newOffsetY) = 0;
|
||||
protected:
|
||||
uint32 sizeX;
|
||||
uint32 sizeY;
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
#include "Mesh.h"
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "GraphicsResources.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class Mesh
|
||||
{
|
||||
public:
|
||||
Mesh(Gfx::PVertexBuffer vertexBuffer, Gfx::PIndexBuffer indexBuffer);
|
||||
~Mesh();
|
||||
private:
|
||||
Gfx::VertexBuffer vertexBuffer;
|
||||
Gfx::IndexBuffer indexBuffer;
|
||||
};
|
||||
}
|
||||
@@ -1,10 +1,17 @@
|
||||
#include "RenderPath.h"
|
||||
|
||||
Seele::RenderPath::RenderPath(Gfx::PGraphics graphics)
|
||||
Seele::RenderPath::RenderPath(Gfx::PGraphics graphics, Gfx::PViewport target)
|
||||
: graphics(graphics)
|
||||
, target(target)
|
||||
{
|
||||
}
|
||||
|
||||
Seele::RenderPath::~RenderPath()
|
||||
{
|
||||
}
|
||||
|
||||
void Seele::RenderPath::applyArea(Rect newArea)
|
||||
{
|
||||
target->resize(newArea.size.x, newArea.size.y);
|
||||
target->move(newArea.offset.x, newArea.offset.y);
|
||||
}
|
||||
@@ -6,17 +6,15 @@ namespace Seele
|
||||
class RenderPath
|
||||
{
|
||||
public:
|
||||
RenderPath(Gfx::PGraphics graphics);
|
||||
RenderPath(Gfx::PGraphics graphics, Gfx::PViewport target);
|
||||
virtual ~RenderPath();
|
||||
virtual void applyArea(Rect area) = 0;
|
||||
virtual void init() = 0;
|
||||
virtual void applyArea(Rect area);
|
||||
virtual void beginFrame() = 0;
|
||||
virtual void render() = 0;
|
||||
virtual void endFrame() = 0;
|
||||
|
||||
protected:
|
||||
Gfx::PGraphics graphics;
|
||||
Rect area;
|
||||
Gfx::PViewport target;
|
||||
};
|
||||
DEFINE_REF(RenderPath);
|
||||
} // namespace Seele
|
||||
@@ -1,31 +1,10 @@
|
||||
#include "SceneRenderPath.h"
|
||||
|
||||
Seele::SceneRenderPath::SceneRenderPath(Gfx::PGraphics graphics)
|
||||
: RenderPath(graphics)
|
||||
Seele::SceneRenderPath::SceneRenderPath(Gfx::PGraphics graphics, Gfx::PViewport target)
|
||||
: RenderPath(graphics, target)
|
||||
{
|
||||
}
|
||||
|
||||
Seele::SceneRenderPath::~SceneRenderPath()
|
||||
{
|
||||
}
|
||||
|
||||
void Seele::SceneRenderPath::applyArea(Rect newArea)
|
||||
{
|
||||
area = newArea;
|
||||
}
|
||||
|
||||
void Seele::SceneRenderPath::init()
|
||||
{
|
||||
}
|
||||
|
||||
void Seele::SceneRenderPath::beginFrame()
|
||||
{
|
||||
}
|
||||
|
||||
void Seele::SceneRenderPath::render()
|
||||
{
|
||||
}
|
||||
|
||||
void Seele::SceneRenderPath::endFrame()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -6,12 +6,10 @@ namespace Seele
|
||||
class SceneRenderPath : public RenderPath
|
||||
{
|
||||
public:
|
||||
SceneRenderPath(Gfx::PGraphics graphics);
|
||||
SceneRenderPath(Gfx::PGraphics graphics, Gfx::PViewport target);
|
||||
virtual ~SceneRenderPath();
|
||||
virtual void applyArea(Rect area) override;
|
||||
virtual void init() override;
|
||||
virtual void beginFrame() override;
|
||||
virtual void render() override;
|
||||
virtual void endFrame() override;
|
||||
virtual void beginFrame() = 0;
|
||||
virtual void render() = 0;
|
||||
virtual void endFrame() = 0;
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "SceneView.h"
|
||||
#include "SceneRenderPath.h"
|
||||
#include "ForwardPlusRenderPath.h"
|
||||
|
||||
Seele::SceneView::SceneView(Gfx::PGraphics graphics)
|
||||
: View(graphics)
|
||||
Seele::SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo& createInfo)
|
||||
: View(graphics, owner, createInfo)
|
||||
{
|
||||
renderer = new SceneRenderPath(graphics);
|
||||
renderer = new ForwardPlusRenderPath(graphics, viewport);
|
||||
}
|
||||
|
||||
Seele::SceneView::~SceneView()
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Seele
|
||||
class SceneView : public View
|
||||
{
|
||||
public:
|
||||
SceneView(Gfx::PGraphics graphics);
|
||||
SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo& createInfo);
|
||||
~SceneView();
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -1,8 +1,11 @@
|
||||
#include "View.h"
|
||||
#include "Window.h"
|
||||
|
||||
Seele::View::View(Gfx::PGraphics graphics)
|
||||
Seele::View::View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& viewportInfo)
|
||||
: graphics(graphics)
|
||||
, owner(owner)
|
||||
{
|
||||
viewport = graphics->createViewport(owner->getGfxHandle(), viewportInfo);
|
||||
}
|
||||
|
||||
Seele::View::~View()
|
||||
@@ -14,6 +17,11 @@ void Seele::View::beginFrame()
|
||||
renderer->beginFrame();
|
||||
}
|
||||
|
||||
void Seele::View::render()
|
||||
{
|
||||
renderer->render();
|
||||
}
|
||||
|
||||
void Seele::View::endFrame()
|
||||
{
|
||||
renderer->endFrame();
|
||||
|
||||
@@ -2,18 +2,22 @@
|
||||
#include "RenderPath.h"
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(Window);
|
||||
// A view is a part of the window, which can be anything from a viewport to an editor
|
||||
class View
|
||||
{
|
||||
public:
|
||||
View(Gfx::PGraphics graphics);
|
||||
View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo);
|
||||
virtual ~View();
|
||||
void beginFrame();
|
||||
void render();
|
||||
void endFrame();
|
||||
void applyArea(Rect area);
|
||||
|
||||
protected:
|
||||
Gfx::PGraphics graphics;
|
||||
Gfx::PViewport viewport;
|
||||
PWindow owner;
|
||||
PRenderPath renderer;
|
||||
};
|
||||
|
||||
|
||||
@@ -332,7 +332,8 @@ class Viewport : public Gfx::Viewport
|
||||
public:
|
||||
Viewport(PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo);
|
||||
virtual ~Viewport();
|
||||
|
||||
virtual void resize(uint32 newX, uint32 newY);
|
||||
virtual void move(uint32 newOffsetX, uint32 newOffsetY);
|
||||
protected:
|
||||
private:
|
||||
PGraphics graphics;
|
||||
|
||||
@@ -241,3 +241,15 @@ Viewport::Viewport(PGraphics graphics, PWindow owner, const ViewportCreateInfo &
|
||||
Viewport::~Viewport()
|
||||
{
|
||||
}
|
||||
|
||||
void Viewport::resize(uint32 newX, uint32 newY)
|
||||
{
|
||||
sizeX = newX;
|
||||
sizeY = newY;
|
||||
}
|
||||
|
||||
void Viewport::move(uint32 newOffsetX, uint32 newOffsetY)
|
||||
{
|
||||
offsetX = newOffsetX;
|
||||
offsetY = newOffsetY;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#include "Window.h"
|
||||
|
||||
Seele::Window::Window(Gfx::PWindow handle)
|
||||
: gfxHandle(handle)
|
||||
{
|
||||
}
|
||||
|
||||
Seele::Window::~Window()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Seele::Window::addView(PView view)
|
||||
{
|
||||
viewports.add(view);
|
||||
}
|
||||
|
||||
void Seele::Window::beginFrame()
|
||||
{
|
||||
gfxHandle->beginFrame();
|
||||
for(auto view : viewports)
|
||||
{
|
||||
view->beginFrame();
|
||||
}
|
||||
}
|
||||
|
||||
void Seele::Window::render()
|
||||
{
|
||||
for(auto view : viewports)
|
||||
{
|
||||
view->render();
|
||||
}
|
||||
}
|
||||
|
||||
void Seele::Window::endFrame()
|
||||
{
|
||||
gfxHandle->endFrame();
|
||||
for(auto view : viewports)
|
||||
{
|
||||
view->endFrame();
|
||||
}
|
||||
}
|
||||
|
||||
Gfx::PWindow Seele::Window::getGfxHandle()
|
||||
{
|
||||
return gfxHandle;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include "GraphicsResources.h"
|
||||
#include "View.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
// The logical window, with the graphics proxy
|
||||
class Window
|
||||
{
|
||||
public:
|
||||
Window(Gfx::PWindow handle);
|
||||
~Window();
|
||||
void addView(PView view);
|
||||
void beginFrame();
|
||||
void render();
|
||||
void endFrame();
|
||||
Gfx::PWindow getGfxHandle();
|
||||
private:
|
||||
Array<PView> viewports;
|
||||
Gfx::PWindow gfxHandle;
|
||||
};
|
||||
DEFINE_REF(Window);
|
||||
}
|
||||
@@ -2,4 +2,6 @@ target_sources(SeeleEngine
|
||||
PRIVATE
|
||||
Math.h
|
||||
Matrix.h
|
||||
Vector.h)
|
||||
Vector.h
|
||||
Transform.h
|
||||
Transform.cpp)
|
||||
@@ -26,7 +26,7 @@ struct Rect
|
||||
};
|
||||
struct Rect3D
|
||||
{
|
||||
Vector3 size;
|
||||
Vector3 offset;
|
||||
Vector size;
|
||||
Vector offset;
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -0,0 +1,84 @@
|
||||
#include "Transform.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
Transform::Transform()
|
||||
: position(Vector4(0, 0, 0, 0)), rotation(Quaternion(0, 0, 0, 0)), scale(Vector4(1, 1, 1, 0))
|
||||
{
|
||||
}
|
||||
|
||||
Transform::Transform(Vector position)
|
||||
: position(Vector4(position, 0)), rotation(Quaternion(0, 0, 0, 0)), scale(Vector4(1, 1, 1, 0))
|
||||
{
|
||||
}
|
||||
Transform::Transform(Vector position, Quaternion rotation)
|
||||
: position(Vector4(position, 0)), rotation(rotation), scale(Vector4(1, 1, 1, 0))
|
||||
{
|
||||
}
|
||||
Transform::Transform(Vector position, Quaternion rotation, Vector scale)
|
||||
: position(Vector4(position, 0)), rotation(rotation), scale(Vector4(scale, 0))
|
||||
{
|
||||
}
|
||||
Transform::Transform(Quaternion rotation, Vector scale)
|
||||
: position(Vector4(0, 0, 0, 0)), rotation(rotation), scale(Vector4(scale, 0))
|
||||
{
|
||||
}
|
||||
Transform::~Transform()
|
||||
{
|
||||
}
|
||||
Vector Transform::inverseTransformPosition(const Vector& v) const
|
||||
{
|
||||
return (unrotateVector(rotation, v - Vector(position))) * getSafeScaleReciprocal(scale);
|
||||
}
|
||||
|
||||
Vector Transform::getSafeScaleReciprocal(const Vector4& inScale, float tolerance)
|
||||
{
|
||||
Vector safeReciprocalScale;
|
||||
if (abs(inScale.x) <= tolerance)
|
||||
{
|
||||
safeReciprocalScale.x = 0.f;
|
||||
}
|
||||
else
|
||||
{
|
||||
safeReciprocalScale.x = 1 / inScale.x;
|
||||
}
|
||||
if (abs(inScale.y) <= tolerance)
|
||||
{
|
||||
safeReciprocalScale.y = 0.f;
|
||||
}
|
||||
else
|
||||
{
|
||||
safeReciprocalScale.y = 1 / inScale.y;
|
||||
}
|
||||
if (abs(inScale.z) <= tolerance)
|
||||
{
|
||||
safeReciprocalScale.z = 0.f;
|
||||
}
|
||||
else
|
||||
{
|
||||
safeReciprocalScale.z = 1 / inScale.z;
|
||||
}
|
||||
return safeReciprocalScale;
|
||||
}
|
||||
|
||||
inline Vector Transform::getPosition() const
|
||||
{
|
||||
return Vector(position);
|
||||
}
|
||||
|
||||
inline Quaternion Transform::getRotation() const
|
||||
{
|
||||
return rotation;
|
||||
}
|
||||
|
||||
inline Vector Transform::getScale() const
|
||||
{
|
||||
return Vector(scale);
|
||||
}
|
||||
|
||||
inline void Transform::multiply(Transform* outTransform, const Transform* a, const Transform* b)
|
||||
{
|
||||
outTransform->rotation = b->rotation * a->rotation;
|
||||
outTransform->position = b->position * (b->scale * a->position) + b->position;
|
||||
outTransform->scale = b->scale * a->scale;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
#include "Vector.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class Transform
|
||||
{
|
||||
public:
|
||||
Transform();
|
||||
Transform(Vector position);
|
||||
Transform(Vector position, Quaternion rotation);
|
||||
Transform(Vector position, Quaternion rotation, Vector scale);
|
||||
Transform(Quaternion rotation, Vector scale);
|
||||
~Transform();
|
||||
Vector inverseTransformPosition(const Vector &v) const;
|
||||
static Vector getSafeScaleReciprocal(const Vector4 &inScale, float tolerance = 0.00001f);
|
||||
|
||||
inline Vector getPosition() const;
|
||||
inline Quaternion getRotation() const;
|
||||
inline Vector getScale() const;
|
||||
|
||||
inline static void multiply(Transform* outTransform, const Transform* a, const Transform* b);
|
||||
|
||||
Transform& operator*(const Transform& other) const
|
||||
{
|
||||
Transform outTransform;
|
||||
multiply(&outTransform, this, &other);
|
||||
return outTransform;
|
||||
}
|
||||
|
||||
private:
|
||||
Vector4 position;
|
||||
Quaternion rotation;
|
||||
Vector4 scale;
|
||||
};
|
||||
} // namespace Seele
|
||||
@@ -2,10 +2,11 @@
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
namespace Seele
|
||||
{
|
||||
typedef glm::vec2 Vector2;
|
||||
typedef glm::vec3 Vector3;
|
||||
typedef glm::vec3 Vector;
|
||||
typedef glm::vec4 Vector4;
|
||||
|
||||
typedef glm::uvec2 UVector2;
|
||||
@@ -15,4 +16,101 @@ typedef glm::uvec4 UVector4;
|
||||
typedef glm::ivec2 IVector2;
|
||||
typedef glm::ivec3 IVector3;
|
||||
typedef glm::ivec4 IVector4;
|
||||
|
||||
typedef glm::quat Quaternion;
|
||||
|
||||
static inline float square(float x)
|
||||
{
|
||||
return x * x;
|
||||
}
|
||||
|
||||
static inline Vector unrotateVector(Quaternion quaternion, Vector v)
|
||||
{
|
||||
const Vector q(-quaternion.x, -quaternion.y, -quaternion.z);
|
||||
const Vector t = 2.f * glm::cross(q, v);
|
||||
const Vector result = v + (quaternion.w * t) + glm::cross(q, t);
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline bool equalsQuaternion(const Quaternion& right, const Quaternion& left, float tolerance)
|
||||
{
|
||||
return (abs(right.x - left.x) <= tolerance && abs(right.y - left.y) <= tolerance && abs(right.z - left.z) <= tolerance && abs(right.w - left.w) <= tolerance)
|
||||
|| (abs(right.x + left.x) <= tolerance && abs(right.y + left.y) <= tolerance && abs(right.z + left.z) <= tolerance && abs(right.w + left.w) <= tolerance);
|
||||
}
|
||||
|
||||
static inline float clampRotatorAxis(float angle)
|
||||
{
|
||||
angle = fmod(angle, 360.f);
|
||||
if (angle < 0.f)
|
||||
{
|
||||
angle += 360.f;
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
static inline float normalizeRotatorAxis(float angle)
|
||||
{
|
||||
angle = clampRotatorAxis(angle);
|
||||
|
||||
if (angle > 180.f)
|
||||
{
|
||||
angle -= 360.f;
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
|
||||
static inline Quaternion toQuaternion(const Vector& other)
|
||||
{
|
||||
Quaternion result;
|
||||
const float DEG_TO_RAD = glm::pi<float>() / (180.f);
|
||||
const float RADS_DIVIDED_BY_2 = DEG_TO_RAD / 2.f;
|
||||
|
||||
const float PitchNoWinding = fmod(other.x, 360.0f);
|
||||
const float YawNoWinding = fmod(other.y, 360.0f);
|
||||
const float RollNoWinding = fmod(other.z, 360.0f);
|
||||
|
||||
const float SP = sin(PitchNoWinding * RADS_DIVIDED_BY_2);
|
||||
const float SY = sin(YawNoWinding * RADS_DIVIDED_BY_2);
|
||||
const float SR = sin(RollNoWinding * RADS_DIVIDED_BY_2);
|
||||
|
||||
const float CP = cos(PitchNoWinding * RADS_DIVIDED_BY_2);
|
||||
const float CY = cos(YawNoWinding * RADS_DIVIDED_BY_2);
|
||||
const float CR = cos(RollNoWinding * RADS_DIVIDED_BY_2);
|
||||
|
||||
result.x = CR * SP * SY - SR * CP * CY;
|
||||
result.y = -CR * SP * CY - SR * CP * SY;
|
||||
result.z = CR * CP * SY - SR * SP * CY;
|
||||
result.w = CR * CP * CY + SR * SP * SY;
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline Vector toRotator(const Quaternion& other)
|
||||
{
|
||||
const float singularityTest = other.z * other.x - other.w * other.y;
|
||||
const float yawY = 2.f * (other.w * other.z + other.x * other.y);
|
||||
const float yawX = (1.f - 2.f * (square(other.y) + square(other.z)));
|
||||
|
||||
const float SINGULARITY_THRESHOLD = 0.4999995f;
|
||||
const float RAD_TO_DEG = (180.f) / glm::pi<float>();
|
||||
Vector rotatorFromQuat;
|
||||
|
||||
if (singularityTest < -SINGULARITY_THRESHOLD)
|
||||
{
|
||||
rotatorFromQuat.x = -90.f;
|
||||
rotatorFromQuat.y = atan2(yawY, yawX) * RAD_TO_DEG;
|
||||
rotatorFromQuat.z = normalizeRotatorAxis(-rotatorFromQuat.y - (2.f * atan2(other.x, other.w) * RAD_TO_DEG));
|
||||
}
|
||||
else if (singularityTest > SINGULARITY_THRESHOLD)
|
||||
{
|
||||
rotatorFromQuat.x = 90.f;
|
||||
rotatorFromQuat.y = atan2(yawY, yawX) * RAD_TO_DEG;
|
||||
rotatorFromQuat.z = normalizeRotatorAxis(rotatorFromQuat.y - (2.f * atan2(other.x, other.w) * RAD_TO_DEG));
|
||||
}
|
||||
else
|
||||
{
|
||||
rotatorFromQuat.x = asin(2.f * (singularityTest)) * RAD_TO_DEG;
|
||||
rotatorFromQuat.y = atan2(yawY, yawX) * RAD_TO_DEG;
|
||||
rotatorFromQuat.z = atan2(-2.f * (other.w * other.x + other.y * other.z), (1.f - 2.f * (square(other.x) + square(other.y)))) * RAD_TO_DEG;
|
||||
}
|
||||
return rotatorFromQuat;
|
||||
}
|
||||
} // namespace Seele
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
target_sources(SeeleEngine
|
||||
PRIVATE
|
||||
Actor.cpp
|
||||
Actor.h)
|
||||
@@ -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)
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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:
|
||||
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "MinimalEngine.h"
|
||||
#include "Actor/Actor.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class Scene
|
||||
{
|
||||
public:
|
||||
Scene();
|
||||
~Scene();
|
||||
private:
|
||||
Array<PActor> rootActors;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user