2 #ifndef KJY_ANIM_ENGINE_CAMERAS_HPP_ 3 #define KJY_ANIM_ENGINE_CAMERAS_HPP_ 5 #include "components/inheritable/camera.hpp" 6 #include "components/attachable/Pose.hpp" 7 #include "EntitiesBase.hpp" 8 #include "util/common.h" 10 #include <glm/gtc/matrix_transform.hpp> 13 #define ENABLE_WORLD_GLFW_UTILITIES 14 #ifdef ENABLE_WORLD_GLFW_UTILITIES 15 #define GLFW_INCLUDE_NONE 16 #include <GLFW/glfw3.h> 19 #pragma warning(disable: 4250) // Disable warnings about dominance in MSVC 24 BaseCameraEntity() : fov(45.0f), near_plane(.01f), far_plane(100.0f), pose(glm::vec3(0.0f)) {}
25 BaseCameraEntity(
float fov,
const glm::vec3 &loc) : fov(fov), near_plane(.01f), far_plane(100.0f), pose(loc){}
26 BaseCameraEntity(
float fov,
const glm::vec3 &loc,
float near_plane,
float far_plane) : fov(fov), near_plane(near_plane), far_plane(far_plane), pose(loc){}
28 virtual glm::vec3 getLocation()
const override{
29 return(pose.getCenterOfSpace());
32 virtual const Pose& getPose()
const override {
return(pose);}
34 virtual void setPose(
const Pose& pose)
override {this->pose = pose;}
36 virtual glm::mat4 getPerspective(
float aspect)
const override{
37 return(glm::perspective(glm::radians(fov), aspect, near_plane, far_plane));
40 virtual glm::mat4 getOrthographic()
const override{
41 return(glm::ortho(-1.0f, 1.0f, -1.0f, 1.0f, near_plane, far_plane));
44 glm::mat4 getOrthographic(
float left,
float right,
float bottom,
float top,
float near_plane,
float far_plane){
45 return(glm::ortho(left, right, bottom, top, near_plane, far_plane));
48 virtual glm::mat4 getView()
const override;
49 virtual glm::vec3 getViewDir()
const override;
50 virtual glm::vec3 getViewDir(
const Pose& aPoseOverride)
const override;
51 virtual glm::mat4 getView(
const Pose& aPoseOverride)
const override;
53 virtual void setNearPlane(
float near_plane){this->near_plane = near_plane;}
54 virtual void setFarPlane(
float far_plane){this->far_plane = far_plane;}
68 LookAtCamera(
float fov,
const glm::vec3 &loc,
float near_plane,
float far_plane,
const glm::vec3& lookat) :
BaseCameraEntity(fov, loc, near_plane, far_plane), lookat(lookat) {}
70 virtual glm::mat4 getView()
const override;
71 virtual glm::vec3 getViewDir()
const override;
74 glm::vec3 lookat = vec3(0.0);
75 glm::vec3 updir = vec3(0.0, 1.0, 0.0);
86 void updateLookWithMouse(
const glm::dvec2& mouse,
double width,
double height);
88 inline void resetFactors() {
89 forward_factor = right_strafe_factor = elevate_factor = 0.0;
92 double mouse_sensitivity = 1.0;
93 double forward_factor = 0.0;
94 double right_strafe_factor = 0.0;
95 double elevate_factor = 0.0;
96 glm::dvec2 look_factor = glm::dvec2(0.0,0.0);
99 glm::dvec2 lastmouse = glm::dvec2(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN());
102 virtual glm::mat4 getView()
const override;
103 virtual glm::vec3 getViewDir()
const override;
104 virtual glm::vec3 getViewDir(
const Pose& aPoseOverride)
const override;
105 virtual glm::mat4 getView(
const Pose& aPoseOverride)
const override;
107 virtual double getSpeed()
const {
return(speed);}
108 virtual double getBoostedSpeed()
const {
return(boosted_speed);}
109 virtual void setSpeed(
double speed) {this->speed = speed;}
110 virtual void setBoostedSpeed(
double speed) {boosted_speed = speed;}
114 #ifdef ENABLE_WORLD_GLFW_UTILITIES 115 virtual void collectAndDrive(GLFWwindow* window);
116 static void collect_camera_controls(GLFWwindow* window,
NavigationParameters& params,
double speed = 2.0,
double boosted_speed = 8.0,
double crawl_speed = 0.5);
120 double azimuth = 0.0;
123 double boosted_speed = 8.0;
124 double crawl_speed = 0.5;
125 glm::vec3 updir = vec3(0.0, 1.0, 0.0);
132 FollowCamera(
float fov, vec3 start_pos,
float linear_acceleration_factor = 3.0f,
float base_velocity_factor = .6f,
float follow_distance = 2.0f,
float distance_exponent = 2.0f)
133 :
BaseCameraEntity(fov, start_pos), linear_acceleration_factor(linear_acceleration_factor), base_velocity_factor(base_velocity_factor), follow_distance(follow_distance), distance_exponent(distance_exponent) {}
136 virtual void follow_explicit(
137 double frametime, vec3 target, vec3 offset, vec3 viewtarget,
138 float linear_acceleration_parameter,
float base_velocity_parameter,
139 float follow_distance_parameter,
float distance_exponent_parameter
141 virtual void follow(
double frametime, vec3 target, vec3 offset, vec3 viewtarget);
142 virtual void reset(
const vec3& start_pos);
143 virtual glm::mat4 getView()
const {
return(look);}
144 virtual vec3 getViewDir()
const{
return(vec3(look*vec4(0.0,0.0,1.0,1.0)));}
146 float getMaximumDistance()
const {
return(max_distance);}
147 void setMaximumDistance(
float max_distance) {this->max_distance = max_distance;}
148 float getAccelerationFactor() {
return(linear_acceleration_factor);}
149 void setAccelerationFactor(
float linear_acceleration_factor) {this->linear_acceleration_factor = linear_acceleration_factor;}
150 float getFollowLength() {
return(follow_distance);}
151 void setFollowLength(
float follow_distance) {follow_distance = follow_distance;}
154 vec3 velocity = vec3(0.0);
155 float linear_acceleration_factor = 3.0f;
156 float base_velocity_factor = .1f;
157 float follow_distance = 2.0f;
158 float distance_exponent = 2.5f;
159 float max_distance = 500.0f;
Definition: CameraEntities.hpp:78
Definition: CameraEntities.hpp:84
Definition: CameraEntities.hpp:21
Definition: EntitiesBase.hpp:82
Definition: EntitiesBase.hpp:59
Definition: CameraEntities.hpp:63
Definition: CameraEntities.hpp:129