[ADD] made camera follow the character with lerp
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include "../toolbox/toolbox.h"
|
||||||
|
|
||||||
namespace entities
|
namespace entities
|
||||||
{
|
{
|
||||||
@@ -8,7 +10,9 @@ namespace entities
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
void Camera::Follow(glm::vec3 follow_position) {
|
void Camera::Follow(glm::vec3 follow_position) {
|
||||||
position.z = follow_position.z + 200;
|
follow_position.z += 100;
|
||||||
|
follow_position.y += 50;
|
||||||
|
position = toolbox::Lerp(position, follow_position, 0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Camera::Move(GLFWwindow* window)
|
void Camera::Move(GLFWwindow* window)
|
||||||
@@ -41,9 +45,14 @@ namespace entities
|
|||||||
{
|
{
|
||||||
up_down_speed += UP_SPEED;
|
up_down_speed += UP_SPEED;
|
||||||
}
|
}
|
||||||
|
if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
up_down_speed -= UP_SPEED;
|
||||||
|
}
|
||||||
|
|
||||||
position.x += side_speed;
|
position.x += side_speed;
|
||||||
position.z += movement_speed;
|
position.z += movement_speed;
|
||||||
position.y += up_down_speed;
|
position.y += up_down_speed;
|
||||||
|
std::cout <<"x= " << position.x <<"\ny= " << position.y << "\nz= " << position.z << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace entities
|
|||||||
glm::vec3 main_character::move(GLFWwindow* window)
|
glm::vec3 main_character::move(GLFWwindow* window)
|
||||||
{
|
{
|
||||||
float movement_speed = -1.0f;
|
float movement_speed = -1.0f;
|
||||||
float up_down_speed = -0.4f;
|
float up_down_speed = -0.2f;
|
||||||
float side_speed = 0;
|
float side_speed = 0;
|
||||||
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
@@ -47,6 +47,11 @@ namespace entities
|
|||||||
up_down_speed -= UP_SPEED;
|
up_down_speed -= UP_SPEED;
|
||||||
}
|
}
|
||||||
IncreasePosition(glm::vec3(side_speed, up_down_speed, movement_speed));
|
IncreasePosition(glm::vec3(side_speed, up_down_speed, movement_speed));
|
||||||
|
if (position.x > 190) position.x = 190;
|
||||||
|
else if (position.x < -190) position.x = -190;
|
||||||
|
if (position.y > 350) position.y = 350;
|
||||||
|
else if (position.y < -40) position.y = -40;
|
||||||
|
MoveCollisionBox();
|
||||||
return glm::vec3(side_speed, up_down_speed, movement_speed );
|
return glm::vec3(side_speed, up_down_speed, movement_speed );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace entities
|
|||||||
{
|
{
|
||||||
class main_character : public CollisionEntity {
|
class main_character : public CollisionEntity {
|
||||||
const float SPEED = 1.0f;
|
const float SPEED = 1.0f;
|
||||||
const float UP_SPEED = 1.0f;
|
const float UP_SPEED = 0.6f;
|
||||||
public:
|
public:
|
||||||
main_character(const models::TexturedModel& model, const glm::vec3& position,
|
main_character(const models::TexturedModel& model, const glm::vec3& position,
|
||||||
const glm::vec3& rotation, float scale, const collision::Box& bounding_box);
|
const glm::vec3& rotation, float scale, const collision::Box& bounding_box);
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace scene
|
|||||||
models::ModelTexture texture;
|
models::ModelTexture texture;
|
||||||
shaders::EntityShader* shader;
|
shaders::EntityShader* shader;
|
||||||
shaders::GuiShader* gui_shader;
|
shaders::GuiShader* gui_shader;
|
||||||
entities::Camera camera(glm::vec3(0, 100, 0), glm::vec3(0, 0, 0));
|
entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0));
|
||||||
std::vector<gui::GuiTexture*> guis;
|
std::vector<gui::GuiTexture*> guis;
|
||||||
|
|
||||||
models::TexturedModel model;
|
models::TexturedModel model;
|
||||||
|
|||||||
@@ -31,4 +31,17 @@ namespace toolbox
|
|||||||
matrix = glm::translate(matrix, negative_cam_pos);
|
matrix = glm::translate(matrix, negative_cam_pos);
|
||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
float Lerp(float from, float to, float amount)
|
||||||
|
{
|
||||||
|
return from + amount * (to - from);
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 Lerp(glm::vec3 from, glm::vec3 to, float amount)
|
||||||
|
{
|
||||||
|
glm::vec3 final;
|
||||||
|
final.x = Lerp(from.x, to.x, amount);
|
||||||
|
final.y = Lerp(from.y, to.y, amount);
|
||||||
|
final.z = Lerp(from.z, to.z, amount);
|
||||||
|
return final;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,4 +46,8 @@ namespace toolbox
|
|||||||
* @return: The view matrix
|
* @return: The view matrix
|
||||||
*/
|
*/
|
||||||
glm::mat4 CreateViewMatrix(entities::Camera& camera);
|
glm::mat4 CreateViewMatrix(entities::Camera& camera);
|
||||||
|
|
||||||
|
float Lerp(float from, float to, float amount);
|
||||||
|
|
||||||
|
glm::vec3 Lerp(glm::vec3 from, glm::vec3 to, float amount);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user