#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] |
|
||||||||||||
|
Definition at line 1221 of file q_math.c.
01221 {
01222 return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
01223 }
|
|
||||||||||||||||
|
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 }
|
|
||||||||||||
|
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 }
|
|
||||||||||||||||||||
|
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 }
|
|
||||||||||||||||
|
Definition at line 1243 of file q_math.c.
01243 {
01244 out[0] = in[0]*scale;
01245 out[1] = in[1]*scale;
01246 out[2] = in[2]*scale;
01247 }
|
|
||||||||||||||||
|
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 }
|
|
||||||||||||||||
|
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 }
|
|
||||||||||||
|
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 }
|
|
|
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 }
|
|
|
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 }
|
|
|
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 }
|
|
||||||||||||||||
|
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 }
|
|
||||||||||||
|
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 }
|
|
||||||||||||
|
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 }
|
|
||||||||||||||||||||
|
|
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 }
|
|
||||||||||||
|
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 }
|
|
||||||||||||||||
|
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 }
|
|
||||||||||||
|
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 }
|
|
|
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 }
|
|
|
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 }
|
|
||||||||||||
|
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 }
|
|
||||||||||||||||
|
Definition at line 333 of file q_math.c. References byte.
|
|
||||||||||||||||||||
|
Definition at line 343 of file q_math.c. References byte.
|
|
|
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 }
|
|
||||||||||||
|
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 }
|
|
||||||||||||
|
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 }
|
|
||||||||||||
|
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 }
|
|
||||||||||||
|
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().
|
|
||||||||||||||||||||
|
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 }
|
|
||||||||||||||||
|
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 }
|
|
||||||||||||
|
Definition at line 1458 of file q_math.c. References min. Referenced by Q_irand().
|
|
||||||||||||||||
|
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 }
|
|
||||||||||||||||
|
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 }
|
|
||||||||||||||||
|
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 }
|
|
||||||||||||
|
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 }
|
|
||||||||||||
|
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 }
|
|
||||||||||||
|
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 }
|
|
||||||||||||||||||||
|
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 }
|
|
||||||||||||
|
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 }
|
|
||||||||||||||||
|
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 }
|
|
|
Definition at line 135 of file q_math.c. References Q_random().
00135 {
00136 return 2.0 * ( Q_random( seed ) - 0.5 );
00137 }
|
|
|
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 }
|
|
||||||||||||
|
Definition at line 1451 of file q_math.c.
01452 {
01453 return flrand(min,max);
01454 }
|
|
||||||||||||
|
|
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 }
|
|
|
Definition at line 126 of file q_math.c. Referenced by Q_random().
00126 {
00127 *seed = (69069 * *seed + 1);
00128 return *seed;
00129 }
|
|
|
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 }
|
|
|
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 }
|
|
||||||||||||
|
Definition at line 1114 of file q_math.c. References fabs(), and vec3_t. Referenced by G_MoverPush().
|
|
|
Definition at line 1434 of file q_math.c.
01435 {
01436 holdrand = seed;
01437 }
|
|
||||||||||||
|
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 }
|
|
||||||||||||||||||||
|
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 }
|
|
|
Definition at line 751 of file q_math.c. References cplane_t, cplane_s::normal, and cplane_s::signbits.
|
|
||||||||||||
|
||||||||||||||||
|
Definition at line 1249 of file q_math.c.
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 }
|
|
|
||||||||||||
|
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 }
|
|
||||||||||||||||
|
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 }
|
|
|
Definition at line 8 of file q_math.c. Referenced by CG_Chunks(), CG_LaunchGib(), and CG_ThrowChunk(). |
|
|
Definition at line 39 of file q_math.c. Referenced by ByteToDir(), and DirToByte(). |
|
|
Definition at line 11 of file q_math.c. Referenced by UI_DrawTextBox(). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Definition at line 18 of file q_math.c. Referenced by CG_DrawInformation(), CG_DrawOldScoreboard(), CG_DrawRadar(), CG_LoadBar(), UI_DrawConnectScreen(), and UI_DrawTextBox(). |
|
|
|
|
|
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(). |
|