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