codemp/game/q_math.c File Reference

#include "q_shared.h"

Go to the source code of this file.

Functions

int Q_rand (int *seed)
float Q_random (int *seed)
float Q_crandom (int *seed)
signed char ClampChar (int i)
signed short ClampShort (int i)
int DirToByte (vec3_t dir)
void ByteToDir (int b, vec3_t dir)
unsigned ColorBytes3 (float r, float g, float b)
unsigned ColorBytes4 (float r, float g, float b, float a)
float NormalizeColor (const vec3_t in, vec3_t out)
qboolean PlaneFromPoints (vec4_t plane, const vec3_t a, const vec3_t b, const vec3_t c)
void RotatePointAroundVector (vec3_t dst, const vec3_t dir, const vec3_t point, float degrees)
void RotateAroundDirection (vec3_t axis[3], float yaw)
void vectoangles (const vec3_t value1, vec3_t angles)
void AnglesToAxis (const vec3_t angles, vec3_t axis[3])
void AxisClear (vec3_t axis[3])
void AxisCopy (vec3_t in[3], vec3_t out[3])
void ProjectPointOnPlane (vec3_t dst, const vec3_t p, const vec3_t normal)
void MakeNormalVectors (const vec3_t forward, vec3_t right, vec3_t up)
void VectorRotate (vec3_t in, vec3_t matrix[3], vec3_t out)
float Q_rsqrt (float number)
float Q_fabs (float f)
float LerpAngle (float from, float to, float frac)
float AngleSubtract (float a1, float a2)
void AnglesSubtract (vec3_t v1, vec3_t v2, vec3_t v3)
float AngleMod (float a)
float AngleNormalize360 (float angle)
float AngleNormalize180 (float angle)
float AngleDelta (float angle1, float angle2)
void SetPlaneSignbits (cplane_t *out)
int BoxOnPlaneSide (vec3_t emins, vec3_t emaxs, struct cplane_s *p)
float RadiusFromBounds (const vec3_t mins, const vec3_t maxs)
void ClearBounds (vec3_t mins, vec3_t maxs)
vec_t DistanceHorizontal (const vec3_t p1, const vec3_t p2)
vec_t DistanceHorizontalSquared (const vec3_t p1, const vec3_t p2)
void AddPointToBounds (const vec3_t v, vec3_t mins, vec3_t maxs)
vec_t VectorNormalize (vec3_t v)
vec_t VectorNormalize2 (const vec3_t v, vec3_t out)
void _VectorMA (const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc)
vec_t _DotProduct (const vec3_t v1, const vec3_t v2)
void _VectorSubtract (const vec3_t veca, const vec3_t vecb, vec3_t out)
void _VectorAdd (const vec3_t veca, const vec3_t vecb, vec3_t out)
void _VectorCopy (const vec3_t in, vec3_t out)
void _VectorScale (const vec3_t in, vec_t scale, vec3_t out)
void Vector4Scale (const vec4_t in, vec_t scale, vec4_t out)
int Q_log2 (int val)
void MatrixMultiply (float in1[3][3], float in2[3][3], float out[3][3])
void AngleVectors (const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
void PerpendicularVector (vec3_t dst, const vec3_t src)
void NormalToLatLong (const vec3_t normal, byte bytes[2])
void Rand_Init (int seed)
float flrand (float min, float max)
float Q_flrand (float min, float max)
int irand (int min, int max)
int Q_irand (int value1, int value2)
float powf (float x, int y)
float DotProductNormalize (const vec3_t inVec1, const vec3_t inVec2)
qboolean G_FindClosestPointOnLineSegment (const vec3_t start, const vec3_t end, const vec3_t from, vec3_t result)
float G_PointDistFromLineSegment (const vec3_t start, const vec3_t end, const vec3_t from)

Variables

vec3_t vec3_origin = {0,0,0}
vec3_t axisDefault [3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }
vec4_t colorBlack = {0, 0, 0, 1}
vec4_t colorRed = {1, 0, 0, 1}
vec4_t colorGreen = {0, 1, 0, 1}
vec4_t colorBlue = {0, 0, 1, 1}
vec4_t colorYellow = {1, 1, 0, 1}
vec4_t colorMagenta = {1, 0, 1, 1}
vec4_t colorCyan = {0, 1, 1, 1}
vec4_t colorWhite = {1, 1, 1, 1}
vec4_t colorLtGrey = {0.75, 0.75, 0.75, 1}
vec4_t colorMdGrey = {0.5, 0.5, 0.5, 1}
vec4_t colorDkGrey = {0.25, 0.25, 0.25, 1}
vec4_t colorLtBlue = {0.367f, 0.261f, 0.722f, 1}
vec4_t colorDkBlue = {0.199f, 0.0f, 0.398f, 1}
vec4_t g_color_table [8]
vec3_t bytedirs [NUMVERTEXNORMALS]


Function Documentation

vec_t _DotProduct const vec3_t  v1,
const vec3_t  v2
 

Definition at line 1221 of file q_math.c.

References vec3_t, and vec_t.

01221                                                       {
01222         return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
01223 }

void _VectorAdd const vec3_t  veca,
const vec3_t  vecb,
vec3_t  out
 

Definition at line 1231 of file q_math.c.

References vec3_t.

01231                                                                     {
01232         out[0] = veca[0]+vecb[0];
01233         out[1] = veca[1]+vecb[1];
01234         out[2] = veca[2]+vecb[2];
01235 }

void _VectorCopy const vec3_t  in,
vec3_t  out
 

Definition at line 1237 of file q_math.c.

References vec3_t.

01237                                                 {
01238         out[0] = in[0];
01239         out[1] = in[1];
01240         out[2] = in[2];
01241 }

void _VectorMA const vec3_t  veca,
float  scale,
const vec3_t  vecb,
vec3_t  vecc
 

Definition at line 1214 of file q_math.c.

References vec3_t.

01214                                                                                 {
01215         vecc[0] = veca[0] + scale*vecb[0];
01216         vecc[1] = veca[1] + scale*vecb[1];
01217         vecc[2] = veca[2] + scale*vecb[2];
01218 }

void _VectorScale const vec3_t  in,
vec_t  scale,
vec3_t  out
 

Definition at line 1243 of file q_math.c.

References vec3_t, and vec_t.

01243                                                               {
01244         out[0] = in[0]*scale;
01245         out[1] = in[1]*scale;
01246         out[2] = in[2]*scale;
01247 }

void _VectorSubtract const vec3_t  veca,
const vec3_t  vecb,
vec3_t  out
 

Definition at line 1225 of file q_math.c.

References vec3_t.

01225                                                                          {
01226         out[0] = veca[0]-vecb[0];
01227         out[1] = veca[1]-vecb[1];
01228         out[2] = veca[2]-vecb[2];
01229 }

void AddPointToBounds const vec3_t  v,
vec3_t  mins,
vec3_t  maxs
 

Definition at line 1148 of file q_math.c.

References vec3_t.

Referenced by Think_SpawnNewDoorTrigger().

01148                                                                   {
01149         if ( v[0] < mins[0] ) {
01150                 mins[0] = v[0];
01151         }
01152         if ( v[0] > maxs[0]) {
01153                 maxs[0] = v[0];
01154         }
01155 
01156         if ( v[1] < mins[1] ) {
01157                 mins[1] = v[1];
01158         }
01159         if ( v[1] > maxs[1]) {
01160                 maxs[1] = v[1];
01161         }
01162 
01163         if ( v[2] < mins[2] ) {
01164                 mins[2] = v[2];
01165         }
01166         if ( v[2] > maxs[2]) {
01167                 maxs[2] = v[2];
01168         }
01169 }

float AngleDelta float  angle1,
float  angle2
 

Definition at line 738 of file q_math.c.

References AngleNormalize180().

Referenced by ClientThink_real(), InFOV(), InFOV3(), NPC_BSJump(), NPC_BSPointShoot(), NPC_GetHFOVPercentage(), NPC_GetVFOVPercentage(), NPC_UpdateAngles(), NPC_UpdateFiringAngles(), NPC_UpdateShootAngles(), Q3_Lerp2Pos(), R2D2_TurnAnims(), and WP_SaberPositionUpdate().

00738                                                 {
00739         return AngleNormalize180( angle1 - angle2 );
00740 }

float AngleMod float  a  ) 
 

Definition at line 697 of file q_math.c.

Referenced by BG_G2PlayerAngles(), BotAI(), BotChangeViewAngle(), BotChangeViewAngles(), BotUpdateInput(), and InFieldOfVision().

00697                           {
00698         a = (360.0/65536) * ((int)(a*(65536/360.0)) & 65535);
00699         return a;
00700 }

float AngleNormalize180 float  angle  ) 
 

Definition at line 722 of file q_math.c.

References AngleNormalize360().

Referenced by AngleDelta(), BG_G2PlayerAngles(), BG_TouchJumpPad(), BG_UpdateLookAngles(), G_EstimateCamPos(), PM_UpdateViewAngles(), PM_VehFaceHyperspacePoint(), PM_VehForcedTurning(), PM_VehicleImpact(), ProcessOrientCommands(), and VEH_TurretAim().

