Loading...
Searching...
No Matches
Cameras.h
Go to the documentation of this file.
1#pragma once
2
3#include "hellfire/ecs/CameraComponent.h"
4
5namespace hellfire {
7 public:
8 static Entity* create(const std::string& name = "PerspectiveCamera",
9 float fov = 45.0f,
10 float aspect = 16.0f / 9.0f,
11 float near_plane = 0.1f,
12 float far_plane = 100.0f,
13 const glm::vec3& position = glm::vec3(0.0f, 0.0f, 0.0f)) {
14
15 Entity* entity = new Entity(name);
16 auto* camera = entity->add_component<CameraComponent>(CameraType::PERSPECTIVE);
17 camera->set_perspective(fov, aspect, near_plane, far_plane);
18
19 entity->transform()->set_position(position.x, position.y, position.z);
20
21 return entity;
22 }
23
24 // Convenience method to create camera looking at target
25 static Entity* create_looking_at(const std::string& name,
26 const glm::vec3& position,
27 const glm::vec3& target,
28 float fov = 45.0f,
29 float aspect = 16.0f / 9.0f,
30 float near_plane = 0.1f,
31 float far_plane = 100.0f) {
32 Entity* entity = create(name, fov, aspect, near_plane, far_plane, position);
33 entity->get_component<CameraComponent>()->look_at(target);
34 return entity;
35 }
36 };
37
38 class OrthographicCamera {
39 public:
40 static Entity* create(const std::string& name = "OrthographicCamera",
41 float size = 10.0f,
42 float aspect = 16.0f / 9.0f,
43 float near_plane = 0.1f,
44 float far_plane = 100.0f,
45 const glm::vec3& position = glm::vec3(0.0f, 0.0f, 0.0f)) {
46
47 Entity* entity = new Entity(name);
48 auto* camera = entity->add_component<CameraComponent>(CameraType::ORTHOGRAPHIC);
49
50 float half_width = size * aspect * 0.5f;
51 float half_height = size * 0.5f;
52 camera->set_orthographic(-half_width, half_width, -half_height, half_height, near_plane, far_plane);
53
54 entity->transform()->set_position(position.x, position.y, position.z);
55
56 return entity;
57 }
58
59 static Entity* create_with_bounds(const std::string& name,
60 float left, float right, float bottom, float top,
61 float near_plane = 0.1f, float far_plane = 100.0f,
62 const glm::vec3& position = glm::vec3(0.0f, 0.0f, 0.0f)) {
63 Entity* entity = new Entity(name);
64 auto* camera = entity->add_component<CameraComponent>(CameraType::ORTHOGRAPHIC);
65 camera->set_orthographic(left, right, bottom, top, near_plane, far_plane);
66
67 entity->transform()->set_position(position.x, position.y, position.z);
68
69 return entity;
70 }
71 };
72
73}
static Entity * create(const std::string &name="OrthographicCamera", float size=10.0f, float aspect=16.0f/9.0f, float near_plane=0.1f, float far_plane=100.0f, const glm::vec3 &position=glm::vec3(0.0f, 0.0f, 0.0f))
Definition Cameras.h:40
static Entity * create_with_bounds(const std::string &name, float left, float right, float bottom, float top, float near_plane=0.1f, float far_plane=100.0f, const glm::vec3 &position=glm::vec3(0.0f, 0.0f, 0.0f))
Definition Cameras.h:59
static Entity * create(const std::string &name="PerspectiveCamera", float fov=45.0f, float aspect=16.0f/9.0f, float near_plane=0.1f, float far_plane=100.0f, const glm::vec3 &position=glm::vec3(0.0f, 0.0f, 0.0f))
Definition Cameras.h:8
static Entity * create_looking_at(const std::string &name, const glm::vec3 &position, const glm::vec3 &target, float fov=45.0f, float aspect=16.0f/9.0f, float near_plane=0.1f, float far_plane=100.0f)
Definition Cameras.h:25