Oolite
Loading...
Searching...
No Matches
OOHPVector.m File Reference
#include "OOMaths.h"
Include dependency graph for OOHPVector.m:

Go to the source code of this file.

Functions

HPVector OORandomUnitHPVector (void)
HPVector OOHPVectorRandomSpatial (OOHPScalar maxLength)
HPVector OOHPVectorRandomRadial (OOHPScalar maxLength)
HPVector OOHPRandomPositionInBoundingBox (BoundingBox bb)
HPVector OORandomPositionInCylinder (HPVector centre1, OOHPScalar exclusion1, HPVector centre2, OOHPScalar exclusion2, OOHPScalar radius)
HPVector OORandomPositionInShell (HPVector centre, OOHPScalar inner, OOHPScalar outer)
HPVector OOProjectHPVectorToPlane (HPVector point, HPVector plane, HPVector normal)

Variables

const HPVector kZeroHPVector = { 0.0, 0.0, 0.0 }
const HPVector kBasisXHPVector = { 1.0, 0.0, 0.0 }
const HPVector kBasisYHPVector = { 0.0, 1.0, 0.0 }
const HPVector kBasisZHPVector = { 0.0, 0.0, 1.0 }
const HPVector2D kZeroHPVector2D = { 0.0, 0.0 }
const HPVector2D kBasisXHPVector2D = { 1.0, 0.0 }
const HPVector2D kBasisYHPVector2D = { 0.0, 1.0 }

Function Documentation

◆ OOHPRandomPositionInBoundingBox()

HPVector OOHPRandomPositionInBoundingBox ( BoundingBox bb)

Definition at line 93 of file OOHPVector.m.

94{
95 HPVector result;
96 result.x = (OOHPScalar)(bb.min.x + randf() * (bb.max.x - bb.min.x));
97 result.y = (OOHPScalar)(bb.min.y + randf() * (bb.max.y - bb.min.y));
98 result.z = (OOHPScalar)(bb.min.z + randf() * (bb.max.z - bb.min.z));
99 return result;
100}
double OOHPScalar
Definition OOMaths.h:51
float randf(void)
OOHPScalar x
Definition OOHPVector.h:36
OOHPScalar y
Definition OOHPVector.h:37
OOHPScalar z
Definition OOHPVector.h:38
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34

References BoundingBox::max, BoundingBox::min, randf(), HPVector::x, Vector::x, HPVector::y, Vector::y, HPVector::z, and Vector::z.

Here is the call graph for this function:

◆ OOHPVectorRandomRadial()

HPVector OOHPVectorRandomRadial ( OOHPScalar maxLength)

Definition at line 88 of file OOHPVector.m.

89{
91}
OOINLINE HPVector HPvector_multiply_scalar(HPVector v, OOHPScalar s) INLINE_CONST_FUNC
Definition OOHPVector.h:198
HPVector OORandomUnitHPVector(void)
Definition OOHPVector.m:62

References HPvector_multiply_scalar(), OORandomUnitHPVector(), and randf().

Referenced by Universe::spawnShip:, VectorStaticRandomDirectionAndLength(), and VectorStaticRandomDirectionAndLength().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOHPVectorRandomSpatial()

HPVector OOHPVectorRandomSpatial ( OOHPScalar maxLength)

Definition at line 75 of file OOHPVector.m.

76{
77 HPVector v;
78 OOHPScalar m;
79
80 do {
81 v = make_HPvector(randf() - 0.5f, randf() - 0.5f, randf() - 0.5f);
82 m = HPmagnitude2(v);
83 } while (m > 0.25); // We're confining to a sphere of radius 0.5 using the sqared magnitude; 0.5 squared is 0.25.
84
85 return HPvector_multiply_scalar(v, maxLength * 2.0); // 2.0 is to compensate for the 0.5-radius sphere.
86}
OOINLINE HPVector make_HPvector(OOHPScalar vx, OOHPScalar vy, OOHPScalar vz) INLINE_CONST_FUNC
Definition OOHPVector.h:149
OOINLINE OOHPScalar HPmagnitude2(HPVector vec) INLINE_CONST_FUNC
Definition OOHPVector.h:255

References HPmagnitude2(), HPvector_multiply_scalar(), make_HPvector(), and randf().

Referenced by Universe::addShipAt:withRole:withinRadius:, Universe::locationByCode:withSun:andPlanet:, OORandomPositionInCylinder(), OORandomPositionInShell(), ShipEntity(PureAI)::setDestinationToCurrentLocation, ShipEntity::updateTrackingCurve, VectorStaticRandom(), and VectorStaticRandom().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OOProjectHPVectorToPlane()

HPVector OOProjectHPVectorToPlane ( HPVector point,
HPVector plane,
HPVector normal )

Definition at line 126 of file OOHPVector.m.

