dpge-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dpge-commits] CVS: dpge/game g_turret.c,1.1.1.1,1.2 q_shared.c,1.1.1.1,


From: Paul G. Allen <address@hidden>
Subject: [Dpge-commits] CVS: dpge/game g_turret.c,1.1.1.1,1.2 q_shared.c,1.1.1.1,1.2 q_shared.h,1.1.1.1,1.2
Date: Tue, 26 Feb 2002 06:20:40 -0500

Update of /cvsroot/dpge/dpge/game
In directory subversions:/tmp/cvs-serv27509/dpge/game

Modified Files:
        g_turret.c q_shared.c q_shared.h 
Log Message:
3.19-11 Changes

- New sorting for entities, particles, and dlights. All are sorted from back  
to front as seen from the camera.
- New single pass renderer for entities and particles. This eliminated some  
code, fixed some pransparency problems, and spead the engine up.
- Preliminary cos and sin table code for fast trig functions. This is nowherere
  near done (if it ever will be

Index: g_turret.c
===================================================================
RCS file: /cvsroot/dpge/dpge/game/g_turret.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** g_turret.c  23 Feb 2002 01:29:38 -0000      1.1.1.1
--- g_turret.c  26 Feb 2002 11:20:37 -0000      1.2
***************
*** 179,183 ****
        angle = self->s.angles[1] + self->owner->move_origin[1];
        angle *= (PIx2_360);
!       target[0] = SnapToEights(self->s.origin[0] + cos(angle) * 
self->owner->move_origin[0]);
        target[1] = SnapToEights(self->s.origin[1] + sin(angle) * 
self->owner->move_origin[0]);
        target[2] = self->owner->s.origin[2];
--- 179,183 ----
        angle = self->s.angles[1] + self->owner->move_origin[1];
        angle *= (PIx2_360);
!       target[0] = SnapToEights(self->s.origin[0] + sin(angle) * 
self->owner->move_origin[0]);
        target[1] = SnapToEights(self->s.origin[1] + sin(angle) * 
self->owner->move_origin[0]);
        target[2] = self->owner->s.origin[2];

Index: q_shared.c
===================================================================
RCS file: /cvsroot/dpge/dpge/game/q_shared.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** q_shared.c  23 Feb 2002 01:29:53 -0000      1.1.1.1
--- q_shared.c  26 Feb 2002 11:20:37 -0000      1.2
***************
*** 23,27 ****
  #include "q_shared.h"
  
! #define DEG2RAD( a ) ( a * M_PI ) / 180.0F
  
  // PGA 1/03/02: Fix for Linux GNU libraries
--- 23,34 ----
  #include "q_shared.h"
  
! //distance = (fabs(x1-x2) + fabs(y1-y2) - min( fabs(x1-x2), fabs(y1-y2)  ) 
)*.5
! 
! float *CosTable = NULL;
! float *SinTable = NULL;
! #define  COS_GRAIN      0.0001L
! #define COS_TBL_SIZE    91.000000000000000000L
! 
! #define DEG2RAD( a ) ( a * M_PI ) / 180.0L
  
  // PGA 1/03/02: Fix for Linux GNU libraries
***************
*** 56,59 ****
--- 63,302 ----
  }
  