00722                                         {
00723         angle = AngleNormalize360( angle );
00724         if ( angle > 180.0 ) {
00725                 angle -= 360.0;
00726         }
00727         return angle;
00728 }

float AngleNormalize360 float  angle  ) 
 

Definition at line 710 of file q_math.c.

Referenced by AngleNormalize180(), Droid_Patrol(), Droid_Spin(), ImperialProbe_Wait(), Interrogator_PartsMove(), NAV_Bypass(), NAVNEW_SidestepBlocker(), NPC_BSGM_Attack(), NPC_BSJump(), NPC_BSPointShoot(), NPC_BSSearch(), NPC_BSWander(), NPC_FacePosition(), NPC_GetMoveDirection(), NPC_GetMoveDirectionAltRoute(), NPC_MoveToGoal(), pas_think(), PM_VehFaceHyperspacePoint(), R2D2_PartsMove(), and Sniper_FaceEnemy().

00710                                         {
00711         return (360.0 / 65536) * ((int)(angle * (65536 / 360.0)) & 65535);
00712 }

void AnglesSubtract vec3_t  v1,
vec3_t  v2,
vec3_t  v3
 

Definition at line 690 of file q_math.c.

References AngleSubtract(), and vec3_t.

Referenced by BG_G2PlayerAngles(), CG_CheckPassengerTurretView(), PM_VehicleImpact(), and VEH_TurretAim().

00690                                                        {
00691         v3[0] = AngleSubtract( v1[0], v2[0] );
00692         v3[1] = AngleSubtract( v1[1], v2[1] );
00693         v3[2] = AngleSubtract( v1[2], v2[2] );
00694 }

void AnglesToAxis const vec3_t  angles,
vec3_t  axis[3]
 

Definition at line 530 of file q_math.c.

References AngleVectors(), vec3_origin, vec3_t, and VectorSubtract.

Referenced by BG_G2PlayerAngles(), BG_VehicleAdjustBBoxForOrientation(), CG_AddFragment(), CG_AddPacketEntities(), CG_AddPlayerWeapon(), CG_AddViewWeapon(), CG_CreateDistortionTrailPart(), CG_CreateModelFromSpawnEnt(), CG_Draw3DModel(), CG_DrawActiveFrame(), CG_DrawAutoMap(), CG_DrawPlayerShield(), CG_DrawPlayerSphere(), CG_EmplacedView(), CG_MiscEnt(), CG_Player(), CG_ScorePlum(), CG_TestModel_f(), G_EstimateCamPos(), Item_Model_Paint(), and WP_SaberPositionUpdate().

00530                                                          {
00531         vec3_t  right;
00532 
00533         // angle vectors returns "right" instead of "y axis"
00534         AngleVectors( angles, axis[0], right, axis[2] );
00535         VectorSubtract( vec3_origin, right, axis[1] );
00536 }

float AngleSubtract float  a1,
float  a2
 

Definition at line 675 of file q_math.c.

References fmod().

Referenced by AnglesSubtract(), BG_EmplacedView(), BG_G2PlayerAngles(), CanCounterThrow(), CG_PredictPlayerState(), EWebPositionUser(), EWebUpdateBoneAngles(), pas_think(), PM_VehFaceHyperspacePoint(), PM_VehForcedTurning(), ProcessOrientCommands(), and Q3_Lerp2Angles().

00675                                             {
00676         float   a;
00677 
00678         a = a1 - a2;
00679         a=fmod(a,360);//chop it down quickly, then level it out
00680         while ( a > 180 ) {
00681                 a -= 360;
00682         }
00683         while ( a < -180 ) {
00684                 a += 360;
00685         }
00686         return a;
00687 }

void AngleVectors const vec3_t  angles,
vec3_t  forward,
vec3_t  right,
vec3_t  up
 

Definition at line 1315 of file q_math.c.

References cos(), M_PI, PITCH, ROLL, sin(), vec3_t, and YAW.

Referenced by AnglesToAxis(), AnimateRiders(), Boba_FireDecide(), Boba_StopKnockdown(), BotFallbackNavigation(), BotInputToUserCommand(), BotSurfaceNear(), BotTrace_Duck(), BotTrace_Jump(), BotTrace_Strafe(), CalcEntitySpot(), CG_AddParticles(), CG_AddParticleToScene(), CG_CalcMuzzlePoint(), CG_CalcVehicleMuzzlePoint(), CG_DamageFeedback(), CG_Disintegration(), CG_DrawAutoMap(), CG_DrawRadar(), CG_EntityEvent(), CG_ParticleBloodCloud(), CG_ParticleDust(), CG_Player(), CG_ROFF_NotetrackCallback(), CG_WorldCoordToScreenCoordFloat(), CheckForFriendInLOF(), ClientCommand(), ClientThink_real(), Cmd_EngageDuel_f(), DeathFX(), DoGripAction(), Drop_Item(), emplaced_gun_use(), EWeb_Create(), ExplodeDeath(), finish_spawning_turretG2(), FireVehicleWeapon(), FireWeapon(), ForceGrip(), ForceShootDrain(), ForceShootLightning(), ForceTelepathy(), ForceTelepathyCheckDirectNPCTarget(), ForceThrow(), G_AddPushVecToUcmd(), G_AttackDelay(), G_CanJumpToEnemyVeh(), G_CreateRotationMatrix(), G_Damage(), G_DeflectMissile(), G_EstimateCamPos(), G_GetDismemberLoc(), G_GetHitLocation(), G_GetHitLocFromSurfName(), G_GetHitQuad(), G_ItemUsable(), G_KnockOffVehicle(), G_MissileImpact(), G_SetMovedir(), G_SPSaberDamageTraceLerped(), G_UcmdMoveForDir(), Howler_TryDamage(), hyperspace_touch(), ImperialProbe_FireBlaster(), ImperialProbe_Strafe(), InFront(), Interrogator_Strafe(), ItemUse_Sentry(), ItemUse_UseDisp(), Jedi_CheckFlipEvasions(), Jedi_FindEnemyInCone(), Jedi_SaberBlockGo(), maglock_link(), Mark1_FireBlaster(), Mark1_FireRocket(), Mark2_FireBlaster(), MeleeCombatHandling(), MineMonster_TryDamage(), NAV_Bypass(), NAV_MoveBlocker(), NAV_Steer(), NAVNEW_Bypass(), NAVNEW_SidestepBlocker(), NPC_BSAdvanceFight(), NPC_BSNoClip(), NPC_BSSniper_Attack(), NPC_BSST_Attack(), NPC_CheckCanAttack(), NPC_Droid_Pain(), NPC_Jedi_Pain(), NPC_MoveDirClear(), NPC_PickAlly(), NPC_ShotEntity(), NPC_SpawnType(), Pickup_Powerup(), pitch_roll_for_slope(), PlaceShield(), player_die(), PM_AdjustAngleForWallJump(), PM_AdjustAngleForWallRun(), PM_AdjustAngleForWallRunUp(), PM_AnglesForSlope(), PM_CanBackstab(), PM_CheckStabDown(), PM_HoverTrace(), PM_ItemUsable(), PM_pitch_roll_for_slope(), PM_RocketLock(), PM_SaberAttackForMovement(), PM_SaberFlipOverAttackMove(), PM_SaberJumpAttackMove(), PM_SaberLungeAttackMove(), PM_SomeoneInFront(), PM_VehicleImpact(), PM_WeaponLightsaber(), PmoveSingle(), Rancor_Attack(), Rancor_Swing(), Remote_Fire(), Remote_Strafe(), SaberCombatHandling(), saberFirstThrown(), saberKnockDown(), Seeker_Strafe(), Sentry_Fire(), Sentry_Strafe(), Sniper_FaceEnemy(), SP_misc_weapon_shooter(), StrafeTracing(), TeleportPlayer(), Touch_Multi(), TryUse(), turret_head_think(), Update(), UpdateClientRenderinfo(), ValidateBoard(), ValidBloodPool(), VEH_StartStrafeRam(), VEH_TryEject(), Wampa_Attack(), Wampa_Slash(), waypoint_testDirection(), WP_DropDetPack(), WP_DropThermal(), WP_GetVelocityForForceJump(), WP_SaberBlock(), WP_SaberBlockNonRandom(), WP_SaberPositionUpdate(), WP_SaberStartMissileBlockCheck(), and WP_VehCheckTraceFromCamPos().

