diff --git a/src/3DEngine.h b/src/3DEngine.h index 513baea..a29f652 100644 --- a/src/3DEngine.h +++ b/src/3DEngine.h @@ -24,7 +24,7 @@ #include "transform.h" #include "camera.h" #include "lighting.h" -#include "gameObject.h" +#include "entity.h" #include "meshRenderer.h" #include "window.h" #include "coreEngine.h" diff --git a/src/camera.cpp b/src/camera.cpp index 32d4e13..d28be30 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -39,9 +39,9 @@ void CameraComponent::AddToEngine(CoreEngine* engine) const engine->GetRenderingEngine()->SetMainCamera(m_camera); } -void CameraComponent::SetParent(GameObject* parent) +void CameraComponent::SetParent(Entity* parent) { - GameComponent::SetParent(parent); + EntityComponent::SetParent(parent); //The camera's transform is initialized here because this is the first point where //there is a parent object with a transform. diff --git a/src/camera.h b/src/camera.h index 5c9ad84..9804a51 100644 --- a/src/camera.h +++ b/src/camera.h @@ -18,7 +18,7 @@ #define CAMERA_H #include "math3d.h" -#include "gameComponent.h" +#include "entityComponent.h" //Cameras represent a location, orientation, and projection from //which the scene can be rendered. @@ -50,7 +50,7 @@ class Camera //CameraComponents are an easy way to use a camera as a component //on a game object. -class CameraComponent : public GameComponent +class CameraComponent : public EntityComponent { public: //The camera's transform is initialized to 0 (null) because @@ -64,7 +64,7 @@ class CameraComponent : public GameComponent inline Matrix4f GetViewProjection() const { return m_camera.GetViewProjection(); } inline void SetProjection(const Matrix4f& projection) { m_camera.SetProjection(projection); } - virtual void SetParent(GameObject* parent); + virtual void SetParent(Entity* parent); protected: private: Camera m_camera; //The camera that's being used like a component. diff --git a/src/gameObject.h b/src/entity.h similarity index 68% rename from src/gameObject.h rename to src/entity.h index 4cd78b1..e857a35 100644 --- a/src/gameObject.h +++ b/src/entity.h @@ -14,51 +14,51 @@ * limitations under the License. */ -#ifndef GAMEOBJECT_H -#define GAMEOBJECT_H +#ifndef ENTITYOBJECT_H +#define ENTITYOBJECT_H #include #include "transform.h" #include "input.h" class Camera; class CoreEngine; -class GameComponent; +class EntityComponent; class Shader; class RenderingEngine; -class GameObject +class Entity { public: - GameObject(const Vector3f& pos = Vector3f(0,0,0), const Quaternion& rot = Quaternion(0,0,0,1), float scale = 1.0f) : + Entity(const Vector3f& pos = Vector3f(0,0,0), const Quaternion& rot = Quaternion(0,0,0,1), float scale = 1.0f) : m_transform(pos, rot, scale), m_coreEngine(0) {} - virtual ~GameObject(); + virtual ~Entity(); - GameObject* AddChild(GameObject* child); - GameObject* AddComponent(GameComponent* component); + Entity* AddChild(Entity* child); + Entity* AddComponent(EntityComponent* component); void ProcessInputAll(const Input& input, float delta); void UpdateAll(float delta); void RenderAll(const Shader& shader, const RenderingEngine& renderingEngine, const Camera& camera) const; - std::vector GetAllAttached(); + std::vector GetAllAttached(); inline Transform* GetTransform() { return &m_transform; } void SetEngine(CoreEngine* engine); protected: private: - std::vector m_children; - std::vector m_components; - Transform m_transform; - CoreEngine* m_coreEngine; + std::vector m_children; + std::vector m_components; + Transform m_transform; + CoreEngine* m_coreEngine; void ProcessInput(const Input& input, float delta); void Update(float delta); void Render(const Shader& shader, const RenderingEngine& renderingEngine, const Camera& camera) const; - GameObject(const GameObject& other) {} - void operator=(const GameObject& other) {} + Entity(const Entity& other) {} + void operator=(const Entity& other) {} }; #endif // GAMEOBJECT_H diff --git a/src/gameComponent.h b/src/entityComponent.h similarity index 77% rename from src/gameComponent.h rename to src/entityComponent.h index 52d4516..6f195f7 100644 --- a/src/gameComponent.h +++ b/src/entityComponent.h @@ -14,21 +14,21 @@ * limitations under the License. */ -#ifndef GAMECOMPONENT_H_INCLUDED -#define GAMECOMPONENT_H_INCLUDED +#ifndef ENTITYCOMPONENT_H_INCLUDED +#define ENTITYCOMPONENT_H_INCLUDED #include "transform.h" -#include "gameObject.h" +#include "entity.h" #include "input.h" class RenderingEngine; class Shader; -class GameComponent +class EntityComponent { public: - GameComponent() : + EntityComponent() : m_parent(0) {} - virtual ~GameComponent() {} + virtual ~EntityComponent() {} virtual void ProcessInput(const Input& input, float delta) {} virtual void Update(float delta) {} @@ -39,12 +39,12 @@ class GameComponent inline Transform* GetTransform() { return m_parent->GetTransform(); } inline const Transform& GetTransform() const { return *m_parent->GetTransform(); } - virtual void SetParent(GameObject* parent) { m_parent = parent; } + virtual void SetParent(Entity* parent) { m_parent = parent; } private: - GameObject* m_parent; + Entity* m_parent; - GameComponent(const GameComponent& other) {} - void operator=(const GameComponent& other) {} + EntityComponent(const EntityComponent& other) {} + void operator=(const EntityComponent& other) {} }; #endif // GAMECOMPONENT_H_INCLUDED diff --git a/src/freeLook.h b/src/freeLook.h index 7d1db27..8e674a2 100644 --- a/src/freeLook.h +++ b/src/freeLook.h @@ -18,9 +18,9 @@ #define FREELOOK_H #include "math3d.h" -#include "gameComponent.h" +#include "entityComponent.h" -class FreeLook : public GameComponent +class FreeLook : public EntityComponent { public: FreeLook(const Vector2f& windowCenter, float sensitivity = 0.5f, int unlockMouseKey = Input::KEY_ESCAPE) : diff --git a/src/freeMove.h b/src/freeMove.h index c9f12dd..b6e022c 100644 --- a/src/freeMove.h +++ b/src/freeMove.h @@ -18,9 +18,9 @@ #define FREEMOVE_H #include "math3d.h" -#include "gameComponent.h" +#include "entityComponent.h" -class FreeMove : public GameComponent +class FreeMove : public EntityComponent { public: FreeMove(float speed = 10.0f, int forwardKey = Input::KEY_W, int backKey = Input::KEY_S, int leftKey = Input::KEY_A, int rightKey = Input::KEY_D) : diff --git a/src/game.h b/src/game.h index f549916..aa84731 100644 --- a/src/game.h +++ b/src/game.h @@ -17,7 +17,7 @@ #ifndef MYGAME_H #define MYGAME_H -#include "gameObject.h" +#include "entity.h" #include "coreEngine.h" #include "profiling.h" @@ -37,14 +37,14 @@ class Game inline void SetEngine(CoreEngine* engine) { m_root.SetEngine(engine); } protected: - void AddToScene(GameObject* child) { m_root.AddChild(child); } + void AddToScene(Entity* child) { m_root.AddChild(child); } private: Game(Game& game) {} void operator=(Game& game) {} ProfileTimer m_updateTimer; ProfileTimer m_inputTimer; - GameObject m_root; + Entity m_root; }; #endif diff --git a/src/gameObject.cpp b/src/gameObject.cpp index 13b8d76..02903b4 100644 --- a/src/gameObject.cpp +++ b/src/gameObject.cpp @@ -14,11 +14,11 @@ * limitations under the License. */ -#include "gameObject.h" -#include "gameComponent.h" +#include "entity.h" +#include "entityComponent.h" #include "coreEngine.h" -GameObject::~GameObject() +Entity::~Entity() { for(unsigned int i = 0; i < m_components.size(); i++) { @@ -37,7 +37,7 @@ GameObject::~GameObject() } } -GameObject* GameObject::AddChild(GameObject* child) +Entity* Entity::AddChild(Entity* child) { m_children.push_back(child); child->GetTransform()->SetParent(&m_transform); @@ -45,14 +45,14 @@ GameObject* GameObject::AddChild(GameObject* child) return this; } -GameObject* GameObject::AddComponent(GameComponent* component) +Entity* Entity::AddComponent(EntityComponent* component) { m_components.push_back(component); component->SetParent(this); return this; } -void GameObject::ProcessInputAll(const Input& input, float delta) +void Entity::ProcessInputAll(const Input& input, float delta) { ProcessInput(input, delta); @@ -62,7 +62,7 @@ void GameObject::ProcessInputAll(const Input& input, float delta) } } -void GameObject::UpdateAll(float delta) +void Entity::UpdateAll(float delta) { Update(delta); @@ -72,7 +72,7 @@ void GameObject::UpdateAll(float delta) } } -void GameObject::RenderAll(const Shader& shader, const RenderingEngine& renderingEngine, const Camera& camera) const +void Entity::RenderAll(const Shader& shader, const RenderingEngine& renderingEngine, const Camera& camera) const { Render(shader, renderingEngine, camera); @@ -82,7 +82,7 @@ void GameObject::RenderAll(const Shader& shader, const RenderingEngine& renderin } } -void GameObject::ProcessInput(const Input& input, float delta) +void Entity::ProcessInput(const Input& input, float delta) { m_transform.Update(); @@ -92,7 +92,7 @@ void GameObject::ProcessInput(const Input& input, float delta) } } -void GameObject::Update(float delta) +void Entity::Update(float delta) { for(unsigned int i = 0; i < m_components.size(); i++) { @@ -100,7 +100,7 @@ void GameObject::Update(float delta) } } -void GameObject::Render(const Shader& shader, const RenderingEngine& renderingEngine, const Camera& camera) const +void Entity::Render(const Shader& shader, const RenderingEngine& renderingEngine, const Camera& camera) const { for(unsigned int i = 0; i < m_components.size(); i++) { @@ -108,7 +108,7 @@ void GameObject::Render(const Shader& shader, const RenderingEngine& renderingEn } } -void GameObject::SetEngine(CoreEngine* engine) +void Entity::SetEngine(CoreEngine* engine) { if(m_coreEngine != engine) { @@ -126,13 +126,13 @@ void GameObject::SetEngine(CoreEngine* engine) } } -std::vector GameObject::GetAllAttached() +std::vector Entity::GetAllAttached() { - std::vector result; + std::vector result; for(unsigned int i = 0; i < m_children.size(); i++) { - std::vector childObjects = m_children[i]->GetAllAttached(); + std::vector childObjects = m_children[i]->GetAllAttached(); result.insert(result.end(), childObjects.begin(), childObjects.end()); } diff --git a/src/lighting.h b/src/lighting.h index 4432c42..c24ba4d 100644 --- a/src/lighting.h +++ b/src/lighting.h @@ -18,7 +18,7 @@ #define LIGHTING_H #include "math3d.h" -#include "gameComponent.h" +#include "entityComponent.h" #include "shader.h" class CoreEngine; @@ -64,7 +64,7 @@ class ShadowInfo float m_minVariance; }; -class BaseLight : public GameComponent +class BaseLight : public EntityComponent { public: BaseLight(const Vector3f& color, float intensity, const Shader& shader) : diff --git a/src/main.cpp b/src/main.cpp index 21a810e..98fda1b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,31 +48,31 @@ void TestGame::Init(const Window& window) } Mesh customMesh("square", square.Finalize()); - AddToScene((new GameObject(Vector3f(0, -1, 5), Quaternion(), 32.0f)) + AddToScene((new Entity(Vector3f(0, -1, 5), Quaternion(), 32.0f)) ->AddComponent(new MeshRenderer(Mesh("terrain02.obj"), Material("bricks")))); - AddToScene((new GameObject(Vector3f(7,0,7))) + AddToScene((new Entity(Vector3f(7,0,7))) ->AddComponent(new PointLight(Vector3f(0,1,0), 0.4f, Attenuation(0,0,1)))); - AddToScene((new GameObject(Vector3f(20,-11.0f,5), Quaternion(Vector3f(1,0,0), ToRadians(-60.0f)) * Quaternion(Vector3f(0,1,0), ToRadians(90.0f)))) + AddToScene((new Entity(Vector3f(20,-11.0f,5), Quaternion(Vector3f(1,0,0), ToRadians(-60.0f)) * Quaternion(Vector3f(0,1,0), ToRadians(90.0f)))) ->AddComponent(new SpotLight(Vector3f(0,1,1), 0.4f, Attenuation(0,0,0.02f), ToRadians(91.1f), 7, 1.0f, 0.5f))); - AddToScene((new GameObject(Vector3f(), Quaternion(Vector3f(1,0,0), ToRadians(-45)))) + AddToScene((new Entity(Vector3f(), Quaternion(Vector3f(1,0,0), ToRadians(-45)))) ->AddComponent(new DirectionalLight(Vector3f(1,1,1), 0.4f, 10, 80.0f, 1.0f))); - AddToScene((new GameObject(Vector3f(0, 2, 0), Quaternion(Vector3f(0,1,0), 0.4f), 1.0f)) + AddToScene((new Entity(Vector3f(0, 2, 0), Quaternion(Vector3f(0,1,0), 0.4f), 1.0f)) ->AddComponent(new MeshRenderer(Mesh("plane3.obj"), Material("bricks2"))) - ->AddChild((new GameObject(Vector3f(0, 0, 25))) + ->AddChild((new Entity(Vector3f(0, 0, 25))) ->AddComponent(new MeshRenderer(Mesh("plane3.obj"), Material("bricks2"))) - ->AddChild((new GameObject()) + ->AddChild((new Entity()) ->AddComponent(new CameraComponent(Matrix4f().InitPerspective(ToRadians(70.0f), window.GetAspect(), 0.1f, 1000.0f))) ->AddComponent(new FreeLook(window.GetCenter())) ->AddComponent(new FreeMove(10.0f))))); - AddToScene((new GameObject(Vector3f(24,-12,5), Quaternion(Vector3f(0,1,0), ToRadians(30.0f)))) + AddToScene((new Entity(Vector3f(24,-12,5), Quaternion(Vector3f(0,1,0), ToRadians(30.0f)))) ->AddComponent(new MeshRenderer(Mesh("cube.obj"), Material("bricks2")))); - AddToScene((new GameObject(Vector3f(0,0,7), Quaternion(), 1.0f)) + AddToScene((new Entity(Vector3f(0,0,7), Quaternion(), 1.0f)) ->AddComponent(new MeshRenderer(Mesh("square"), Material("bricks2")))); } diff --git a/src/meshRenderer.h b/src/meshRenderer.h index 1e17b41..9931561 100644 --- a/src/meshRenderer.h +++ b/src/meshRenderer.h @@ -17,10 +17,10 @@ #ifndef MESHRENDERER_H_INCLUDED #define MESHRENDERER_H_INCLUDED -#include "gameComponent.h" +#include "entityComponent.h" #include "mesh.h" -class MeshRenderer : public GameComponent +class MeshRenderer : public EntityComponent { public: MeshRenderer(const Mesh& mesh, const Material& material) : diff --git a/src/renderingEngine.cpp b/src/renderingEngine.cpp index a51602a..04bf419 100644 --- a/src/renderingEngine.cpp +++ b/src/renderingEngine.cpp @@ -16,7 +16,7 @@ #include "renderingEngine.h" #include "window.h" -#include "gameObject.h" +#include "entity.h" #include "shader.h" #include #include "mesh.h" @@ -133,7 +133,7 @@ void RenderingEngine::ApplyFilter(const Shader& filter, const Texture& source, c SetTexture("filterTexture", 0); } -void RenderingEngine::Render(const GameObject& object) +void RenderingEngine::Render(const Entity& object) { m_renderProfileTimer.StartInvocation(); GetTexture("displayTexture").BindAsRenderTarget(); diff --git a/src/renderingEngine.h b/src/renderingEngine.h index 33c476a..51988ac 100644 --- a/src/renderingEngine.h +++ b/src/renderingEngine.h @@ -26,7 +26,7 @@ #include "profiling.h" #include #include -class GameObject; +class Entity; class RenderingEngine : public MappedValues { @@ -34,7 +34,7 @@ class RenderingEngine : public MappedValues RenderingEngine(const Window& window); virtual ~RenderingEngine() {} - void Render(const GameObject& object); + void Render(const Entity& object); inline void AddLight(const BaseLight& light) { m_lights.push_back(&light); } inline void SetMainCamera(const Camera& camera) { m_mainCamera = &camera; }