Loading...
Searching...
No Matches
CameraFactory.cpp
Go to the documentation of this file.
2#include "hellfire/scene/Scene.h"
3#include "hellfire/ecs/CameraComponent.h"
4#include "hellfire/ecs/TransformComponent.h"
5
6namespace hellfire {
7 EntityID PerspectiveCamera::create(Scene* scene, const std::string& name,
8 float fov, float aspect, float near_plane,
9 float far_plane, const glm::vec3& position) {
10 EntityID id = scene->create_entity(name);
11 Entity* entity = scene->get_entity(id);
12
13 auto* camera = entity->add_component<CameraComponent>(CameraType::PERSPECTIVE);
14 camera->set_perspective(fov, aspect, near_plane, far_plane);
15
16 entity->transform()->set_position(position.x, position.y, position.z);
17
18 return id;
19 }
20
21 EntityID PerspectiveCamera::create_looking_at(Scene* scene, const std::string& name,
22 const glm::vec3& position,
23 const glm::vec3& target,
24 float fov, float aspect,
25 float near_plane, float far_plane) {
26 EntityID id = create(scene, name, fov, aspect, near_plane, far_plane, position);
27 Entity* entity = scene->get_entity(id);
28 entity->get_component<CameraComponent>()->look_at(target);
29 return id;
30 }
31
32 EntityID OrthographicCamera::create(Scene* scene, const std::string& name,
33 float size, float aspect, float near_plane,
34 float far_plane, const glm::vec3& position) {
35 EntityID id = scene->create_entity(name);
36 Entity* entity = scene->get_entity(id);
37
38 auto* camera = entity->add_component<CameraComponent>(CameraType::ORTHOGRAPHIC);
39
40 float half_width = size * aspect * 0.5f;
41 float half_height = size * 0.5f;
42 camera->set_orthographic(-half_width, half_width, -half_height, half_height, near_plane, far_plane);
43
44 entity->transform()->set_position(position.x, position.y, position.z);
45
46 return id;
47 }
48
49 EntityID OrthographicCamera::create_with_bounds(Scene* scene, const std::string& name,
50 float left, float right, float bottom,
51 float top, float near_plane, float far_plane,
52 const glm::vec3& position) {
53 EntityID id = scene->create_entity(name);
54 Entity* entity = scene->get_entity(id);
55
56 auto* camera = entity->add_component<CameraComponent>(CameraType::ORTHOGRAPHIC);
57 camera->set_orthographic(left, right, bottom, top, near_plane, far_plane);
58
59 entity->transform()->set_position(position.x, position.y, position.z);
60
61 return id;
62 }
63}
TransformComponent * transform()
Definition Entity.cpp:42
Manages a collection of entities and their hierarchical relationships.
Definition Scene.h:24
Entity * get_entity(EntityID id)
Retrieves an entity by its ID.
Definition Scene.cpp:81
EntityID create_entity(const std::string &name="GameObject")
Creates a new entity in the scene.
Definition Scene.cpp:29
void set_position(float x, float y, float z)