2 This file is part of XRay, a photorealistic 3D rendering library.
3 Copyright (C) 2005 John Tsiombikas
5 XRay is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 XRay is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with XRay; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * @author John Tsiombikas
32 #include "vmath_types.h"
39 Vector2(scalar_t x = 0.0, scalar_t y = 0.0);
40 Vector2(const Vector3 &vec);
41 Vector2(const Vector4 &vec);
43 inline scalar_t &operator [](int elem);
46 friend inline Vector2 operator -(const Vector2 &vec);
48 // binary vector (op) vector operations
49 friend inline scalar_t dot_product(const Vector2 &v1, const Vector2 &v2);
51 friend inline Vector2 operator +(const Vector2 &v1, const Vector2 &v2);
52 friend inline Vector2 operator -(const Vector2 &v1, const Vector2 &v2);
53 friend inline Vector2 operator *(const Vector2 &v1, const Vector2 &v2);
54 friend inline Vector2 operator /(const Vector2 &v1, const Vector2 &v2);
55 friend inline bool operator ==(const Vector2 &v1, const Vector2 &v2);
57 friend inline void operator +=(Vector2 &v1, const Vector2 &v2);
58 friend inline void operator -=(Vector2 &v1, const Vector2 &v2);
59 friend inline void operator *=(Vector2 &v1, const Vector2 &v2);
60 friend inline void operator /=(Vector2 &v1, const Vector2 &v2);
62 // binary vector (op) scalar and scalar (op) vector operations
63 friend inline Vector2 operator +(const Vector2 &vec, scalar_t scalar);
64 friend inline Vector2 operator +(scalar_t scalar, const Vector2 &vec);
65 friend inline Vector2 operator -(const Vector2 &vec, scalar_t scalar);
66 friend inline Vector2 operator -(scalar_t scalar, const Vector2 &vec);
67 friend inline Vector2 operator *(const Vector2 &vec, scalar_t scalar);
68 friend inline Vector2 operator *(scalar_t scalar, const Vector2 &vec);
69 friend inline Vector2 operator /(const Vector2 &vec, scalar_t scalar);
70 friend inline Vector2 operator /(scalar_t scalar, const Vector2 &vec);
72 friend inline void operator +=(Vector2 &vec, scalar_t scalar);
73 friend inline void operator -=(Vector2 &vec, scalar_t scalar);
74 friend inline void operator *=(Vector2 &vec, scalar_t scalar);
75 friend inline void operator /=(Vector2 &vec, scalar_t scalar);
77 inline scalar_t length() const;
78 inline scalar_t length_sq() const;
80 Vector2 normalized() const;
82 void transform(const Matrix3x3 &mat);
83 Vector2 transformed(const Matrix3x3 &mat) const;
85 void rotate(scalar_t angle);
86 Vector2 rotated(scalar_t angle) const;
88 Vector2 reflection(const Vector2 &normal) const;
89 Vector2 refraction(const Vector2 &normal, scalar_t src_ior, scalar_t dst_ior) const;
91 friend std::ostream &operator <<(std::ostream &out, const Vector2 &vec);
99 Vector3(scalar_t x = 0.0, scalar_t y = 0.0, scalar_t z = 0.0);
100 Vector3(const Vector2 &vec);
101 Vector3(const Vector4 &vec);
102 Vector3(const SphVector &sph);
104 Vector3 &operator =(const SphVector &sph);
106 inline scalar_t &operator [](int elem);
109 friend inline Vector3 operator -(const Vector3 &vec);
111 // binary vector (op) vector operations
112 friend inline scalar_t dot_product(const Vector3 &v1, const Vector3 &v2);
113 friend inline Vector3 cross_product(const Vector3 &v1, const Vector3 &v2);
115 friend inline Vector3 operator +(const Vector3 &v1, const Vector3 &v2);
116 friend inline Vector3 operator -(const Vector3 &v1, const Vector3 &v2);
117 friend inline Vector3 operator *(const Vector3 &v1, const Vector3 &v2);
118 friend inline Vector3 operator /(const Vector3 &v1, const Vector3 &v2);
119 friend inline bool operator ==(const Vector3 &v1, const Vector3 &v2);
121 friend inline void operator +=(Vector3 &v1, const Vector3 &v2);
122 friend inline void operator -=(Vector3 &v1, const Vector3 &v2);
123 friend inline void operator *=(Vector3 &v1, const Vector3 &v2);
124 friend inline void operator /=(Vector3 &v1, const Vector3 &v2);
126 // binary vector (op) scalar and scalar (op) vector operations
127 friend inline Vector3 operator +(const Vector3 &vec, scalar_t scalar);
128 friend inline Vector3 operator +(scalar_t scalar, const Vector3 &vec);
129 friend inline Vector3 operator -(const Vector3 &vec, scalar_t scalar);
130 friend inline Vector3 operator -(scalar_t scalar, const Vector3 &vec);
131 friend inline Vector3 operator *(const Vector3 &vec, scalar_t scalar);
132 friend inline Vector3 operator *(scalar_t scalar, const Vector3 &vec);
133 friend inline Vector3 operator /(const Vector3 &vec, scalar_t scalar);
134 friend inline Vector3 operator /(scalar_t scalar, const Vector3 &vec);
136 friend inline void operator +=(Vector3 &vec, scalar_t scalar);
137 friend inline void operator -=(Vector3 &vec, scalar_t scalar);
138 friend inline void operator *=(Vector3 &vec, scalar_t scalar);
139 friend inline void operator /=(Vector3 &vec, scalar_t scalar);
141 inline scalar_t length() const;
142 inline scalar_t length_sq() const;
144 Vector3 normalized() const;
146 void transform(const Matrix3x3 &mat);
147 Vector3 transformed(const Matrix3x3 &mat) const;
148 void transform(const Matrix4x4 &mat);
149 Vector3 transformed(const Matrix4x4 &mat) const;
150 void transform(const Quaternion &quat);
151 Vector3 transformed(const Quaternion &quat) const;
153 void rotate(const Vector3 &euler);
154 Vector3 rotated(const Vector3 &euler) const;
156 Vector3 reflection(const Vector3 &normal) const;
157 Vector3 refraction(const Vector3 &normal, scalar_t src_ior, scalar_t dst_ior) const;
159 friend std::ostream &operator <<(std::ostream &out, const Vector3 &vec);
167 Vector4(scalar_t x = 0.0, scalar_t y = 0.0, scalar_t z = 0.0, scalar_t w = 0.0);
168 Vector4(const Vector2 &vec);
169 Vector4(const Vector3 &vec);
171 inline scalar_t &operator [](int elem);
174 friend inline Vector4 operator -(const Vector4 &vec);
176 // binary vector (op) vector operations
177 friend inline scalar_t dot_product(const Vector4 &v1, const Vector4 &v2);
178 friend inline Vector4 cross_product(const Vector4 &v1, const Vector4 &v2, const Vector4 &v3);
180 friend inline Vector4 operator +(const Vector4 &v1, const Vector4 &v2);
181 friend inline Vector4 operator -(const Vector4 &v1, const Vector4 &v2);
182 friend inline Vector4 operator *(const Vector4 &v1, const Vector4 &v2);
183 friend inline Vector4 operator /(const Vector4 &v1, const Vector4 &v2);
184 friend inline bool operator ==(const Vector4 &v1, const Vector4 &v2);
186 friend inline void operator +=(Vector4 &v1, const Vector4 &v2);
187 friend inline void operator -=(Vector4 &v1, const Vector4 &v2);
188 friend inline void operator *=(Vector4 &v1, const Vector4 &v2);
189 friend inline void operator /=(Vector4 &v1, const Vector4 &v2);
191 // binary vector (op) scalar and scalar (op) vector operations
192 friend inline Vector4 operator +(const Vector4 &vec, scalar_t scalar);
193 friend inline Vector4 operator +(scalar_t scalar, const Vector4 &vec);
194 friend inline Vector4 operator -(const Vector4 &vec, scalar_t scalar);
195 friend inline Vector4 operator -(scalar_t scalar, const Vector4 &vec);
196 friend inline Vector4 operator *(const Vector4 &vec, scalar_t scalar);
197 friend inline Vector4 operator *(scalar_t scalar, const Vector4 &vec);
198 friend inline Vector4 operator /(const Vector4 &vec, scalar_t scalar);
199 friend inline Vector4 operator /(scalar_t scalar, const Vector4 &vec);
201 friend inline void operator +=(Vector4 &vec, scalar_t scalar);
202 friend inline void operator -=(Vector4 &vec, scalar_t scalar);
203 friend inline void operator *=(Vector4 &vec, scalar_t scalar);
204 friend inline void operator /=(Vector4 &vec, scalar_t scalar);
206 inline scalar_t length() const;
207 inline scalar_t length_sq() const;
209 Vector4 normalized() const;
211 void transform(const Matrix4x4 &mat);
212 Vector4 transformed(const Matrix4x4 &mat) const;
214 Vector4 reflection(const Vector4 &normal) const;
215 Vector4 refraction(const Vector4 &normal, scalar_t src_ior, scalar_t dst_ior) const;
217 friend std::ostream &operator <<(std::ostream &out, const Vector4 &vec);
220 #include "vector.inl"