Browse Source

Simplify camera controllers perspective movement calculation

master
Riyyi 4 years ago
parent
commit
bcd2dc8192
  1. 14
      assets/lua/cameracontroller.lua
  2. 14
      inferno/src/inferno/script/cameracontroller.cpp

14
assets/lua/cameracontroller.lua

@ -119,25 +119,23 @@ LuaScript = {
-- WASD movement -- WASD movement
if Input.isKeyPressed(keyCode("GLFW_KEY_W")) then if Input.isKeyPressed(keyCode("GLFW_KEY_W")) then
self.transform.translate = glm.vec3( self.transform.translate + cameraSpeed * self.transform.rotate ) self.transform.translate = self.transform.translate + self.transform.rotate * cameraSpeed
end end
if Input.isKeyPressed(keyCode("GLFW_KEY_S")) then if Input.isKeyPressed(keyCode("GLFW_KEY_S")) then
self.transform.translate = glm.vec3( self.transform.translate - cameraSpeed * self.transform.rotate ) self.transform.translate = self.transform.translate - self.transform.rotate * cameraSpeed
end end
if Input.isKeyPressed(keyCode("GLFW_KEY_A")) then if Input.isKeyPressed(keyCode("GLFW_KEY_A")) then
self.transform.translate = glm.vec3( self.transform.translate - self.transform.translate = self.transform.translate - glm.normalize(glm.cross(self.transform.rotate, self.camera.up)) * cameraSpeed
glm.normalize(glm.cross(self.transform.rotate, self.camera.up)) * cameraSpeed )
end end
if Input.isKeyPressed(keyCode("GLFW_KEY_D")) then if Input.isKeyPressed(keyCode("GLFW_KEY_D")) then
self.transform.translate = glm.vec3( self.transform.translate + self.transform.translate = self.transform.translate + glm.normalize(glm.cross(self.transform.rotate, self.camera.up)) * cameraSpeed
glm.normalize(glm.cross(self.transform.rotate, self.camera.up)) * cameraSpeed )
end end
-- Up / down movement -- Up / down movement
if Input.isKeyPressed(keyCode("GLFW_KEY_SPACE")) then if Input.isKeyPressed(keyCode("GLFW_KEY_SPACE")) then
self.transform.translate = glm.vec3( self.transform.translate.x, self.transform.translate.y + cameraSpeed, self.transform.translate.z ) self.transform.translate.y = self.transform.translate.y + cameraSpeed
end end
if Input.isKeyPressed(keyCode("GLFW_KEY_LEFT_SHIFT")) then if Input.isKeyPressed(keyCode("GLFW_KEY_LEFT_SHIFT")) then
self.transform.translate = glm.vec3( self.transform.translate.x, self.transform.translate.y - cameraSpeed, self.transform.translate.z ) self.transform.translate.y = self.transform.translate.y - cameraSpeed
end end
end, end,

14
inferno/src/inferno/script/cameracontroller.cpp

@ -98,25 +98,23 @@ namespace Inferno {
// WASD movement // WASD movement
if (Input::isKeyPressed(KeyCode("GLFW_KEY_W"))) { if (Input::isKeyPressed(KeyCode("GLFW_KEY_W"))) {
transform->translate = { transform->translate + cameraSpeed * transform->rotate }; transform->translate += transform->rotate * cameraSpeed;
} }
if (Input::isKeyPressed(KeyCode("GLFW_KEY_S"))) { if (Input::isKeyPressed(KeyCode("GLFW_KEY_S"))) {
transform->translate = { transform->translate - cameraSpeed * transform->rotate }; transform->translate -= transform->rotate * cameraSpeed;
} }
if (Input::isKeyPressed(KeyCode("GLFW_KEY_A"))) { if (Input::isKeyPressed(KeyCode("GLFW_KEY_A"))) {
transform->translate = { transform->translate - transform->translate -= glm::normalize(glm::cross(transform->rotate, m_camera->up)) * cameraSpeed;
glm::normalize(glm::cross(transform->rotate, m_camera->up)) * cameraSpeed };
} }
if (Input::isKeyPressed(KeyCode("GLFW_KEY_D"))) { if (Input::isKeyPressed(KeyCode("GLFW_KEY_D"))) {
transform->translate = { transform->translate + transform->translate += glm::normalize(glm::cross(transform->rotate, m_camera->up)) * cameraSpeed;
glm::normalize(glm::cross(transform->rotate, m_camera->up)) * cameraSpeed };
} }
// Up / down movement // Up / down movement
if (Input::isKeyPressed(KeyCode("GLFW_KEY_SPACE"))) { if (Input::isKeyPressed(KeyCode("GLFW_KEY_SPACE"))) {
transform->translate = { transform->translate.x, transform->translate.y + cameraSpeed, transform->translate.z }; transform->translate.y += cameraSpeed;
} }
if (Input::isKeyPressed(KeyCode("GLFW_KEY_LEFT_SHIFT"))) { if (Input::isKeyPressed(KeyCode("GLFW_KEY_LEFT_SHIFT"))) {
transform->translate = { transform->translate.x, transform->translate.y - cameraSpeed, transform->translate.z }; transform->translate.y -= cameraSpeed;
} }
} }
} }

Loading…
Cancel
Save