Skip to content
Snippets Groups Projects
Commit ec7236af authored by JonShard's avatar JonShard
Browse files

Improved flight controls a bit.

parent 2cd066b1
No related branches found
No related tags found
No related merge requests found
...@@ -39,6 +39,8 @@ using namespace overkill; ...@@ -39,6 +39,8 @@ using namespace overkill;
#define DEBUG #define DEBUG
const float turnSpeed = 0.04f;
const float speedAcceleration = 0.03f;
int main(int argc, char** args) int main(int argc, char** args)
{ {
...@@ -88,6 +90,8 @@ int main(int argc, char** args) ...@@ -88,6 +90,8 @@ int main(int argc, char** args)
"April", "May", "June", "April", "May", "June",
"Juli", "August", "September", "Juli", "August", "September",
"October", "November", "December"}; "October", "November", "December"};
float yawAccl = 0; // Acceleration.
float pitchAccl = 0; // Acceleration.
//exit(0); // for performance analysis, check resource loading time. //exit(0); // for performance analysis, check resource loading time.
float oldT = 0, t = 0, dt = 0, frameTime = 0; float oldT = 0, t = 0, dt = 0, frameTime = 0;
...@@ -171,28 +175,40 @@ int main(int argc, char** args) ...@@ -171,28 +175,40 @@ int main(int argc, char** args)
glm::vec3 rot = glm::radians(plane-> getRotation()); glm::vec3 rot = glm::radians(plane-> getRotation());
if (Input::m_navKeyPressed[W]) if (Input::m_navKeyPressed[W])
{ {
rot += glm::vec3(0.01, 0, 0); // Not need to multiply with dt on transformation pitchAccl += turnSpeed * dt;
// rot += glm::vec3(0.002, 0, 0); // Not need to multiply with dt on transformation
} // operations, since it is done by Scene in Scene::update(). } // operations, since it is done by Scene in Scene::update().
if (Input::m_navKeyPressed[S]) if (Input::m_navKeyPressed[S])
{ {
rot -= glm::vec3(0.01, 0, 0); pitchAccl -= turnSpeed * dt;
// rot -= glm::vec3(0.002, 0, 0);
} }
if (Input::m_navKeyPressed[A]) if (Input::m_navKeyPressed[A])
{ {
rot += glm::vec3(0, 0.01, 0); // rot += glm::vec3(0, 0.01, 0);
yawAccl += turnSpeed * dt;
} }
if (Input::m_navKeyPressed[D]) if (Input::m_navKeyPressed[D])
{ {
rot -= glm::vec3(0, 0.01, 0); yawAccl -= turnSpeed * dt;
// rot -= glm::vec3(0, 0.01, 0);
} }
if (Input::m_navKeyPressed[period] && Input::m_planeSpeed < Input::m_planeMaxSpeed) if (Input::m_navKeyPressed[period] && Input::m_planeSpeed < Input::m_planeMaxSpeed)
{ {
Input::m_planeSpeed += 0.03 * dt; // This is not done in scene, so here we muliply with dt. Input::m_planeSpeed += speedAcceleration * dt; // This is not done in scene, so here we muliply with dt.
} }
if (Input::m_navKeyPressed[comma] && Input::m_planeSpeed > Input::m_planeMinSpeed) if (Input::m_navKeyPressed[comma] && Input::m_planeSpeed > Input::m_planeMinSpeed)
{ {
Input::m_planeSpeed -= 0.03 * dt; Input::m_planeSpeed -= speedAcceleration * dt;
} }
yawAccl *= 0.96;
pitchAccl *= 0.98;
rot.y += yawAccl;
rot.x += pitchAccl;
// rot.z += glm::radians(-fakeRoll * 30 * glm::cos(rot.y)); // Math is hard.
// rot.x += glm::radians(-fakeRoll * 30 * glm::sin(rot.y));
// The math on this part was co-written with Jonas Solvik. // The math on this part was co-written with Jonas Solvik.
pos += glm::vec3(Input::m_planeSpeed) * glm::vec3(glm::sin(rot.y) * glm::cos(rot.x), pos += glm::vec3(Input::m_planeSpeed) * glm::vec3(glm::sin(rot.y) * glm::cos(rot.x),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment