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

Go to the source code of this file.

Functions

Vector OORandomUnitVector (void)
Vector OOVectorRandomSpatial (OOScalar maxLength)
Vector OOVectorRandomRadial (OOScalar maxLength)
Vector OORandomPositionInBoundingBox (BoundingBox bb)

Variables

const Vector kZeroVector = { 0.0f, 0.0f, 0.0f }
const Vector kBasisXVector = { 1.0f, 0.0f, 0.0f }
const Vector kBasisYVector = { 0.0f, 1.0f, 0.0f }
const Vector kBasisZVector = { 0.0f, 0.0f, 1.0f }
const Vector2D kZeroVector2D = { 0.0f, 0.0f }
const Vector2D kBasisXVector2D = { 1.0f, 0.0f }
const Vector2D kBasisYVector2D = { 0.0f, 1.0f }
const BoundingBox kZeroBoundingBox = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }

Function Documentation

◆ OORandomPositionInBoundingBox()

Vector OORandomPositionInBoundingBox ( BoundingBox bb)

Definition at line 107 of file OOVector.m.

108{
109 Vector result;
110 result.x = bb.min.x + randf() * (bb.max.x - bb.min.x);
111 result.y = bb.min.y + randf() * (bb.max.y - bb.min.y);
112 result.z = bb.min.z + randf() * (bb.max.z - bb.min.z);
113 return result;
114}
float y
float x
float randf(void)
OOScalar x
Definition OOVector.h:32
OOScalar y
Definition OOVector.h:33
OOScalar z
Definition OOVector.h:34

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

Referenced by ShipEntity::becomeExplosion, and ShipEntity::releaseCargoPodsDebris.

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

◆ OORandomUnitVector()

Vector OORandomUnitVector ( void )

Definition at line 76 of file OOVector.m.

77{
78 Vector v;
79 float m;
80
81 do {
82 v = make_vector(randf() - 0.5f, randf() - 0.5f, randf() - 0.5f);
83 m = magnitude2(v);
84 } while (m > 0.25f || m == 0.0f); // We're confining to a sphere of radius 0.5 using the sqared magnitude; 0.5 squared is 0.25.
85
86 return vector_normal(v);
87}
OOINLINE Vector make_vector(OOScalar vx, OOScalar vy, OOScalar vz) INLINE_CONST_FUNC
Definition OOVector.h:149
OOINLINE OOScalar magnitude2(Vector vec) INLINE_CONST_FUNC
Definition OOVector.h:237
OOINLINE Vector vector_normal(Vector vec) INLINE_CONST_FUNC
Definition OOVector.h:270

References magnitude2(), make_vector(), randf(), and vector_normal().

Referenced by OOParticleSystem::initWithPosition:velocity:count:minSpeed:maxSpeed:duration:baseColor:, and OOVectorRandomRadial().

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

◆ OOVectorRandomRadial()

Vector OOVectorRandomRadial ( OOScalar maxLength)

Definition at line 102 of file OOVector.m.

103{
104 return vector_multiply_scalar(OORandomUnitVector(), randf() * maxLength);
105}
OOINLINE Vector vector_multiply_scalar(Vector v, OOScalar s) INLINE_CONST_FUNC
Definition OOVector.h:180
Vector OORandomUnitVector(void)
Definition OOVector.m:76

References OORandomUnitVector(), randf(), and vector_multiply_scalar().

Referenced by HeadUpDisplay(Private)::drawScanner:.

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

◆ OOVectorRandomSpatial()

Vector OOVectorRandomSpatial ( OOScalar maxLength)

Definition at line 89 of file OOVector.m.

90{
91 Vector v;
92 float m;
93
94 do {
95 v = make_vector(randf() - 0.5f, randf() - 0.5f, randf() - 0.5f);
96 m = magnitude2(v);
97 } while (m > 0.25f); // We're confining to a sphere of radius 0.5 using the sqared magnitude; 0.5 squared is 0.25.
98
99 return vector_multiply_scalar(v, maxLength * 2.0f); // 2.0 is to compensate for the 0.5-radius sphere.
100}

References magnitude2(), make_vector(), randf(), and vector_multiply_scalar().

Referenced by ShipEntity(PureAI)::setDestinationToJinkPosition.

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

Variable Documentation

◆ kBasisXVector

