[EDIT] camera controls
This commit is contained in:
@@ -9,24 +9,42 @@ namespace entities
|
|||||||
|
|
||||||
void Camera::Move(GLFWwindow* window)
|
void Camera::Move(GLFWwindow* window)
|
||||||
{
|
{
|
||||||
|
float movement_speed = 0;
|
||||||
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
position.z -= SPEED;
|
movement_speed -= SPEED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
position.z += SPEED;
|
movement_speed += SPEED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
position.x += SPEED;
|
rotation.y += ROT_SPEED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
|
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
position.x -= SPEED;
|
rotation.y -= ROT_SPEED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
rotation.x -= ROT_SPEED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS)
|
||||||
|
{
|
||||||
|
rotation.x += ROT_SPEED;
|
||||||
|
}
|
||||||
|
|
||||||
|
float dx = glm::cos(glm::radians(rotation.y + 90)) * movement_speed;
|
||||||
|
float dz = glm::sin(glm::radians(rotation.y + 90)) * movement_speed;
|
||||||
|
|
||||||
|
position.x += dx;
|
||||||
|
position.z += dz;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ namespace entities
|
|||||||
private:
|
private:
|
||||||
// The movement speed of the camera
|
// The movement speed of the camera
|
||||||
const float SPEED = 0.52f;
|
const float SPEED = 0.52f;
|
||||||
|
const float ROT_SPEED = 1.0f;
|
||||||
|
|
||||||
glm::vec3 position;
|
glm::vec3 position;
|
||||||
glm::vec3 rotation;
|
glm::vec3 rotation;
|
||||||
|
|||||||
@@ -99,12 +99,12 @@ int main(void)
|
|||||||
// Update
|
// Update
|
||||||
const double delta = UpdateDelta();
|
const double delta = UpdateDelta();
|
||||||
camera.Move(window);
|
camera.Move(window);
|
||||||
|
|
||||||
button.Update(window);
|
button.Update(window);
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
render_engine::renderer::Prepare();
|
render_engine::renderer::Prepare();
|
||||||
|
|
||||||
|
// Start rendering the entities
|
||||||
shader.Start();
|
shader.Start();
|
||||||
shader.LoadSkyColor(render_engine::renderer::SKY_COLOR);
|
shader.LoadSkyColor(render_engine::renderer::SKY_COLOR);
|
||||||
shader.LoadLights(lights);
|
shader.LoadLights(lights);
|
||||||
@@ -119,7 +119,6 @@ int main(void)
|
|||||||
// Stop rendering the entities
|
// Stop rendering the entities
|
||||||
shader.Stop();
|
shader.Stop();
|
||||||
|
|
||||||
|
|
||||||
// Render GUI items
|
// Render GUI items
|
||||||
render_engine::renderer::Render(guis, gui_shader);
|
render_engine::renderer::Render(guis, gui_shader);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user