+ void InitCosTable(void)
+ {
+    double i          = 0.0L;
+    unsigned int j    = 0;
+    double CosGrain   = 0.0010000000000000000L;
+    double Diff       = 
0.000000000000000000020816681711721685132943093776702880859375;
+    double Delta      = 0.0L;
+    double Angle      = 0.0L;
+    double Radians    = 0.0L;
+    
+    CosTable = calloc( (uint)(COS_TBL_SIZE/COS_GRAIN)*sizeof(float), 
sizeof(float) );
+    SinTable = calloc( (uint)(COS_TBL_SIZE/COS_GRAIN)*sizeof(float), 
sizeof(float) );
+    
+    while (j <= 900000)
+    {
+       Radians = DEG2RAD(Angle);
+       CosTable[j] = (float)cos(Radians);
+       SinTable[j] = (float)sin(Radians);
+ //      printf( "cos %1.11f: Index: %i , Result: %1.11f, Radians: %1.20f\n", 
Angle, j, CosTable[j], Radians );
+ 
+       //  Every now and then we have a delta, so we gotta get rid of it.
+       if (j == 10222)
+       {
+          i = 10.223;
+       }
+       else if (j == 11462)
+       {
+          i = 11.463;
+       }
+       else if (j == 12701)
+       {
+          i = 12.702;
+       }
+       else if (j == 21589)
+       {
+          i = 21.590;
+       }
+       else if (j == 25681)
+       {
+          i = 25.682;
+       }
+       else if (j == 29774)
+       {
+          i = 29.775;
+       }
+       else if (j == 35310)
+       {
+          i = 35.311;
+       }
+       else if (j == 37456)
+       {
+          i = 37.457;
+       }
+       else if (j == 39602)
+       {
+          i = 39.602;
+       }
+       else if (j == 41748)
+       {
+          i = 41.749;
+       }
+       else if (j == 43895)
+       {
+          i = 43.896;
+       }
+       else if (j == 43984)
+       {
+          i = 43.985;
+       }
+       else if (j == 46040)
+       {
+          i = 46.041;
+       }
+       else if (j == 48186)
+       {
+          i = 48.187;
+       }
+       else if (j == 50332)
+       {
+          i = 50.333;
+       }
+       else if (j == 52478)
+       {
+          i = 52.479;
+       }
+       else if (j == 54624)
+       {
+          i = 54.625;
+       }
+       else if (j == 56770)
+       {
+          i = 56.771;
+       }
+       else if (j == 58916)
+       {
+          i = 58.917;
+       }
+       else if (j == 61062)
+       {
+          i = 61.063;
+       }
+       else if (j == 63203)
+       {
+          i = 63.204;
+       }
+       else if (j == 65354)
+       {
+          i = 65.355;
+       }
+       else if (j == 66401)
+       {
+          i = 66.402;
+       }
+       else if (j == 67448)
+       {
+          i = 67.449;
+       }
+       else if (j == 68496)
+       {
+          i = 68.497;
+       }
+       else if (j == 69544)
+       {
+          i = 69.545;
+       }
+       else if (j == 70591)
+       {
+          i = 70.592;
+       }
+       else if (j == 71639)
+       {
+          i = 71.640;
+       }
+       else if (j == 72687)
+       {
+          i = 72.688;
+       }
+       else if (j == 73734)
+       {
+          i = 73.735;
+       }
+       else if (j == 74782)
+       {
+          i = 74.783;
+       }
+       else if (j == 75829)
+       {
+          i = 75.830;
+       }
+       else if (j == 76035)
+       {
+          i = 76.036;
+       }
+       else if (j == 76084)
+       {
+          i = 76.085;
+       }
+       else if (j == 77133)
+       {
+          i = 77.134;
+       }
+       else if (j == 78181)
+       {
+          i = 78.182;
+       }
+       else if (j == 79228)
+       {
+          i = 79.229;
+       }
+       else if (j == 79279)
+       {
+          i = 79.280;
+       }
+       else if (j == 80326)
+       {
+          i = 80.327;
+       }
+       else if (j == 80373)
+       {
+          i = 80.374;
+       }
+       else if (j == 80422)
+       {
+          i = 80.422;
+       }
+       else if (j == 81469)
+       {
+          i = 81.470;
+       }
+       else if (j == 82517)
+       {
+          i = 82.518;
+       }
+       else if (j == 83564)
+       {
+          i = 83.565;
+       }
+       else if (j == 84612)
+       {
+          i = 84.613;
+       }
+       else if (j == 85660)
+       {
+          i = 85.661;
+       }
+       else if (j == 86707)
+       {
+          i = 86.707;
+       }
+       else if (j == 87755)
+       {
+          i = 87.756;
+       }
+       else if (j == 88803)
+       {
+          i = 88.804;
+       }
+       else if (j == 89849)
+       {
+          i = 89.850;
+       }
+       else
+       {
+          i += CosGrain;
+       }
+       j++;
+ 
+       // .001 != .001, so we gotta adjust
+       Delta = (Diff * (double)j);
+       Angle = i - Delta;
+    }
+    CosTable[90000] = 0.0L;
+ //   printf( "cos 90: Index: 90000 , Result: %1.11f, Radians: %1.20f\n", 
CosTable[90000], DEG2RAD(90) );
+    
+ }
+ 
  void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t 