01315                                                                                  {
01316         float           angle;
01317         static float            sr, sp, sy, cr, cp, cy;
01318         // static to help MS compiler fp bugs
01319 
01320         angle = angles[YAW] * (M_PI*2 / 360);
01321         sy = sin(angle);
01322         cy = cos(angle);
01323         angle = angles[PITCH] * (M_PI*2 / 360);
01324         sp = sin(angle);
01325         cp = cos(angle);
01326         angle = angles[ROLL] * (M_PI*2 / 360);
01327         sr = sin(angle);
01328         cr = cos(angle);
01329 
01330         if (forward)
01331         {
01332                 forward[0] = cp*cy;
01333                 forward[1] = cp*sy;
01334                 forward[2] = -sp;
01335         }
01336         if (right)
01337         {
01338                 right[0] = (-1*sr*sp*cy+-1*cr*-sy);
01339                 right[1] = (-1*sr*sp*sy+-1*cr*cy);
01340                 right[2] = -1*sr*cp;
01341         }
01342         if (up)
01343         {
01344                 up[0] = (cr*sp*cy+-sr*-sy);
01345                 up[1] = (cr*sp*sy+-sr*cy);
01346                 up[2] = cr*cp;
01347         }
01348 }

void AxisClear vec3_t  axis[3]  ) 
 

Definition at line 538 of file q_math.c.

References vec3_t.

Referenced by CG_Beam(), CG_Draw3DModel(), CG_MakeExplosion(), FX_AddOrientedLine(), and Item_Model_Paint().

00538                                  {
00539         axis[0][0] = 1;
00540         axis[0][1] = 0;
00541         axis[0][2] = 0;
00542         axis[1][0] = 0;
00543         axis[1][1] = 1;
00544         axis[1][2] = 0;
00545         axis[2][0] = 0;
00546         axis[2][1] = 0;
00547         axis[2][2] = 1;
00548 }

void AxisCopy vec3_t  in[3],
vec3_t  out[3]
 

Definition at line 550 of file q_math.c.

References vec3_t, and VectorCopy.

Referenced by CG_Chunks(), CG_LaunchGib(), and CG_ThrowChunk().

00550                                              {
00551         VectorCopy( in[0], out[0] );
00552         VectorCopy( in[1], out[1] );
00553         VectorCopy( in[2], out[2] );
00554 }

int BoxOnPlaneSide vec3_t  emins,
vec3_t  emaxs,
struct cplane_s p
 

Definition at line 809 of file q_math.c.

References cplane_s::dist, cplane_s::normal, cplane_s::signbits, cplane_s::type, and vec3_t.

00810 {
00811         float   dist1, dist2;
00812         int             sides;
00813 
00814 // fast axial cases
00815         if (p->type < 3)
00816         {
00817                 if (p->dist <= emins[p->type])
00818                         return 1;
00819                 if (p->dist >= emaxs[p->type])
00820                         return 2;
00821                 return 3;
00822         }
00823 
00824 // general case
00825         switch (p->signbits)
00826         {
00827         case 0:
00828                 dist1 = p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
00829                 dist2 = p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
00830                 break;
00831         case 1:
00832                 dist1 = p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
00833                 dist2 = p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
00834                 break;
00835         case 2:
00836                 dist1 = p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
00837                 dist2 = p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
00838                 break;
00839         case 3:
00840                 dist1 = p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
00841                 dist2 = p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
00842                 break;
00843         case 4:
00844                 dist1 = p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
00845                 dist2 = p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
00846                 break;
00847         case 5:
00848                 dist1 = p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emins[2];
00849                 dist2 = p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emaxs[2];
00850                 break;
00851         case 6:
00852                 dist1 = p->normal[0]*emaxs[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
00853                 dist2 = p->normal[0]*emins[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
00854                 break;
00855         case 7:
00856                 dist1 = p->normal[0]*emins[0] + p->normal[1]*emins[1] + p->normal[2]*emins[2];
00857                 dist2 = p->normal[0]*emaxs[0] + p->normal[1]*emaxs[1] + p->normal[2]*emaxs[2];
00858                 break;
00859         default:
00860                 dist1 = dist2 = 0;              // shut up compiler
00861                 break;
00862         }
00863 
00864         sides = 0;
00865         if (dist1 >= p->dist)
00866                 sides = 1;
00867         if (dist2 < p->dist)
00868                 sides |= 2;
00869 
00870         return sides;
00871 }

void ByteToDir int  b,
vec3_t  dir
 

Definition at line 324 of file q_math.c.

References bytedirs, NUMVERTEXNORMALS, vec3_origin, vec3_t, and VectorCopy.

Referenced by CG_EntityEvent(), and CG_VehicleWeaponImpact().

00324                                     {
00325         if ( b < 0 || b >= NUMVERTEXNORMALS ) {
00326                 VectorCopy( vec3_origin, dir );
00327                 return;
00328         }
00329         VectorCopy (bytedirs[b], dir);
00330 }

signed char ClampChar int  i  ) 
 

Definition at line 279 of file q_math.c.

00279                                {
00280         if ( i < -128 ) {
00281                 return -128;
00282         }
00283         if ( i > 127 ) {
00284                 return 127;
00285         }
00286         return i;
00287 }

signed short ClampShort int  i  ) 
 

Definition at line 289 of file q_math.c.

00289                                  {
00290         if ( i < -32768 ) {
00291                 return -32768;
00292         }
00293         if ( i > 0x7fff ) {
00294                 return 0x7fff;
00295         }
00296         return i;
00297 }

void ClearBounds vec3_t  mins,
vec3_t  maxs
 

Definition at line 1129 of file q_math.c.

References vec3_t.

01129                                              {
01130         mins[0] = mins[1] = mins[2] = 99999;
01131         maxs[0] = maxs[1] = maxs[2] = -99999;
01132 }

unsigned ColorBytes3 float  r,
float  g,
float  b
 

Definition at line 333 of file q_math.c.

References byte.

00333                                                  {
00334         unsigned        i;
00335 
00336         ( (byte *)&i )[0] = r * 255;
00337         ( (byte *)&i )[1] = g * 255;
00338         ( (byte *)&i )[2] = b * 255;
00339 
00340         return i;
00341 }

unsigned ColorBytes4 float  r,
float  g,
float  b,
float  a
 

Definition at line 343 of file q_math.c.

References byte.

00343                                                           {
00344         unsigned        i;
00345 
00346         ( (byte *)&i )[0] = r * 255;
00347         ( (byte *)&i )[1] = g * 255;
00348         ( (byte *)&i )[2] = b * 255;
00349         ( (byte *)&i )[3] = a * 255;
00350 
00351         return i;
00352 }

int DirToByte vec3_t  dir  ) 
 

Definition at line 301 of file q_math.c.

References bytedirs, DotProduct, NUMVERTEXNORMALS, and vec3_t.

Referenced by ForceDrainDamage(), G_Damage(), G_ExplodeMissile(), G_MissileImpact(), locateCamera(), thermalDetonatorExplode(), and WP_DisruptorAltFire().

00301                             {
00302         int             i, best;
00303         float   d, bestd;
00304 
00305         if ( !dir ) {
00306                 return 0;
00307         }
00308 
00309         bestd = 0;
00310         best = 0;
00311         for (i=0 ; i<NUMVERTEXNORMALS ; i++)
00312         {
00313                 d = DotProduct (dir, bytedirs[i]);
00314                 if (d > bestd)
00315                 {
00316                         bestd = d;
00317                         best = i;
00318                 }
00319         }
00320 
00321         return best;
00322 }

vec_t DistanceHorizontal const vec3_t  p1,
const vec3_t  p2
 

Definition at line 1134 of file q_math.c.

References sqrt(), vec3_t, vec_t, and VectorSubtract.

01134                                                              {
01135         vec3_t  v;
01136 
01137         VectorSubtract( p2, p1, v );
01138         return sqrt( v[0]*v[0] + v[1]*v[1] );   //Leave off the z component
01139 }

vec_t DistanceHorizontalSquared const vec3_t  p1,
const vec3_t  p2
 

Definition at line 1141 of file q_math.c.

References vec3_t, vec_t, and VectorSubtract.

Referenced by ATST_Attack(), Howler_Combat(), ImperialProbe_AttackDecision(), Interrogator_Attack(), Jedi_CheckAmbushPlayer(), Mark1_AttackDecision(), Mark2_AttackDecision(), MineMonster_Combat(), NPC_BSGM_Attack(), NPC_BSGrenadier_Attack(), NPC_FindCombatPoint(), Remote_Attack(), Seeker_Attack(), Seeker_FindEnemy(), Seeker_FollowOwner(), and Sentry_AttackDecision().

01141                                                                     {
01142         vec3_t  v;
01143 
01144         VectorSubtract( p2, p1, v );
01145         return v[0]*v[0] + v[1]*v[1];   //Leave off the z component
01146 }

float DotProductNormalize const vec3_t  inVec1,
const vec3_t  inVec2
 

Definition at line 1508 of file q_math.c.

References DotProduct, vec3_t, and VectorNormalize2().

Referenced by G_FindClosestPointOnLineSegment(), and G_PointDistFromLineSegment().

01509 {
01510         vec3_t  v1, v2;
01511 
01512         VectorNormalize2( inVec1, v1 );
01513         VectorNormalize2( inVec2, v2 );
01514 
01515         return DotProduct(v1, v2);
01516 }

float flrand float  min,
float  max
 

Definition at line 1441 of file q_math.c.

References min.

