home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 58 / pcpp58a.iso / extras / quake 3 source / Q3A_ToolSource.exe / Main / IEpairs.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-02  |  3.3 KB  |  165 lines

  1. //-----------------------------------------------------------------------------
  2. //
  3. // $LogFile$
  4. // $Revision: 1.1.1.4 $
  5. // $Author: ttimo $
  6. // $Date: 2000/01/18 00:17:12 $
  7. // $Log: IEpairs.cpp,v $
  8. // Revision 1.1.1.4  2000/01/18 00:17:12  ttimo
  9. // merging in for RC
  10. //
  11. // Revision 1.3  2000/01/17 23:53:41  TBesset
  12. // ready for merge in sourceforge (RC candidate)
  13. //
  14. // Revision 1.2  2000/01/07 16:40:10  TBesset
  15. // merged from BSP frontend
  16. // Revision 1.1.1.3  1999/12/29 18:31:26  TBesset
  17. // Q3Radiant public version
  18. //
  19. //
  20. // Revision 1.2  1999/11/22 17:46:45  Timo & Christine
  21. // merged EARadiant into the main tree
  22. // bug fixes for Q3Plugin / EAPlugin
  23. // export for Robert
  24. //
  25. // Revision 1.1.2.1  1999/11/03 20:37:59  Timo & Christine
  26. // MEAN plugin for Q3Radiant, alpha version
  27. //
  28. //
  29. // DESCRIPTION:
  30. // virtual class to allow plugin operations on entities epairs
  31. //
  32.  
  33. #include "stdafx.h"
  34.  
  35. void CEpairsWrapper::GetVectorForKey( char* key, vec3_t vec )
  36. {
  37.     ::GetVectorForKey( m_pEnt, key, vec );
  38. }
  39.  
  40. float CEpairsWrapper::FloatForKey( char *key )
  41. {
  42.     return ::FloatForKey( m_pEnt, key );
  43. }
  44.  
  45. char* CEpairsWrapper::ValueForKey( char *key )
  46. {
  47.     return ::ValueForKey( m_pEnt, key );
  48. }
  49.  
  50. void CEpairsWrapper::SetKeyValue( char *key, char *value )
  51. {
  52.     ::SetKeyValue( m_pEnt, key, value );
  53. }
  54.  
  55. void CEpairsWrapper::GetEntityOrigin( vec3_t vec )
  56. {
  57.     VectorCopy( m_pEnt->origin, vec );
  58. }
  59.  
  60. // taken from Ritual's version of Q3Radiant ( Entity_CalculateRotatedBounds )
  61. void CEpairsWrapper::CalculateRotatedBounds( vec3_t mins, vec3_t maxs )
  62. {
  63.     entity_t *ent = m_pEnt;
  64.     int i;
  65.     float angle;
  66.     vec3_t angles;
  67.     vec3_t forward,right,up;
  68.     vec3_t rotmins, rotmaxs;
  69.     float trans[3][3];
  70.     qboolean changed;
  71.     char tempangles[ 128 ]; 
  72.     
  73.     memset( angles, 0, sizeof(vec3_t) );
  74.     ::GetVectorForKey (ent, "angles", angles);
  75.     
  76.     changed = false;
  77.     while ( angles[0] < 0 )
  78.     {
  79.         changed = true;
  80.         angles[0] += 360;
  81.     }
  82.     while ( angles[0] > 359 )
  83.     {
  84.         changed = true;
  85.         angles[0] -= 360;
  86.     }
  87.     while ( angles[1] < 0 )
  88.     {
  89.         changed = true;
  90.         angles[1] += 360;
  91.     }
  92.     while ( angles[1] > 359 )
  93.     {
  94.         changed = true;
  95.         angles[1] -= 360;
  96.     }
  97.     while ( angles[2] < 0 )
  98.     {
  99.         changed = true;
  100.         angles[2] += 360;
  101.     }
  102.     while ( angles[2] > 359 )
  103.     {
  104.         changed = true;
  105.         angles[2] -= 360;
  106.     }
  107.     
  108.     if ( changed )
  109.     {
  110.         sprintf( tempangles, "%d %d %d", (int)angles[0], (int)angles[1], (int)angles[2] );
  111.         ::SetKeyValue ( ent, "angles", tempangles );
  112.     }
  113.     
  114.     
  115.     angle = ::FloatForKey (ent, "angle");
  116.     if ( fabs(angle) > 2 )
  117.     {
  118.         angles[1] = angle;
  119.     }
  120.     else if (angle == -1)
  121.     {
  122.         angles[0] = -90;
  123.     }
  124.     else if (angle == -2)
  125.     {
  126.         angles[0] = 90;
  127.     }
  128.     ::AngleVectors( angles, forward, right, up );
  129.     for (i=0 ; i<3 ; i++)
  130.        {
  131.         trans[i][0] =  forward[i];
  132.         trans[i][1] =  -right[i];
  133.         trans[i][2] =  up[i];
  134.        }
  135.     ClearBounds( rotmins, rotmaxs );
  136.     for ( i = 0; i < 8; i++ )
  137.        {
  138.         int j;
  139.         vec3_t   tmp, rottemp;
  140.         
  141.         if ( i & 1 )
  142.             tmp[0] = mins[0];
  143.         else
  144.             tmp[0] = maxs[0];
  145.         
  146.         if ( i & 2 )
  147.             tmp[1] = mins[1];
  148.         else
  149.             tmp[1] = maxs[1];
  150.         
  151.         if ( i & 4 )
  152.             tmp[2] = mins[2];
  153.         else
  154.             tmp[2] = maxs[2];
  155.         
  156.         for (j=0; j<3 ; j++)
  157.         {
  158.             rottemp[j] =  DotProduct( tmp, trans[j] );
  159.         }
  160.         AddPointToBounds( rottemp, rotmins, rotmaxs );
  161.     }
  162.     VectorCopy( rotmins, mins );
  163.     VectorCopy( rotmaxs, maxs );
  164. }
  165.