29#ifndef INCLUDED_OOMATHS_h
30 #error Do not include OOHPVector.h directly; include OOMaths.h.
34#ifndef OOMATHS_EXTERNAL_VECTOR_TYPES
36typedef struct HPVector
44typedef struct HPVector2D
71#if !OOMATHS_STANDALONE
93#define HPvector_between(a, b) HPvector_subtract(b, a)
137OOINLINE HPVector HPnormal_to_surface(HPVector v1, HPVector v2, HPVector v3)
CONST_FUNC;
140NSString *HPVectorDescription(HPVector vector);
141NSArray *ArrayFromHPVector(HPVector vector);
145#if OOMATHS_OPENGL_INTEGRATION
147#define GLVertexOOHPVector(v) do { HPVector v_ = v; glVertex3f(v_.x, v_.y, v_.z); } while (0)
148#define GLTranslateOOHPVector(v) do { HPVector v_ = v; OOGL(glTranslatef(v_.x, v_.y, v_.z)); } while (0)
172OOINLINE HPVector vectorToHPVector(Vector v) {
180OOINLINE Vector HPVectorToVector(HPVector v) {
219OOINLINE HPVector HPvector_add(HPVector a, HPVector b)
231 return make_HPvector(OOLerpd(a.x, b.x, where),
232 OOLerpd(a.y, b.y, where),
233 OOLerpd(a.z, b.z, where));
239 return make_HPvector(a.x + b.x * where,
245OOINLINE HPVector HPvector_subtract(HPVector a, HPVector b)
255OOINLINE HPVector HPvector_flip(HPVector v)
261OOINLINE bool HPvector_equal(HPVector a, HPVector b)
263 return a.x == b.x && a.y == b.y && a.z == b.z;
269 return vec.x * vec.x + vec.y * vec.y + vec.z * vec.z;
275 return sqrt(HPmagnitude2(vec));
279OOINLINE HPVector HPvector_normal_or_fallback(HPVector vec, HPVector fallback)
283 return HPvector_multiply_scalar(vec, 1.0 / sqrt(mag2));
287OOINLINE HPVector HPvector_normal_or_xbasis(HPVector vec)
293OOINLINE HPVector HPvector_normal_or_ybasis(HPVector vec)
299OOINLINE HPVector HPvector_normal_or_zbasis(HPVector vec)
305OOINLINE HPVector HPvector_normal(HPVector vec)
313 return HPmagnitude2(HPvector_subtract(v1, v2));
319 return HPmagnitude(HPvector_subtract(v1, v2));
323OOINLINE HPVector HPtrue_cross_product(HPVector first, HPVector second)
326 result.x = (first.y * second.z) - (first.z * second.y);
327 result.y = (first.z * second.x) - (first.x * second.z);
328 result.z = (first.x * second.y) - (first.y * second.x);
333OOINLINE HPVector HPcross_product(HPVector first, HPVector second)
335 return HPvector_normal(HPtrue_cross_product(first, second));
341 return (a.x * b.x) + (a.y * b.y) + (a.z * b.z);
347 return HPdot_product(first, HPtrue_cross_product(second, third));
351OOINLINE HPVector HPnormal_to_surface(HPVector v1, HPVector v2, HPVector v3)
354 d0 = HPvector_subtract(v2, v1);
355 d1 = HPvector_subtract(v3, v2);
356 return HPcross_product(d0, d1);
#define ALWAYS_INLINE_FUNC
#define INLINE_CONST_FUNC
const HPVector kBasisXHPVector
HPVector OOHPVectorRandomRadial(OOHPScalar maxLength)
HPVector OOProjectHPVectorToPlane(HPVector point, HPVector plane, HPVector normal)
HPVector OORandomPositionInShell(HPVector centre, OOHPScalar inner, OOHPScalar outer)
const HPVector2D kBasisYHPVector2D
const HPVector kBasisYHPVector
const HPVector kZeroHPVector
HPVector OORandomUnitHPVector(void)
const HPVector2D kBasisXHPVector2D
HPVector OOHPVectorRandomSpatial(OOHPScalar maxLength)
const HPVector2D kZeroHPVector2D
const HPVector kBasisZHPVector
HPVector OORandomPositionInCylinder(HPVector centre1, OOHPScalar exclusion1, HPVector centre2, OOHPScalar exclusion2, OOHPScalar radius)