Referenced by asteroid_field_think(), CG_AddGhoul2Mark(), CG_Chunks(), CG_FireWeapon(), CG_G2MarkEvent(), CG_G2PlayerHeadAnims(), CG_RagDoll(), CG_SaberCompWork(), Do_Strike(), G_RunObject(), misc_faller_create(), NPC_AimWiggle(), NPC_BSFlee(), NPC_BSGM_Attack(), NPC_BSSearch(), NPC_BSWander(), NPC_CheckAttack(), NPC_FacePosition(), NPC_UpdateFiringAngles(), Q_flrand(), Rancor_Swing(), Remote_Attack(), Seeker_MaintainHeight(), Sniper_FaceEnemy(), Sniper_UpdateEnemyPos(), and Wampa_Slash().

01442 {
01443         float   result;
01444 
01445         holdrand = (holdrand * 214013L) + 2531011L;
01446         result = (float)(holdrand >> 17);                                               // 0 - 32767 range
01447         result = ((result * (max - min)) / 32768.0F) + min;
01448 
01449         return(result);
01450 }

qboolean G_FindClosestPointOnLineSegment const vec3_t  start,
const vec3_t  end,
const vec3_t  from,
vec3_t  result
 

Definition at line 1524 of file q_math.c.

References cos(), DEG2RAD, DotProductNormalize(), qboolean, qfalse, qtrue, vec3_t, VectorCopy, VectorMA, VectorNormalize(), and VectorSubtract.

Referenced by NAV_MoveToGoal(), and ShortestLineSegBewteen2LineSegs().

01525 {
01526         vec3_t  vecStart2From, vecStart2End, vecEnd2Start, vecEnd2From;
01527         float   distEnd2From, distEnd2Result, theta, cos_theta, dot;
01528 
01529         //Find the perpendicular vector to vec from start to end
01530         VectorSubtract( from, start, vecStart2From);
01531         VectorSubtract( end, start, vecStart2End);
01532 
01533         dot = DotProductNormalize( vecStart2From, vecStart2End );
01534 
01535         if ( dot <= 0 )
01536         {
01537                 //The perpendicular would be beyond or through the start point
01538                 VectorCopy( start, result );
01539                 return qfalse;
01540         }
01541 
01542         if ( dot == 1 )
01543         {
01544                 //parallel, closer of 2 points will be the target
01545                 if( (VectorLengthSquared( vecStart2From )) < (VectorLengthSquared( vecStart2End )) )
01546                 {
01547                         VectorCopy( from, result );
01548                 }
01549                 else
01550                 {
01551                         VectorCopy( end, result );
01552                 }
01553                 return qfalse;
01554         }
01555 
01556         //Try other end
01557         VectorSubtract( from, end, vecEnd2From);
01558         VectorSubtract( start, end, vecEnd2Start);
01559 
01560         dot = DotProductNormalize( vecEnd2From, vecEnd2Start );
01561 
01562         if ( dot <= 0 )
01563         {//The perpendicular would be beyond or through the start point
01564                 VectorCopy( end, result );
01565                 return qfalse;
01566         }
01567 
01568         if ( dot == 1 )
01569         {//parallel, closer of 2 points will be the target
01570                 if( (VectorLengthSquared( vecEnd2From )) < (VectorLengthSquared( vecEnd2Start )))
01571                 {
01572                         VectorCopy( from, result );
01573                 }
01574                 else
01575                 {
01576                         VectorCopy( end, result );
01577                 }
01578                 return qfalse;
01579         }
01580 
01581         //                    /|
01582         //                c  / |
01583         //                  /  |a
01584         //      theta  /)__|    
01585         //                    b
01586         //cos(theta) = b / c
01587         //solve for b
01588         //b = cos(theta) * c
01589 
01590         //angle between vecs end2from and end2start, should be between 0 and 90
01591         theta = 90 * (1 - dot);//theta
01592         
01593         //Get length of side from End2Result using sine of theta
01594         distEnd2From = VectorLength( vecEnd2From );//c
01595         cos_theta = cos(DEG2RAD(theta));//cos(theta)
01596         distEnd2Result = cos_theta * distEnd2From;//b
01597 
01598         //Extrapolate to find result
01599         VectorNormalize( vecEnd2Start );
01600         VectorMA( end, distEnd2Result, vecEnd2Start, result );
01601         
01602         //perpendicular intersection is between the 2 endpoints
01603         return qtrue;
01604 }

float G_PointDistFromLineSegment const vec3_t  start,
const vec3_t  end,
const vec3_t  from
 

Definition at line 1606 of file q_math.c.

References cos(), DEG2RAD, DotProductNormalize(), vec3_t, VectorMA, VectorNormalize(), and VectorSubtract.

01607 {
01608         vec3_t  vecStart2From, vecStart2End, vecEnd2Start, vecEnd2From, intersection;
01609         float   distEnd2From, distStart2From, distEnd2Result, theta, cos_theta, dot;
01610 
01611         //Find the perpendicular vector to vec from start to end
01612         VectorSubtract( from, start, vecStart2From);
01613         VectorSubtract( end, start, vecStart2End);
01614         VectorSubtract( from, end, vecEnd2From);
01615         VectorSubtract( start, end, vecEnd2Start);
01616 
01617         dot = DotProductNormalize( vecStart2From, vecStart2End );
01618 
01619         distStart2From = Distance( start, from );
01620         distEnd2From = Distance( end, from );
01621 
01622         if ( dot <= 0 )
01623         {
01624                 //The perpendicular would be beyond or through the start point
01625                 return distStart2From;
01626         }
01627 
01628         if ( dot == 1 )
01629         {
01630                 //parallel, closer of 2 points will be the target
01631                 return ((distStart2From<distEnd2From)?distStart2From:distEnd2From);
01632         }
01633 
01634         //Try other end
01635 
01636         dot = DotProductNormalize( vecEnd2From, vecEnd2Start );
01637 
01638         if ( dot <= 0 )
01639         {//The perpendicular would be beyond or through the end point
01640                 return distEnd2From;
01641         }
01642 
01643         if ( dot == 1 )
01644         {//parallel, closer of 2 points will be the target
01645                 return ((distStart2From<distEnd2From)?distStart2From:distEnd2From);
01646         }
01647 
01648         //                    /|
01649         //                c  / |
01650         //                  /  |a
01651         //      theta  /)__|    
01652         //                    b
01653         //cos(theta) = b / c
01654         //solve for b
01655         //b = cos(theta) * c
01656 
01657         //angle between vecs end2from and end2start, should be between 0 and 90
01658         theta = 90 * (1 - dot);//theta
01659         
01660         //Get length of side from End2Result using sine of theta
01661         cos_theta = cos(DEG2RAD(theta));//cos(theta)
01662         distEnd2Result = cos_theta * distEnd2From;//b
01663 
01664         //Extrapolate to find result
01665         VectorNormalize( vecEnd2Start );
01666         VectorMA( end, distEnd2Result, vecEnd2Start, intersection );
01667         
01668         //perpendicular intersection is between the 2 endpoints, return dist to it from from
01669         return Distance( intersection, from );
01670 }

int irand int  min,
int  max
 

Definition at line 1458 of file q_math.c.

References min.

Referenced by Q_irand().

01459 {
01460         int             result;
01461 
01462         assert((max - min) < 32768);
01463 
01464         max++;
01465         holdrand = (holdrand * 214013L) + 2531011L;
01466         result = holdrand >> 17;
01467         result = ((result * (max - min)) >> 15) + min;
01468         return(result);
01469 }

float LerpAngle float  from,
float  to,
float  frac
 

Definition at line 653 of file q_math.c.

Referenced by G_SPSaberDamageTraceLerped().

00653                                                    {
00654         float   a;
00655 
00656         if ( to - from > 180 ) {
00657                 to -= 360;
00658         }
00659         if ( to - from < -180 ) {
00660                 to += 360;
00661         }
00662         a = from + frac * (to - from);
00663 
00664         return a;
00665 }

void MakeNormalVectors const vec3_t  forward,
vec3_t  right,
vec3_t  up
 

Definition at line 587 of file q_math.c.

References DotProduct, vec3_t, VectorMA, and VectorNormalize().

00587                                                                        {
00588         float           d;
00589 
00590         // this rotate and negate guarantees a vector
00591         // not colinear with the original
00592         right[1] = -forward[0];
00593         right[2] = forward[1];
00594         right[0] = forward[2];
00595 
00596         d = DotProduct (right, forward);
00597         VectorMA (right, -d, forward, right);
00598         VectorNormalize (right);
00599         CrossProduct (right, forward, up);
00600 }

void MatrixMultiply float  in1[3][3],
float  in2[3][3],
float  out[3][3]
 

Definition at line 1293 of file q_math.c.

Referenced by CG_GetTagWorldPosition(), CG_PositionEntityOnTag(), CG_PositionRotatedEntityOnTag(), and RotatePointAroundVector().

