33 #include "math_defs.h" 34 #include "math_funcs.h" 48 #ifdef USE_QUAD_VECTORS 69 _FORCE_INLINE_
const real_t& operator[](
int p_axis)
const {
74 _FORCE_INLINE_ real_t& operator[](
int p_axis) {
79 void set_axis(
int p_axis,real_t p_value);
80 real_t get_axis(
int p_axis)
const;
85 _FORCE_INLINE_ real_t length()
const;
86 _FORCE_INLINE_ real_t length_squared()
const;
88 _FORCE_INLINE_
void normalize();
89 _FORCE_INLINE_
Vector3 normalized()
const;
90 _FORCE_INLINE_
Vector3 inverse()
const;
92 _FORCE_INLINE_
void zero();
94 void snap(
float p_val);
95 Vector3 snapped(
float p_val)
const;
97 void rotate(
const Vector3& p_axis,
float p_phi);
102 _FORCE_INLINE_
Vector3 linear_interpolate(
const Vector3& p_b,
float p_t)
const;
107 _FORCE_INLINE_ real_t dot(
const Vector3& p_b)
const;
109 _FORCE_INLINE_
Vector3 abs()
const;
110 _FORCE_INLINE_
Vector3 floor()
const;
111 _FORCE_INLINE_
Vector3 ceil()
const;
113 _FORCE_INLINE_ real_t distance_to(
const Vector3& p_b)
const;
114 _FORCE_INLINE_ real_t distance_squared_to(
const Vector3& p_b)
const;
134 _FORCE_INLINE_
Vector3& operator*=(real_t p_scalar);
135 _FORCE_INLINE_
Vector3 operator*(real_t p_scalar)
const;
136 _FORCE_INLINE_
Vector3& operator/=(real_t p_scalar);
137 _FORCE_INLINE_
Vector3 operator/(real_t p_scalar)
const;
139 _FORCE_INLINE_
Vector3 operator-()
const;
141 _FORCE_INLINE_
bool operator==(
const Vector3& p_v)
const;
142 _FORCE_INLINE_
bool operator!=(
const Vector3& p_v)
const;
143 _FORCE_INLINE_
bool operator<(
const Vector3& p_v)
const;
144 _FORCE_INLINE_
bool operator<=(
const Vector3& p_v)
const;
148 _FORCE_INLINE_
Vector3() { x=y=z=0; }
149 _FORCE_INLINE_
Vector3(real_t p_x,real_t p_y,real_t p_z) { x=p_x; y=p_y; z=p_z; }
153 #ifdef VECTOR3_IMPL_OVERRIDE 155 #include "vector3_inline.h" 162 (y * p_b.z) - (z * p_b.y),
163 (z * p_b.x) - (x * p_b.z),
164 (x * p_b.y) - (y * p_b.x)
169 real_t Vector3::dot(
const Vector3& p_b)
const {
171 return x*p_b.x + y*p_b.y + z*p_b.z;
176 return Vector3( Math::abs(x), Math::abs(y), Math::abs(z) );
179 Vector3 Vector3::floor()
const {
181 return Vector3( Math::floor(x), Math::floor(y), Math::floor(z) );
184 Vector3 Vector3::ceil()
const {
186 return Vector3( Math::ceil(x), Math::ceil(y), Math::ceil(z) );
189 Vector3 Vector3::linear_interpolate(
const Vector3& p_b,
float p_t)
const {
201 real_t Vector3::distance_to(
const Vector3& p_b)
const {
202 return (p_b-*
this).length();
204 real_t Vector3::distance_squared_to(
const Vector3& p_b)
const {
206 return (p_b-*
this).length_squared();
220 return Vector3(x+p_v.x, y+p_v.y, z+ p_v.z);
232 return Vector3(x-p_v.x, y-p_v.y, z- p_v.z);
246 return Vector3(x*p_v.x, y*p_v.y, z* p_v.z);
258 return Vector3(x/p_v.x, y/p_v.y, z/ p_v.z);
261 Vector3& Vector3::operator*=(real_t p_scalar) {
269 _FORCE_INLINE_
Vector3 operator*(real_t p_scalar,
const Vector3& p_vec) {
270 return p_vec * p_scalar;
273 Vector3 Vector3::operator*(real_t p_scalar)
const {
275 return Vector3( x*p_scalar, y*p_scalar, z*p_scalar);
278 Vector3& Vector3::operator/=(real_t p_scalar) {
286 Vector3 Vector3::operator/(real_t p_scalar)
const {
288 return Vector3( x/p_scalar, y/p_scalar, z/p_scalar);
291 Vector3 Vector3::operator-()
const {
297 bool Vector3::operator==(
const Vector3& p_v)
const {
299 return (x==p_v.x && y==p_v.y && z==p_v.z);
302 bool Vector3::operator!=(
const Vector3& p_v)
const {
304 return (x!=p_v.x || y!=p_v.y || z!=p_v.z);
307 bool Vector3::operator<(
const Vector3& p_v)
const {
319 bool Vector3::operator<=(
const Vector3& p_v)
const {
333 return p_a.cross(p_b);
336 _FORCE_INLINE_ real_t vec3_dot(
const Vector3& p_a,
const Vector3& p_b) {
341 real_t Vector3::length()
const {
347 return Math::sqrt(x2+y2+z2);
349 real_t Vector3::length_squared()
const {
359 void Vector3::normalize() {
372 Vector3 Vector3::normalized()
const {
379 Vector3 Vector3::inverse()
const {
381 return Vector3( 1.0/x, 1.0/y, 1.0/z );
384 void Vector3::zero() {
391 return p_vec - *
this * this->dot(p_vec);
395 return p_vec - *
this * this->dot(p_vec) * 2.0;