BROKE BUILD: entity system lol time to dieee

This commit is contained in:
Ben
2019-11-07 23:40:29 +00:00
parent dc8d6c2741
commit 11445de644
12 changed files with 89 additions and 23 deletions

View File

@@ -12,6 +12,7 @@
#include "renderer/camera.hpp"
#include "world/chunk/chunk.hpp"
#include "world/entity.hpp"
#include "world/world.hpp"
#include "world/block.hpp"
@@ -82,10 +83,9 @@ void Game::Setup(int w, int h) {
*m_logger << LOGGER_ENDL;
IsDisplayOpen = true;
m_cameras["Default"] = std::make_shared<Camera>(w, h);
m_activeCamera = m_cameras["Default"];
m_activeCamera->Position = { 0, 70, 0 };
m_activeCamera->UpdateView();
m_player = std::make_shared<Entity>(0, 70, 0);
m_player->EntityCamera = std::make_shared<Camera>(w, h);
std::shared_ptr<CBlockDictionary> BlockDictionary = CBlockDictionary::GetInstance();
@@ -132,7 +132,7 @@ void Game::Input(SDL_Event* e) {
if (e->window.event == SDL_WINDOWEVENT_RESIZED) {
m_activeCamera->UpdateProjection(e->window.data1, e->window.data2);
m_player->EntityCamera->UpdateProjection(e->window.data1, e->window.data2);
glViewport(0, 0, e->window.data1, e->window.data2);
}
@@ -152,11 +152,11 @@ void Game::Input(SDL_Event* e) {
}
if (IsMouseActive) m_activeCamera->HandleMouse(*e);
if (IsMouseActive) m_player->EntityCamera->HandleMouse(*e);
}
m_activeCamera->MoveCamera(state);
m_player->EntityCamera->MoveCamera(state);
}
@@ -175,7 +175,8 @@ void Game::Run() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearBufferfv(GL_COLOR, 0, clear);
m_renderer->Render(m_world , m_activeCamera);
m_world->Update(m_player);
m_renderer->Render(m_world, m_player);
SDL_GL_SwapWindow(m_window);

View File

@@ -22,6 +22,7 @@ class Logger;
class Renderer;
class Camera;
class Entity;
class World;
class Game {
@@ -47,9 +48,8 @@ private:
std::shared_ptr<Renderer> m_renderer;
std::shared_ptr<World> m_world;
std::map<std::string, std::shared_ptr<Camera>> m_cameras;
std::shared_ptr<Camera> m_activeCamera;
std::shared_ptr<Entity> m_player;
};
#endif

View File

@@ -1,5 +1,20 @@
#include "camera.hpp"
Camera::Camera() {
projMatrix = glm::perspective(glm::radians(45.0f), 1.0f, 0.1f, 1000.0f);
roll = 0.0f;
pitch = 0.0f;
yaw = 0.0f;
Position = {};
LookDirection = {};
viewMatrix = {};
}
Camera::Camera(int w, int h) {
projMatrix = glm::perspective(glm::radians(45.0f), (float)w / float(h), 0.1f, 1000.0f);

View File

@@ -5,6 +5,7 @@
class Camera {
public:
Camera();
Camera(int w, int h);
void UpdateView();

View File

@@ -0,0 +1,3 @@
#include "frustrum.hpp"

View File

@@ -22,6 +22,7 @@ class FrustrumPlane {
public:
};

View File

@@ -9,8 +9,8 @@ Renderer::Renderer() {
}
// Perform the render passes
void Renderer::Render(std::shared_ptr<World> world, std::shared_ptr<Camera> camera) {
void Renderer::Render(std::shared_ptr<World> world, std::shared_ptr<Entity> entity) {
world->Render(camera);
world->Render(entity);
}

View File

@@ -3,7 +3,7 @@
#include "../common.hpp"
class Camera;
class Entity;
class World;
// Does GL render passes then returns to the game loop
@@ -11,7 +11,7 @@ class Renderer {
public:
Renderer();
void Render(std::shared_ptr<World> world, std::shared_ptr<Camera> camera);
void Render(std::shared_ptr<World> world, std::shared_ptr<Entity> entity);
};

View File

@@ -1,3 +1,19 @@
#include "entity.hpp"
#include "../renderer/camera.hpp"
Entity::Entity(glm::vec3 postion, glm::vec3 direction, std::shared_ptr<Camera> camera)
: Position(Position)
, Direction(direction)
, EntityCamera(camera)
{
if (EntityCamera) {
EntityCamera->UpdateView();
}
}
Player::Player {
}

View File

@@ -3,27 +3,49 @@
#include "../common.hpp"
class Camera;
class Entity {
public:
Entity();
Entity(glm::vec3 position, glm::vec3 direction = { 0.0f, 0.0f, 0.0f }, std::shared_ptr<Camera> camera = std::make_shared<Camera>());
// World position
bool Player = false;
// World position, 1.7 units below the
// camera position.
glm::vec3 Position;
// Look direction
// Look direction of the camera
glm::vec3 Direction;
// Velocity in direction
// of movement
glm::vec3 Velocity;
// Can be null
std::shared_ptr<Camera> EntityCamera;
// Collider
// Mesh (or reference to)
};
class Player : public Entity {
public:
Player(glm::vec3 position, glm::vec3 direction = {0.0f, 0.0f, 0.0f});
void Move(Uint8* state);
void HandleMouse(SDL_Event e);
void UpdatePosition(glm::vec3 position);
void UpdateDirection(glm::vec3 direction);
void CameaUpdateProjection(int xres, int yres);
};
#endif

View File

@@ -4,9 +4,11 @@
#include "../renderer/shader.hpp"
#include "../config.hpp"
#include "../util/fastnoise.hpp"
#include "../config.hpp"
#include "entity.hpp"
World::World() {
}
@@ -87,7 +89,11 @@ std::vector<std::shared_ptr<Chunk>> World::GetRenderableChunks() {
}
void World::Render(std::shared_ptr<Camera> camera) {
void World::Update(std::shared_ptr<Entity> player) {
}
void World::Render(std::shared_ptr<Entity> player) {
glBindTexture(GL_TEXTURE_2D_ARRAY, m_textureMapID);
@@ -96,7 +102,7 @@ void World::Render(std::shared_ptr<Camera> camera) {
for (int i = 0; i < chunks.size(); i++) {
chunks[i]->Render(camera, m_shaders["Basic"]);
chunks[i]->Render(player->EntityCamera, m_shaders["Basic"]);
}

View File

@@ -15,6 +15,7 @@
class FastNoise;
class Shader;
class Entity;
class World {
public:
@@ -33,8 +34,8 @@ public:
std::vector<std::shared_ptr<Chunk>> GetRenderableChunks();
void Render(std::shared_ptr<Camera> camera);
void Update(std::shared_ptr<Entity> player);
void Render(std::shared_ptr<Entity> player);
~World();