01293                                                                        {
01294         out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] +
01295                                 in1[0][2] * in2[2][0];
01296         out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] +
01297                                 in1[0][2] * in2[2][1];
01298         out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] +
01299                                 in1[0][2] * in2[2][2];
01300         out[1][0] = in1[1][0] * in2[0][0] + in1[1][1] * in2[1][0] +
01301                                 in1[1][2] * in2[2][0];
01302         out[1][1] = in1[1][0] * in2[0][1] + in1[1][1] * in2[1][1] +
01303                                 in1[1][2] * in2[2][1];
01304         out[1][2] = in1[1][0] * in2[0][2] + in1[1][1] * in2[1][2] +
01305                                 in1[1][2] * in2[2][2];
01306         out[2][0] = in1[2][0] * in2[0][0] + in1[2][1] * in2[1][0] +
01307                                 in1[2][2] * in2[2][0];
01308         out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] +
01309                                 in1[2][2] * in2[2][1];
01310         out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] +
01311                                 in1[2][2] * in2[2][2];
01312 }

float NormalizeColor const vec3_t  in,
vec3_t  out
 

Definition at line 354 of file q_math.c.

References vec3_t, and VectorClear.

00354                                                     {
00355         float   max;
00356         
00357         max = in[0];
00358         if ( in[1] > max ) {
00359                 max = in[1];
00360         }
00361         if ( in[2] > max ) {
00362                 max = in[2];
00363         }
00364 
00365         if ( !max ) {
00366                 VectorClear( out );
00367         } else {
00368                 out[0] = in[0] / max;
00369                 out[1] = in[1] / max;
00370                 out[2] = in[2] / max;
00371         }
00372         return max;
00373 }

void NormalToLatLong const vec3_t  normal,
byte  bytes[2]
 

Definition at line 1394 of file q_math.c.

References acos(), atan2(), byte, RAD2DEG, vec3_t, and vec_t.

01395 {
01396         // check for singularities
01397         if (!normal[0] && !normal[1])
01398         {
01399                 if ( normal[2] > 0.0f )
01400                 {
01401                         bytes[0] = 0;
01402                         bytes[1] = 0;           // lat = 0, long = 0
01403                 }
01404                 else
01405                 {
01406                         bytes[0] = 128;
01407                         bytes[1] = 0;           // lat = 0, long = 128
01408                 }
01409         }
01410         else
01411         {
01412                 int     a, b;
01413 
01414                 a = (int)(RAD2DEG( (vec_t)atan2( normal[1], normal[0] ) ) * (255.0f / 360.0f ));
01415                 a &= 0xff;
01416 
01417                 b = (int)(RAD2DEG( (vec_t)acos( normal[2] ) ) * ( 255.0f / 360.0f ));
01418                 b &= 0xff;
01419 
01420                 bytes[0] = b;   // longitude
01421                 bytes[1] = a;   // lattitude
01422         }
01423 }

void PerpendicularVector vec3_t  dst,
const vec3_t  src
 

Definition at line 1353 of file q_math.c.

References fabs(), ProjectPointOnPlane(), vec3_t, and VectorNormalize().

Referenced by CG_ImpactMark(), NAV_StackedCanyon(), RotateAroundDirection(), RotatePointAroundVector(), and Use_Shooter().

01354 {
01355         int     pos;
01356         int i;
01357         float minelem = 1.0F;
01358         vec3_t tempvec;
01359 
01360         /*
01361         ** find the smallest magnitude axially aligned vector
01362         */
01363         for ( pos = 0, i = 0; i < 3; i++ )
01364         {
01365                 if ( fabs( src[i] ) < minelem )
01366                 {
01367                         pos = i;
01368                         minelem = fabs( src[i] );
01369                 }
01370         }
01371         tempvec[0] = tempvec[1] = tempvec[2] = 0.0F;
01372         tempvec[pos] = 1.0F;
01373 
01374         /*
01375         ** project the point onto the plane defined by src
01376         */
01377         ProjectPointOnPlane( dst, tempvec, src );
01378 
01379         /*
01380         ** normalize the result
01381         */
01382         VectorNormalize( dst );
01383 }

qboolean PlaneFromPoints vec4_t  plane,
const vec3_t  a,
const vec3_t  b,
const vec3_t  c
 

Definition at line 384 of file q_math.c.

References DotProduct, qboolean, qfalse, qtrue, vec3_t, vec4_t, VectorNormalize(), and VectorSubtract.

00384                                                                                          {
00385         vec3_t  d1, d2;
00386 
00387         VectorSubtract( b, a, d1 );
00388         VectorSubtract( c, a, d2 );
00389         CrossProduct( d2, d1, plane );
00390         if ( VectorNormalize( plane ) == 0 ) {
00391                 return qfalse;
00392         }
00393 
00394         plane[3] = DotProduct( a, plane );
00395         return qtrue;
00396 }

float powf float  x,
int  y
 

Definition at line 1476 of file q_math.c.

01477 {
01478         float r = x;
01479         for ( y--; y>0; y-- )
01480                 r = r * r;
01481         return r;
01482 }

void ProjectPointOnPlane vec3_t  dst,
const vec3_t  p,
const vec3_t  normal
 

Definition at line 556 of file q_math.c.

References DotProduct, Q_fabs(), and vec3_t.

Referenced by PerpendicularVector().

00557 {
00558         float d;
00559         vec3_t n;
00560         float inv_denom;
00561 
00562         inv_denom =  DotProduct( normal, normal );
00563 #ifndef Q3_VM
00564         assert( Q_fabs(inv_denom) != 0.0f ); // bk010122 - zero vectors get here
00565 #endif
00566         inv_denom = 1.0f / inv_denom;
00567 
00568         d = DotProduct( normal, p ) * inv_denom;
00569 
00570         n[0] = normal[0] * inv_denom;
00571         n[1] = normal[1] * inv_denom;
00572         n[2] = normal[2] * inv_denom;
00573 
00574         dst[0] = p[0] - d * n[0];
00575         dst[1] = p[1] - d * n[1];
00576         dst[2] = p[2] - d * n[2];
00577 }

float Q_crandom int *  seed  ) 
 

Definition at line 135 of file q_math.c.

References Q_random().

00135                                {
00136         return 2.0 * ( Q_random( seed ) - 0.5 );
00137 }

float Q_fabs float  f  ) 
 

Definition at line 638 of file q_math.c.

Referenced by pitch_roll_for_slope(), PM_AnglesForSlope(), PM_pitch_roll_for_slope(), and ProjectPointOnPlane().

00638                         {
00639         int tmp = * ( int * ) &f;
00640         tmp &= 0x7FFFFFFF;
00641         return * ( float * ) &tmp;
00642 }

float Q_flrand float  min,
float  max
 

Definition at line 1451 of file q_math.c.

References flrand(), and min.

01452 {
01453         return flrand(min,max);
01454 }

int Q_irand int  value1,
int  value2
 

Definition at line 1471 of file q_math.c.

References irand().

