28#ifndef INCLUDED_OOMATHS_h
29 #error Do not include OOVector.h directly; include OOMaths.h.
33#ifndef OOMATHS_EXTERNAL_VECTOR_TYPES
43typedef struct Vector2D
67#if !OOMATHS_STANDALONE
86#define vector_between(a, b) vector_subtract(b, a)
133NSString *VectorDescription(Vector vector);
136@interface OONativeVector: NSObject
141- (id) initWithVector:(Vector)vect;
148#if OOMATHS_OPENGL_INTEGRATION
150#define GLVertexOOVector(v) do { Vector v_ = v; glVertex3f(v_.x, v_.y, v_.z); } while (0)
151#define GLTranslateOOVector(v) do { Vector v_ = v; OOGL(glTranslatef(v_.x, v_.y, v_.z)); } while (0)
207OOINLINE Vector vector_add(Vector a, Vector b)
219 return make_vector(OOLerp(a.x, b.x, where),
220 OOLerp(a.y, b.y, where),
221 OOLerp(a.z, b.z, where));
227 return make_vector(a.x + b.x * where,
233OOINLINE Vector vector_subtract(Vector a, Vector b)
243OOINLINE Vector vector_flip(Vector v)
249OOINLINE bool vector_equal(Vector a, Vector b)
251 return a.x == b.x && a.y == b.y && a.z == b.z;
257 return vec.x * vec.x + vec.
y * vec.
y + vec.z * vec.z;
263 return sqrt(magnitude2(vec));
267OOINLINE Vector vector_normal_or_fallback(Vector vec, Vector fallback)
270 if (
EXPECT_NOT(mag2 == 0.0f))
return fallback;
271 return vector_multiply_scalar(vec, 1.0f / sqrt(mag2));
275OOINLINE Vector vector_normal_or_xbasis(Vector vec)
281OOINLINE Vector vector_normal_or_ybasis(Vector vec)
287OOINLINE Vector vector_normal_or_zbasis(Vector vec)
293OOINLINE Vector vector_normal(Vector vec)
295 return vector_normal_or_fallback(vec,
kZeroVector);
301 return magnitude2(vector_subtract(v1, v2));
307 return magnitude(vector_subtract(v1, v2));
311OOINLINE Vector true_cross_product(Vector first, Vector second)
314 result.x = (first.y * second.z) - (first.z * second.y);
315 result.y = (first.z * second.x) - (first.x * second.z);
316 result.z = (first.x * second.y) - (first.y * second.x);
321OOINLINE Vector cross_product(Vector first, Vector second)
323 return vector_normal(true_cross_product(first, second));
329 return (a.x * b.x) + (a.
y * b.
y) + (a.z * b.z);
335 return dot_product(first, true_cross_product(second, third));
339OOINLINE Vector normal_to_surface(Vector v1, Vector v2, Vector v3)
342 d0 = vector_subtract(v2, v1);
343 d1 = vector_subtract(v3, v2);
344 return cross_product(d0, d1);
#define ALWAYS_INLINE_FUNC
#define INLINE_CONST_FUNC
const Vector2D kBasisYVector2D
const Vector2D kZeroVector2D
const Vector kBasisYVector
Vector OORandomUnitVector(void)
const Vector2D kBasisXVector2D
const Vector kBasisZVector
const Vector kBasisXVector
Vector OOVectorRandomRadial(OOScalar maxLength)
Vector OOVectorRandomSpatial(OOScalar maxLength)