127{
128 return HPvector_subtract(point, HPvector_multiply_scalar(normal, HPdot_product(HPvector_subtract(point, plane), normal)));
129}
OOINLINE OOHPScalar HPdot_product(HPVector first, HPVector second) INLINE_CONST_FUNC
Definition OOHPVector.h:317
OOINLINE HPVector HPvector_subtract(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:236

References HPdot_product(), HPvector_multiply_scalar(), and HPvector_subtract().

Referenced by Universe::locationByCode:withSun:andPlanet:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OORandomPositionInCylinder()

HPVector OORandomPositionInCylinder ( HPVector centre1,
OOHPScalar exclusion1,
HPVector centre2,
OOHPScalar exclusion2,
OOHPScalar radius )

Definition at line 102 of file OOHPVector.m.

103{
104 OOHPScalar exc12 = exclusion1 * exclusion1;
105 OOHPScalar exc22 = exclusion2 * exclusion2;
106 if (HPdistance(centre1, centre2) < (exclusion1 + exclusion2) * 1.2) {
107 OOLog(@"position.cylinder.error", @"Trying to generate cylinder position in range %f long with exclusions %f and %f", HPdistance(centre1, centre2), exclusion1, exclusion2);
108 }
109 HPVector result;
110 do {
111 result = HPvector_add(OOHPVectorInterpolate(centre1, centre2, randf()), OOHPVectorRandomSpatial(radius));
112 } while (HPdistance2(result, centre1) < exc12 || HPdistance2(result, centre2) < exc22);
113 return result;
114}
OOINLINE OOHPScalar HPdistance2(HPVector v1, HPVector v2) INLINE_CONST_FUNC
Definition OOHPVector.h:293
OOINLINE HPVector HPvector_add(HPVector a, HPVector b) INLINE_CONST_FUNC
Definition OOHPVector.h:213
OOINLINE OOHPScalar HPdistance(HPVector v1, HPVector v2) INLINE_CONST_FUNC
Definition OOHPVector.h:298
OOINLINE HPVector OOHPVectorInterpolate(HPVector a, HPVector b, OOHPScalar where) INLINE_CONST_FUNC
Definition OOHPVector.h:222
HPVector OOHPVectorRandomSpatial(OOHPScalar maxLength)
Definition OOHPVector.m:75
#define OOLog(class, format,...)
Definition OOLogging.h:84

References HPdistance(), HPdistance2(), HPvector_add(), OOHPVectorInterpolate(), OOHPVectorRandomSpatial(), OOLog, and randf().

Referenced by Universe::locationByCode:withSun:andPlanet:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OORandomPositionInShell()

HPVector OORandomPositionInShell ( HPVector centre,
OOHPScalar inner,
OOHPScalar outer )

Definition at line 116 of file OOHPVector.m.

117{
118 HPVector result;
119 OOHPScalar inner2 = inner * inner;
120 do {
121 result = HPvector_add(centre, OOHPVectorRandomSpatial(outer));
122 } while (HPdistance2(result, centre) < inner2);
123 return result;
124}

References HPdistance2(), HPvector_add(), and OOHPVectorRandomSpatial().

Referenced by Universe::locationByCode:withSun:andPlanet:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OORandomUnitHPVector()

HPVector OORandomUnitHPVector ( void )

Definition at line 62 of file OOHPVector.m.

63{
64 HPVector v;
65 OOHPScalar m;
66
67 do {
68 v = make_HPvector(randf() - 0.5f, randf() - 0.5f, randf() - 0.5f);
69 m = HPmagnitude2(v);
70 } while (m > 0.25 || m == 0.0); // We're confining to a sphere of radius 0.5 using the sqared magnitude; 0.5 squared is 0.25.
71
72 return HPvector_normal(v);
73}
OOINLINE HPVector HPvector_normal(HPVector vec) INLINE_CONST_FUNC
Definition OOHPVector.h:288

References HPmagnitude2(), HPvector_normal(), make_HPvector(), and randf().

Referenced by OOHPVectorRandomRadial(), VectorStaticRandomDirection(), and VectorStaticRandomDirection().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ kBasisXHPVector

const HPVector kBasisXHPVector = { 1.0, 0.0, 0.0 }

Definition at line 28 of file OOHPVector.m.

28{ 1.0, 0.0, 0.0 };

◆ kBasisXHPVector2D

const HPVector2D kBasisXHPVector2D = { 1.0, 0.0 }

Definition at line 33 of file OOHPVector.m.

33{ 1.0, 0.0 };

◆ kBasisYHPVector

const HPVector kBasisYHPVector = { 0.0, 1.0, 0.0 }

Definition at line 29 of file OOHPVector.m.

29{ 0.0, 1.0, 0.0 };

◆ kBasisYHPVector2D

const HPVector2D kBasisYHPVector2D = { 0.0, 1.0 }

Definition at line 34 of file OOHPVector.m.

34{ 0.0, 1.0 };

◆ kBasisZHPVector

const HPVector kBasisZHPVector = { 0.0, 0.0, 1.0 }

Definition at line 30 of file OOHPVector.m.

30{ 0.0, 0.0, 1.0 };

◆ kZeroHPVector

◆ kZeroHPVector2D

const HPVector2D kZeroHPVector2D = { 0.0, 0.0 }

Definition at line 32 of file OOHPVector.m.

32{ 0.0, 0.0 };