Referenced by AI_GroupMemberKilled(), AI_RefreshGroup(), AnimateRiders(), asteroid_field_think(), asteroid_pick_random_asteroid(), ATST_Attack(), ATST_Ranged(), BG_BrokenParryForParry(), BG_PickAnim(), Boba_FireDecide(), Boba_FireFlameThrower(), Boba_FlyStart(), Boba_FlyStop(), Boba_StopKnockdown(), BotDoChat(), BotGetFlagBack(), BotGuardFlagCarrier(), BotInputToUserCommand(), CG_AddRandomLightning(), CG_AddSaberBlade(), CG_Chunks(), CG_CreateDebris(), CG_EntityEvent(), CG_FragmentBounceSound(), CG_G2MarkEvent(), CG_G2SaberEffects(), CG_GlassShatter_Old(), CG_Player(), CG_PlayerAnimEventDo(), CG_PlayerAnimEvents(), CG_SaberCompWork(), charge_stick(), ClientThink_real(), CombatBotAI(), CommanderBotTeamplayAI(), DeathFX(), DEMP2_AltRadiusDamage(), DetPackDie(), DetPackPain(), DoGripAction(), Droid_Patrol(), Droid_Spin(), emplaced_gun_update(), faller_touch(), ForceLightningDamage(), ForceThrow(), funcBBrushPain(), G_AimSet(), G_AttackDelay(), G_BounceMissile(), G_BreakArm(), G_CanJumpToEnemyVeh(), G_CheckClientIdle(), G_CheckForDismemberment(), G_CheckVictoryScript(), G_Damage(), G_Dismember(), G_DroidSounds(), G_MissileImpact(), G_PickDeathAnim(), G_RunFrame(), G_SetEnemy(), GetBestIdleGoal(), GetIdealDestination(), GM_Dying(), HolocronPopOut(), ImperialProbe_AttackDecision(), ImperialProbe_FireBlaster(), ImperialProbe_Patrol(), ImperialProbe_Ranged(), Interrogator_Attack(), Interrogator_die(), Interrogator_Melee(), Interrogator_PartsMove(), Jedi_Ambush(), Jedi_CheckAmbushPlayer(), Jedi_CheckDanger(), Jedi_CheckFlipEvasions(), Jedi_DodgeEvasion(), Jedi_PlayDeflectSound(), Jedi_RageStop(), Jedi_ReCalcParryTime(), Jedi_SaberBlockGo(), MakeDeadSaber(), Mark1_AttackDecision(), Mark1_BlasterAttack(), Mark1_die(), Mark1_dying(), Mark1_RocketAttack(), Mark2_AttackDecision(), Mark2_BlasterAttack(), Mark2_Patrol(), MeleeCombatHandling(), MineMonster_TryDamage(), misc_faller_create(), misc_faller_think(), NAVNEW_MoveToGoal(), NPC_AimAdjust(), NPC_Begin(), NPC_BSEmplaced(), NPC_BSFollowLeader(), NPC_BSGM_Attack(), NPC_BSGrenadier_Patrol(), NPC_BSJedi_Default(), NPC_BSRancor_Default(), NPC_BSSearch(), NPC_BSSniper_Attack(), NPC_BSSniper_Patrol(), NPC_BSST_Attack(), NPC_BSST_Patrol(), NPC_BSWampa_Default(), NPC_BSWander(), NPC_CheckCharmed(), NPC_CheckEnemyStealth(), NPC_ChoosePainAnimation(), NPC_Droid_Pain(), NPC_GM_Pain(), NPC_Grenadier_Pain(), NPC_Grenadier_PlayConfusionSound(), NPC_HandleAIFlags(), NPC_Jedi_Pain(), NPC_Jedi_PlayConfusionSound(), NPC_Jedi_RateNewEnemy(), NPC_Mark1_Pain(), NPC_Pain(), NPC_ParseParms(), NPC_PlayConfusionSound(), NPC_Rancor_Pain(), NPC_Respond(), NPC_Sentry_Pain(), NPC_Sentry_Patrol(), NPC_Sniper_Pain(), NPC_Sniper_PlayConfusionSound(), NPC_ST_Pain(), NPC_ST_SayMovementSpeech(), NPC_StartFlee(), NPC_Surrender(), NPC_TempLookTarget(), NPC_UpdateFiringAngles(), NPC_Wampa_Pain(), PM_HoverTrace(), PM_SaberLockBreak(), PmoveSingle(), R2D2_PartsMove(), Rancor_Attack(), Rancor_Bite(), Rancor_Combat(), Rancor_Patrol(), Rancor_Smash(), Rancor_Swing(), Remote_Attack(), Remote_MaintainHeight(), Remote_Ranged(), saberCheckKnockdown_BrokenParry(), saberCheckKnockdown_DuelLoss(), saberCheckKnockdown_Thrown(), SaberCombatHandling(), saberKnockDown(), Seeker_MaintainHeight(), Seeker_Ranged(), SeekerDroneUpdate(), Sentry_AttackDecision(), Sentry_RangedAttack(), ShootThink(), SiegeItemThink(), Sniper_FaceEnemy(), Sniper_StartHide(), SP_misc_faller(), SP_NPC_BespinCop(), SP_NPC_Cultist(), SP_NPC_Gran(), SP_NPC_ImpWorker(), SP_NPC_Jedi(), SP_NPC_Prisoner(), SP_NPC_Rebel(), SP_NPC_ShadowTrooper(), SP_NPC_Stormtrooper(), SP_NPC_Ugnaught(), SP_NPC_Weequay(), ST_ApproachEnemy(), ST_Commander(), ST_GetCPFlags(), ST_HuntEnemy(), ST_MarkToCover(), ST_ResolveBlockedShot(), ST_TrackEnemy(), ST_TransferMoveGoal(), StandardBotAI(), StrafeTracing(), target_random_use(), Think_Strike(), TranslateSaberColor(), turret_head_think(), UI_FeederSelection(), VEH_StartStrafeRam(), Wampa_Attack(), Wampa_CheckRoar(), Wampa_Combat(), Wampa_Move(), Wampa_Patrol(), Wampa_Slash(), WP_FireMelee(), WP_FireStunBaton(), WP_SaberBlock(), WP_SaberBounceSound(), WP_SaberPositionUpdate(), WP_SabersCheckLock(), and WP_SaberStartMissileBlockCheck().

01472 {
01473         return irand(value1, value2);
01474 }

int Q_log2 int  val  ) 
 

Definition at line 1257 of file q_math.c.

01257                       {
01258         int answer;
01259 
01260         answer = 0;
01261         while ( ( val>>=1 ) != 0 ) {
01262                 answer++;
01263         }
01264         return answer;
01265 }

int Q_rand int *  seed  ) 
 

Definition at line 126 of file q_math.c.

Referenced by Q_random().

00126                                     {
00127         *seed = (69069 * *seed + 1);
00128         return *seed;
00129 }

float Q_random int *  seed  ) 
 

Definition at line 131 of file q_math.c.

References Q_rand().

Referenced by CG_SmokePuff(), PM_irand_timesync(), and Q_crandom().

00131                               {
00132         return ( Q_rand( seed ) & 0xffff ) / (float)0x10000;
00133 }

float Q_rsqrt float  number  ) 
 

Definition at line 616 of file q_math.c.

00617 {
00618         long i;
00619         float x2, y;
00620         const float threehalfs = 1.5F;
00621 
00622         x2 = number * 0.5F;
00623         y  = number;
00624         i  = * ( long * ) &y;                                           // evil floating point bit level hacking
00625         i  = 0x5f3759df - ( i >> 1 );               // what the fuck?
00626         y  = * ( float * ) &i;
00627         y  = y * ( threehalfs - ( x2 * y * y ) );   // 1st iteration
00628 //      y  = y * ( threehalfs - ( x2 * y * y ) );   // 2nd iteration, this can be removed
00629 
00630 #ifndef Q3_VM
00631 #ifdef __linux__
00632         assert( !isnan(y) ); // bk010122 - FPE?
00633 #endif
00634 #endif
00635         return y;
00636 }

float RadiusFromBounds const vec3_t  mins,
const vec3_t  maxs
 

Definition at line 1114 of file q_math.c.

References fabs(), and vec3_t.

Referenced by G_MoverPush().

01114                                                                {
01115         int             i;
01116         vec3_t  corner;
01117         float   a, b;
01118 
01119         for (i=0 ; i<3 ; i++) {
01120                 a = fabs( mins[i] );
01121                 b = fabs( maxs[i] );
01122                 corner[i] = a > b ? a : b;
01123         }
01124 
01125         return VectorLength (corner);
01126 }

void Rand_Init int  seed  ) 
 

Definition at line 1434 of file q_math.c.

01435 {
01436         holdrand = seed;
01437 }

void RotateAroundDirection vec3_t  axis[3],
float  yaw
 

Definition at line 466 of file q_math.c.

References PerpendicularVector(), RotatePointAroundVector(), vec3_t, and VectorCopy.

Referenced by CG_MakeExplosion(), and FX_AddOrientedLine().

00466                                                         {
00467 
00468         // create an arbitrary axis[1] 
00469         PerpendicularVector( axis[1], axis[0] );
00470 
00471         // rotate it around axis[0] by yaw
00472         if ( yaw ) {
00473                 vec3_t  temp;
00474 
00475                 VectorCopy( axis[1], temp );
00476                 RotatePointAroundVector( axis[1], axis[0], temp, yaw );
00477         }
00478 
00479         // cross to get axis[2]
00480         CrossProduct( axis[0], axis[1], axis[2] );
00481 }

void RotatePointAroundVector vec3_t  dst,
const vec3_t  dir,
const vec3_t  point,
float  degrees
 

Definition at line 405 of file q_math.c.

References cos(), DEG2RAD, MatrixMultiply(), memcpy(), memset(), PerpendicularVector(), sin(), and vec3_t.

Referenced by CG_ImpactMark(), and RotateAroundDirection().

00406                                                                          {
00407         float   m[3][3];
00408         float   im[3][3];
00409         float   zrot[3][3];
00410         float   tmpmat[3][3];
00411         float   rot[3][3];
00412         int     i;
00413         vec3_t vr, vup, vf;
00414         float   rad;
00415 
00416         vf[0] = dir[0];
00417         vf[1] = dir[1];
00418         vf[2] = dir[2];
00419 
00420         PerpendicularVector( vr, dir );
00421         CrossProduct( vr, vf, vup );
00422 
00423         m[0][0] = vr[0];
00424         m[1][0] = vr[1];
00425         m[2][0] = vr[2];
00426 
00427         m[0][1] = vup[0];
00428         m[1][1] = vup[1];
00429         m[2][1] = vup[2];
00430 
00431         m[0][2] = vf[0];
00432         m[1][2] = vf[1];
00433         m[2][2] = vf[2];
00434 
00435         memcpy( im, m, sizeof( im ) );
00436 
00437         im[0][1] = m[1][0];
00438         im[0][2] = m[2][0];
00439         im[1][0] = m[0][1];
00440         im[1][2] = m[2][1];
00441         im[2][0] = m[0][2];
00442         im[2][1] = m[1][2];
00443 
00444         memset( zrot, 0, sizeof( zrot ) );
00445         zrot[0][0] = zrot[1][1] = zrot[2][2] = 1.0F;
00446 
00447         rad = DEG2RAD( degrees );
00448         zrot[0][0] = cos( rad );
00449         zrot[0][1] = sin( rad );
00450         zrot[1][0] = -sin( rad );
00451         zrot[1][1] = cos( rad );
00452 
00453         MatrixMultiply( m, zrot, tmpmat );
00454         MatrixMultiply( tmpmat, im, rot );
00455 
00456         for ( i = 0; i < 3; i++ ) {
00457                 dst[i] = rot[i][0] * point[0] + rot[i][1] * point[1] + rot[i][2] * point[2];
00458         }
00459 }