const Vector kBasisXVector = { 1.0f, 0.0f, 0.0f }

Definition at line 28 of file OOVector.m.

28{ 1.0f, 0.0f, 0.0f };

◆ kBasisXVector2D

const Vector2D kBasisXVector2D = { 1.0f, 0.0f }

Definition at line 33 of file OOVector.m.

33{ 1.0f, 0.0f };

◆ kBasisYVector

const Vector kBasisYVector = { 0.0f, 1.0f, 0.0f }

Definition at line 29 of file OOVector.m.

29{ 0.0f, 1.0f, 0.0f };

◆ kBasisYVector2D

const Vector2D kBasisYVector2D = { 0.0f, 1.0f }

Definition at line 34 of file OOVector.m.

34{ 0.0f, 1.0f };

◆ kBasisZVector

const Vector kBasisZVector = { 0.0f, 0.0f, 1.0f }

Definition at line 30 of file OOVector.m.

30{ 0.0f, 0.0f, 1.0f };

◆ kZeroBoundingBox

const BoundingBox kZeroBoundingBox = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }

Definition at line 36 of file OOVector.m.

36{ { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } };

Referenced by bounding_box_reset(), OODrawable::boundingBox, and OOMesh::init.

◆ kZeroVector

const Vector kZeroVector = { 0.0f, 0.0f, 0.0f }

Definition at line 27 of file OOVector.m.

27{ 0.0f, 0.0f, 0.0f };

Referenced by ShipEntity::behaviour_attack_broadside:, ShipEntity::behaviour_attack_fly_from_target:, ShipEntity::behaviour_attack_target:, ShipEntity::behaviour_running_defense:, OOMesh(Private)::calculateVertexNormalsAndTangentsWithFaceRefs:, OOMesh(Private)::calculateVertexTangentsWithFaceRefs:, OOMesh(Private)::checkNormalsAndAdjustWinding, ShipEntity::collideWithShip:, HeadUpDisplay(Private)::drawDirectionCue:, OOECMBlastEntity::drawImmediate:translucent:, Universe::drawUniverse, PlayerEntity::engageAutopilotToStation:, ShipEntity::fireMissileWithIdentifier:andTarget:, Universe::firstEntityTargetedByPlayerPrecisely, PlayerEntity::getDestroyedBy:damageType:, OOMesh(Private)::getNormal:andTangent:forVertex:inSmoothGroup:, ShipEntity::getWeaponOffsetFrom:withKey:inMode:, HeadUpDisplay::hudRotateViewpointForVirtualDepth, OOMesh::init, OOSoundSource::init, Octree::isHitByLine:v1:, PlayerEntity::leaveDock:, PlayerEntity::leaveWitchspace, ShipEntity::missileTrackPrimaryTarget:, OOMatrixFromBasisVectors(), PlayerEntity(OOPrivate)::performInFlightUpdates:, PlayerShipSetCustomView(), PlayerShipSetCustomView(), StationEntity::portUpVectorForShip:, ShipEntity::positionOffsetForAlignment:, ShipEntity::positionOffsetForShipInRotationToAlignment, Octree::randomPoint, ShipEntity(Private)::refreshEscortPositions, OOExhaustPlumeEntity::resetPlume, PlayerEntity::setCustomViewDataFromDictionary:withScaling:, PlayerEntity::setDefaultViewOffsets, ShipEntity::setEvasiveJink:, PlayerEntity::setUpAndConfirmOK:saveGame:, OOVisualEffectEntity::setUpVisualEffectFromDictionary:, SystemSetPopulator(), SystemSetPopulator(), ShipEntity::trackDestination:retreat:, ShipEntity::trackPrimaryTarget:retreat:, ShipEntity::trackSideTarget:leftside:, ShipEntity::update:, OOShipRegistry(OODataLoader)::validateNewStyleFlasherDeclaration:forShip:fatalError:, OOShipRegistry(OODataLoader)::validateNewStyleStandardSubentityDeclaration:forShip:fatalError:, vector_flip(), vector_normal(), Verify_Vector(), PlayerEntity::viewpointOffset, PlayerEntity::weaponViewOffset, and ShipEntity::witchspaceLeavingEffects.

◆ kZeroVector2D

const Vector2D kZeroVector2D = { 0.0f, 0.0f }

Definition at line 32 of file OOVector.m.

32{ 0.0f, 0.0f };