1 /* Copyright (C) 2012 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 R4 and allows vector and
20 * scalar operations on it
23 #ifndef INCLUDED_VECTOR4D
24 #define INCLUDED_VECTOR4D
31 CVector4D() : X(0.0f
), Y(0.0f
), Z(0.0f
), W(0.0f
) { }
33 CVector4D(float x
, float y
, float z
, float w
) : X(x
), Y(y
), Z(z
), W(w
) { }
35 bool operator==(const CVector4D
& t
) const
37 return (X
== t
.X
&& Y
== t
.Y
&& Z
== t
.Z
&& W
== t
.W
);
40 bool operator!=(const CVector4D
& t
) const
45 CVector4D
operator-() const
47 return CVector4D(-X
, -Y
, -Z
, -W
);
50 CVector4D
operator+(const CVector4D
& t
) const
52 return CVector4D(X
+t
.X
, Y
+t
.Y
, Z
+t
.Z
, W
+t
.W
);
55 CVector4D
operator-(const CVector4D
& t
) const
57 return CVector4D(X
-t
.X
, Y
-t
.Y
, Z
-t
.Z
, W
-t
.W
);
60 CVector4D
operator*(const CVector4D
& t
) const
62 return CVector4D(X
*t
.X
, Y
*t
.Y
, Z
*t
.Z
, W
*t
.W
);
65 CVector4D
operator*(float f
) const
67 return CVector4D(X
*f
, Y
*f
, Z
*f
, W
*f
);
70 CVector4D
operator/(float f
) const
72 float inv_f
= 1.0f
/ f
;
73 return CVector4D(X
*inv_f
, Y
*inv_f
, Z
*inv_f
, W
*inv_f
);
76 CVector4D
& operator+=(const CVector4D
& t
)
85 CVector4D
& operator-=(const CVector4D
& t
)
94 CVector4D
& operator*=(const CVector4D
& t
)
103 CVector4D
& operator*=(float f
)
112 CVector4D
& operator/=(float f
)
114 float inv_f
= 1.0f
/ f
;
122 float Dot(const CVector4D
& a
) const
124 return X
*a
.X
+ Y
*a
.Y
+ Z
*a
.Z
+ W
*a
.W
;