void SetPlaneSignbits cplane_t out  ) 
 

Definition at line 751 of file q_math.c.

References cplane_t, cplane_s::normal, and cplane_s::signbits.

00751                                       {
00752         int     bits, j;
00753 
00754         // for fast box on planeside test
00755         bits = 0;
00756         for (j=0 ; j<3 ; j++) {
00757                 if (out->normal[j] < 0) {
00758                         bits |= 1<<j;
00759                 }
00760         }
00761         out->signbits = bits;
00762 }

void vectoangles const vec3_t  value1,
vec3_t  angles
 

Definition at line 485 of file q_math.c.

References atan2(), M_PI, PITCH, ROLL, sqrt(), vec3_t, and YAW.

Referenced by BG_AttachToRancor(), BG_G2PlayerAngles(), BG_TouchJumpPad(), Boba_FireDecide(), BotAimLeading(), BotTrace_Duck(), BotTrace_Jump(), BotTrace_Strafe(), CanCounterThrow(), CG_AddParticles(), CG_AddParticleToScene(), CG_CheckPassengerTurretView(), CG_Disintegration(), CG_DrawActiveFrame(), CG_DrawPlayerSphere(), CG_ParticleBloodCloud(), CG_ParticleDust(), CG_Player(), CG_PlayerShieldHit(), CG_PredictPlayerState(), CG_RagDoll(), CG_VehicleAttachDroidUnit(), charge_stick(), ClientThink_real(), CombatBotAI(), drop_charge(), emplaced_gun_use(), EWebFire(), EWebPositionUser(), FindIntermissionPoint(), ForceTelepathy(), ForceThrow(), fx_runner_link(), G_EstimateCamPos(), G_SPSaberDamageTraceLerped(), G_VehicleAttachDroidUnit(), GetAnglesForDirection(), ImperialProbe_FireBlaster(), InFOV(), InFOV3(), laserTrapStick(), LaunchItem(), maglock_link(), Mark1_FireBlaster(), Mark1_FireRocket(), Mark2_FireBlaster(), MeleeCombatHandling(), misc_weapon_shooter_aim(), NAV_MoveBlocker(), NAVNEW_Bypass(), NPC_BSAdvanceFight(), NPC_BSCinematic(), NPC_BSDefault(), NPC_BSFollowLeader(), NPC_BSGM_Attack(), NPC_BSGrenadier_Patrol(), NPC_BSJump(), NPC_BSNoClip(), NPC_BSPointShoot(), NPC_BSSniper_Patrol(), NPC_CheckCanAttack(), NPC_GetHFOVPercentage(), NPC_GetMoveDirection(), NPC_GetMoveDirectionAltRoute(), NPC_GetVFOVPercentage(), NPC_MoveToGoal(), P_DamageFeedback(), pas_think(), pitch_roll_for_slope(), PM_AnglesForSlope(), PM_pitch_roll_for_slope(), PM_VehForcedTurning(), PM_VehicleImpact(), ref_link(), Remote_Fire(), SaberCombatHandling(), ScanForEnemies(), StandardBotAI(), TurretClientRun(), ValidBloodPool(), VEH_TurretAim(), VEH_TurretAnglesToEnemy(), and WP_SaberPositionUpdate().

00485                                                        {
00486         float   forward;
00487         float   yaw, pitch;
00488         
00489         if ( value1[1] == 0 && value1[0] == 0 ) {
00490                 yaw = 0;
00491                 if ( value1[2] > 0 ) {
00492                         pitch = 90;
00493                 }
00494                 else {
00495                         pitch = 270;
00496                 }
00497         }
00498         else {
00499                 if ( value1[0] ) {
00500                         yaw = ( atan2 ( value1[1], value1[0] ) * 180 / M_PI );
00501                 }
00502                 else if ( value1[1] > 0 ) {
00503                         yaw = 90;
00504                 }
00505                 else {
00506                         yaw = 270;
00507                 }
00508                 if ( yaw < 0 ) {
00509                         yaw += 360;
00510                 }
00511 
00512                 forward = sqrt ( value1[0]*value1[0] + value1[1]*value1[1] );
00513                 pitch = ( atan2(value1[2], forward) * 180 / M_PI );
00514                 if ( pitch < 0 ) {
00515                         pitch += 360;
00516                 }
00517         }
00518 
00519         angles[PITCH] = -pitch;
00520         angles[YAW] = yaw;
00521         angles[ROLL] = 0;
00522 }

void Vector4Scale const vec4_t  in,
vec_t  scale,
vec4_t  out
 

Definition at line 1249 of file q_math.c.

References vec4_t, and vec_t.

01249                                                               {
01250         out[0] = in[0]*scale;
01251         out[1] = in[1]*scale;
01252         out[2] = in[2]*scale;
01253         out[3] = in[3]*scale;
01254 }

vec_t VectorNormalize vec3_t  v  ) 
 

Definition at line 1172 of file q_math.c.

References sqrt(), vec3_t, and vec_t.

Referenced by AimAtTarget(), AnimateRiders(), BG_G2PlayerAngles(), BG_VehTraceFromCamPos(), Boba_FireDecide(), BotAimLeading(), BotTrace_Strafe(), CanGetToVectorTravel(), CG_AddGhoul2Mark(), CG_AddLightningBeam(), CG_AddSaberBlade(), CG_AddScorePlum(), CG_BracketEntity(), CG_BubbleTrail(), CG_CalcEntityLerpPositions(), CG_CheckThirdPersonAlpha(), CG_Chunks(), CG_CreateDistortionTrailPart(), CG_CreateSaberMarks(), CG_Disintegration(), CG_DoCameraShake(), CG_DrawActiveFrame(), CG_DrawPlayerSphere(), CG_DrawRadar(), CG_EntityEvent(), CG_ExplosionEffects(), CG_MiscModelExplosion(), CG_Player(), CG_RagDoll(), CG_SaberClashFlare(), CG_SaberCompWork(), CG_SurfaceExplosion(), charge_stick(), ClientCommand(), ClientThink_real(), DebugLine(), DoGripAction(), DoImpact(), drop_charge(), emplaced_gun_use(), ForceShootDrain(), ForceShootLightning(), ForceTelepathyCheckDirectNPCTarget(), ForceThrow(), funcBBrushDieGo(), funcBBrushPain(), fx_runner_link(), G_AddPushVecToUcmd(), G_AttackDelay(), G_BounceProjectile(), G_CanJumpToEnemyVeh(), G_Damage(), G_DeflectMissile(), G_Dismember(), G_EstimateCamPos(), G_FindClosestPointOnLineSegment(), G_GetDismemberBolt(), G_GetHitLocation(), G_GetHitQuad(), G_KnockOffVehicle(), G_MoverTouchPushTriggers(), G_PointDistFromLineSegment(), G_ReflectMissile(), G_RunExPhys(), G_SPSaberDamageTraceLerped(), G_StartObjectMoving(), G_UcmdMoveForDir(), GlassUse(), ImperialProbe_Hunt(), InFront(), Interrogator_Hunt(), Jedi_CheckFlipEvasions(), Jedi_FindEnemyInCone(), locateCamera(), MakeNormalVectors(), NAV_MoveToGoal(), NAV_ResolveEntityCollision(), NAVNEW_DanceWithBlocker(), NAVNEW_MoveToGoal(), NAVNEW_ResolveEntityCollision(), NPC_BSAdvanceFight(), NPC_BSFlee(), NPC_BSFollowLeader(), NPC_BSGM_Attack(), NPC_BSJump(), NPC_BSNoClip(), NPC_BSST_Attack(), NPC_CheckCanAttack(), NPC_Droid_Pain(), NPC_FindCombatPoint(), NPC_GetMoveInformation(), NPC_PickAlly(), NPC_PickEnemy(), NPC_Probe_Pain(), NPC_SpawnType(), pas_fire(), PerpendicularVector(), Pickup_Powerup(), PlaneFromPoints(), PM_SaberLockBreak(), PM_SlideMove(), PM_StepSlideMove(), PM_VehicleImpact(), RaySphereIntersections(), ref_link(), Remote_Hunt(), rocketThink(), saberBackToOwner(), saberCheckKnockdown_BrokenParry(), saberCheckKnockdown_DuelLoss(), SaberCombatHandling(), saberFirstThrown(), Seeker_Fire(), Seeker_Hunt(), Seeker_Strafe(), SeekerDroneUpdate(), Sentry_Hunt(), ST_Commander(), StandardBotAI(), target_laser_think(), ThrowSaberToAttacker(), trigger_push_touch(), TurretClientRun(), UI_SaberDrawBlade(), Use_Shooter(), ValidateBoard(), VEH_TryEject(), VEH_TurretAnglesToEnemy(), WP_DropDetPack(), WP_LobFire(), WP_SaberBlock(), WP_SaberBlockNonRandom(), WP_SaberPositionUpdate(), WP_SaberRadiusDamage(), WP_SabersIntersect(), WP_SaberStartMissileBlockCheck(), WP_VehCheckTraceFromCamPos(), and WP_VehLeadCrosshairVeh().