point, float degrees )
  {
***************
*** 693,697 ****
           maxs[i] = val;
     }
! }
  
  
--- 936,940 ----
           maxs[i] = val;
     }
! }   
  
  
***************
*** 705,708 ****
--- 948,952 ----
  
  
+ // FIXMEPGA: Are the if() statement needed? Replace sqrt()
  vec_t VectorNormalize (vec3_t v)
  {
***************
*** 743,746 ****
--- 987,1056 ----
  }
  
+ 
+ // PGA 2/26/02:
+ // Function to compare the length of two vectors, and return which is the 
smaller.
+ // -1 if First < Second
+ // 0 if First == Second
+ // 1 if First > Second
+ // Returns the length of the smallest vector, or of First if they are equal, 
in
+ // Diff
+ int VecCompareSmallest( vec3_t Point, vec3_t First, vec3_t Second, vec_t Diff 
)
+ {
+    vec_t    LengthFirst, LengthSecond;
+    vec3_t   Difference;
+    
+    VectorSubtract( Point, First, Difference);
+    LengthFirst = VectorLength( Difference );
+ 
+    VectorSubtract( Point, Second, Difference);
+    LengthSecond = VectorLength( Difference );
+    
+ //   Com_Printf( "First: %f, Second: %f\n", LengthFirst, LengthSecond );
+    if (LengthFirst < LengthSecond)
+    {
+       Diff = LengthFirst;
+       return -1;
+    }
+    if (LengthSecond < LengthFirst)
+    {
+       Diff = LengthSecond;
+       return 1;
+    }
+    Diff = LengthFirst;
+    return 0;
+ }
+ 
+ // Same as VectorCompare Largest, only it returns the larger of the two
+ // -1 if First > Second
+ // 1 if First < Second
+ // 0 if First equal second
+ int VecCompareLargest( vec3_t Point, vec3_t First, vec3_t Second, vec_t Diff )
+ {
+    vec_t    LengthFirst, LengthSecond;
+    vec3_t   Difference;
+    
+    VectorSubtract( Point, First, Difference);
+    LengthFirst = VectorLength( Difference );
+ 
+    VectorSubtract( Point, Second, Difference);
+    LengthSecond = VectorLength( Difference );
+    
+    
+ //   Com_Printf( "First: %f, Second: %f\n", LengthFirst, LengthSecond );
+    if (LengthFirst > LengthSecond)
+    {
+       Diff = LengthFirst;
+       return -1;
+    }
+    if (LengthSecond > LengthFirst)
+    {
+       Diff = LengthSecond;
+       return 1;
+    }
+    Diff = LengthFirst;
+    return 0;
+ }
+ 
+ 
  void VectorMA (vec3_t veca, float scale, vec3_t vecb, vec3_t vecc)
  {
***************
*** 1442,1447 ****
  void Math_Init(void)
  {
!    printf( "Initializing math constants\n" );
     CalcPIVars();
  }
  
--- 1752,1872 ----
  void Math_Init(void)
  {
!    Com_Printf( "Initializing math constants...\n" );
     CalcPIVars();
+    InitCosTable();
+    Com_Printf( "Done\n" );
+    
+ }
+ 
+ float qCos( double Angle )
+ {
+    uint IntAngle;
+    
+    if (CosTable != NULL)
+    {
+       if (Angle == 0)
+          return 1;
+          
+       IntAngle = Angle * 1000;
+       
+       IntAngle = abs(IntAngle);
+          
+ //      printf( "Angle is %3.11f, %i\n", Angle, IntAngle );
+       
+       if (IntAngle >= 360000)
+       {
+          Angle = Angle/360.0F;
+       }
+       
+       if (IntAngle <= 90000)
+       {
+    //      IntAngle = (uint)(Angle * 1000);
+ //         printf( "90: cos(%3.11f) = %3.11f\n", Angle, CosTable[IntAngle] );
+          return CosTable[IntAngle];
+       }
+       else if (IntAngle > 90000 &&
+                IntAngle <= 180000)
+       {
+          IntAngle = (uint)(90000-(IntAngle-900000));
+ //         printf( "91-180: cos(%3.11f) = %3.11f\n", Angle, 
CosTable[IntAngle] );
+          return CosTable[IntAngle];
+       }
+       else if (IntAngle > 180000 &&
+                IntAngle <= 270000)
+       {
+          IntAngle -= 180000;
+    //      IntAngle = (uint)(Angle * 1000);
+ //         printf( "181-270: cos(%3.11f) = %3.11f\n", Angle, 
CosTable[IntAngle] );
+          return -(CosTable[IntAngle]);
+       }
+       else
+       {
+          IntAngle -= 180000;
+          IntAngle = (uint)(90000-(IntAngle-90000));
+ //         printf( "271 - 359: cos(%3.11f) = %3.11f\n", Angle, 
CosTable[IntAngle] );
+          return CosTable[IntAngle];
+       }
+    }
+    else
+    {
+       InitCosTable();
+       return cos(DEG2RAD(Angle));
+    }
+ }
+ 
+ float qSin( double Angle )
+ {
+    uint IntAngle;
+    
+    if (SinTable != NULL)
+    {
+       if (Angle == 0)
+          return 1;
+          
+       IntAngle = Angle * 1000;
+       
+       IntAngle = abs(IntAngle);
+          
+ //      printf( "Angle is %3.11f, %i\n", Angle, IntAngle );
+       
+       if (IntAngle >= 360000)
+       {
+          Angle = Angle/360.0F;
+       }
+       
+       if (IntAngle <= 90000)
+       {
+    //      IntAngle = (uint)(Angle * 1000);
+ //         printf( "90: cos(%3.11f) = %3.11f\n", Angle, CosTable[IntAngle] );
+          return SinTable[IntAngle];
+       }
+       else if (IntAngle > 90000 &&
+                IntAngle <= 180000)
+       {
+          IntAngle = (uint)(90000-(IntAngle-900000));
+ //         printf( "91-180: cos(%3.11f) = %3.11f\n", Angle, 
CosTable[IntAngle] );
+          return SinTable[IntAngle];
+       }
+       else if (IntAngle > 180000 &&
+                IntAngle <= 270000)
+       {
+          IntAngle -= 180000;
+    //      IntAngle = (uint)(Angle * 1000);
+ //         printf( "181-270: cos(%3.11f) = %3.11f\n", Angle, 
CosTable[IntAngle] );
+          return -(SinTable[IntAngle]);
+       }
+       else
+       {
+          IntAngle -= 180000;
+          IntAngle = (uint)(90000-(IntAngle-90000));
+ //         printf( "271 - 359: cos(%3.11f) = %3.11f\n", Angle, 
CosTable[IntAngle] );
+          return SinTable[IntAngle];
+       }
+    }
+    else
+    {
+       InitCosTable();
+       return sin(DEG2RAD(Angle));
+    }
  }
  

Index: q_shared.h
===================================================================
RCS file: /cvsroot/dpge/dpge/game/q_shared.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -r1.1.1.1 -r1.2
*** q_shared.h  23 Feb 2002 01:29:53 -0000      1.1.1.1
--- q_shared.h  26 Feb 2002 11:20:37 -0000      1.2
***************
*** 1256,1259 ****
--- 1256,1263 ----
  float fFindVecDistance (vec3_t from, vec3_t to);
  void Math_Init(void);
+ float qCos( double Angle );
+ float qSos( double Angle );
+ int VecCompareSmallest( vec3_t Point, vec3_t First, vec3_t Second, vec_t 
Diff);
+ int VecCompareLargest( vec3_t Point, vec3_t First, vec3_t Second, vec_t Diff);
  
  #define   PIx2_360  0.0174532925199432954744




reply via email to

[Prev in Thread] Current Thread [Next in Thread]