diff options
| author | Joursoir <chat@joursoir.net> | 2021-04-11 13:06:28 +0000 | 
|---|---|---|
| committer | Joursoir <chat@joursoir.net> | 2021-04-11 13:06:28 +0000 | 
| commit | e7ba13097919d96ef1a2d1da9344e2ed4595b9cc (patch) | |
| tree | de760f5c6fe715758aad09612e8f6485603e9e79 | |
| parent | a8b3118e8305fd1c668ea25e07157b625c9747ff (diff) | |
| download | space-simulator-e7ba13097919d96ef1a2d1da9344e2ed4595b9cc.tar.gz space-simulator-e7ba13097919d96ef1a2d1da9344e2ed4595b9cc.tar.bz2 space-simulator-e7ba13097919d96ef1a2d1da9344e2ed4595b9cc.zip  | |
Camera: refactor, make it more universal
| -rw-r--r-- | src/graphics/Camera.cpp | 25 | ||||
| -rw-r--r-- | src/graphics/Camera.hpp | 23 | 
2 files changed, 26 insertions, 22 deletions
diff --git a/src/graphics/Camera.cpp b/src/graphics/Camera.cpp index 2058d5e..cf6b165 100644 --- a/src/graphics/Camera.cpp +++ b/src/graphics/Camera.cpp @@ -5,29 +5,36 @@ using namespace glm;  Camera::Camera(vec3 a_pos, vec3 a_front, vec3 a_up,  	GLfloat a_yaw, GLfloat a_pitch) -	: move_speed(init_speed), -	mouse_sensitivity(init_sensitivity), -	fov(init_fov)  {  	position = a_pos;  	up = a_up;  	world_up = up; +  	yaw = a_yaw;  	pitch = a_pitch; + +	move_speed = 1.0f; +	mouse_sensitivity = 0.25f; + +	fov = radians(45.0f); +	near = 0.1f; +	far = 100.0f;  	UpdateVectors();  }  mat4 Camera::GetProjViewMatrix(int w_width, int w_height)  { -	return  -		perspective(fov, (GLfloat)w_width / (GLfloat)w_height, 0.1f, 100.0f) * +	return +		perspective(fov, +			(GLfloat)w_width / (GLfloat)w_height, near, far) *  		lookAt(position, position + front, up);  }  mat4 Camera::GetSkyboxMatrix(int w_width, int w_height)  { -	return  -		perspective(fov, (GLfloat)w_width / (GLfloat)w_height, 0.1f, 100.0f) * +	return +		perspective(fov, +			(GLfloat)w_width / (GLfloat)w_height, near, far) *  		mat4(mat3(lookAt(position, position + front, up)));  } @@ -52,7 +59,7 @@ void Camera::Movement(camera_move direction, GLfloat delta_time)  	UpdateVectors();  } -void Camera::View(GLfloat delta_x, GLfloat delta_y) +void Camera::UpdateView(GLfloat delta_x, GLfloat delta_y)  {  	yaw += delta_x * mouse_sensitivity;  	pitch -= delta_y * mouse_sensitivity; // if '+' then inverse @@ -65,7 +72,7 @@ void Camera::View(GLfloat delta_x, GLfloat delta_y)  	UpdateVectors();  } -void Camera::Fov(GLfloat delta_y) +void Camera::UpdateFov(GLfloat delta_y)  {  	if(!delta_y)  		return; diff --git a/src/graphics/Camera.hpp b/src/graphics/Camera.hpp index 6182b5f..fe8be22 100644 --- a/src/graphics/Camera.hpp +++ b/src/graphics/Camera.hpp @@ -11,18 +11,9 @@ enum camera_move {      RIGHT  }; -const GLfloat -			init_yaw = -90.0f, -			init_pitch = 0.0f, -			init_speed = 2.5f, -			init_sensitivity = 0.25f, -			init_fov = glm::radians(45.0f); -  class Camera {  	glm::vec3 position; -	glm::vec3 front; -	glm::vec3 up; -	glm::vec3 right; +	glm::vec3 front, up, right;  	glm::vec3 world_up;  	GLfloat yaw; // around x @@ -30,18 +21,24 @@ class Camera {  	GLfloat move_speed;  	GLfloat mouse_sensitivity; +  	GLfloat fov; +	GLfloat near, far;  public:  	Camera(glm::vec3 a_pos = glm::vec3(0.0f, 0.0f, 5.0f),  		glm::vec3 a_front = glm::vec3(0.0f, 0.0f, -1.0f),  		glm::vec3 a_up = glm::vec3(0.0f, 1.0f, 0.0f), -		GLfloat a_yaw = init_yaw, GLfloat a_pitch = init_pitch); +		GLfloat a_yaw = -90.0f, GLfloat a_pitch = 0.0f); +	void SetSpeed(GLfloat a_speed) { move_speed = a_speed; } +	void SetSensitivity(GLfloat a_sens) { mouse_sensitivity = a_sens; } +	void SetPerspective(GLfloat a_fov, GLfloat a_near, GLfloat a_far) +		{ fov = a_fov; near = a_near; far = a_far; }  	glm::mat4 GetProjViewMatrix(int w_width, int w_height);  	glm::mat4 GetSkyboxMatrix(int w_width, int w_height);  	void Movement(camera_move direction, GLfloat deltaTime); -	void View(GLfloat delta_x, GLfloat delta_y); -	void Fov(GLfloat delta_y); +	void UpdateView(GLfloat delta_x, GLfloat delta_y); +	void UpdateFov(GLfloat delta_y);  private:  	void UpdateVectors();  };  | 