01172                                   {
01173         float   length, ilength;
01174 
01175         length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
01176         length = sqrt (length);
01177 
01178         if ( length ) {
01179                 ilength = 1/length;
01180                 v[0] *= ilength;
01181                 v[1] *= ilength;
01182                 v[2] *= ilength;
01183         }
01184                 
01185         return length;
01186 }

vec_t VectorNormalize2 const vec3_t  v,
vec3_t  out
 

Definition at line 1188 of file q_math.c.

References sqrt(), vec3_t, vec_t, and VectorClear.

Referenced by Boba_StopKnockdown(), CG_ImpactMark(), ClientThink_real(), DotProductNormalize(), FX_BlasterAltFireThink(), FX_BlasterProjectileThink(), FX_BowcasterAltProjectileThink(), FX_BowcasterProjectileThink(), FX_BryarAltProjectileThink(), FX_BryarProjectileThink(), FX_ConcussionProjectileThink(), FX_DEMP2_ProjectileThink(), FX_FlechetteAltProjectileThink(), FX_FlechetteProjectileThink(), FX_RepeaterAltProjectileThink(), FX_RepeaterProjectileThink(), FX_RocketAltProjectileThink(), FX_RocketProjectileThink(), FX_TurretProjectileThink(), Jedi_SaberBlockGo(), NAV_Bypass(), NAV_TrueCollision(), PM_SlideMove(), PM_VehicleImpact(), and WP_SaberStartMissileBlockCheck().

01188                                                     {
01189         float   length, ilength;
01190 
01191         length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
01192         length = sqrt (length);
01193 
01194         if (length)
01195         {
01196 #ifndef Q3_VM // bk0101022 - FPE related
01197 //        assert( ((Q_fabs(v[0])!=0.0f) || (Q_fabs(v[1])!=0.0f) || (Q_fabs(v[2])!=0.0f)) );
01198 #endif
01199                 ilength = 1/length;
01200                 out[0] = v[0]*ilength;
01201                 out[1] = v[1]*ilength;
01202                 out[2] = v[2]*ilength;
01203         } else {
01204 #ifndef Q3_VM // bk0101022 - FPE related
01205 //        assert( ((Q_fabs(v[0])==0.0f) && (Q_fabs(v[1])==0.0f) && (Q_fabs(v[2])==0.0f)) );
01206 #endif
01207                 VectorClear( out );
01208         }
01209                 
01210         return length;
01211 
01212 }

void VectorRotate vec3_t  in,
vec3_t  matrix[3],
vec3_t  out
 

Definition at line 603 of file q_math.c.

References DotProduct, and vec3_t.

00604 {
00605         out[0] = DotProduct( in, matrix[0] );
00606         out[1] = DotProduct( in, matrix[1] );
00607         out[2] = DotProduct( in, matrix[2] );
00608 }


Variable Documentation

vec3_t axisDefault[3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }
 

Definition at line 8 of file q_math.c.

Referenced by CG_Chunks(), CG_LaunchGib(), and CG_ThrowChunk().

vec3_t bytedirs[NUMVERTEXNORMALS]
 

Definition at line 39 of file q_math.c.

Referenced by ByteToDir(), and DirToByte().

vec4_t colorBlack = {0, 0, 0, 1}
 

Definition at line 11 of file q_math.c.

Referenced by UI_DrawTextBox().

vec4_t colorBlue = {0, 0, 1, 1}
 

Definition at line 14 of file q_math.c.

vec4_t colorCyan = {0, 1, 1, 1}
 

Definition at line 17 of file q_math.c.

vec4_t colorDkBlue = {0.199f, 0.0f, 0.398f, 1}
 

Definition at line 24 of file q_math.c.

vec4_t colorDkGrey = {0.25, 0.25, 0.25, 1}
 

Definition at line 21 of file q_math.c.

vec4_t colorGreen = {0, 1, 0, 1}
 

Definition at line 13 of file q_math.c.

vec4_t colorLtBlue = {0.367f, 0.261f, 0.722f, 1}
 

Definition at line 23 of file q_math.c.

vec4_t colorLtGrey = {0.75, 0.75, 0.75, 1}
 

Definition at line 19 of file q_math.c.

vec4_t colorMagenta = {1, 0, 1, 1}
 

Definition at line 16 of file q_math.c.

vec4_t colorMdGrey = {0.5, 0.5, 0.5, 1}
 

Definition at line 20 of file q_math.c.

vec4_t colorRed = {1, 0, 0, 1}
 

Definition at line 12 of file q_math.c.

vec4_t colorWhite = {1, 1, 1, 1}
 

Definition at line 18 of file q_math.c.

Referenced by CG_DrawInformation(), CG_DrawOldScoreboard(), CG_DrawRadar(), CG_LoadBar(), UI_DrawConnectScreen(), and UI_DrawTextBox().

vec4_t colorYellow = {1, 1, 0, 1}
 

Definition at line 15 of file q_math.c.

vec4_t g_color_table[8]
 

Initial value:

        {
        {0.0, 0.0, 0.0, 1.0},
        {1.0, 0.0, 0.0, 1.0},
        {0.0, 1.0, 0.0, 1.0},
        {1.0, 1.0, 0.0, 1.0},
        {0.0, 0.0, 1.0, 1.0},
        {0.0, 1.0, 1.0, 1.0},
        {1.0, 0.0, 1.0, 1.0},
        {1.0, 1.0, 1.0, 1.0},
        }

Definition at line 26 of file q_math.c.

Referenced by CG_BracketEntity(), CG_DrawRadar(), CG_DrawStringExt(), CG_DrawVehicleAmmo(), CG_DrawVehicleAmmoLower(), and CG_DrawVehicleAmmoUpper().

vec3_t vec3_origin = {0,0,0}
 

Definition at line 7 of file q_math.c.

Referenced by AnglesToAxis(), BeginAutoPathRoutine(), BG_G2PlayerAngles(), BG_IK_MoveArm(), BG_VehTraceFromCamPos(), Boba_FireDecide(), ByteToDir(), CalcEntitySpot(), CanDamage(), CG_AddLightningBeam(), CG_AddPlayerWeapon(), CG_BloodTrail(), CG_BracketEntity(), CG_CheckThirdPersonAlpha(), CG_CreateSaberMarks(), CG_DamageFeedback(), CG_EntityEvent(), CG_PlayDoorLoopSound(), CG_Player(), CG_RagDoll(), CheckTournament(), ClientCommand(), ClientConnect(), DoImpact(), EWeb_Create(), FindIntermissionPoint(), FireVehicleWeapon(), ForceShootDrain(), ForceShootLightning(), ForceThrow(), FX_DisruptorAltMiss(), G_CheckClientIdle(), G_CheckForDismemberment(), G_CheckMovingLoopingSounds(), G_Damage(), G_ExpandPointToBBox(), G_GetHitLocation(), G_LocationBasedDamageModifier(), G_MoverTeam(), G_MuteSound(), G_PortalifyEntities(), G_RunStuckMissile(), G_TryPushingEntity(), GM_Dying(), Howler_TryDamage(), ImperialProbe_FireBlaster(), InFOV(), InitTrigger(), Jedi_FindEnemyInCone(), maglock_link(), MineMonster_TryDamage(), NAV_Bypass(), NAVNEW_DanceWithBlocker(), NAVNEW_PushBlocker(), NPC_BSFollowLeader(), NPC_BSGM_Attack(), NPC_Droid_Pain(), NPC_GM_StartLaser(), NPC_Seeker_Pain(), NPC_ShotEntity(), pitch_roll_for_slope(), PM_pitch_roll_for_slope(), PM_VehicleImpact(), PrintCTFMessage(), Rancor_Attack(), Rancor_Bite(), Rancor_Smash(), Rancor_Swing(), SelectCTFSpawnPoint(), SelectInitialSpawnPoint(), SelectSiegeSpawnPoint(), Sniper_FaceEnemy(), StandardBotAI(), TossClientItems(), TryUse(), TurretClientRun(), turretG2_set_models(), UI_SaberDrawBlade(), Wampa_Slash(), WP_InitForcePowers(), WP_SaberDamageAdd(), WP_SaberRadiusDamage(), and WP_VehCheckTraceFromCamPos().