Physics_StaticMulti.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #pragma hdrstop
  21. #include "../../idlib/precompiled.h"
  22. #include "../Game_local.h"
  23. CLASS_DECLARATION( idPhysics, idPhysics_StaticMulti )
  24. END_CLASS
  25. staticPState_t defaultState;
  26. staticInterpolatePState_t defaultInterpolateState;
  27. /*
  28. ================
  29. idPhysics_StaticMulti::idPhysics_StaticMulti
  30. ================
  31. */
  32. idPhysics_StaticMulti::idPhysics_StaticMulti() {
  33. self = NULL;
  34. hasMaster = false;
  35. isOrientated = false;
  36. defaultState.origin.Zero();
  37. defaultState.axis.Identity();
  38. defaultState.localOrigin.Zero();
  39. defaultState.localAxis.Identity();
  40. defaultInterpolateState.origin.Zero();
  41. defaultInterpolateState.axis = defaultState.axis.ToQuat();
  42. defaultInterpolateState.localAxis = defaultInterpolateState.axis;
  43. defaultInterpolateState.localOrigin.Zero();
  44. current.SetNum( 1 );
  45. current[0] = defaultState;
  46. previous.SetNum( 1 );
  47. previous[0] = defaultInterpolateState;
  48. next.SetNum( 1 );
  49. next[0] = defaultInterpolateState;
  50. clipModels.SetNum( 1 );
  51. clipModels[0] = NULL;
  52. }
  53. /*
  54. ================
  55. idPhysics_StaticMulti::~idPhysics_StaticMulti
  56. ================
  57. */
  58. idPhysics_StaticMulti::~idPhysics_StaticMulti() {
  59. if ( self && self->GetPhysics() == this ) {
  60. self->SetPhysics( NULL );
  61. }
  62. idForce::DeletePhysics( this );
  63. for ( int i = 0; i < clipModels.Num(); i++ ) {
  64. delete clipModels[i];
  65. }
  66. }
  67. /*
  68. ================
  69. idPhysics_StaticMulti::Save
  70. ================
  71. */
  72. void idPhysics_StaticMulti::Save( idSaveGame *savefile ) const {
  73. int i;
  74. savefile->WriteObject( self );
  75. savefile->WriteInt(current.Num());
  76. for ( i = 0; i < current.Num(); i++ ) {
  77. savefile->WriteVec3( current[i].origin );
  78. savefile->WriteMat3( current[i].axis );
  79. savefile->WriteVec3( current[i].localOrigin );
  80. savefile->WriteMat3( current[i].localAxis );
  81. }
  82. savefile->WriteInt( clipModels.Num() );
  83. for ( i = 0; i < clipModels.Num(); i++ ) {
  84. savefile->WriteClipModel( clipModels[i] );
  85. }
  86. savefile->WriteBool(hasMaster);
  87. savefile->WriteBool(isOrientated);
  88. }
  89. /*
  90. ================
  91. idPhysics_StaticMulti::Restore
  92. ================
  93. */
  94. void idPhysics_StaticMulti::Restore( idRestoreGame *savefile ) {
  95. int i, num;
  96. savefile->ReadObject( reinterpret_cast<idClass *&>( self ) );
  97. savefile->ReadInt(num);
  98. current.AssureSize( num );
  99. for ( i = 0; i < num; i++ ) {
  100. savefile->ReadVec3( current[i].origin );
  101. savefile->ReadMat3( current[i].axis );
  102. savefile->ReadVec3( current[i].localOrigin );
  103. savefile->ReadMat3( current[i].localAxis );
  104. }
  105. savefile->ReadInt(num);
  106. clipModels.SetNum( num );
  107. for ( i = 0; i < num; i++ ) {
  108. savefile->ReadClipModel( clipModels[i] );
  109. }
  110. savefile->ReadBool(hasMaster);
  111. savefile->ReadBool(isOrientated);
  112. }
  113. /*
  114. ================
  115. idPhysics_StaticMulti::SetSelf
  116. ================
  117. */
  118. void idPhysics_StaticMulti::SetSelf( idEntity *e ) {
  119. assert( e );
  120. self = e;
  121. }
  122. /*
  123. ================
  124. idPhysics_StaticMulti::RemoveIndex
  125. ================
  126. */
  127. void idPhysics_StaticMulti::RemoveIndex( int id, bool freeClipModel ) {
  128. if ( id < 0 || id >= clipModels.Num() ) {
  129. return;
  130. }
  131. if ( clipModels[id] && freeClipModel ) {
  132. delete clipModels[id];
  133. clipModels[id] = NULL;
  134. }
  135. clipModels.RemoveIndex( id );
  136. current.RemoveIndex( id );
  137. }
  138. /*
  139. ================
  140. idPhysics_StaticMulti::SetClipModel
  141. ================
  142. */
  143. void idPhysics_StaticMulti::SetClipModel( idClipModel *model, float density, int id, bool freeOld ) {
  144. int i;
  145. assert( self );
  146. if ( id >= clipModels.Num() ) {
  147. current.AssureSize( id+1, defaultState );
  148. clipModels.AssureSize( id+1, NULL );
  149. }
  150. if ( clipModels[id] && clipModels[id] != model && freeOld ) {
  151. delete clipModels[id];
  152. }
  153. clipModels[id] = model;
  154. if ( clipModels[id] ) {
  155. clipModels[id]->Link( gameLocal.clip, self, id, current[id].origin, current[id].axis );
  156. }
  157. for ( i = clipModels.Num() - 1; i >= 1; i-- ) {
  158. if ( clipModels[i] ) {
  159. break;
  160. }
  161. }
  162. current.SetNum( i+1 );
  163. clipModels.SetNum( i+1 );
  164. // Assure that on first setup, our next/previous is the same as current.
  165. previous.SetNum( current.Num() );
  166. next.SetNum( previous.Num() );
  167. for( int curIdx = 0; curIdx < current.Num(); curIdx++ ) {
  168. previous[curIdx] = ConvertPStateToInterpolateState( current[curIdx] );
  169. previous[curIdx] = next[curIdx];
  170. }
  171. }
  172. /*
  173. ================
  174. idPhysics_StaticMulti::GetClipModel
  175. ================
  176. */
  177. idClipModel *idPhysics_StaticMulti::GetClipModel( int id ) const {
  178. if ( id >= 0 && id < clipModels.Num() && clipModels[id] ) {
  179. return clipModels[id];
  180. }
  181. return gameLocal.clip.DefaultClipModel();
  182. }
  183. /*
  184. ================
  185. idPhysics_StaticMulti::GetNumClipModels
  186. ================
  187. */
  188. int idPhysics_StaticMulti::GetNumClipModels() const {
  189. return clipModels.Num();
  190. }
  191. /*
  192. ================
  193. idPhysics_StaticMulti::SetMass
  194. ================
  195. */
  196. void idPhysics_StaticMulti::SetMass( float mass, int id ) {
  197. }
  198. /*
  199. ================
  200. idPhysics_StaticMulti::GetMass
  201. ================
  202. */
  203. float idPhysics_StaticMulti::GetMass( int id ) const {
  204. return 0.0f;
  205. }
  206. /*
  207. ================
  208. idPhysics_StaticMulti::SetContents
  209. ================
  210. */
  211. void idPhysics_StaticMulti::SetContents( int contents, int id ) {
  212. int i;
  213. if ( id >= 0 && id < clipModels.Num() ) {
  214. if ( clipModels[id] ) {
  215. clipModels[id]->SetContents( contents );
  216. }
  217. } else if ( id == -1 ) {
  218. for ( i = 0; i < clipModels.Num(); i++ ) {
  219. if ( clipModels[i] ) {
  220. clipModels[i]->SetContents( contents );
  221. }
  222. }
  223. }
  224. }
  225. /*
  226. ================
  227. idPhysics_StaticMulti::GetContents
  228. ================
  229. */
  230. int idPhysics_StaticMulti::GetContents( int id ) const {
  231. int i, contents = 0;
  232. if ( id >= 0 && id < clipModels.Num() ) {
  233. if ( clipModels[id] ) {
  234. contents = clipModels[id]->GetContents();
  235. }
  236. } else if ( id == -1 ) {
  237. for ( i = 0; i < clipModels.Num(); i++ ) {
  238. if ( clipModels[i] ) {
  239. contents |= clipModels[i]->GetContents();
  240. }
  241. }
  242. }
  243. return contents;
  244. }
  245. /*
  246. ================
  247. idPhysics_StaticMulti::SetClipMask
  248. ================
  249. */
  250. void idPhysics_StaticMulti::SetClipMask( int mask, int id ) {
  251. }
  252. /*
  253. ================
  254. idPhysics_StaticMulti::GetClipMask
  255. ================
  256. */
  257. int idPhysics_StaticMulti::GetClipMask( int id ) const {
  258. return 0;
  259. }
  260. /*
  261. ================
  262. idPhysics_StaticMulti::GetBounds
  263. ================
  264. */
  265. const idBounds &idPhysics_StaticMulti::GetBounds( int id ) const {
  266. int i;
  267. static idBounds bounds;
  268. if ( id >= 0 && id < clipModels.Num() ) {
  269. if ( clipModels[id] ) {
  270. return clipModels[id]->GetBounds();
  271. }
  272. }
  273. if ( id == -1 ) {
  274. bounds.Clear();
  275. for ( i = 0; i < clipModels.Num(); i++ ) {
  276. if ( clipModels[i] ) {
  277. bounds.AddBounds( clipModels[i]->GetAbsBounds() );
  278. }
  279. }
  280. for ( i = 0; i < clipModels.Num(); i++ ) {
  281. if ( clipModels[i] ) {
  282. bounds[0] -= clipModels[i]->GetOrigin();
  283. bounds[1] -= clipModels[i]->GetOrigin();
  284. break;
  285. }
  286. }
  287. return bounds;
  288. }
  289. return bounds_zero;
  290. }
  291. /*
  292. ================
  293. idPhysics_StaticMulti::GetAbsBounds
  294. ================
  295. */
  296. const idBounds &idPhysics_StaticMulti::GetAbsBounds( int id ) const {
  297. int i;
  298. static idBounds absBounds;
  299. if ( id >= 0 && id < clipModels.Num() ) {
  300. if ( clipModels[id] ) {
  301. return clipModels[id]->GetAbsBounds();
  302. }
  303. }
  304. if ( id == -1 ) {
  305. absBounds.Clear();
  306. for ( i = 0; i < clipModels.Num(); i++ ) {
  307. if ( clipModels[i] ) {
  308. absBounds.AddBounds( clipModels[i]->GetAbsBounds() );
  309. }
  310. }
  311. return absBounds;
  312. }
  313. return bounds_zero;
  314. }
  315. /*
  316. ================
  317. idPhysics_StaticMulti::Evaluate
  318. ================
  319. */
  320. bool idPhysics_StaticMulti::Evaluate( int timeStepMSec, int endTimeMSec ) {
  321. int i;
  322. idVec3 masterOrigin;
  323. idMat3 masterAxis;
  324. if ( hasMaster ) {
  325. self->GetMasterPosition( masterOrigin, masterAxis );
  326. for ( i = 0; i < clipModels.Num(); i++ ) {
  327. current[i].origin = masterOrigin + current[i].localOrigin * masterAxis;
  328. if ( isOrientated ) {
  329. current[i].axis = current[i].localAxis * masterAxis;
  330. } else {
  331. current[i].axis = current[i].localAxis;
  332. }
  333. if ( clipModels[i] ) {
  334. clipModels[i]->Link( gameLocal.clip, self, i, current[i].origin, current[i].axis );
  335. }
  336. }
  337. // FIXME: return false if master did not move
  338. return true;
  339. }
  340. return false;
  341. }
  342. /*
  343. ================
  344. idPhysics_StaticMulti::Interpolate
  345. ================
  346. */
  347. bool idPhysics_StaticMulti::Interpolate( const float fraction ) {
  348. // If the sizes don't match, just use the latest version.
  349. // TODO: This might cause visual snapping, is there a better solution?
  350. if ( current.Num() != previous.Num() ||
  351. current.Num() != next.Num() ) {
  352. current.SetNum( next.Num() );
  353. for ( int i = 0; i < next.Num(); ++i ) {
  354. current[i] = InterpolateStaticPState( next[i], next[i], 1.0f );
  355. }
  356. return true;
  357. }
  358. for ( int i = 0; i < current.Num(); ++i ) {
  359. current[i] = InterpolateStaticPState( previous[i], next[i], fraction );
  360. }
  361. return true;
  362. }
  363. /*
  364. ================
  365. idPhysics_StaticMulti::UpdateTime
  366. ================
  367. */
  368. void idPhysics_StaticMulti::UpdateTime( int endTimeMSec ) {
  369. }
  370. /*
  371. ================
  372. idPhysics_StaticMulti::GetTime
  373. ================
  374. */
  375. int idPhysics_StaticMulti::GetTime() const {
  376. return 0;
  377. }
  378. /*
  379. ================
  380. idPhysics_StaticMulti::GetImpactInfo
  381. ================
  382. */
  383. void idPhysics_StaticMulti::GetImpactInfo( const int id, const idVec3 &point, impactInfo_t *info ) const {
  384. memset( info, 0, sizeof( *info ) );
  385. }
  386. /*
  387. ================
  388. idPhysics_StaticMulti::ApplyImpulse
  389. ================
  390. */
  391. void idPhysics_StaticMulti::ApplyImpulse( const int id, const idVec3 &point, const idVec3 &impulse ) {
  392. }
  393. /*
  394. ================
  395. idPhysics_StaticMulti::AddForce
  396. ================
  397. */
  398. void idPhysics_StaticMulti::AddForce( const int id, const idVec3 &point, const idVec3 &force ) {
  399. }
  400. /*
  401. ================
  402. idPhysics_StaticMulti::Activate
  403. ================
  404. */
  405. void idPhysics_StaticMulti::Activate() {
  406. }
  407. /*
  408. ================
  409. idPhysics_StaticMulti::PutToRest
  410. ================
  411. */
  412. void idPhysics_StaticMulti::PutToRest() {
  413. }
  414. /*
  415. ================
  416. idPhysics_StaticMulti::IsAtRest
  417. ================
  418. */
  419. bool idPhysics_StaticMulti::IsAtRest() const {
  420. return true;
  421. }
  422. /*
  423. ================
  424. idPhysics_StaticMulti::GetRestStartTime
  425. ================
  426. */
  427. int idPhysics_StaticMulti::GetRestStartTime() const {
  428. return 0;
  429. }
  430. /*
  431. ================
  432. idPhysics_StaticMulti::IsPushable
  433. ================
  434. */
  435. bool idPhysics_StaticMulti::IsPushable() const {
  436. return false;
  437. }
  438. /*
  439. ================
  440. idPhysics_StaticMulti::SaveState
  441. ================
  442. */
  443. void idPhysics_StaticMulti::SaveState() {
  444. }
  445. /*
  446. ================
  447. idPhysics_StaticMulti::RestoreState
  448. ================
  449. */
  450. void idPhysics_StaticMulti::RestoreState() {
  451. }
  452. /*
  453. ================
  454. idPhysics_StaticMulti::SetOrigin
  455. ================
  456. */
  457. void idPhysics_StaticMulti::SetOrigin( const idVec3 &newOrigin, int id ) {
  458. idVec3 masterOrigin;
  459. idMat3 masterAxis;
  460. if ( id >= 0 && id < clipModels.Num() ) {
  461. current[id].localOrigin = newOrigin;
  462. if ( hasMaster ) {
  463. self->GetMasterPosition( masterOrigin, masterAxis );
  464. current[id].origin = masterOrigin + newOrigin * masterAxis;
  465. } else {
  466. current[id].origin = newOrigin;
  467. }
  468. if ( clipModels[id] ) {
  469. clipModels[id]->Link( gameLocal.clip, self, id, current[id].origin, current[id].axis );
  470. }
  471. } else if ( id == -1 ) {
  472. if ( hasMaster ) {
  473. self->GetMasterPosition( masterOrigin, masterAxis );
  474. Translate( masterOrigin + masterAxis * newOrigin - current[0].origin );
  475. } else {
  476. Translate( newOrigin - current[0].origin );
  477. }
  478. }
  479. }
  480. /*
  481. ================
  482. idPhysics_StaticMulti::SetAxis
  483. ================
  484. */
  485. void idPhysics_StaticMulti::SetAxis( const idMat3 &newAxis, int id ) {
  486. idVec3 masterOrigin;
  487. idMat3 masterAxis;
  488. if ( id >= 0 && id < clipModels.Num() ) {
  489. current[id].localAxis = newAxis;
  490. if ( hasMaster && isOrientated ) {
  491. self->GetMasterPosition( masterOrigin, masterAxis );
  492. current[id].axis = newAxis * masterAxis;
  493. } else {
  494. current[id].axis = newAxis;
  495. }
  496. if ( clipModels[id] ) {
  497. clipModels[id]->Link( gameLocal.clip, self, id, current[id].origin, current[id].axis );
  498. }
  499. } else if ( id == -1 ) {
  500. idMat3 axis;
  501. idRotation rotation;
  502. if ( hasMaster ) {
  503. self->GetMasterPosition( masterOrigin, masterAxis );
  504. axis = current[0].axis.Transpose() * ( newAxis * masterAxis );
  505. } else {
  506. axis = current[0].axis.Transpose() * newAxis;
  507. }
  508. rotation = axis.ToRotation();
  509. rotation.SetOrigin( current[0].origin );
  510. Rotate( rotation );
  511. }
  512. }
  513. /*
  514. ================
  515. idPhysics_StaticMulti::Translate
  516. ================
  517. */
  518. void idPhysics_StaticMulti::Translate( const idVec3 &translation, int id ) {
  519. int i;
  520. if ( id >= 0 && id < clipModels.Num() ) {
  521. current[id].localOrigin += translation;
  522. current[id].origin += translation;
  523. if ( clipModels[id] ) {
  524. clipModels[id]->Link( gameLocal.clip, self, id, current[id].origin, current[id].axis );
  525. }
  526. } else if ( id == -1 ) {
  527. for ( i = 0; i < clipModels.Num(); i++ ) {
  528. current[i].localOrigin += translation;
  529. current[i].origin += translation;
  530. if ( clipModels[i] ) {
  531. clipModels[i]->Link( gameLocal.clip, self, i, current[i].origin, current[i].axis );
  532. }
  533. }
  534. }
  535. }
  536. /*
  537. ================
  538. idPhysics_StaticMulti::Rotate
  539. ================
  540. */
  541. void idPhysics_StaticMulti::Rotate( const idRotation &rotation, int id ) {
  542. int i;
  543. idVec3 masterOrigin;
  544. idMat3 masterAxis;
  545. if ( id >= 0 && id < clipModels.Num() ) {
  546. current[id].origin *= rotation;
  547. current[id].axis *= rotation.ToMat3();
  548. if ( hasMaster ) {
  549. self->GetMasterPosition( masterOrigin, masterAxis );
  550. current[id].localAxis *= rotation.ToMat3();
  551. current[id].localOrigin = ( current[id].origin - masterOrigin ) * masterAxis.Transpose();
  552. } else {
  553. current[id].localAxis = current[id].axis;
  554. current[id].localOrigin = current[id].origin;
  555. }
  556. if ( clipModels[id] ) {
  557. clipModels[id]->Link( gameLocal.clip, self, id, current[id].origin, current[id].axis );
  558. }
  559. } else if ( id == -1 ) {
  560. for ( i = 0; i < clipModels.Num(); i++ ) {
  561. current[i].origin *= rotation;
  562. current[i].axis *= rotation.ToMat3();
  563. if ( hasMaster ) {
  564. self->GetMasterPosition( masterOrigin, masterAxis );
  565. current[i].localAxis *= rotation.ToMat3();
  566. current[i].localOrigin = ( current[i].origin - masterOrigin ) * masterAxis.Transpose();
  567. } else {
  568. current[i].localAxis = current[i].axis;
  569. current[i].localOrigin = current[i].origin;
  570. }
  571. if ( clipModels[i] ) {
  572. clipModels[i]->Link( gameLocal.clip, self, i, current[i].origin, current[i].axis );
  573. }
  574. }
  575. }
  576. }
  577. /*
  578. ================
  579. idPhysics_StaticMulti::GetOrigin
  580. ================
  581. */
  582. const idVec3 &idPhysics_StaticMulti::GetOrigin( int id ) const {
  583. if ( id >= 0 && id < clipModels.Num() ) {
  584. return current[id].origin;
  585. }
  586. if ( clipModels.Num() ) {
  587. return current[0].origin;
  588. } else {
  589. return vec3_origin;
  590. }
  591. }
  592. /*
  593. ================
  594. idPhysics_StaticMulti::GetAxis
  595. ================
  596. */
  597. const idMat3 &idPhysics_StaticMulti::GetAxis( int id ) const {
  598. if ( id >= 0 && id < clipModels.Num() ) {
  599. return current[id].axis;
  600. }
  601. if ( clipModels.Num() ) {
  602. return current[0].axis;
  603. } else {
  604. return mat3_identity;
  605. }
  606. }
  607. /*
  608. ================
  609. idPhysics_StaticMulti::SetLinearVelocity
  610. ================
  611. */
  612. void idPhysics_StaticMulti::SetLinearVelocity( const idVec3 &newLinearVelocity, int id ) {
  613. }
  614. /*
  615. ================
  616. idPhysics_StaticMulti::SetAngularVelocity
  617. ================
  618. */
  619. void idPhysics_StaticMulti::SetAngularVelocity( const idVec3 &newAngularVelocity, int id ) {
  620. }
  621. /*
  622. ================
  623. idPhysics_StaticMulti::GetLinearVelocity
  624. ================
  625. */
  626. const idVec3 &idPhysics_StaticMulti::GetLinearVelocity( int id ) const {
  627. return vec3_origin;
  628. }
  629. /*
  630. ================
  631. idPhysics_StaticMulti::GetAngularVelocity
  632. ================
  633. */
  634. const idVec3 &idPhysics_StaticMulti::GetAngularVelocity( int id ) const {
  635. return vec3_origin;
  636. }
  637. /*
  638. ================
  639. idPhysics_StaticMulti::SetGravity
  640. ================
  641. */
  642. void idPhysics_StaticMulti::SetGravity( const idVec3 &newGravity ) {
  643. }
  644. /*
  645. ================
  646. idPhysics_StaticMulti::GetGravity
  647. ================
  648. */
  649. const idVec3 &idPhysics_StaticMulti::GetGravity() const {
  650. static idVec3 gravity( 0, 0, -g_gravity.GetFloat() );
  651. return gravity;
  652. }
  653. /*
  654. ================
  655. idPhysics_StaticMulti::GetGravityNormal
  656. ================
  657. */
  658. const idVec3 &idPhysics_StaticMulti::GetGravityNormal() const {
  659. static idVec3 gravity( 0, 0, -1 );
  660. return gravity;
  661. }
  662. /*
  663. ================
  664. idPhysics_StaticMulti::ClipTranslation
  665. ================
  666. */
  667. void idPhysics_StaticMulti::ClipTranslation( trace_t &results, const idVec3 &translation, const idClipModel *model ) const {
  668. memset( &results, 0, sizeof( trace_t ) );
  669. gameLocal.Warning( "idPhysics_StaticMulti::ClipTranslation called" );
  670. }
  671. /*
  672. ================
  673. idPhysics_StaticMulti::ClipRotation
  674. ================
  675. */
  676. void idPhysics_StaticMulti::ClipRotation( trace_t &results, const idRotation &rotation, const idClipModel *model ) const {
  677. memset( &results, 0, sizeof( trace_t ) );
  678. gameLocal.Warning( "idPhysics_StaticMulti::ClipRotation called" );
  679. }
  680. /*
  681. ================
  682. idPhysics_StaticMulti::ClipContents
  683. ================
  684. */
  685. int idPhysics_StaticMulti::ClipContents( const idClipModel *model ) const {
  686. int i, contents;
  687. contents = 0;
  688. for ( i = 0; i < clipModels.Num(); i++ ) {
  689. if ( clipModels[i] ) {
  690. if ( model ) {
  691. contents |= gameLocal.clip.ContentsModel( clipModels[i]->GetOrigin(), clipModels[i], clipModels[i]->GetAxis(), -1,
  692. model->Handle(), model->GetOrigin(), model->GetAxis() );
  693. } else {
  694. contents |= gameLocal.clip.Contents( clipModels[i]->GetOrigin(), clipModels[i], clipModels[i]->GetAxis(), -1, NULL );
  695. }
  696. }
  697. }
  698. return contents;
  699. }
  700. /*
  701. ================
  702. idPhysics_StaticMulti::DisableClip
  703. ================
  704. */
  705. void idPhysics_StaticMulti::DisableClip() {
  706. int i;
  707. for ( i = 0; i < clipModels.Num(); i++ ) {
  708. if ( clipModels[i] ) {
  709. clipModels[i]->Disable();
  710. }
  711. }
  712. }
  713. /*
  714. ================
  715. idPhysics_StaticMulti::EnableClip
  716. ================
  717. */
  718. void idPhysics_StaticMulti::EnableClip() {
  719. int i;
  720. for ( i = 0; i < clipModels.Num(); i++ ) {
  721. if ( clipModels[i] ) {
  722. clipModels[i]->Enable();
  723. }
  724. }
  725. }
  726. /*
  727. ================
  728. idPhysics_StaticMulti::UnlinkClip
  729. ================
  730. */
  731. void idPhysics_StaticMulti::UnlinkClip() {
  732. int i;
  733. for ( i = 0; i < clipModels.Num(); i++ ) {
  734. if ( clipModels[i] ) {
  735. clipModels[i]->Unlink();
  736. }
  737. }
  738. }
  739. /*
  740. ================
  741. idPhysics_StaticMulti::LinkClip
  742. ================
  743. */
  744. void idPhysics_StaticMulti::LinkClip() {
  745. int i;
  746. for ( i = 0; i < clipModels.Num(); i++ ) {
  747. if ( clipModels[i] ) {
  748. clipModels[i]->Link( gameLocal.clip, self, i, current[i].origin, current[i].axis );
  749. }
  750. }
  751. }
  752. /*
  753. ================
  754. idPhysics_StaticMulti::EvaluateContacts
  755. ================
  756. */
  757. bool idPhysics_StaticMulti::EvaluateContacts() {
  758. return false;
  759. }
  760. /*
  761. ================
  762. idPhysics_StaticMulti::GetNumContacts
  763. ================
  764. */
  765. int idPhysics_StaticMulti::GetNumContacts() const {
  766. return 0;
  767. }
  768. /*
  769. ================
  770. idPhysics_StaticMulti::GetContact
  771. ================
  772. */
  773. const contactInfo_t &idPhysics_StaticMulti::GetContact( int num ) const {
  774. static contactInfo_t info;
  775. memset( &info, 0, sizeof( info ) );
  776. return info;
  777. }
  778. /*
  779. ================
  780. idPhysics_StaticMulti::ClearContacts
  781. ================
  782. */
  783. void idPhysics_StaticMulti::ClearContacts() {
  784. }
  785. /*
  786. ================
  787. idPhysics_StaticMulti::AddContactEntity
  788. ================
  789. */
  790. void idPhysics_StaticMulti::AddContactEntity( idEntity *e ) {
  791. }
  792. /*
  793. ================
  794. idPhysics_StaticMulti::RemoveContactEntity
  795. ================
  796. */
  797. void idPhysics_StaticMulti::RemoveContactEntity( idEntity *e ) {
  798. }
  799. /*
  800. ================
  801. idPhysics_StaticMulti::HasGroundContacts
  802. ================
  803. */
  804. bool idPhysics_StaticMulti::HasGroundContacts() const {
  805. return false;
  806. }
  807. /*
  808. ================
  809. idPhysics_StaticMulti::IsGroundEntity
  810. ================
  811. */
  812. bool idPhysics_StaticMulti::IsGroundEntity( int entityNum ) const {
  813. return false;
  814. }
  815. /*
  816. ================
  817. idPhysics_StaticMulti::IsGroundClipModel
  818. ================
  819. */
  820. bool idPhysics_StaticMulti::IsGroundClipModel( int entityNum, int id ) const {
  821. return false;
  822. }
  823. /*
  824. ================
  825. idPhysics_StaticMulti::SetPushed
  826. ================
  827. */
  828. void idPhysics_StaticMulti::SetPushed( int deltaTime ) {
  829. }
  830. /*
  831. ================
  832. idPhysics_StaticMulti::GetPushedLinearVelocity
  833. ================
  834. */
  835. const idVec3 &idPhysics_StaticMulti::GetPushedLinearVelocity( const int id ) const {
  836. return vec3_origin;
  837. }
  838. /*
  839. ================
  840. idPhysics_StaticMulti::GetPushedAngularVelocity
  841. ================
  842. */
  843. const idVec3 &idPhysics_StaticMulti::GetPushedAngularVelocity( const int id ) const {
  844. return vec3_origin;
  845. }
  846. /*
  847. ================
  848. idPhysics_StaticMulti::SetMaster
  849. ================
  850. */
  851. void idPhysics_StaticMulti::SetMaster( idEntity *master, const bool orientated ) {
  852. int i;
  853. idVec3 masterOrigin;
  854. idMat3 masterAxis;
  855. if ( master ) {
  856. if ( !hasMaster ) {
  857. // transform from world space to master space
  858. self->GetMasterPosition( masterOrigin, masterAxis );
  859. for ( i = 0; i < clipModels.Num(); i++ ) {
  860. current[i].localOrigin = ( current[i].origin - masterOrigin ) * masterAxis.Transpose();
  861. if ( orientated ) {
  862. current[i].localAxis = current[i].axis * masterAxis.Transpose();
  863. } else {
  864. current[i].localAxis = current[i].axis;
  865. }
  866. }
  867. hasMaster = true;
  868. isOrientated = orientated;
  869. }
  870. } else {
  871. if ( hasMaster ) {
  872. hasMaster = false;
  873. }
  874. }
  875. }
  876. /*
  877. ================
  878. idPhysics_StaticMulti::GetBlockingInfo
  879. ================
  880. */
  881. const trace_t *idPhysics_StaticMulti::GetBlockingInfo() const {
  882. return NULL;
  883. }
  884. /*
  885. ================
  886. idPhysics_StaticMulti::GetBlockingEntity
  887. ================
  888. */
  889. idEntity *idPhysics_StaticMulti::GetBlockingEntity() const {
  890. return NULL;
  891. }
  892. /*
  893. ================
  894. idPhysics_StaticMulti::GetLinearEndTime
  895. ================
  896. */
  897. int idPhysics_StaticMulti::GetLinearEndTime() const {
  898. return 0;
  899. }
  900. /*
  901. ================
  902. idPhysics_StaticMulti::GetAngularEndTime
  903. ================
  904. */
  905. int idPhysics_StaticMulti::GetAngularEndTime() const {
  906. return 0;
  907. }
  908. /*
  909. ================
  910. idPhysics_StaticMulti::WriteToSnapshot
  911. ================
  912. */
  913. void idPhysics_StaticMulti::WriteToSnapshot( idBitMsg &msg ) const {
  914. int i;
  915. idCQuat quat, localQuat;
  916. msg.WriteByte( current.Num() );
  917. for ( i = 0; i < current.Num(); i++ ) {
  918. quat = current[i].axis.ToCQuat();
  919. localQuat = current[i].localAxis.ToCQuat();
  920. msg.WriteFloat( current[i].origin[0] );
  921. msg.WriteFloat( current[i].origin[1] );
  922. msg.WriteFloat( current[i].origin[2] );
  923. msg.WriteFloat( quat.x );
  924. msg.WriteFloat( quat.y );
  925. msg.WriteFloat( quat.z );
  926. msg.WriteDeltaFloat( current[i].origin[0], current[i].localOrigin[0] );
  927. msg.WriteDeltaFloat( current[i].origin[1], current[i].localOrigin[1] );
  928. msg.WriteDeltaFloat( current[i].origin[2], current[i].localOrigin[2] );
  929. msg.WriteDeltaFloat( quat.x, localQuat.x );
  930. msg.WriteDeltaFloat( quat.y, localQuat.y );
  931. msg.WriteDeltaFloat( quat.z, localQuat.z );
  932. }
  933. }
  934. /*
  935. ================
  936. idPhysics_StaticMulti::ReadFromSnapshot
  937. ================
  938. */
  939. void idPhysics_StaticMulti::ReadFromSnapshot( const idBitMsg &msg ) {
  940. int i, num;
  941. idCQuat quat, localQuat;
  942. num = msg.ReadByte();
  943. assert( num == current.Num() );
  944. previous = next;
  945. next.SetNum( num );
  946. for ( i = 0; i < current.Num(); i++ ) {
  947. next[i] = ReadStaticInterpolatePStateFromSnapshot( msg );
  948. }
  949. }