cleaned some stuff up a little
This commit is contained in:
@@ -101,17 +101,19 @@ void Game::Setup(int w, int h) {
|
||||
|
||||
void Game::Input(SDL_Event* e) {
|
||||
|
||||
Uint8* state = (Uint8*)SDL_GetKeyboardState(NULL);
|
||||
|
||||
while (SDL_PollEvent(e)) {
|
||||
|
||||
m_activeCamera->HandleMouse(*e);
|
||||
if (e->type == SDL_KEYDOWN)
|
||||
if (SDL_GetKeyboardState(NULL)[SDL_SCANCODE_ESCAPE])
|
||||
if (state[SDL_SCANCODE_ESCAPE])
|
||||
IsDisplayOpen = false;
|
||||
if (e->type == SDL_QUIT)
|
||||
IsDisplayOpen = false;
|
||||
}
|
||||
|
||||
m_activeCamera->MoveCamera();
|
||||
m_activeCamera->MoveCamera(state);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -49,13 +49,11 @@ void Camera::HandleMouse(SDL_Event e) {
|
||||
MouseMoved(mouseDelta);
|
||||
}
|
||||
|
||||
void Camera::MoveCamera() {
|
||||
void Camera::MoveCamera(Uint8* state) {
|
||||
float dx = 0;
|
||||
float dz = 0;
|
||||
float dy = 0;
|
||||
|
||||
const Uint8* state = SDL_GetKeyboardState(NULL);
|
||||
|
||||
// Rotate by camera direction
|
||||
glm::mat2 rotate {
|
||||
cos(yaw), -sin(yaw),
|
||||
@@ -65,46 +63,34 @@ void Camera::MoveCamera() {
|
||||
glm::vec2 f(0.0, 1.0);
|
||||
f = f * rotate;
|
||||
|
||||
if (state[SDL_SCANCODE_W])
|
||||
{
|
||||
if (state[SDL_SCANCODE_W]) {
|
||||
dz -= f.y;
|
||||
dx -= f.x;
|
||||
}
|
||||
if (state[SDL_SCANCODE_S])
|
||||
{
|
||||
if (state[SDL_SCANCODE_S]) {
|
||||
dz += f.y;
|
||||
dx += f.x;
|
||||
}
|
||||
if (state[SDL_SCANCODE_A])
|
||||
{
|
||||
if (state[SDL_SCANCODE_A]) {
|
||||
dz += f.x;
|
||||
dx += -f.y;
|
||||
}
|
||||
if (state[SDL_SCANCODE_D])
|
||||
{
|
||||
if (state[SDL_SCANCODE_D]) {
|
||||
dz -= f.x;
|
||||
dx -= -f.y;
|
||||
}
|
||||
if (state[SDL_SCANCODE_SPACE])
|
||||
{
|
||||
if (state[SDL_SCANCODE_SPACE]) {
|
||||
dy += 1;
|
||||
}
|
||||
if (state[SDL_SCANCODE_LSHIFT])
|
||||
{
|
||||
if (state[SDL_SCANCODE_LSHIFT]) {
|
||||
dy -= 1;
|
||||
}
|
||||
// if (state[SDL_SCANCODE_Z])
|
||||
|
||||
// if (state[SDL_SCANCODE_LSHIFT])
|
||||
|
||||
// get current view matrix
|
||||
glm::mat4 mat = GetViewMatrix();
|
||||
glm::vec3 forward(mat[0][2], mat[1][2], mat[2][2]);
|
||||
glm::vec3 strafe(mat[0][0], mat[1][0], mat[2][0]);
|
||||
|
||||
|
||||
|
||||
|
||||
// forward vector must be negative to look forward.
|
||||
// read :http://in2gpu.com/2015/05/17/view-matrix/
|
||||
eyeVector.x += dx * CameraSpeed;
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
glm::vec3 GetPos();
|
||||
|
||||
void HandleMouse(SDL_Event e);
|
||||
void MoveCamera();
|
||||
void MoveCamera(Uint8* state);
|
||||
void MouseMoved(glm::vec2 mouseDelta);
|
||||
|
||||
float MouseSensitivity = 0.1f;
|
||||
|
||||
@@ -12,8 +12,11 @@ Renderer::Renderer() {
|
||||
void Renderer::Render(std::shared_ptr<World> world, std::shared_ptr<Camera> camera) {
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, world->TextureID);
|
||||
|
||||
for (int i = 0; i < world->Faces.size(); i++) {
|
||||
|
||||
world->Faces[i]->Render(camera, world->Shaders["Basic"]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,11 +28,12 @@ GLuint Texture::LoadTextures(std::vector<std::pair<int, std::string>> textures)
|
||||
int cR = 0;
|
||||
|
||||
unsigned char* texture = stbi_load(path.c_str(), &xR, &yR, &cR, STBI_rgb_alpha);
|
||||
logger << LOGGER_INFO << "Texture at '" << path << "' Loaded..." << LOGGER_ENDL;
|
||||
|
||||
memcpy(texels + (i * x * y * 4), texture, x * y * 4);
|
||||
|
||||
stbi_image_free(texture);
|
||||
logger << LOGGER_INFO << "Texture at '" << path << "' Loaded..." << LOGGER_ENDL;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,16 +3,3 @@
|
||||
#include "../config.hpp"
|
||||
|
||||
// Texture winding order - top, bottom, left, right, front, back
|
||||
|
||||
// std::vector<std::pair<int, std::string>> TextureIdsAndPaths {
|
||||
// {1, "dirt.png"},
|
||||
// {2, "grass_side.png"},
|
||||
// {3, "grass_top.png"}
|
||||
// };
|
||||
|
||||
|
||||
|
||||
std::vector<std::shared_ptr<Block>> BlockAtlas() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,20 +3,10 @@
|
||||
|
||||
#include "../common.hpp"
|
||||
|
||||
struct Block {
|
||||
std::string Name;
|
||||
int id;
|
||||
|
||||
public:
|
||||
Block();
|
||||
};
|
||||
|
||||
static std::vector<std::pair<int, std::string>> TextureIdsAndPaths {
|
||||
{0, "dirt.png"},
|
||||
{1, "grass_side.png"},
|
||||
{2, "grass_top.png"}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user