UFO: Alien Invasion
|
math primitives More...
Go to the source code of this file.
Macros | |
#define | logf(x) ((float)log((double)(x))) |
#define | RT2 0.70710678118654752440084436210485 |
cos 45 degree More... | |
#define | DIRECTION_EAST 0 |
#define | DIRECTION_WEST 1 |
#define | DIRECTION_NORTH 2 |
#define | DIRECTION_SOUTH 3 |
#define | DIRECTION_NORTHEAST 4 |
#define | DIRECTION_SOUTHWEST 5 |
#define | DIRECTION_NORTHWEST 6 |
#define | DIRECTION_SOUTHEAST 7 |
Functions | |
int | AngleToDir (int angle) |
Returns the index of array directionAngles[DIRECTIONS] whose value is the closest to angle. More... | |
vec_t | Q_rint (const vec_t in) |
Round to nearest integer. More... | |
double | GetDistanceOnGlobe (const vec2_t pos1, const vec2_t pos2) |
Calculate distance on the geoscape. More... | |
vec_t | ColorNormalize (const vec3_t in, vec3_t out) |
bool | VectorNearer (const vec3_t v1, const vec3_t v2, const vec3_t comp) |
Checks whether the given vector v1 is closer to comp as the vector v2 . More... | |
vec_t | VectorNormalize2 (const vec3_t v, vec3_t out) |
Calculated the normal vector for a given vec3_t. More... | |
void | VectorMA (const vec3_t veca, const float scale, const vec3_t vecb, vec3_t outVector) |
Sets vector_out (vc) to vevtor1 (va) + scale * vector2 (vb) More... | |
void | VectorClampMA (vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc) |
void | MatrixMultiply (const vec3_t a[3], const vec3_t b[3], vec3_t c[3]) |
Multiply 3*3 matrix by 3*3 matrix. More... | |
void | GLMatrixAssemble (const vec3_t origin, const vec3_t angles, float *matrix) |
Builds an opengl translation and rotation matrix. More... | |
void | GLMatrixMultiply (const float a[16], const float b[16], float c[16]) |
Multiply 4*4 matrix by 4*4 matrix. More... | |
void | GLVectorTransform (const float m[16], const vec4_t in, vec4_t out) |
Multiply 4*4 matrix by 4d vector. More... | |
void | GLPositionTransform (const float m[16], const vec3_t in, vec3_t out) |
Transform position (xyz) vector by OpenGL rules. More... | |
void | VectorRotate (vec3_t m[3], const vec3_t va, vec3_t vb) |
Rotate a vector with a rotation matrix. More... | |
int | VectorCompareEps (const vec3_t v1, const vec3_t v2, float epsilon) |
Compare two vectors that may have an epsilon difference but still be the same vectors. More... | |
vec_t | VectorLength (const vec3_t v) |
Calculate the length of a vector. More... | |
void | VectorMix (const vec3_t v1, const vec3_t v2, float mix, vec3_t out) |
Calculate a position on v1 v2 line. More... | |
void | VectorInverse (vec3_t v) |
Inverse a vector. More... | |
void | VectorMidpoint (const vec3_t point1, const vec3_t point2, vec3_t midpoint) |
Calculates the midpoint between two vectors. More... | |
float | VectorAngleBetween (const vec3_t vec1, const vec3_t vec2) |
Calculates the angle (in radians) between the two given vectors. More... | |
int | Q_log2 (int val) |
float | frand (void) |
Return random values between 0 and 1. More... | |
float | crand (void) |
Return random values between -1 and 1. More... | |
void | gaussrand (float *gauss1, float *gauss2) |
generate two gaussian distributed random numbers with median at 0 and stdev of 1 More... | |
void | CalculateMinsMaxs (const vec3_t angles, const AABB &relBox, const vec3_t origin, AABB &absBox) |
Calculates the bounding box in absolute coordinates, also for rotating objects. WARNING: do not use this for angles other than 90, 180 or 270 !! More... | |
void | VectorCreateRotationMatrix (const vec3_t angles, vec3_t matrix[3]) |
void | VectorRotatePoint (vec3_t point, vec3_t matrix[3]) |
void | AngleVectors (const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up) |
Create the rotation matrix in order to rotate something. More... | |
bool | FrustumVis (const vec3_t origin, int dir, const vec3_t point) |
Checks whether a point is visible from a given position. More... | |
static void | ProjectPointOnPlane (vec3_t dst, const vec3_t point, const vec3_t normal) |
Projects a point on a plane passing through the origin. More... | |
static float | Q_rsqrtApprox (const float number) |
vec_t | VectorNormalize (vec3_t v) |
Calculate unit vector for a given vec3_t. More... | |
void | VectorNormalizeFast (vec3_t v) |
fast vector normalize routine that does not check to make sure that length != 0, nor does it return length More... | |
void | PerpendicularVector (vec3_t dst, const vec3_t src) |
Finds a vector perpendicular to the source vector. More... | |
void | CrossProduct (const vec3_t v1, const vec3_t v2, vec3_t cross) |
binary operation on vectors in a three-dimensional space More... | |
static void | R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3]) |
void | RotatePointAroundVector (vec3_t dst, const vec3_t dir, const vec3_t point, float degrees) |
Rotate a point around a given vector. More... | |
void | PolarToVec (const vec2_t a, vec3_t v) |
Converts longitude and latitude to a 3D vector in Euclidean coordinates. More... | |
void | VecToPolar (const vec3_t v, vec2_t a) |
Converts vector coordinates into polar coordinates. More... | |
void | VecToAngles (const vec3_t value1, vec3_t angles) |
Converts a vector to an angle vector. More... | |
bool | Q_IsPowerOfTwo (int i) |
Checks whether i is power of two value. More... | |
float | LerpAngle (float a2, float a1, float frac) |
Returns the angle resulting from turning fraction * angle from angle1 to angle2. More... | |
float | AngleNormalize360 (float angle) |
returns angle normalized to the range [0 <= angle < 360] More... | |
float | AngleNormalize180 (float angle) |
returns angle normalized to the range [-180 < angle <= 180] More... | |
void | VectorCalcMinsMaxs (const vec3_t center, const vec3_t size, vec3_t mins, vec3_t maxs) |
Calculates a bounding box from a center and a size. More... | |
void | ClearBounds (vec3_t mins, vec3_t maxs) |
Sets mins and maxs to their starting points before using AddPointToBounds. More... | |
void | AddPointToBounds (const vec3_t v, vec3_t mins, vec3_t maxs) |
If the point is outside the box defined by mins and maxs, expand the box to accommodate it. Sets mins and maxs to their new values. More... | |
void | TangentVectors (const vec3_t normal, const vec3_t sdir, const vec3_t tdir, vec4_t tangent, vec3_t binormal) |
Projects the normalized directional vectors on to the normal's plane. The fourth component of the resulting tangent vector represents sidedness. More... | |
void | Orthogonalize (vec3_t out, const vec3_t in) |
Grahm-Schmidt orthogonalization. More... | |
void | MatrixTranspose (const vec3_t m[3], vec3_t t[3]) |
Transposes m and stores the result in t . More... | |
bool | RayIntersectAABB (const vec3_t start, const vec3_t end, const AABB &aabb) |
Variables | |
const vec2_t | vec2_origin = { 0, 0 } |
const vec3_t | vec3_origin = { 0, 0, 0 } |
const vec4_t | vec4_origin = { 0, 0, 0, 0 } |
const pos3_t | pos3_origin = { 0, 0, 0 } |
const vec4_t | dvecs [PATHFINDING_DIRECTIONS] |
const float | dvecsn [CORE_DIRECTIONS][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1}, {RT2, RT2}, {-RT2, -RT2}, {-RT2, RT2}, {RT2, -RT2} } |
const float | directionAngles [CORE_DIRECTIONS] = { 0, 180.0f, 90.0f, 270.0f, 45.0f, 225.0f, 135.0f, 315.0f } |
const byte | dvright [CORE_DIRECTIONS] |
const byte | dvleft [CORE_DIRECTIONS] |
math primitives
Definition in file mathlib.cpp.
#define DIRECTION_EAST 0 |
Definition at line 107 of file mathlib.cpp.
#define DIRECTION_NORTH 2 |
Definition at line 109 of file mathlib.cpp.
#define DIRECTION_NORTHEAST 4 |
Definition at line 111 of file mathlib.cpp.
#define DIRECTION_NORTHWEST 6 |
Definition at line 113 of file mathlib.cpp.
#define DIRECTION_SOUTH 3 |
Definition at line 110 of file mathlib.cpp.
#define DIRECTION_SOUTHEAST 7 |
Definition at line 114 of file mathlib.cpp.
#define DIRECTION_SOUTHWEST 5 |
Definition at line 112 of file mathlib.cpp.
#define DIRECTION_WEST 1 |
Definition at line 108 of file mathlib.cpp.
#define logf | ( | x | ) | ((float)log((double)(x))) |
Definition at line 31 of file mathlib.cpp.
Referenced by gaussrand().
#define RT2 0.70710678118654752440084436210485 |
cos 45 degree
Definition at line 40 of file mathlib.cpp.
If the point is outside the box defined by mins and maxs, expand the box to accommodate it. Sets mins and maxs to their new values.
Definition at line 1042 of file mathlib.cpp.
References i.
Referenced by SL_BSPSlice(), and WindingBounds().
float AngleNormalize180 | ( | float | angle | ) |
returns angle normalized to the range [-180 < angle <= 180]
[in] | angle | Angle |
Definition at line 1004 of file mathlib.cpp.
References AngleNormalize360().
float AngleNormalize360 | ( | float | angle | ) |
returns angle normalized to the range [0 <= angle < 360]
[in] | angle | Angle |
Definition at line 995 of file mathlib.cpp.
References int().
Referenced by AngleNormalize180().
Returns the index of array directionAngles[DIRECTIONS] whose value is the closest to angle.
[in] | angle | The angle (in degrees) which is tested. |
Definition at line 130 of file mathlib.cpp.
References Com_Printf(), and CORE_DIRECTIONS.
Referenced by AIL_positionwander(), G_Actor2x2Spawn(), G_ActorSpawn(), G_ClientShoot(), G_GetImpactDirection(), G_InitCamera(), and fireDef_s::getShotOrigin().
Create the rotation matrix in order to rotate something.
[in] | angles | Contains the three angles PITCH, YAW and ROLL (in degree) of rotation around idle frame ({0, 1, 0}, {0, 0, 1} ,{1, 0, 0}) (in this order!) |
[out] | forward | return the first line of the rotation matrix. |
[out] | right | return the second line of the rotation matrix. |
[out] | up | return the third line of the rotation matrix. |
right
). Exemple : to rotate v2 into v : AngleVectors(angles, m[0], m[1], m[2]); VectorInverse(m[1]); VectorRotate(m, v2, v); Definition at line 631 of file mathlib.cpp.
References PITCH, ROLL, torad, and YAW.
Referenced by BuildLights(), CL_CameraMove(), CM_HintedTransformedBoxTrace(), Door_SlidingUse(), G_ShootGrenade(), G_ShootSingle(), GLMatrixAssemble(), LET_SlideDoor(), R_CullMeshModel(), R_GetSpriteVectors(), R_SetupFrustum(), SEQ_SetCamera(), SP_worldspawn(), U2M_SetDefaultConfigValues(), and VectorCreateRotationMatrix().
void CalculateMinsMaxs | ( | const vec3_t | angles, |
const AABB & | relBox, | ||
const vec3_t | origin, | ||
AABB & | absBox | ||
) |
Calculates the bounding box in absolute coordinates, also for rotating objects. WARNING: do not use this for angles other than 90, 180 or 270 !!
Definition at line 546 of file mathlib.cpp.
References AABB::getCenter(), m, AABB::maxs, AABB::set(), AABB::shift(), VectorAdd, VectorCreateRotationMatrix(), VectorNotEmpty, VectorRotate(), and VectorSubtract.
Referenced by CM_GetInlineModelAABB(), Grid_RecalcRouting(), LE_AddEdictHighlight(), and SV_LinkEdict().
Sets mins and maxs to their starting points before using AddPointToBounds.
Definition at line 1032 of file mathlib.cpp.
Referenced by WindingBounds().
Definition at line 190 of file mathlib.cpp.
References EQUAL, f, VectorClear, and VectorScale.
Referenced by BuildLights(), SP_worldspawn(), and U2M_SetDefaultConfigValues().
float crand | ( | void | ) |
Return random values between -1 and 1.
Definition at line 517 of file mathlib.cpp.
Referenced by AI_HideNeeded(), AIR_PilotSurvivedCrash(), CL_ParticleFunction(), G_ClientShoot(), G_ShootSingle(), gaussrand(), LE_AddGrenade(), and Weather::update().
binary operation on vectors in a three-dimensional space
[in] | v1 | directional vector |
[in] | v2 | directional vector |
[out] | cross | output |
Definition at line 820 of file mathlib.cpp.
Referenced by AddBrushBevels(), AIR_GetDestinationWhilePursuing(), BaseWindingForPlane(), Check_EdgeEdgeIntersection(), GEO_AngleOfPath2D(), GEO_AngleOfPath3D(), GEO_CalcLine(), PlaneFromPoints(), R_GenerateGrass(), R_GetSpriteVectors(), R_ModCalcNormalsAndTangents(), R_ModCalcUniqueNormalsAndTangents(), R_PlantGrass(), RotatePointAroundVector(), TangentVectors(), TryMergeWinding(), and WindingArea().
float frand | ( | void | ) |
Return random values between 0 and 1.
Definition at line 506 of file mathlib.cpp.
Referenced by AI_CheckUsingDoor(), AI_CivilianCalcActionScore(), AI_FighterCalcActionScore(), AI_FindBestFiredef(), AI_InitPlayer(), AI_PanicCalcActionScore(), AI_SetStats(), AIRFIGHT_BaseShoot(), AIRFIGHT_ExecuteActions(), AIRFIGHT_InstallationShoot(), AIRFIGHT_MissTarget(), AM_CheckFire(), AM_FillTeamFromBattleParams(), AM_UpdateSurivorsAfterBattle(), B_BuildFromTemplate(), B_Destroy_AntimaterStorage_f(), Weather::changeTo(), CHRSH_CharGenAbilitySkills(), CL_AddMapParticle(), CL_ParticleFunction(), CL_RunMapParticles(), CP_BaseAttackChooseBase(), CP_CheckNewMissionDetectedOnGeoscape(), CP_ChooseNation(), CP_CreateBattleParameters(), CP_GetRandomPosOnGeoscape(), CP_GetRandomPosOnGeoscapeWithParameters(), CP_InterceptChooseInstallation(), CP_InterceptMissionSet(), CP_MissionChooseUFO(), CP_ReconMissionChoose(), CP_ReconMissionNewGroundMission(), CP_SelectNewMissionType(), CP_SpawnNewMissions(), Date_Random(), E_InitialEmployees(), InventoryInterface::EquipActorNormal(), G_GetStartingTeam(), G_MoraleBehaviour(), G_MoraleStopPanic(), G_MoraleStopRage(), BodyData::getHitBodyPart(), BodyData::getRandomBodyPart(), TerrainDefs::getWeather(), ReactionFire::isEnemy(), MIS_IsSpawnedFromGround(), R_AddClump(), R_GenerateGrass(), R_PlantGrass(), RADAR_CheckUFOSensored(), Weather::setDefaults(), Weather::update(), and UR_DialogInitSell_f().
Checks whether a point is visible from a given position.
[in] | origin | Origin to test from |
[in] | dir | Direction to test into |
[in] | point | This is the point we want to check the visibility for |
Definition at line 666 of file mathlib.cpp.
References DIRECTIONS, dvecsn, and VectorNormalizeFast().
Referenced by G_FrustumVis().
void gaussrand | ( | float * | gauss1, |
float * | gauss2 | ||
) |
generate two gaussian distributed random numbers with median at 0 and stdev of 1
[out] | gauss1 | First gaussian distributed random number |
[out] | gauss2 | Second gaussian distributed random number |
Definition at line 529 of file mathlib.cpp.
Referenced by G_ShootGrenade(), G_ShootSingle(), and UFO_SetRandomDestAround().
Calculate distance on the geoscape.
[in] | pos1 | Position at the start. |
[in] | pos2 | Position at the end. |
Definition at line 171 of file mathlib.cpp.
Referenced by AB_SetAlienBasePosition(), AB_UpdateStealthForOneBase(), AIR_AircraftHasEnoughFuel(), AIR_AircraftHasEnoughFuelOneWay(), AIR_GetDestinationWhilePursuing(), AIR_SortByDistance(), AIRFIGHT_BaseShoot(), AIRFIGHT_ChooseWeapon(), AIRFIGHT_InstallationShoot(), AIRFIGHT_MissTarget(), AIRFIGHT_ProjectileReachedTarget(), BDEF_AutoTarget(), CL_DisplayPopupInterceptMission(), CP_DrawXVIOverlayPixel(), GEO_GetAircraftText(), GEO_PositionCloseToBase(), PR_CalculateTotalFrames(), RADAR_AddDetectedUFOToEveryRadar(), RADAR_CheckRadarSensored(), RADAR_CheckUFOSensored(), TR_TransferStart(), UFO_CampaignCheckEvents(), UFO_SearchAircraftTarget(), UFO_UpdateAlienInterestForOneBase(), UFO_UpdateAlienInterestForOneInstallation(), and US_GetClosestStoredUFO().
Builds an opengl translation and rotation matrix.
origin | The translation vector |
angles | The angle vector that is used to calculate the rotation part of the matrix |
matrix | The resulting matrix, must be of dimension 16 |
Definition at line 325 of file mathlib.cpp.
References AngleVectors(), and VectorInverse().
Referenced by CL_ActorGetMuzzle(), and R_CalcTransform().
void GLMatrixMultiply | ( | const float | a[16], |
const float | b[16], | ||
float | c[16] | ||
) |
Multiply 4*4 matrix by 4*4 matrix.
[out] | c | The result of the multiplication matrix = a * b (not the same as b * a as matrix multiplication is not commutative) |
[in] | a | First matrix. |
[in] | b | Second matrix. |
Definition at line 350 of file mathlib.cpp.
References i.
Referenced by CL_ActorGetMuzzle(), and R_CalcTransform().
Transform position (xyz) vector by OpenGL rules.
[out] | out | the result of the multiplication = m * in . |
[in] | m | 4*4 matrix |
[in] | in | 3d vector. |
Definition at line 380 of file mathlib.cpp.
References i.
Referenced by R_EnableModelLights(), and R_EnableWorldLights().
Multiply 4*4 matrix by 4d vector.
[out] | out | the result of the multiplication = m * in . |
[in] | m | 4*4 matrix |
[in] | in | 4d vector. |
Definition at line 366 of file mathlib.cpp.
References i.
Referenced by R_InitModelProgram(), and R_UseModelProgram().
float LerpAngle | ( | float | a2, |
float | a1, | ||
float | frac | ||
) |
Returns the angle resulting from turning fraction * angle from angle1 to angle2.
Definition at line 981 of file mathlib.cpp.
Multiply 3*3 matrix by 3*3 matrix.
[out] | c | The result of the multiplication matrix = a * b (not the same as b * a !) |
[in] | a | First matrix. |
[in] | b | Second matrix. |
Definition at line 304 of file mathlib.cpp.
Transposes m
and stores the result in t
.
[in] | m | The matrix to transpose |
[out] | t | The transposed matrix |
Definition at line 1101 of file mathlib.cpp.
References i.
Grahm-Schmidt orthogonalization.
[out] | out | Orthogonalized vector |
[in] | in | Reference vector |
Definition at line 1088 of file mathlib.cpp.
References DotProduct, VectorMul, VectorNormalizeFast(), and VectorSubtract.
Referenced by R_ModCalcNormalsAndTangents(), and R_ModCalcUniqueNormalsAndTangents().
Finds a vector perpendicular to the source vector.
[in] | src | The source vector |
[out] | dst | A vector perpendicular to src |
dst
is a perpendicular vector to src
such that it is the closest to one of the three axis: {1,0,0}, {0,1,0} and {0,0,1} (chosen in that order in case of equality) src
is normalized Definition at line 780 of file mathlib.cpp.
References i, ProjectPointOnPlane(), and VectorNormalizeFast().
Referenced by GEO_MapDrawEquidistantPoints(), and RotatePointAroundVector().
Converts longitude and latitude to a 3D vector in Euclidean coordinates.
[in] | a | The longitude and latitude in a 2D vector |
[out] | v | The resulting normal 3D vector |
Definition at line 910 of file mathlib.cpp.
References torad, and VectorSet.
Referenced by AIR_GetDestinationWhilePursuing(), AIRFIGHT_GetNextPointInPathFromVector(), GEO_3DMapToScreen(), GEO_AngleOfPath2D(), GEO_AngleOfPath3D(), GEO_CalcLine(), GEO_MapDrawEquidistantPoints(), and R_PlantGrass().
|
inlinestatic |
Projects a point on a plane passing through the origin.
[in] | point | Coordinates of the point to project |
[in] | normal | The normal vector of the plane |
[out] | dst | Coordinates of the projection on the plane |
Non-null
pointers and a normalized normal vector. < closest distance from the point to the plane
Definition at line 692 of file mathlib.cpp.
References DotProduct.
Referenced by PerpendicularVector().
bool Q_IsPowerOfTwo | ( | int | i | ) |
Checks whether i is power of two value.
Definition at line 972 of file mathlib.cpp.
Referenced by CIN_ROQ_DecodeInfo(), and R_CvarCheckMaxLightmap().
Definition at line 492 of file mathlib.cpp.
Round to nearest integer.
Definition at line 156 of file mathlib.cpp.
Referenced by GetVertexnum(), and SnapPlane().
|
inlinestatic |
Definition at line 716 of file mathlib.cpp.
Referenced by VectorNormalizeFast().
|
inlinestatic |
Definition at line 827 of file mathlib.cpp.
Referenced by RotatePointAroundVector().
Definition at line 1110 of file mathlib.cpp.
References f, i, AABB::maxs, AABB::mins, and VectorSubtract.
Referenced by G_SmokeVis(), and G_TeamPointVis().
Rotate a point around a given vector.
[in] | dir | The vector around which to rotate |
[in] | point | The point to be rotated |
[in] | degrees | How many degrees to rotate the point by |
[out] | dst | The point after rotation |
dst
must be different from point
(otherwise the result has no meaning) dir
must be normalized Definition at line 849 of file mathlib.cpp.
References CrossProduct(), DotProduct, i, m, OBJZERO, PerpendicularVector(), R_ConcatRotations(), and torad.
Referenced by AIR_GetDestinationWhilePursuing(), AIRFIGHT_GetNextPointInPathFromVector(), GEO_3DMapToScreen(), GEO_AngleOfPath2D(), GEO_AngleOfPath3D(), GEO_MapDrawEquidistantPoints(), R_PlantGrass(), R_RotateCelestialBody(), R_SetupFrustum(), and uiGeoscapeNode::screenTo3DMap().
void TangentVectors | ( | const vec3_t | normal, |
const vec3_t | sdir, | ||
const vec3_t | tdir, | ||
vec4_t | tangent, | ||
vec3_t | binormal | ||
) |
Projects the normalized directional vectors on to the normal's plane. The fourth component of the resulting tangent vector represents sidedness.
Definition at line 1057 of file mathlib.cpp.
References CrossProduct(), DotProduct, VectorCopy, VectorMA(), VectorNormalizeFast(), and VectorScale.
Referenced by BuildFacelights(), and R_LoadBspVertexArrays().
Converts a vector to an angle vector.
[in] | value1 | |
[in] | angles | Target vector for pitch, yaw, roll |
Definition at line 934 of file mathlib.cpp.
References EQUAL, f, PITCH, ROLL, todeg, Vector2Empty, and YAW.
Referenced by G_ShootGrenade(), G_ShootSingle(), LE_AddProjectile(), and LET_Projectile().
Converts vector coordinates into polar coordinates.
Definition at line 922 of file mathlib.cpp.
References todeg.
Referenced by AIR_GetDestinationWhilePursuing(), AIRFIGHT_GetNextPointInPathFromVector(), GEO_CalcLine(), GEO_MapDrawEquidistantPoints(), and uiGeoscapeNode::screenTo3DMap().
Calculates the angle (in radians) between the two given vectors.
Definition at line 484 of file mathlib.cpp.
References DotProduct.
Referenced by G_GetImpactDirection().
Calculates a bounding box from a center and a size.
[in] | center | The center vector |
[in] | size | The size vector to calculate the bbox |
[out] | mins | The lower end of the bounding box |
[out] | maxs | The upper end of the bounding box |
Definition at line 1019 of file mathlib.cpp.
Definition at line 268 of file mathlib.cpp.
References f, i, and VectorMA().
Compare two vectors that may have an epsilon difference but still be the same vectors.
[in] | v1 | vector to compare with v2 |
[in] | v2 | vector to compare with v1 |
[in] | epsilon | The epsilon the vectors may differ to still be the same |
Definition at line 413 of file mathlib.cpp.
References VectorSubtract.
Referenced by CL_CameraRoute(), CP_InterceptAttackInstallation(), CP_InterceptMissionLeave(), PTL_Trace(), TR_TestLineDM(), and TR_TileTestLineDM().
angles | The angles to calulcate the rotation matrix for |
matrix | The resulting rotation matrix. The right part of this matrix is inversed because of the coordinate system we are using internally. |
Definition at line 592 of file mathlib.cpp.
References AngleVectors(), and VectorInverse().
Referenced by CalculateMinsMaxs(), Grid_RecalcRouting(), and AABB::rotateAround().
Inverse a vector.
[in,out] | v | Vector to inverse. Output value is -v . |
Definition at line 460 of file mathlib.cpp.
Referenced by GLMatrixAssemble(), R_PlantGrass(), and VectorCreateRotationMatrix().
Calculate the length of a vector.
[in] | v | Vector to calculate the length of |
Definition at line 434 of file mathlib.cpp.
References DotProduct.
Referenced by BuildVertexNormals(), CalcLightinfoVectors(), Check_EdgeEdgeIntersection(), Check_EdgePlaneIntersection(), Check_SidesOverlap(), CL_CameraMove(), CL_CameraRoute(), CL_TargetingGrenade(), Com_GrenadeTarget(), CreateNewFloatPlane(), FixWinding(), G_FindRadius(), G_ShootGrenade(), G_ShotMorale(), GEO_AngleOfPath2D(), GEO_AngleOfPath3D(), GEO_StartCenter(), LE_AddProjectile(), LE_FindRadius(), R_CreateSurfaceFlare(), R_GenerateGrass(), R_GetLevelOfDetailForModel(), R_RadiusFromBounds(), R_UpdateLightList(), Weather::render(), S_LoopSample(), SampleNormal(), uiGeoscapeNode::smoothRotate(), TestEdge(), UI_GeoscapeNodeScroll_f(), VectorNearer(), WindingArea(), and WindingIsTiny().
Sets vector_out (vc) to vevtor1 (va) + scale * vector2 (vb)
[in] | veca | Position to start from |
[in] | scale | Speed of the movement |
[in] | vecb | Movement direction |
[out] | outVector | Target vector |
Definition at line 261 of file mathlib.cpp.
Referenced by BaseWindingForPlane(), BuildFacelights(), BuildPatch(), CalcLightinfoVectors(), CL_ActorVis(), CL_BattlescapeMouseDragging(), CL_CameraMove(), CL_GetWorldCoordsUnderMouse(), CL_ParticleRun2(), CL_TargetingStraight(), FinishSubdividePatch(), G_ActorVis(), G_ClientShoot(), G_ShootGrenade(), G_ShootSingle(), G_SplashDamage(), GatherSampleLight(), GatherSampleSunlight(), LE_AddProjectile(), LET_PathMove(), NudgeSamplePosition(), R_CreateSurfaceFlare(), R_DrawAliasTags(), R_DrawBspNormals(), R_DrawSprite(), R_GenerateGrass(), R_ModLoadAliasMD2MeshIndexed(), R_ModLoadAliasMD2MeshUnindexed(), R_PlantGrass(), R_UpdateLightList(), SEQ_Render3D(), SEQ_SetCamera(), SV_ModLoadAliasMD2Model(), TangentVectors(), TestEdge(), UI_DrawModelNode(), and VectorClampMA().
Calculates the midpoint between two vectors.
[in] | point1 | vector of first point. |
[in] | point2 | vector of second point. |
[out] | midpoint | calculated midpoint vector. |
Definition at line 473 of file mathlib.cpp.
References f, VectorAdd, and VectorScale.
Calculate a position on v1
v2
line.
[in] | v1 | First point of the line. |
[in] | v2 | Second point of the line. |
[in] | mix | Position on the line. If 0 < mix < 1, out is between v1 and v2 . if mix < 0, out is outside v1 and v2 , on v1 side. |
[out] | out | The resulting point |
Definition at line 447 of file mathlib.cpp.
Referenced by FinalLightFace(), GatherSampleLight(), GatherSampleSunlight(), and S_LoopSample().
Checks whether the given vector v1
is closer to comp
as the vector v2
.
[in] | v1 | Vector to check whether it's closer to comp as v2 |
[in] | v2 | Vector to check against |
[in] | comp | The vector to check the distance from |
v1
is closer to comp
as v2
Definition at line 219 of file mathlib.cpp.
References VectorLength(), and VectorSubtract.
Referenced by TR_TestLineDist_r(), TR_TestLineDM(), and TR_TileTestLineDM().
Calculate unit vector for a given vec3_t.
[in] | v | Vector to normalize |
Definition at line 745 of file mathlib.cpp.
References DotProduct, and length.
Referenced by AddBrushBevels(), AIR_GetDestinationWhilePursuing(), BaseWindingForPlane(), BuildFacelights(), BuildLights(), BuildVertexNormals(), CalcLightinfoVectors(), Check_EdgeEdgeIntersection(), CL_ActorVis(), CL_CameraMove(), CL_CameraRoute(), CL_TargetingStraight(), FixFaceEdges(), G_GetImpactDirection(), GatherSampleLight(), GEO_AngleOfPath2D(), GEO_AngleOfPath3D(), GEO_CalcLine(), NudgeSamplePosition(), PlaneFromPoints(), R_DrawFlareSurfaces(), RemoveColinearPoints(), S_SpatializeChannel(), uiGeoscapeNode::screenTo3DMap(), SL_SliceTheWorld(), SubdivideFace(), and TryMergeWinding().
Calculated the normal vector for a given vec3_t.
[in] | v | Vector to normalize |
[out] | out | The normalized vector |
Definition at line 237 of file mathlib.cpp.
References DotProduct, EQUAL, f, and length.
Referenced by CL_CameraMove(), and R_SphereGenerate().
fast vector normalize routine that does not check to make sure that length != 0, nor does it return length
Definition at line 762 of file mathlib.cpp.
References DotProduct, and Q_rsqrtApprox().
Referenced by AI_CheckFF(), AI_FindHerdLocation(), Com_GrenadeTarget(), FrustumVis(), G_ActorVis(), G_ShootSingle(), Orthogonalize(), PerpendicularVector(), R_DrawSprite(), R_GetSpriteVectors(), R_InterpolateTransform(), R_ModCalcNormalsAndTangents(), R_ModCalcUniqueNormalsAndTangents(), R_PlantGrass(), R_StageTexCoord(), and TangentVectors().
Rotate a vector with a rotation matrix.
[out] | vb | The result of multiplication (ie vector va after rotation). |
[in] | m | The 3*3 matrix (rotation matrix in case of a rotation). |
[in] | va | The vector that should be multiplied (ie rotated in case of rotation). |
m
* va:
this is the same than GLVectorTransform in 3D. This can be used for other applications than rotation. Definition at line 395 of file mathlib.cpp.
Referenced by CalculateMinsMaxs(), Grid_RecalcRouting(), R_PlantGrass(), and AABB::rotateAround().
[out] | point | The vector to rotate around and the location of the rotated vector |
[in] | matrix | The input rotation matrix |
Definition at line 603 of file mathlib.cpp.
References DotProduct, and VectorCopy.
const float directionAngles[CORE_DIRECTIONS] = { 0, 180.0f, 90.0f, 270.0f, 45.0f, 225.0f, 135.0f, 315.0f } |
Definition at line 105 of file mathlib.cpp.
Referenced by CL_ActorAppear(), CL_ActorDoTurn(), CL_CameraAppear(), G_ActorDoTurn(), LE_DoPathMove(), and UI_RadarNodeDrawActor().
const vec4_t dvecs[PATHFINDING_DIRECTIONS] |
Definition at line 58 of file mathlib.cpp.
Referenced by Step::calcNewPos(), CMod_RerouteMap(), G_GetImpactDirection(), fireDef_s::getShotOrigin(), and RT_UpdateConnectionColumn().
const float dvecsn[CORE_DIRECTIONS][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1}, {RT2, RT2}, {-RT2, -RT2}, {-RT2, RT2}, {RT2, -RT2} } |
Definition at line 102 of file mathlib.cpp.
Referenced by FrustumVis().
const byte dvleft[CORE_DIRECTIONS] |
Definition at line 119 of file mathlib.cpp.
Referenced by AIL_positionwander(), and G_ActorDoTurn().
const byte dvright[CORE_DIRECTIONS] |
Definition at line 116 of file mathlib.cpp.
Referenced by AIL_positionwander(), and G_ActorDoTurn().
const pos3_t pos3_origin = { 0, 0, 0 } |
Definition at line 37 of file mathlib.cpp.
Referenced by AiAreaSearch::AiAreaSearch().
const vec2_t vec2_origin = { 0, 0 } |
Definition at line 34 of file mathlib.cpp.
Referenced by GEO_GetGeoscapeAngle().
const vec3_t vec3_origin = { 0, 0, 0 } |
Definition at line 35 of file mathlib.cpp.
Referenced by AABB::AABB(), KeyValuePair::asVec3(), BaseWindingForNode(), BaseWindingForPlane(), BuildNodeChildren(), CalcLightinfoVectors(), CL_HullForEntity(), CM_EntTestLineDM(), CreateNewFloatPlane(), EmitBrushes(), G_EventSpawnSound(), G_TraceDraw(), GridBox::GridBox(), Line::Line(), MakeNodePortal(), ParseBrush(), R_Draw2DMapMarkers(), R_Draw3DMapMarkers(), R_RenderFrame(), SV_ClipMoveToEntities(), SV_HullForEntity(), SV_LinkEdict(), TEST_F(), and WindingCenter().
const vec4_t vec4_origin = { 0, 0, 0, 0 } |
Definition at line 36 of file mathlib.cpp.
Referenced by R_DrawModelDirect(), and R_DrawModelParticle().