Viewport controls
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#include "Actor.h"
|
||||
#include "Scene/Scene.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
Actor::Actor(PScene scene)
|
||||
: Entity(scene)
|
||||
{
|
||||
scene->attachComponent<Component::Transform>(identifier);
|
||||
}
|
||||
|
||||
Actor::~Actor()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Actor::setParent(PActor newParent)
|
||||
{
|
||||
if(parent != nullptr)
|
||||
{
|
||||
parent->removeChild(this);
|
||||
}
|
||||
parent = newParent;
|
||||
}
|
||||
void Actor::addChild(PActor child)
|
||||
{
|
||||
children.add(child);
|
||||
child->setParent(this);
|
||||
}
|
||||
void Actor::removeChild(PActor child)
|
||||
{
|
||||
children.remove(children.find(child), false);
|
||||
child->setParent(nullptr);
|
||||
}
|
||||
const Component::Transform& Actor::getTransform() const
|
||||
{
|
||||
return scene->accessComponent<Component::Transform>(identifier);
|
||||
}
|
||||
|
||||
//Component::Transform& Actor::getTransform()
|
||||
//{
|
||||
// return scene->accessComponent<Component::Transform>(identifier);
|
||||
//}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include "Entity.h"
|
||||
#include "Component/Transform.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
DECLARE_REF(Actor)
|
||||
// Actors are entities that are part of the scene hierarchy
|
||||
// In order for that hierarchy to make sense it requires at least a transform component
|
||||
class Actor : public Entity
|
||||
{
|
||||
public:
|
||||
Actor(PScene scene);
|
||||
virtual ~Actor();
|
||||
|
||||
PActor getParent();
|
||||
void addChild(PActor child);
|
||||
void removeChild(PActor child);
|
||||
Array<PActor> getChildren();
|
||||
|
||||
// Returns a read-only copy of the actors transform
|
||||
const Component::Transform& getTransform() const;
|
||||
|
||||
protected:
|
||||
//Component::Transform& getTransform();
|
||||
void setParent(PActor parent);
|
||||
PActor parent;
|
||||
Array<PActor> children;
|
||||
};
|
||||
DEFINE_REF(Actor)
|
||||
} // namespace Seele
|
||||
@@ -0,0 +1,8 @@
|
||||
target_sources(Engine
|
||||
PRIVATE
|
||||
Actor.cpp
|
||||
Actor.h
|
||||
CameraActor.cpp
|
||||
CameraActor.h
|
||||
Entity.cpp
|
||||
Entity.h)
|
||||
@@ -0,0 +1,25 @@
|
||||
#include "CameraActor.h"
|
||||
#include "Scene/Scene.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
CameraActor::CameraActor(PScene scene)
|
||||
: Actor(scene)
|
||||
{
|
||||
scene->attachComponent<Component::Camera>(identifier);
|
||||
scene->accessComponent<Component::Transform>(identifier).setRelativeLocation(Math::Vector(10, 5, 14));
|
||||
}
|
||||
|
||||
CameraActor::~CameraActor()
|
||||
{
|
||||
}
|
||||
|
||||
Component::Camera& CameraActor::getCameraComponent()
|
||||
{
|
||||
return scene->accessComponent<Component::Camera>(identifier);
|
||||
}
|
||||
|
||||
const Component::Camera& CameraActor::getCameraComponent() const
|
||||
{
|
||||
return scene->accessComponent<Component::Camera>(identifier);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "Actor.h"
|
||||
#include "Component/Camera.h"
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
class CameraActor : public Actor
|
||||
{
|
||||
public:
|
||||
CameraActor(PScene scene);
|
||||
virtual ~CameraActor();
|
||||
Component::Camera& getCameraComponent();
|
||||
const Component::Camera& getCameraComponent() const;
|
||||
private:
|
||||
};
|
||||
DEFINE_REF(CameraActor)
|
||||
} // namespace Seele
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "Entity.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
Entity::Entity(PScene scene)
|
||||
: identifier(scene->createEntity())
|
||||
, scene(scene)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Entity::~Entity()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include <entt/entt.hpp>
|
||||
#include "MinimalEngine.h"
|
||||
#include "Scene/Scene.h"
|
||||
namespace Seele
|
||||
{
|
||||
// An entity describes a part of a scene
|
||||
// It is just a wrapper the ID of a registry
|
||||
class Entity
|
||||
{
|
||||
public:
|
||||
Entity(PScene scene);
|
||||
virtual ~Entity();
|
||||
|
||||
template<typename Component, typename... Args>
|
||||
void attachComponent(Args... args)
|
||||
{
|
||||
scene->attachComponent<Component>(identifier, args...);
|
||||
}
|
||||
protected:
|
||||
PScene scene;
|
||||
entt::entity identifier;
|
||||
};
|
||||
DEFINE_REF(Entity)
|
||||
} // namespace Seele
|
||||
Reference in New Issue
Block a user