Commit bda71f63 authored by Adam Štěpánek's avatar Adam Štěpánek
Browse files

Fix naming conventions in RotateCamera

parent cec0e556
Loading
Loading
Loading
Loading
+16 −14
Original line number Original line Diff line number Diff line
@@ -13,52 +13,54 @@ class RotateCamera
  private:
  private:
	/// Constants that defines the behaviour of the camera
	/// Constants that defines the behaviour of the camera
	///		- Minimum elevation in radians
	///		- Minimum elevation in radians
	static const float min_elevation;
	static const float minElevation;
	///		- Maximum elevation in radians
	///		- Maximum elevation in radians
	static const float max_elevation;
	static const float maxElevation;
	///		- Minimum distance from the point of interest
	///		- Minimum distance from the point of interest
	static const float min_distance;
	static const float minDistance;
	///		- Sensitivity of the mouse when changing elevation or direction angles
	///		- Sensitivity of the mouse when changing elevation or direction angles
	static const float angle_sensitivity;
	static const float angleSensitivity;
	///		- Sensitivity of the mouse when changing zoom
	///		- Sensitivity of the mouse when changing zoom
	static const float zoom_sensitivity;
	static const float zoomSensitivity;


	/// angle_direction is an angle in which determines into which direction in xz plane I look.
	/// angle_direction is an angle in which determines into which direction in xz plane I look.
	///		- 0 degrees .. I look in -z direction
	///		- 0 degrees .. I look in -z direction
	///		- 90 degrees .. I look in -x direction
	///		- 90 degrees .. I look in -x direction
	///		- 180 degrees .. I look in +z direction
	///		- 180 degrees .. I look in +z direction
	///		- 270 degrees .. I look in +x direction
	///		- 270 degrees .. I look in +x direction
	float angle_direction;
	float angleDirection;


	/// angle_direction is an angle in which determines from which "height" I look.
	/// angle_direction is an angle in which determines from which "height" I look.
	///		- positive elevation .. I look from above the xz plane
	///		- positive elevation .. I look from above the xz plane
	///		- negative elevation .. I look from below the xz plane
	///		- negative elevation .. I look from below the xz plane
	float angle_elevation;
	float angleElevation;


	/// Distance from (0,0,0), the point at which I look
	/// Distance from (0,0,0), the point at which I look
	float distance;
	float distance;


	/// Final position of the eye in world space coordinates, for LookAt or shaders
	/// Final position of the eye in world space coordinates, for LookAt or shaders
	glm::vec3 eye_position;
	glm::vec3 eyePosition;


	/// Last X and Y coordinates of the mouse cursor
	/// Last X and Y coordinates of the mouse cursor
	int last_x, last_y;
	int lastX, lastY;


	/// True or false if moused buttons are pressed and the user rotates/zooms the camera
	/// True or false if moused buttons are pressed and the user rotates/zooms the camera
	bool is_rotating, is_zooming;
	bool isRotating, isZooming;


	/// Recomputes 'eye_position' from 'angle_direction', 'angle_elevation', and 'distance'
	/// Recomputes 'eye_position' from 'angle_direction', 'angle_elevation', and 'distance'
	void update_eye_pos();
	void updateEyePos();


  public:
  public:
	RotateCamera();
	RotateCamera();


	/// Call when the user presses or releases a mouse button (see glfwSetMouseButtonCallback)
	/// Call when the user presses or releases a mouse button (see glfwSetMouseButtonCallback)
	void on_mouse_button(int button, int action, int mods);
	void onMouseButton(int button, int action, int mods);


	/// Call when the user moves with the mouse cursor (see glfwSetCursorPosCallback)
	/// Call when the user moves with the mouse cursor (see glfwSetCursorPosCallback)
	void on_mouse_move(double x, double y);
	void onMouseMove(double x, double y);


	/// Returns the position of the eye in world space coordinates
	/// Returns the position of the eye in world space coordinates
	glm::vec3 get_eye_position() const;
	glm::vec3 getEyePosition() const {
		return eyePosition;
	}
};
};
+34 −39
Original line number Original line Diff line number Diff line
@@ -2,74 +2,69 @@


