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
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
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
if Input.isKeyPressed(keyCode("GLFW_KEY_A")) then
self.transform.translate = glm.vec3( self.transform.translate -
glm.normalize(glm.cross(self.transform.rotate, self.camera.up)) * cameraSpeed )
self.transform.translate = self.transform.translate - glm.normalize(glm.cross(self.transform.rotate, self.camera.up)) * cameraSpeed
end
if Input.isKeyPressed(keyCode("GLFW_KEY_D")) then
self.transform.translate = glm.vec3( self.transform.translate +
glm.normalize(glm.cross(self.transform.rotate, self.camera.up)) * cameraSpeed )
self.transform.translate = self.transform.translate + glm.normalize(glm.cross(self.transform.rotate, self.camera.up)) * cameraSpeed
end
-- Up / down movement
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
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,

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

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

Loading…
Cancel
Save