[ADD] camera follows the only at the z position

This commit is contained in:
Nathalie Seen
2021-06-04 14:44:41 +02:00
parent 2523e1abfa
commit 86383aace5
5 changed files with 34 additions and 8 deletions

View File

@@ -7,6 +7,10 @@ namespace entities
rotation(rotation)
{}
void Camera::Follow(glm::vec3 follow_position) {
position.z = follow_position.z + 200;
}
void Camera::Move(GLFWwindow* window)
{
float movement_speed = 0;

View File

@@ -28,6 +28,8 @@ namespace entities
* @param window: The OpenGL window
*/
void Move(GLFWwindow* window);
void Follow(glm::vec3 follow_position);
inline glm::vec3 GetPosition() const{ return position; }
inline glm::vec3 GetRotation() const{ return rotation; }

View File

@@ -14,8 +14,8 @@ namespace entities
}
glm::vec3 main_character::move(GLFWwindow* window)
{
float movement_speed = 0;
float up_down_speed = 0;
float movement_speed = -1.0f;
float up_down_speed = -0.4f;
float side_speed = 0;
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
@@ -42,6 +42,10 @@ namespace entities
{
up_down_speed += UP_SPEED;
}
if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS)
{
up_down_speed -= UP_SPEED;
}
IncreasePosition(glm::vec3(side_speed, up_down_speed, movement_speed));
return glm::vec3(side_speed, up_down_speed, movement_speed );
}

View File

@@ -5,9 +5,8 @@
namespace entities
{
class main_character : public CollisionEntity {
const int SPEED = 10;
const float SPEED = 1.0f;
const float UP_SPEED = 1.0f;
public:
main_character(const models::TexturedModel& model, const glm::vec3& position,

View File

@@ -3,6 +3,7 @@
#include <GLFW/glfw3.h>
#include "in_Game_Scene.h"
#include "startup_Scene.h"
#include "../entities/main_character.h"
#include "../gui/gui_interactable.h"
#include "../models/model.h"
#include "../renderEngine/loader.h"
@@ -19,14 +20,15 @@
namespace scene
{
std::deque<entities::Entity> house_models;
std::vector<entities::main_character*> main_character;
std::deque<entities::Light> lights;
std::deque<entities::Entity> trees;
models::RawModel raw_model;
models::RawModel raw_model, raw_model_char;
models::ModelTexture texture;
shaders::EntityShader* shader;
shaders::GuiShader* gui_shader;
entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0));
entities::Camera camera(glm::vec3(0, 100, 0), glm::vec3(0, 0, 0));
std::vector<gui::GuiTexture*> guis;
models::TexturedModel model;
@@ -61,6 +63,7 @@ namespace scene
house_models.push_front(entities::Entity(model, glm::vec3(0, -50, -50 - z_offset), glm::vec3(0, 90, 0), 20));
trees.push_front(entities::Entity(tree, glm::vec3(0, 0, -50 - z_offset), glm::vec3(0, 90, 0), 3));
}
@@ -76,12 +79,16 @@ namespace scene
models::ModelTexture tree_texture = { render_engine::loader::LoadTexture("res/TreeTexture.png") };
tree = { raw_tree_model, tree_texture };
raw_model_char = render_engine::LoadObjModel("res/beeTwo.obj");
models::TexturedModel model_char = { raw_model_char, texture };
// load the first few house models
for (int i = 0; i <= UPCOMING_MODEL_AMOUNT; i++)
{
load_chunk(i);
}
entities::main_character character{ model_char, glm::vec3(0, -50, -100), glm::vec3(0, 90, 0), 5,collision::Box() };
main_character.push_back(&character);
lights.push_back(entities::Light(glm::vec3(0, 1000, -7000), glm::vec3(5, 5, 5))); // sun
lights.push_back(entities::Light(glm::vec3(0, 0, -30), glm::vec3(2, 0, 2), glm::vec3(0.0001f, 0.0001f, 0.0001f)));
@@ -132,6 +139,10 @@ namespace scene
{
render_engine::renderer::Render(tree_entity, *shader);
}
for (entities::Entity* main_char : main_character)
{
render_engine::renderer::Render(*main_char, *shader);
}
// Render GUI items
render_engine::renderer::Render(guis, *gui_shader);
@@ -142,7 +153,13 @@ namespace scene
void scene::In_Game_Scene::update(GLFWwindow* window)
{
camera.Move(window);
//camera.Move(window);
entities::main_character* character = main_character[0];
glm::vec3 movement = character->move(window);
std::cout << "x: " << character->GetPosition().x << "\ny: " << character->GetPosition().y << "\nz: " << character->GetPosition().z << "\n";
std::cout << "x get: " << movement.x << "\ny get: " << movement.y << "\nz get: " << movement.z << "\n";
camera.Follow(character->GetPosition());
// calculate where the next house model should be loaded
static int last_model_pos = 0;
@@ -159,7 +176,7 @@ namespace scene
void scene::In_Game_Scene::onKey(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
{
return_value = scene::Scenes::STOP;
}