#include <GLFW/glfw3.h>
#include <GLFW/glfw3.h>


const float RotateCamera::min_elevation = -1.5f;
const float RotateCamera::minElevation = -1.5f;
const float RotateCamera::max_elevation = 1.5f;
const float RotateCamera::maxElevation = 1.5f;
const float RotateCamera::min_distance = 1.0f;
const float RotateCamera::minDistance = 1.0f;
const float RotateCamera::angle_sensitivity = 0.008f;
const float RotateCamera::angleSensitivity = 0.008f;
const float RotateCamera::zoom_sensitivity = 0.003f;
const float RotateCamera::zoomSensitivity = 0.003f;


RotateCamera::RotateCamera()
RotateCamera::RotateCamera()
    : angle_direction(0.0f), angle_elevation(0.785398163f), distance(15.0f), last_x(0), last_y(0), is_rotating(false),
    : angleDirection(0.0f), angleElevation(0.785398163f), distance(15.0f), lastX(0), lastY(0), isRotating(false),
      is_zooming(false)
      isZooming(false)
{
{
	update_eye_pos();
	updateEyePos();
}
}


void RotateCamera::update_eye_pos()
void RotateCamera::updateEyePos()
{
{
	eye_position.x = distance * cosf(angle_elevation) * -sinf(angle_direction);
	eyePosition.x = distance * cosf(angleElevation) * -sinf(angleDirection);
	eye_position.y = distance * sinf(angle_elevation);
	eyePosition.y = distance * sinf(angleElevation);
	eye_position.z = distance * cosf(angle_elevation) * cosf(angle_direction);
	eyePosition.z = distance * cosf(angleElevation) * cosf(angleDirection);
}
}


void RotateCamera::on_mouse_button(int button, int action, int mods)
void RotateCamera::onMouseButton(int button, int action, int mods)
{
{
	// Left mouse button affects the angles
	// Left mouse button affects the angles
	if (button == GLFW_MOUSE_BUTTON_LEFT) {
	if (button == GLFW_MOUSE_BUTTON_LEFT) {
		if (action == GLFW_PRESS) {
		if (action == GLFW_PRESS) {
			is_rotating = true;
			isRotating = true;
		} else {
		} else {
			is_rotating = false;
			isRotating = false;
		}
		}
	}
	}
	// Right mouse button affects the zoom
	// Right mouse button affects the zoom
	if (button == GLFW_MOUSE_BUTTON_RIGHT) {
	if (button == GLFW_MOUSE_BUTTON_RIGHT) {
		if (action == GLFW_PRESS) {
		if (action == GLFW_PRESS) {
			is_zooming = true;
			isZooming = true;
		} else {
		} else {
			is_zooming = false;
			isZooming = false;
		}
		}
	}
	}
}
}


