IEpairs.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. //-----------------------------------------------------------------------------
  19. //
  20. // $LogFile$
  21. // $Revision: 1.1.1.4 $
  22. // $Author: ttimo $
  23. // $Date: 2000/01/18 00:17:12 $
  24. // $Log: IEpairs.cpp,v $
  25. // Revision 1.1.1.4 2000/01/18 00:17:12 ttimo
  26. // merging in for RC
  27. //
  28. // Revision 1.3 2000/01/17 23:53:41 TBesset
  29. // ready for merge in sourceforge (RC candidate)
  30. //
  31. // Revision 1.2 2000/01/07 16:40:10 TBesset
  32. // merged from BSP frontend
  33. // Revision 1.1.1.3 1999/12/29 18:31:26 TBesset
  34. // Q3Radiant public version
  35. //
  36. //
  37. // Revision 1.2 1999/11/22 17:46:45 Timo & Christine
  38. // merged EARadiant into the main tree
  39. // bug fixes for Q3Plugin / EAPlugin
  40. // export for Robert
  41. //
  42. // Revision 1.1.2.1 1999/11/03 20:37:59 Timo & Christine
  43. // MEAN plugin for Q3Radiant, alpha version
  44. //
  45. //
  46. // DESCRIPTION:
  47. // virtual class to allow plugin operations on entities epairs
  48. //
  49. #include "stdafx.h"
  50. void CEpairsWrapper::GetVectorForKey( char* key, vec3_t vec )
  51. {
  52. ::GetVectorForKey( m_pEnt, key, vec );
  53. }
  54. float CEpairsWrapper::FloatForKey( char *key )
  55. {
  56. return ::FloatForKey( m_pEnt, key );
  57. }
  58. char* CEpairsWrapper::ValueForKey( char *key )
  59. {
  60. return ::ValueForKey( m_pEnt, key );
  61. }
  62. void CEpairsWrapper::SetKeyValue( char *key, char *value )
  63. {
  64. ::SetKeyValue( m_pEnt, key, value );
  65. }
  66. void CEpairsWrapper::GetEntityOrigin( vec3_t vec )
  67. {
  68. VectorCopy( m_pEnt->origin, vec );
  69. }
  70. // taken from Ritual's version of Q3Radiant ( Entity_CalculateRotatedBounds )
  71. void CEpairsWrapper::CalculateRotatedBounds( vec3_t mins, vec3_t maxs )
  72. {
  73. entity_t *ent = m_pEnt;
  74. int i;
  75. float angle;
  76. vec3_t angles;
  77. vec3_t forward,right,up;
  78. vec3_t rotmins, rotmaxs;
  79. float trans[3][3];
  80. qboolean changed;
  81. char tempangles[ 128 ];
  82. memset( angles, 0, sizeof(vec3_t) );
  83. ::GetVectorForKey (ent, "angles", angles);
  84. changed = false;
  85. while ( angles[0] < 0 )
  86. {
  87. changed = true;
  88. angles[0] += 360;
  89. }
  90. while ( angles[0] > 359 )
  91. {
  92. changed = true;
  93. angles[0] -= 360;
  94. }
  95. while ( angles[1] < 0 )
  96. {
  97. changed = true;
  98. angles[1] += 360;
  99. }
  100. while ( angles[1] > 359 )
  101. {
  102. changed = true;
  103. angles[1] -= 360;
  104. }
  105. while ( angles[2] < 0 )
  106. {
  107. changed = true;
  108. angles[2] += 360;
  109. }
  110. while ( angles[2] > 359 )
  111. {
  112. changed = true;
  113. angles[2] -= 360;
  114. }
  115. if ( changed )
  116. {
  117. sprintf( tempangles, "%d %d %d", (int)angles[0], (int)angles[1], (int)angles[2] );
  118. ::SetKeyValue ( ent, "angles", tempangles );
  119. }
  120. angle = ::FloatForKey (ent, "angle");
  121. if ( fabs(angle) > 2 )
  122. {
  123. angles[1] = angle;
  124. }
  125. else if (angle == -1)
  126. {
  127. angles[0] = -90;
  128. }
  129. else if (angle == -2)
  130. {
  131. angles[0] = 90;
  132. }
  133. ::AngleVectors( angles, forward, right, up );
  134. for (i=0 ; i<3 ; i++)
  135. {
  136. trans[i][0] = forward[i];
  137. trans[i][1] = -right[i];
  138. trans[i][2] = up[i];
  139. }
  140. ClearBounds( rotmins, rotmaxs );
  141. for ( i = 0; i < 8; i++ )
  142. {
  143. int j;
  144. vec3_t tmp, rottemp;
  145. if ( i & 1 )
  146. tmp[0] = mins[0];
  147. else
  148. tmp[0] = maxs[0];
  149. if ( i & 2 )
  150. tmp[1] = mins[1];
  151. else
  152. tmp[1] = maxs[1];
  153. if ( i & 4 )
  154. tmp[2] = mins[2];
  155. else
  156. tmp[2] = maxs[2];
  157. for (j=0; j<3 ; j++)
  158. {
  159. rottemp[j] = DotProduct( tmp, trans[j] );
  160. }
  161. AddPointToBounds( rottemp, rotmins, rotmaxs );
  162. }
  163. VectorCopy( rotmins, mins );
  164. VectorCopy( rotmaxs, maxs );
  165. }