Completed Vector3 vectors

Former-commit-id: 73c16102c22fe1d01b9b9411aa3e1bf82949542c
This commit is contained in:
Lynix 2013-03-21 22:52:19 +01:00
parent c7fdf25432
commit 23b760139e
3 changed files with 71 additions and 3 deletions

View File

@ -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();

View File

@ -36,8 +36,12 @@ template<typename T> 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<typename T> 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();

View File

@ -111,6 +111,18 @@ T NzVector3<T>::GetSquaredLength() const
return x*x + y*y + z*z;
}
template<typename T>
NzVector3<T>& NzVector3<T>::MakeBackward()
{
return Set(F(0.0), F(0.0), F(1.0));
}
template<typename T>
NzVector3<T>& NzVector3<T>::MakeDown()
{
return Set(F(0.0), F(-1.0), F(0.0));
}
template<typename T>
NzVector3<T>& NzVector3<T>::MakeForward()
{
@ -123,6 +135,18 @@ NzVector3<T>& NzVector3<T>::MakeLeft()
return Set(F(-1.0), F(0.0), F(0.0));
}
template<typename T>
NzVector3<T>& NzVector3<T>::MakeRight()
{
return Set(F(1.0), F(0.0), F(0.0));
}
template<typename T>
NzVector3<T>& NzVector3<T>::MakeUnit()
{
return Set(F(1.0), F(1.0), F(1.0));
}
template<typename T>
NzVector3<T>& NzVector3<T>::MakeUnitX()
{
@ -526,6 +550,24 @@ T NzVector3<T>::DotProduct(const NzVector3& vec1, const NzVector3& vec2)
return vec1.DotProduct(vec2);
}
template<typename T>
NzVector3<T> NzVector3<T>::Backward()
{
NzVector3 vector;
vector.MakeBackward();
return vector;
}
template<typename T>
NzVector3<T> NzVector3<T>::Down()
{
NzVector3 vector;
vector.MakeDown();
return vector;
}
template<typename T>
NzVector3<T> NzVector3<T>::Forward()
{
@ -556,6 +598,24 @@ NzVector3<T> NzVector3<T>::Normalize(const NzVector3& vec)
return vec.GetNormal();
}
template<typename T>
NzVector3<T> NzVector3<T>::Right()
{
NzVector3 vector;
vector.MakeRight();
return vector;
}
template<typename T>
NzVector3<T> NzVector3<T>::Unit()
{
NzVector3 vector;
vector.MakeUnit();
return vector;
}
template<typename T>
NzVector3<T> NzVector3<T>::UnitX()
{