void RotateCamera::on_mouse_move(double x, double y)
void RotateCamera::onMouseMove(double x, double y)
{
{
	float dx = float(x - last_x);
	float dx = float(x - lastX);
	float dy = float(y - last_y);
	float dy = float(y - lastY);
	last_x = static_cast<int>(x);
	lastX = static_cast<int>(x);
	last_y = static_cast<int>(y);
	lastY = static_cast<int>(y);


	if (is_rotating) {
	if (isRotating) {
		angle_direction += dx * angle_sensitivity;
		angleDirection += dx * angleSensitivity;
		angle_elevation += dy * angle_sensitivity;
		angleElevation += dy * angleSensitivity;


		// Clamp the results
		// Clamp the results
		if (angle_elevation > max_elevation)
		if (angleElevation > maxElevation)
			angle_elevation = max_elevation;
			angleElevation = maxElevation;
		if (angle_elevation < min_elevation)
		if (angleElevation < minElevation)
			angle_elevation = min_elevation;
			angleElevation = minElevation;
	}
	}
	if (is_zooming) {
	if (isZooming) {
		distance *= (1.0f + dy * zoom_sensitivity);
		distance *= (1.0f + dy * zoomSensitivity);


		// Clamp the results
		// Clamp the results
		if (distance < min_distance)
		if (distance < minDistance)
			distance = min_distance;
			distance = minDistance;
	}
	}
	update_eye_pos();
	updateEyePos();
}

glm::vec3 RotateCamera::get_eye_position() const
{
	return eye_position;
}
}
+6 −6
Original line number Original line Diff line number Diff line
@@ -4,9 +4,9 @@ Application::Application(size_t initialWidth, size_t initialHeight) {
	this->width = initialWidth;
	this->width = initialWidth;
	this->height = initialHeight;
	this->height = initialHeight;


	cameraUbo.position = glm::vec4(camera.get_eye_position(), 1.0f);
	cameraUbo.position = glm::vec4(camera.getEyePosition(), 1.0f);
	cameraUbo.projection = glm::perspective(glm::radians(45.0f), float(width) / float(height), 0.01f, 1000.0f);
	cameraUbo.projection = glm::perspective(glm::radians(45.0f), float(width) / float(height), 0.01f, 1000.0f);
	cameraUbo.view = glm::lookAt(camera.get_eye_position(), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
	cameraUbo.view = glm::lookAt(camera.getEyePosition(), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));


	LightUBO directionalLight;
	LightUBO directionalLight;
	directionalLight.position = glm::vec4(1.0f, 1.0f, 1.0f, 0.0f);
	directionalLight.position = glm::vec4(1.0f, 1.0f, 1.0f, 0.0f);
@@ -92,9 +92,9 @@ void Application::render() {
	// Camera
	// Camera
	glm::vec3 cameraPosition;
	glm::vec3 cameraPosition;
	if (followedProbe) {
	if (followedProbe) {
		cameraPosition = glm::vec3(*followedProbe * glm::vec4(camera.get_eye_position(), 1.0f));
		cameraPosition = glm::vec3(*followedProbe * glm::vec4(camera.getEyePosition(), 1.0f));
	} else {
	} else {
		cameraPosition = camera.get_eye_position();
		cameraPosition = camera.getEyePosition();
	}
	}
	cameraUbo.position = glm::vec4(cameraPosition, 1.0f);
	cameraUbo.position = glm::vec4(cameraPosition, 1.0f);
	cameraUbo.view = glm::lookAt(cameraPosition, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
	cameraUbo.view = glm::lookAt(cameraPosition, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
@@ -197,10 +197,10 @@ void Application::onResize(GLFWwindow *window, int width, int height) {
	//glNamedFramebufferTexture(postprocessFramebuffer, GL_DEPTH_ATTACHMENT, postprocessFramebufferDepth, 0);
	//glNamedFramebufferTexture(postprocessFramebuffer, GL_DEPTH_ATTACHMENT, postprocessFramebufferDepth, 0);
}
}
void Application::onMouseMove(GLFWwindow *window, double x, double y) {
void Application::onMouseMove(GLFWwindow *window, double x, double y) {
	camera.on_mouse_move(x, y);
	camera.onMouseMove(x, y);
}
}
void Application::onMousePressed(GLFWwindow *window, int button, int action, int mods) {
void Application::onMousePressed(GLFWwindow *window, int button, int action, int mods) {
	camera.on_mouse_button(button, action, mods);
	camera.onMouseButton(button, action, mods);
}
}
void Application::onKeyPressed(GLFWwindow *window, int key, int scancode, int action, int mods) {
void Application::onKeyPressed(GLFWwindow *window, int key, int scancode, int action, int mods) {
	switch (key) {
	switch (key) {