1 /* Copyright (C) 2020 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
19 * Provides an interface for a vector in R3 and allows vector and
20 * scalar operations on it
23 #include "precompiled.h"
28 #include "FixedVector3D.h"
34 CVector3D::CVector3D(const CFixedVector3D
& v
) :
35 X(v
.X
.ToFloat()), Y(v
.Y
.ToFloat()), Z(v
.Z
.ToFloat())
40 CVector3D
CVector3D::Max()
42 const float max_float
= std::numeric_limits
<float>::max();
43 return CVector3D(max_float
, max_float
, max_float
);
47 CVector3D
CVector3D::Min()
49 const float max_float
= std::numeric_limits
<float>::max();
50 return CVector3D(-max_float
, -max_float
, -max_float
);
53 int CVector3D::operator ! () const
64 float CVector3D::LengthSquared () const
66 return ( SQR(X
) + SQR(Y
) + SQR(Z
) );
69 float CVector3D::Length () const
71 return sqrtf ( LengthSquared() );
74 void CVector3D::Normalize ()
76 float scale
= 1.0f
/Length ();
83 CVector3D
CVector3D::Normalized () const
85 float scale
= 1.0f
/Length ();
87 return CVector3D(X
* scale
, Y
* scale
, Z
* scale
);
91 //-----------------------------------------------------------------------------
93 float MaxComponent(const CVector3D
& v
)
95 return std::max({v
.X
, v
.Y
, v
.Z
});