diff --git a/examples/FirstScene/main.cpp b/examples/FirstScene/main.cpp index 02234dc0d..42672c5d3 100644 --- a/examples/FirstScene/main.cpp +++ b/examples/FirstScene/main.cpp @@ -196,7 +196,7 @@ int main() // Si la flèche du bas ou la touche S est pressée, on recule if (NzKeyboard::IsKeyPressed(NzKeyboard::Down) || NzKeyboard::IsKeyPressed(NzKeyboard::S)) - camera.Move(NzVector3f::Forward() * -cameraSpeed * elapsedTime); + camera.Move(NzVector3f::Backward() * cameraSpeed * elapsedTime); // Etc... if (NzKeyboard::IsKeyPressed(NzKeyboard::Left) || NzKeyboard::IsKeyPressed(NzKeyboard::Q)) @@ -204,7 +204,7 @@ int main() // Etc... if (NzKeyboard::IsKeyPressed(NzKeyboard::Right) || NzKeyboard::IsKeyPressed(NzKeyboard::D)) - camera.Move(NzVector3f::Left() * -cameraSpeed * elapsedTime); + camera.Move(NzVector3f::Right() * cameraSpeed * elapsedTime); // Majuscule pour monter, mais dans l'espace global (Sans tenir compte de la rotation) if (NzKeyboard::IsKeyPressed(NzKeyboard::LShift) || NzKeyboard::IsKeyPressed(NzKeyboard::RShift)) @@ -212,7 +212,7 @@ int main() // Contrôle (Gauche ou droite) pour descendre dans l'espace global, etc... if (NzKeyboard::IsKeyPressed(NzKeyboard::LControl) || NzKeyboard::IsKeyPressed(NzKeyboard::RControl)) - camera.Move(NzVector3f::Up() * -cameraSpeed * elapsedTime, nzCoordSys_Global); + camera.Move(NzVector3f::Down() * cameraSpeed * elapsedTime, nzCoordSys_Global); // On relance l'horloge updateClock.Restart(); diff --git a/include/Nazara/Math/Vector3.hpp b/include/Nazara/Math/Vector3.hpp index 5d427c8f3..0dc195353 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -36,8 +36,12 @@ template class NzVector3 NzVector3 GetNormal(T* length = nullptr) const; T GetSquaredLength() const; + NzVector3& MakeBackward(); + NzVector3& MakeDown(); NzVector3& MakeForward(); NzVector3& MakeLeft(); + NzVector3& MakeRight(); + NzVector3& MakeUnit(); NzVector3& MakeUnitX(); NzVector3& MakeUnitY(); NzVector3& MakeUnitZ(); @@ -90,12 +94,16 @@ template class NzVector3 bool operator>(const NzVector3& vec) const; bool operator>=(const NzVector3& vec) const; + static NzVector3 Backward(); static NzVector3 CrossProduct(const NzVector3& vec1, const NzVector3& vec2); static T DotProduct(const NzVector3& vec1, const NzVector3& vec2); + static NzVector3 Down(); static NzVector3 Forward(); static NzVector3 Left(); static NzVector3 Lerp(const NzVector3& from, const NzVector3& to, T interpolation); static NzVector3 Normalize(const NzVector3& vec); + static NzVector3 Right(); + static NzVector3 Unit(); static NzVector3 UnitX(); static NzVector3 UnitY(); static NzVector3 UnitZ(); diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index c81c11dc9..8690fade3 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -111,6 +111,18 @@ T NzVector3::GetSquaredLength() const return x*x + y*y + z*z; } +template +NzVector3& NzVector3::MakeBackward() +{ + return Set(F(0.0), F(0.0), F(1.0)); +} + +template +NzVector3& NzVector3::MakeDown() +{ + return Set(F(0.0), F(-1.0), F(0.0)); +} + template NzVector3& NzVector3::MakeForward() { @@ -123,6 +135,18 @@ NzVector3& NzVector3::MakeLeft() return Set(F(-1.0), F(0.0), F(0.0)); } +template +NzVector3& NzVector3::MakeRight() +{ + return Set(F(1.0), F(0.0), F(0.0)); +} + +template +NzVector3& NzVector3::MakeUnit() +{ + return Set(F(1.0), F(1.0), F(1.0)); +} + template NzVector3& NzVector3::MakeUnitX() { @@ -526,6 +550,24 @@ T NzVector3::DotProduct(const NzVector3& vec1, const NzVector3& vec2) return vec1.DotProduct(vec2); } +template +NzVector3 NzVector3::Backward() +{ + NzVector3 vector; + vector.MakeBackward(); + + return vector; +} + +template +NzVector3 NzVector3::Down() +{ + NzVector3 vector; + vector.MakeDown(); + + return vector; +} + template NzVector3 NzVector3::Forward() { @@ -556,6 +598,24 @@ NzVector3 NzVector3::Normalize(const NzVector3& vec) return vec.GetNormal(); } +template +NzVector3 NzVector3::Right() +{ + NzVector3 vector; + vector.MakeRight(); + + return vector; +} + +template +NzVector3 NzVector3::Unit() +{ + NzVector3 vector; + vector.MakeUnit(); + + return vector; +} + template NzVector3 NzVector3::UnitX() {