At this point idk what im doing

This commit is contained in:
Ben
2019-10-29 22:40:57 +00:00
parent efafd4e71e
commit 671ab913ab
5 changed files with 53 additions and 21 deletions

View File

@@ -89,14 +89,9 @@ void Game::Setup(int w, int h) {
m_world = std::make_unique<World>();
Texture texture;
m_world->TextureID = texture.LoadTextures(BlockDictionary->Textures);
m_world->SetTextureMap(texture.LoadTextures(BlockDictionary->Textures));
for (int x = 0; x < 2; x++)
for (int y = 0; y < 2; y++) {
m_world->Chunks.push_back(std::make_shared<Chunk>(x, y));
}
m_world->LoadWorld();
m_world->Shaders["Basic"] = std::make_shared<Shader>();
m_world->Shaders["Basic"]->Load(GameConfig.ResourceBase + "shaders/simple");

View File

@@ -8,7 +8,9 @@ Camera::Camera(int w, int h) {
pitch = 0.0f;
yaw = 0.0f;
eyeVector = {};
Position = {};
LookDirection = {};
viewMatrix = {};
}
@@ -28,10 +30,17 @@ void Camera::UpdateView() {
glm::mat4 rotate = matRoll * matPitch * matYaw;
glm::mat4 translate = glm::mat4(1.0f);
translate = glm::translate(translate, -eyeVector);
translate = glm::translate(translate, -Position);
viewMatrix = rotate * translate;
// Work out Look Vector
glm::mat4 inverseView = glm::inverse(viewMatrix);
LookDirection.x = inverseView[2][0];
LookDirection.y = inverseView[2][1];
LookDirection.z = inverseView[2][2];
}
glm::mat4 Camera::GetViewMatrix() {
@@ -52,12 +61,6 @@ void Camera::UpdateProjection(int width, int height) {
}
glm::vec3 Camera::GetPos() {
return eyeVector;
}
void Camera::HandleMouse(SDL_Event e) {
if (e.type != SDL_MOUSEMOTION)
@@ -118,9 +121,10 @@ void Camera::MoveCamera(Uint8* state) {
// forward vector must be negative to look forward.
// read :http://in2gpu.com/2015/05/17/view-matrix/
eyeVector.x += dx * CameraSpeed;
eyeVector.z += dz * CameraSpeed;
eyeVector.y += dy * CameraSpeed;
Position.x += dx * CameraSpeed;
Position.z += dz * CameraSpeed;
Position.y += dy * CameraSpeed;
// update the view matrix
UpdateView();

View File

@@ -11,9 +11,8 @@ public:
glm::mat4 GetViewMatrix();
glm::mat4 GetProjectionMatrix();
void UpdateProjection(int width, int height);
glm::vec3 GetPos();
void UpdateProjection(int width, int height);
void HandleMouse(SDL_Event e);
void MoveCamera(Uint8* state);
@@ -22,9 +21,11 @@ public:
float MouseSensitivity = 0.1f;
float CameraSpeed = 0.2f;
glm::vec3 Position = {};
glm::vec3 LookDirection = {};
private:
float roll, pitch, yaw;
glm::vec3 eyeVector = {};
glm::mat4 viewMatrix = {};
glm::mat4 projMatrix = {};

View File

@@ -1,3 +1,22 @@
#include "world.hpp"
World::World() {
}
void World::LoadWorld() {
}
void World::SetTextureMap(GLuint map) {
}
glm::vec2 World::GetChunkCoords(glm::vec3) {
}
std::vector<std::shared_ptr<Chunk>> World::GetRenderableChunks() {
}

View File

@@ -13,6 +13,16 @@ class Chunk;
class World {
public:
World();
void LoadWorld();
void SetTextureMap(GLuint map);
// Takes world coordinates and gets a chunks coordinates
glm::vec2 GetChunkCoords(glm::vec3);
std::vector<std::shared_ptr<Chunk>> GetRenderableChunks();
private:
@@ -24,6 +34,9 @@ private:
std::vector<std::thread> m_generatorThreads;
// Chuks
std::vector<std::shared_ptr<Chunk>> m_renderableChunks;
std::unordered_map<glm::vec2, std::shared_ptr<Chunk>> m_chunks;
};