mech3d.cpp 153 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120
  1. //-------------------------------------------------------------------------------
  2. //
  3. // Mech 3D layer. Controls how the mech moves through animations
  4. //
  5. // For MechCommander 2
  6. //
  7. // Replace Mactor for better looking mechs!
  8. //
  9. //---------------------------------------------------------------------------//
  10. // Copyright (C) Microsoft Corporation. All rights reserved. //
  11. //===========================================================================//
  12. #ifndef MECH3D_H
  13. #include "mech3d.h"
  14. #endif
  15. #ifndef CAMERA_H
  16. #include "camera.h"
  17. #endif
  18. #ifndef DBASEGUI_H
  19. #include "dbasegui.h"
  20. #endif
  21. #ifndef TERRAIN_H
  22. #include "terrain.h"
  23. #endif
  24. #ifndef MSTATES_H
  25. #include "mstates.h"
  26. #endif
  27. #ifndef OBJSTATUS_H
  28. #include "objstatus.h"
  29. #endif
  30. #ifndef CIDENT_H
  31. #include "cident.h"
  32. #endif
  33. #ifndef PATHS_H
  34. #include "paths.h"
  35. #endif
  36. #ifndef USERINPUT_H
  37. #include "userinput.h"
  38. #endif
  39. #ifndef TIMING_H
  40. #include "timing.h"
  41. #endif
  42. #ifndef UTILITIES_H
  43. #include "utilities.h"
  44. #endif
  45. #ifndef CEVFX_H
  46. #include "cevfx.h"
  47. #endif
  48. #ifndef TXMMGR_H
  49. #include "txmmgr.h"
  50. #endif
  51. #ifndef CELINE_H
  52. #include "celine.h"
  53. #endif
  54. #ifndef WEAPONFX_H
  55. #include "weaponfx.h"
  56. #endif
  57. #ifndef CRATER_H
  58. #include "crater.h"
  59. #endif
  60. #ifndef GVACTOR_H
  61. #include "gvactor.h"
  62. #endif
  63. //-------------------------------------------------------------------------------
  64. // Static Globals
  65. extern float worldUnitsPerMeter;
  66. extern bool useFog;
  67. extern float metersPerWorldUnit;
  68. extern MidLevelRenderer::MLRClipper * theClipper;
  69. bool useNonWeaponEffects = true;
  70. bool useHighObjectDetail = true;
  71. bool InEditor = false;
  72. extern bool MLRVertexLimitReached;
  73. extern bool useShadows;
  74. #define BODYSTATE_NORMAL 0
  75. #define BODYSTATE_STANDING 1
  76. #define BODYSTATE_PARKED 2
  77. #define BODYSTATE_FALLEN_BACKWARD 3
  78. #define BODYSTATE_FALLEN_FORWARD 4
  79. #define EXPAND_FACTOR (1.25f)
  80. #define HELICOPTER_FACTOR (25.0f)
  81. char MechStateByGesture[MAX_MECH_ANIMATIONS] = {
  82. BODYSTATE_PARKED, // GesturePark 0 -- Park
  83. BODYSTATE_STANDING, // GestureParkToStand 1 -- ParkToStand
  84. BODYSTATE_STANDING, // GestureStand 2 -- Stand
  85. BODYSTATE_NORMAL, // GestureStandToWalk 3 -- StandToWalk
  86. BODYSTATE_NORMAL, // GestureWalk 4 -- Walk
  87. BODYSTATE_PARKED, // GestureStandToPark 5 -- StandToPark
  88. BODYSTATE_NORMAL, // GestureWalkToRun 6 -- WalkToRun
  89. BODYSTATE_NORMAL, // GestureRun 7 -- Run
  90. BODYSTATE_NORMAL, // GestureRunToWalk 8 -- RunToWalk
  91. BODYSTATE_NORMAL, // GestureReverse 9 -- Reverse
  92. BODYSTATE_NORMAL, // GestureStandToReverse 10 -- StandToReverse
  93. BODYSTATE_NORMAL, // GestureLimpLeft 11 -- LimpLeft
  94. BODYSTATE_NORMAL, // GestureLimpRight 12 -- LimpRight
  95. BODYSTATE_STANDING, // GestureIdle 13 -- Idle
  96. BODYSTATE_FALLEN_BACKWARD, // GestureFallBackward 14 -- FallBackward
  97. BODYSTATE_FALLEN_FORWARD, // GestureFallForward 15 -- FallForward
  98. BODYSTATE_NORMAL, // GestureHitFront 16 -- HitFront
  99. BODYSTATE_NORMAL, // GestureHitBack 17 -- HitBack
  100. BODYSTATE_NORMAL, // GestureHitLeft 18 -- HitLeft
  101. BODYSTATE_NORMAL, // GestureHitRight 19 -- HitRight
  102. BODYSTATE_NORMAL, // GestureJump 20 -- Jump
  103. BODYSTATE_FALLEN_FORWARD, // GestureRollover 21 -- Rollover from FallBack to FallForward
  104. BODYSTATE_FALLEN_FORWARD, // GestureGetup 22 -- Get up from FallForward
  105. BODYSTATE_FALLEN_FORWARD, // GestureFallenForward 23 -- Fallen Forward (Single Frame, mech on ground)
  106. BODYSTATE_FALLEN_FORWARD, // GestureFallenBackward 24 -- Fallen Backward (Single Frame, mech on ground)
  107. };
  108. #define MAX_ANIMATION_FILES 25
  109. #define idleMAX (20.0f)
  110. #define FX_POOF_ID 32
  111. #define FX_JUMP_ID 43
  112. #define FX_SMOKE_ID 48
  113. #define SPIN_RATE 90.0f
  114. #define JUMP_PITCH (90.0f)
  115. extern bool reloadBounds;
  116. char* MechAnimationNames[MaxGestures+2] =
  117. {
  118. "StandToPark", //GesturePark 0 -- Park
  119. "ParkToStand", //GestureParkToStand 1 -- ParkToStand
  120. "", //GestureStand 2 -- Stand
  121. "STtoWK", //GestureStandToWalk 3 -- StandToWalk
  122. "Walk", //GestureWalk 4 -- Walk
  123. "StandToPark", //GestureStandToPark 5 -- StandToPark
  124. "WKtoRN", //GestureWalkToRun 6 -- WalkToRun
  125. "Run", //GestureRun 7 -- Run
  126. "RNToWK", //GestureRunToWalk 8 -- RunToWalk
  127. "Walk", //GestureReverse 9 -- Reverse
  128. "WKtoST", //GestureStandToReverse 10 -- StandToReverse
  129. "LimpLeft", //GestureLimpLeft 11 -- LimpLeft
  130. "LimpRight", //GestureLimpRight 12 -- LimpRight
  131. "Idle", //GestureIdle 13 -- Idle
  132. "FallBackward", //GestureFallBackward 14 -- FallBackward
  133. "FallForward", //GestureFallForward 15 -- FallForward
  134. "HitFront", //GestureHitFront 16 -- HitFront
  135. "HitBack", //GestureHitBack 17 -- HitBack
  136. "HitLeft", //GestureHitLeft 18 -- HitLeft
  137. "HitRight", //GestureHitRight 19 -- HitRight
  138. "Jump", //GestureJump 20 -- Jump
  139. "GetupBack", //GestureRollover 21 -- Getup from FallBack
  140. "GetupFront", //GestureGetup 22 -- Getup from FallForward
  141. "FallForward", //GestureFallenForward 23 -- Fallen Forward (Single Frame, mech on ground)
  142. "FallBackward", //GestureFallenBackward 24 -- Fallen Backward (Single Frame, mech on ground)
  143. "FallBackwardDam", //Destroyed States
  144. "FallForwardDam" //Destroyed States
  145. };
  146. PaintSchemataPtr Mech3DAppearance::paintSchemata = NULL;
  147. DWORD Mech3DAppearance::numPaintSchemata = 0;
  148. TG_TypeMultiShapePtr Mech3DAppearanceType::SensorSquareShape = NULL;
  149. extern long ObjectTextureSize;
  150. #define FOOTPRINT_SLOP 2
  151. bool Mech3DAppearanceType::animationLoadingEnabled = true;
  152. //-------------------------------------------------------------------------------
  153. // class Mech3DAppearanceType
  154. void Mech3DAppearanceType::init (char * fileName)
  155. {
  156. AppearanceType::init(fileName);
  157. //---------------------------------------------------
  158. // Load the Gesture Data. Should be in filename.ini
  159. FullPathFileName mechIniName;
  160. mechIniName.init(tglPath,fileName,".ini");
  161. gosASSERT(fileExists(mechIniName));
  162. FitIniFile mechFile;
  163. long result = mechFile.open(mechIniName);
  164. gosASSERT(result == NO_ERR);
  165. for (long i=0;i<MaxGestures;i++)
  166. {
  167. char blockId[256];
  168. sprintf(blockId,"Gestures%d",i);
  169. result = mechFile.seekBlock(blockId);
  170. gosASSERT(result == NO_ERR);
  171. result = mechFile.readIdFloat("StartVel",gestures[i].startVel);
  172. gosASSERT(result == NO_ERR);
  173. result = mechFile.readIdFloat("EndVel",gestures[i].endVel);
  174. gosASSERT(result == NO_ERR);
  175. result = mechFile.readIdLong("StartFrame",gestures[i].frameStart);
  176. gosASSERT(result == NO_ERR);
  177. result = mechFile.readIdBoolean("Reverse",gestures[i].reverse);
  178. gosASSERT(result == NO_ERR);
  179. result = mechFile.readIdLong("RightFootDown0",gestures[i].rightFootDownFrame0);
  180. if (result != NO_ERR)
  181. gestures[i].rightFootDownFrame0 = 99999;
  182. result = mechFile.readIdLong("RightFootDown1",gestures[i].rightFootDownFrame1);
  183. if (result != NO_ERR)
  184. gestures[i].rightFootDownFrame1 = 99999;
  185. result = mechFile.readIdLong("LeftFootDown0",gestures[i].leftFootDownFrame0);
  186. if (result != NO_ERR)
  187. gestures[i].leftFootDownFrame0 = 99999;
  188. result = mechFile.readIdLong("LeftFootDown1",gestures[i].leftFootDownFrame1);
  189. if (result != NO_ERR)
  190. gestures[i].leftFootDownFrame1 = 99999;
  191. }
  192. result = mechFile.seekBlock("TGLData");
  193. if (result != NO_ERR)
  194. STOP(("Mech %s has no TGL Data",fileName));
  195. char aseFileName[512];
  196. result = mechFile.readIdString("FileName",aseFileName,511);
  197. if (result != NO_ERR)
  198. {
  199. //Check for LOD filenames
  200. char aseFileName[512];
  201. for (long i=0;i<MAX_LODS;i++)
  202. {
  203. char baseName[256];
  204. char baseLODDist[256];
  205. sprintf(baseName,"FileName%d",i);
  206. sprintf(baseLODDist,"Distance%d",i);
  207. result = mechFile.readIdString(baseName,aseFileName,511);
  208. if (result == NO_ERR)
  209. {
  210. result = mechFile.readIdFloat(baseLODDist,lodDistance[i]);
  211. if (result != NO_ERR)
  212. STOP(("LOD %d has no distance value in file %s",i,fileName));
  213. //----------------------------------------------
  214. // Base LOD shape. In stand Pose by default.
  215. mechShape[i] = new TG_TypeMultiShape;
  216. gosASSERT(mechShape[i] != NULL);
  217. FullPathFileName mechName;
  218. mechName.init(tglPath,aseFileName,".ase");
  219. mechShape[i]->LoadTGMultiShapeFromASE(mechName);
  220. }
  221. else if (!i)
  222. {
  223. STOP(("No base LOD for shape %s",fileName));
  224. }
  225. }
  226. }
  227. else
  228. {
  229. FullPathFileName mechName;
  230. mechName.init(tglPath,aseFileName,".ase");
  231. //----------------------------------------------
  232. // Base shape. In stand Pose by default.
  233. mechShape[0] = new TG_TypeMultiShape;
  234. gosASSERT(mechShape[0] != NULL);
  235. mechShape[0]->LoadTGMultiShapeFromASE(mechName);
  236. }
  237. result = mechFile.readIdString("ShadowName",aseFileName,511);
  238. if (result == NO_ERR)
  239. {
  240. //----------------------------------------------
  241. // Base Shadow shape.
  242. mechShadowShape = new TG_TypeMultiShape;
  243. gosASSERT(mechShadowShape != NULL);
  244. FullPathFileName gvName;
  245. gvName.init(tglPath,aseFileName,".ase");
  246. mechShadowShape->LoadTGMultiShapeFromASE(gvName);
  247. }
  248. //------------------------------------
  249. // Load Arms to blow off Next.
  250. char leftArmName[1024];
  251. sprintf(leftArmName,"%sLeftArm",fileName);
  252. FullPathFileName mechLeftArmName;
  253. mechLeftArmName.init(tglPath,leftArmName,".ase");
  254. char rightArmName[1024];
  255. sprintf(rightArmName,"%sRightArm",fileName);
  256. FullPathFileName mechRightArmName;
  257. mechRightArmName.init(tglPath,rightArmName,".ase");
  258. rightArm = new TG_TypeMultiShape;
  259. gosASSERT(rightArm != NULL);
  260. result = rightArm->LoadTGMultiShapeFromASE(mechRightArmName);
  261. if (result)
  262. {
  263. delete rightArm;
  264. rightArm = NULL;
  265. }
  266. leftArm = new TG_TypeMultiShape;
  267. gosASSERT(leftArm != NULL);
  268. result = leftArm->LoadTGMultiShapeFromASE(mechLeftArmName);
  269. if (result)
  270. {
  271. delete leftArm;
  272. leftArm = NULL;
  273. }
  274. //----------------------------------------------
  275. //-----------------------------------------------
  276. // Load Damaged States
  277. // They are named mechnamefallForward and mechnameFallBackward
  278. //
  279. char forwardName[1024];
  280. sprintf(forwardName,"%sFallForwardDam",fileName);
  281. char backwardName[1024];
  282. sprintf(backwardName,"%sFallForwardDam",fileName);
  283. {
  284. FullPathFileName dmgName;
  285. dmgName.init(tglPath,forwardName,".ase");
  286. mechForwardDmgShape = new TG_TypeMultiShape;
  287. gosASSERT(mechForwardDmgShape != NULL);
  288. mechForwardDmgShape->LoadTGMultiShapeFromASE(dmgName);
  289. if (!mechForwardDmgShape->GetNumShapes())
  290. {
  291. delete mechForwardDmgShape;
  292. mechForwardDmgShape = NULL;
  293. }
  294. }
  295. {
  296. FullPathFileName dmgName;
  297. dmgName.init(tglPath,backwardName,".ase");
  298. mechBackwardDmgShape = new TG_TypeMultiShape;
  299. gosASSERT(mechBackwardDmgShape != NULL);
  300. mechBackwardDmgShape->LoadTGMultiShapeFromASE(dmgName);
  301. if (!mechBackwardDmgShape->GetNumShapes())
  302. {
  303. delete mechBackwardDmgShape;
  304. mechBackwardDmgShape = NULL;
  305. }
  306. }
  307. //-----------------------
  308. // Load Animations Next.
  309. if (animationLoadingEnabled)
  310. {
  311. for (i=0;i<MAX_ANIMATION_FILES;i++)
  312. {
  313. char animName[512];
  314. sprintf(animName,"%s%s",fileName,MechAnimationNames[i]);
  315. FullPathFileName animPath;
  316. animPath.init(tglPath,animName,".ase");
  317. FullPathFileName otherPath;
  318. otherPath.init(tglPath,animName,".agl");
  319. if (fileExists(animPath) || fileExists(otherPath))
  320. {
  321. mechAnim[i] = new TG_AnimateShape;
  322. gosASSERT(mechAnim[i] != NULL);
  323. //---------------------------------------------------------------------------------------------
  324. // If this animation does not exist, it is not a problem!
  325. // Mech will simply freeze until animation is "over" and then move to next animation in chain.
  326. mechAnim[i]->LoadTGMultiShapeAnimationFromASE(animPath,mechShape[0]);
  327. if (gestures[i].reverse)
  328. mechAnim[i]->ReverseFrameRate();
  329. }
  330. else
  331. mechAnim[i] = NULL;
  332. }
  333. }
  334. //------------------------------
  335. // Load up the foot print type.
  336. result = mechFile.seekBlock("FootPrint");
  337. if (result != NO_ERR)
  338. {
  339. leftFootprintType = 0;
  340. rightFootprintType = 0;
  341. }
  342. result = mechFile.readIdLong("FootprintType",rightFootprintType);
  343. if (result != NO_ERR)
  344. {
  345. result = mechFile.readIdLong("RightFootprintType",rightFootprintType);
  346. if (result != NO_ERR)
  347. {
  348. leftFootprintType = 0;
  349. rightFootprintType = 0;
  350. }
  351. result = mechFile.readIdLong("LeftFootprintType",leftFootprintType);
  352. if (result != NO_ERR)
  353. leftFootprintType = rightFootprintType;
  354. }
  355. else
  356. {
  357. leftFootprintType = rightFootprintType;
  358. }
  359. //-----------------------------------------------
  360. // Load up the Node Data.
  361. result = mechFile.seekBlock("Nodes");
  362. if (result != NO_ERR)
  363. numSmokeNodes = numWeaponNodes = numJumpNodes = 0;
  364. result = mechFile.readIdLong("NumSmoke",numSmokeNodes);
  365. if (result != NO_ERR)
  366. numSmokeNodes = 0;
  367. result = mechFile.readIdLong("NumWeapon",numWeaponNodes);
  368. if (result != NO_ERR)
  369. numWeaponNodes = 0;
  370. result = mechFile.readIdLong("NumJumpjet",numJumpNodes);
  371. if (result != NO_ERR)
  372. numJumpNodes = 0;
  373. result = mechFile.readIdLong("NumFeet",numFootNodes);
  374. if (result != NO_ERR)
  375. numFootNodes = 0;
  376. if (numJumpNodes+numWeaponNodes+numSmokeNodes+numFootNodes)
  377. {
  378. nodeData = (NodeData *)AppearanceTypeList::appearanceHeap->Malloc(sizeof(NodeData)*(numJumpNodes+numWeaponNodes+numSmokeNodes+numFootNodes));
  379. gosASSERT(nodeData != NULL);
  380. for (i=0;i<numSmokeNodes;i++)
  381. {
  382. char blockId[512];
  383. sprintf(blockId,"SmokeNode%d",i);
  384. result = mechFile.seekBlock(blockId);
  385. gosASSERT(result == NO_ERR);
  386. char smokeName[512];
  387. result = mechFile.readIdString("SmokeNodeName",smokeName,511);
  388. gosASSERT(result == NO_ERR);
  389. nodeData[i].nodeId = (char *)AppearanceTypeList::appearanceHeap->Malloc(strlen(smokeName)+1);
  390. gosASSERT(nodeData[i].nodeId != NULL);
  391. strcpy(nodeData[i].nodeId,smokeName);
  392. nodeData[i].weaponType = MECH3D_WEAPONTYPE_NONE;
  393. }
  394. for (i=0;i<numWeaponNodes;i++)
  395. {
  396. char blockId[512];
  397. sprintf(blockId,"WeaponNode%d",i);
  398. result = mechFile.seekBlock(blockId);
  399. gosASSERT(result == NO_ERR);
  400. char weaponName[512];
  401. result = mechFile.readIdString("WeaponNodeName",weaponName,511);
  402. gosASSERT(result == NO_ERR);
  403. long weaponType;
  404. result = mechFile.readIdLong("WeaponType",weaponType);
  405. gosASSERT(result == NO_ERR);
  406. nodeData[i+numSmokeNodes].nodeId = (char *)AppearanceTypeList::appearanceHeap->Malloc(strlen(weaponName)+1);
  407. gosASSERT(nodeData[i+numSmokeNodes].nodeId != NULL);
  408. strcpy(nodeData[i+numSmokeNodes].nodeId,weaponName);
  409. nodeData[i+numSmokeNodes].weaponType = weaponType;
  410. }
  411. for (i=0;i<numJumpNodes;i++)
  412. {
  413. char blockId[512];
  414. sprintf(blockId,"JumpJetNode%d",i);
  415. result = mechFile.seekBlock(blockId);
  416. gosASSERT(result == NO_ERR);
  417. char jumpName[512];
  418. result = mechFile.readIdString("JumpNodeName",jumpName,511);
  419. gosASSERT(result == NO_ERR);
  420. nodeData[i+numSmokeNodes+numWeaponNodes].nodeId = (char *)AppearanceTypeList::appearanceHeap->Malloc(strlen(jumpName)+1);
  421. gosASSERT(nodeData[i+numSmokeNodes+numWeaponNodes].nodeId != NULL);
  422. strcpy(nodeData[i+numSmokeNodes+numWeaponNodes].nodeId,jumpName);
  423. nodeData[i+numSmokeNodes+numWeaponNodes].weaponType = MECH3D_WEAPONTYPE_NONE;
  424. }
  425. for (i=0;i<numFootNodes;i++)
  426. {
  427. char blockId[512];
  428. sprintf(blockId,"FootNode%d",i);
  429. result = mechFile.seekBlock(blockId);
  430. gosASSERT(result == NO_ERR);
  431. char footName[512];
  432. result = mechFile.readIdString("FootNodeName",footName,511);
  433. gosASSERT(result == NO_ERR);
  434. nodeData[i+numSmokeNodes+numWeaponNodes+numJumpNodes].nodeId = (char *)AppearanceTypeList::appearanceHeap->Malloc(strlen(footName)+1);
  435. gosASSERT(nodeData[i+numSmokeNodes+numWeaponNodes+numJumpNodes].nodeId != NULL);
  436. strcpy(nodeData[i+numSmokeNodes+numWeaponNodes+numJumpNodes].nodeId,footName);
  437. nodeData[i+numSmokeNodes+numWeaponNodes+numJumpNodes].weaponType = MECH3D_WEAPONTYPE_NONE;
  438. }
  439. }
  440. //----------------------------------------------
  441. // Load up sensor textures if not yet defined.
  442. // For helicopters, load up the vehicle one!!
  443. if (SensorSquareShape == NULL && numJumpNodes)
  444. {
  445. FullPathFileName sensorName;
  446. sensorName.init(tglPath,"squarecontact",".ase");
  447. SensorSquareShape = new TG_TypeMultiShape;
  448. gosASSERT(SensorSquareShape != NULL);
  449. SensorSquareShape->LoadTGMultiShapeFromASE(sensorName);
  450. }
  451. if (GVAppearanceType::SensorCircleShape == NULL && !numJumpNodes)
  452. {
  453. FullPathFileName sensorName;
  454. sensorName.init(tglPath,"circularcontact",".ase");
  455. GVAppearanceType::SensorCircleShape = new TG_TypeMultiShape;
  456. gosASSERT(GVAppearanceType::SensorCircleShape != NULL);
  457. GVAppearanceType::SensorCircleShape->LoadTGMultiShapeFromASE(sensorName);
  458. }
  459. if (GVAppearanceType::SensorTriangleShape == NULL)
  460. {
  461. FullPathFileName sensorName;
  462. sensorName.init(tglPath,"trianglecontact",".ase");
  463. GVAppearanceType::SensorTriangleShape = new TG_TypeMultiShape;
  464. gosASSERT(GVAppearanceType::SensorTriangleShape != NULL);
  465. GVAppearanceType::SensorTriangleShape->LoadTGMultiShapeFromASE(sensorName);
  466. }
  467. }
  468. //----------------------------------------------------------------------------
  469. void Mech3DAppearanceType::destroy (void)
  470. {
  471. AppearanceType::destroy();
  472. long i=0;
  473. for (i=0;i<MAX_LODS;i++)
  474. {
  475. if (mechShape[i])
  476. {
  477. delete mechShape[i];
  478. mechShape[i] = NULL;
  479. }
  480. }
  481. if (mechShadowShape)
  482. {
  483. delete mechShadowShape;
  484. mechShadowShape = NULL;
  485. }
  486. if (rightArm)
  487. {
  488. delete rightArm;
  489. rightArm = NULL;
  490. }
  491. if (leftArm)
  492. {
  493. delete leftArm;
  494. leftArm = NULL;
  495. }
  496. if (mechForwardDmgShape)
  497. {
  498. delete mechForwardDmgShape;
  499. mechForwardDmgShape = NULL;
  500. }
  501. if (mechBackwardDmgShape)
  502. {
  503. delete mechBackwardDmgShape;
  504. mechBackwardDmgShape = NULL;
  505. }
  506. for (i=0;i<MAX_ANIMATION_FILES;i++)
  507. {
  508. delete mechAnim[i];
  509. mechAnim[i] = NULL;
  510. }
  511. for (i=0;i<getTotalNodes();i++)
  512. {
  513. AppearanceTypeList::appearanceHeap->Free(nodeData[i].nodeId);
  514. nodeData[i].nodeId = NULL;
  515. }
  516. AppearanceTypeList::appearanceHeap->Free(nodeData);
  517. nodeData = NULL;
  518. numSmokeNodes = numWeaponNodes = numJumpNodes = 0;
  519. }
  520. //----------------------------------------------------------------------------
  521. void Mech3DAppearanceType::setAnimation (TG_MultiShapePtr shape, DWORD animationNum)
  522. {
  523. gosASSERT(shape != NULL);
  524. gosASSERT(animationNum != 0xffffffff);
  525. gosASSERT(animationNum < MaxGestures);
  526. if (mechAnim[animationNum])
  527. mechAnim[animationNum]->SetAnimationState(shape);
  528. else
  529. shape->ClearAnimation();
  530. }
  531. //-----------------------------------------------------------------------------
  532. #define MAX_MECHS 1
  533. Stuff::Vector3D debugMechActorPosition[MAX_MECHS];
  534. float mechDebugAngle[MAX_MECHS];
  535. float torsoDebugAngle[MAX_MECHS];
  536. //-----------------------------------------------------------------------------
  537. // class Mech3DAppearance
  538. void Mech3DAppearance::resetWeaponNodes (void)
  539. {
  540. //THis should never be called after the game inits!!
  541. for (long i=0;i<mechType->numWeaponNodes;i++)
  542. {
  543. nodeUsed[i] = 0;
  544. nodeRecycle[i] = BASE_NODE_RECYCLE_TIME;
  545. }
  546. }
  547. //-----------------------------------------------------------------------------
  548. void Mech3DAppearance::setWeaponNodeUsed (long weaponNode)
  549. {
  550. //THis should never be called after the game inits!!
  551. weaponNode -= mechType->numSmokeNodes;
  552. if ((weaponNode >= 0) && (weaponNode < mechType->numWeaponNodes))
  553. {
  554. nodeUsed[weaponNode]++;
  555. nodeRecycle[weaponNode] = BASE_NODE_RECYCLE_TIME;
  556. }
  557. }
  558. //-----------------------------------------------------------------------------
  559. void Mech3DAppearance::setWeaponNodeRecycle(long nodeId, float time)
  560. {
  561. nodeId -= mechType->numSmokeNodes;
  562. if ((nodeId >= 0) && (nodeId < mechType->numWeaponNodes))
  563. nodeRecycle[nodeId] = time;
  564. }
  565. //-----------------------------------------------------------------------------
  566. Stuff::Vector3D Mech3DAppearance::getWeaponNodePosition (long nodeId)
  567. {
  568. Stuff::Vector3D result = position;
  569. if ((nodeId < mechType->numSmokeNodes) || (nodeId >= (mechType->numSmokeNodes+mechType->numWeaponNodes)))
  570. return result;
  571. if (!inView)
  572. return result;
  573. //We already know we are using this node. Do NOT increment recycle or nodeUsed!
  574. //-------------------------------------------
  575. // Create Matrix to conform to.
  576. Stuff::UnitQuaternion qRotation;
  577. float yaw = rotation * DEGREES_TO_RADS;
  578. qRotation = Stuff::EulerAngles(0.0f, yaw, 0.0f);
  579. Stuff::Point3D xlatPosition;
  580. xlatPosition.x = -position.x;
  581. xlatPosition.y = position.z;
  582. xlatPosition.z = position.y;
  583. Stuff::UnitQuaternion torsoRot;
  584. torsoRot = Stuff::EulerAngles(0.0f,(torsoRotation * DEGREES_TO_RADS),0.0f);
  585. if (rotationalNodeIndex == -1)
  586. rotationalNodeIndex = mechShape->SetNodeRotation("joint_torso",&torsoRot);
  587. mechShape->SetNodeRotation(rotationalNodeIndex,&torsoRot);
  588. result = mechShape->GetTransformedNodePosition(&xlatPosition,&qRotation,mechType->nodeData[nodeId].nodeId);
  589. if ((result.x == 0.0f) &&
  590. (result.y == 0.0f) &&
  591. (result.z == 0.0f))
  592. result = position;
  593. return result;
  594. }
  595. //-----------------------------------------------------------------------------
  596. Stuff::Vector3D Mech3DAppearance::getNodeNamePosition (char *nodeName)
  597. {
  598. Stuff::Vector3D result = position;
  599. if (!inView)
  600. return result;
  601. //-------------------------------------------
  602. // Create Matrix to conform to.
  603. Stuff::UnitQuaternion qRotation;
  604. float yaw = rotation * DEGREES_TO_RADS;
  605. qRotation = Stuff::EulerAngles(0.0f, yaw, 0.0f);
  606. Stuff::Point3D xlatPosition;
  607. xlatPosition.x = -position.x;
  608. xlatPosition.y = position.z;
  609. xlatPosition.z = position.y;
  610. Stuff::UnitQuaternion torsoRot;
  611. torsoRot = Stuff::EulerAngles(0.0f,(torsoRotation * DEGREES_TO_RADS),0.0f);
  612. if (rotationalNodeIndex == -1)
  613. rotationalNodeIndex = mechShape->SetNodeRotation("joint_torso",&torsoRot);
  614. mechShape->SetNodeRotation(rotationalNodeIndex,&torsoRot);
  615. result = mechShape->GetTransformedNodePosition(&xlatPosition,&qRotation,nodeName);
  616. if ((result.x == 0.0f) &&
  617. (result.y == 0.0f) &&
  618. (result.z == 0.0f))
  619. result = position;
  620. return result;
  621. }
  622. //-----------------------------------------------------------------------------
  623. Stuff::Vector3D Mech3DAppearance::getNodeIdPosition (long nodeId)
  624. {
  625. Stuff::Vector3D result = position;
  626. if (!inView)
  627. return result;
  628. //-------------------------------------------
  629. // Create Matrix to conform to.
  630. Stuff::UnitQuaternion qRotation;
  631. float yaw = rotation * DEGREES_TO_RADS;
  632. qRotation = Stuff::EulerAngles(0.0f, yaw, 0.0f);
  633. Stuff::Point3D xlatPosition;
  634. xlatPosition.x = -position.x;
  635. xlatPosition.y = position.z;
  636. xlatPosition.z = position.y;
  637. Stuff::UnitQuaternion torsoRot;
  638. torsoRot = Stuff::EulerAngles(0.0f,(torsoRotation * DEGREES_TO_RADS),0.0f);
  639. if (rotationalNodeIndex == -1)
  640. rotationalNodeIndex = mechShape->SetNodeRotation("joint_torso",&torsoRot);
  641. mechShape->SetNodeRotation(rotationalNodeIndex,&torsoRot);
  642. result = mechShape->GetTransformedNodePosition(&xlatPosition,&qRotation,nodeId);
  643. if ((result.x == 0.0f) &&
  644. (result.y == 0.0f) &&
  645. (result.z == 0.0f))
  646. result = position;
  647. return result;
  648. }
  649. //-----------------------------------------------------------------------------
  650. Stuff::Vector3D Mech3DAppearance::getNodePosition (long nodeId)
  651. {
  652. Stuff::Vector3D result = position;
  653. if ((nodeId < 0) || (nodeId >= mechType->getTotalNodes()))
  654. return result;
  655. if (!inView)
  656. return result;
  657. //-------------------------------------------
  658. // Create Matrix to conform to.
  659. Stuff::UnitQuaternion qRotation;
  660. float yaw = rotation * DEGREES_TO_RADS;
  661. qRotation = Stuff::EulerAngles(0.0f, yaw, 0.0f);
  662. Stuff::Point3D xlatPosition;
  663. xlatPosition.x = -position.x;
  664. xlatPosition.y = position.z;
  665. xlatPosition.z = position.y;
  666. Stuff::UnitQuaternion torsoRot;
  667. torsoRot = Stuff::EulerAngles(0.0f,(torsoRotation * DEGREES_TO_RADS),0.0f);
  668. if (rotationalNodeIndex == -1)
  669. rotationalNodeIndex = mechShape->SetNodeRotation("joint_torso",&torsoRot);
  670. mechShape->SetNodeRotation(rotationalNodeIndex,&torsoRot);
  671. result = mechShape->GetTransformedNodePosition(&xlatPosition,&qRotation,mechType->nodeData[nodeId].nodeId);
  672. return result;
  673. }
  674. //-----------------------------------------------------------------------------
  675. long Mech3DAppearance::getLowestWeaponNode (void)
  676. {
  677. //------------------------------------------------
  678. // Scan all weapon nodes and find least used one.
  679. long bestNode = -1;
  680. float lowestPosZ;
  681. long numSmokeNodes = mechType->numSmokeNodes;
  682. lowestPosZ = 9999999999999.0f;
  683. for (long i=0;i<mechType->numWeaponNodes;i++)
  684. {
  685. Stuff::Vector3D nodePosition = getNodePosition(i+numSmokeNodes);
  686. if (nodePosition.z < lowestPosZ)
  687. {
  688. lowestPosZ = nodePosition.z;
  689. bestNode = i+numSmokeNodes;
  690. }
  691. }
  692. if ((lowestPosZ == 0.0f) || (bestNode < 0) || (bestNode >= mechType->getTotalNodes()))
  693. return -1;
  694. return bestNode;
  695. }
  696. //-----------------------------------------------------------------------------
  697. long Mech3DAppearance::getWeaponNode (long weaponType)
  698. {
  699. //------------------------------------------------
  700. // Scan all weapon nodes and find least used one.
  701. // BIG change here. This is ONLY called at load time.
  702. // NEVER during actual game execution. In this way,
  703. // Weapons always fire from the same nodes!!
  704. long leastUsed = 999999999;
  705. long bestNode = -1;
  706. long numSmokeNodes = mechType->numSmokeNodes;
  707. for (long i=0;i<mechType->numWeaponNodes;i++)
  708. {
  709. switch (weaponType)
  710. {
  711. case MECH3D_WEAPONTYPE_MISSILE:
  712. if ((mechType->nodeData[numSmokeNodes+i].weaponType == weaponType) ||
  713. (mechType->nodeData[numSmokeNodes+i].weaponType == MECH3D_WEAPONTYPE_ANY) ||
  714. (mechType->nodeData[numSmokeNodes+i].weaponType == MECH3D_WEAPONTYPE_NONENERGY))
  715. {
  716. //This node is blown off.
  717. if (rightArmOff && mechType->nodeData[i+numSmokeNodes].isRArmNode)
  718. continue;
  719. //This node is blown off.
  720. if (leftArmOff && mechType->nodeData[i+numSmokeNodes].isLArmNode)
  721. continue;
  722. if (nodeUsed[i] < leastUsed)
  723. {
  724. leastUsed = nodeUsed[i];
  725. bestNode = i + numSmokeNodes;
  726. }
  727. }
  728. break;
  729. case MECH3D_WEAPONTYPE_BALLISTIC:
  730. if ((mechType->nodeData[numSmokeNodes+i].weaponType == weaponType) ||
  731. (mechType->nodeData[numSmokeNodes+i].weaponType == MECH3D_WEAPONTYPE_ANY) ||
  732. (mechType->nodeData[numSmokeNodes+i].weaponType == MECH3D_WEAPONTYPE_DIRECT) ||
  733. (mechType->nodeData[numSmokeNodes+i].weaponType == MECH3D_WEAPONTYPE_NONENERGY))
  734. {
  735. //This node is blown off.
  736. if (rightArmOff && mechType->nodeData[i+numSmokeNodes].isRArmNode)
  737. continue;
  738. //This node is blown off.
  739. if (leftArmOff && mechType->nodeData[i+numSmokeNodes].isLArmNode)
  740. continue;
  741. if (nodeUsed[i] < leastUsed)
  742. {
  743. leastUsed = nodeUsed[i];
  744. bestNode = i + numSmokeNodes;
  745. }
  746. }
  747. break;
  748. case MECH3D_WEAPONTYPE_ENERGY:
  749. if ((mechType->nodeData[numSmokeNodes+i].weaponType == weaponType) ||
  750. (mechType->nodeData[numSmokeNodes+i].weaponType == MECH3D_WEAPONTYPE_DIRECT) ||
  751. (mechType->nodeData[numSmokeNodes+i].weaponType == MECH3D_WEAPONTYPE_ANY))
  752. {
  753. //This node is blown off.
  754. if (rightArmOff && mechType->nodeData[i+numSmokeNodes].isRArmNode)
  755. continue;
  756. //This node is blown off.
  757. if (leftArmOff && mechType->nodeData[i+numSmokeNodes].isLArmNode)
  758. continue;
  759. if (nodeUsed[i] < leastUsed)
  760. {
  761. leastUsed = nodeUsed[i];
  762. bestNode = i + numSmokeNodes;
  763. }
  764. }
  765. break;
  766. case MECH3D_WEAPONTYPE_ANY:
  767. //This node is blown off.
  768. if (rightArmOff && mechType->nodeData[i+numSmokeNodes].isRArmNode)
  769. continue;
  770. //This node is blown off.
  771. if (leftArmOff && mechType->nodeData[i+numSmokeNodes].isLArmNode)
  772. continue;
  773. if (nodeUsed[i] < leastUsed)
  774. {
  775. leastUsed = nodeUsed[i];
  776. bestNode = i + numSmokeNodes;
  777. }
  778. break;
  779. default:
  780. STOP(("Sent down a bad weapon type %d",weaponType));
  781. }
  782. }
  783. if ((bestNode < 0) || (bestNode >= mechType->getTotalNodes()))
  784. return -1;
  785. //This should never be called AFTER the game inits!!!
  786. setWeaponNodeUsed(bestNode);
  787. return bestNode;
  788. }
  789. //-----------------------------------------------------------------------------
  790. float Mech3DAppearance::getWeaponNodeRecycle (long node)
  791. {
  792. node -= mechType->numSmokeNodes;
  793. if ((node >=0) && (node < mechType->numWeaponNodes))
  794. return nodeRecycle[node];
  795. return 9999.0f; //NOT a weapon node, never recycled!!
  796. }
  797. //-----------------------------------------------------------------------------
  798. void Mech3DAppearance::init (AppearanceTypePtr tree, GameObjectPtr obj)
  799. {
  800. Appearance::init(tree,obj);
  801. mechType = (Mech3DAppearanceType *)tree;
  802. mechName[0] = 0;
  803. pilotNameID = -1;
  804. paintScheme = -1;
  805. objectNameId = 30862;
  806. baseRootNodeHeight = -99999.9f;
  807. baseRootNodeDifference = 0.0f;
  808. rotationalNodeIndex = -1;
  809. hitLeftNodeIndex = hitRightNodeIndex = -1;
  810. rootNodeIndex = lightCircleNodeIndex = -1;
  811. leftArmNodeIndex = rightArmNodeIndex = -1;
  812. screenPos.x = screenPos.y = screenPos.z = screenPos.w = -999.0f;
  813. frameNum = 0.0f;
  814. rightShoulderPos.x = rightShoulderPos.y = rightShoulderPos.z = -99999.9f;
  815. leftShoulderPos.x = leftShoulderPos.y = leftShoulderPos.z = -99999.9f;
  816. idleTime = RandomNumber(idleMAX);
  817. hazeFactor = 0.0f;
  818. rotation = torsoRotation = leftArmRotation = rightArmRotation = 0;
  819. leftArmOff = rightArmOff = fallen = false;
  820. position.x = position.y = position.z = 0.0f;
  821. velocity = 0.0f;
  822. teamId = paintScheme = -1;
  823. homeTeamRelationship = 0;
  824. selected = 0;
  825. status = 0;
  826. lockRotation = oncePerFrame = false;
  827. sensorLevel = 0;
  828. sensorSpin = 0.0f;
  829. OBBRadius = 0.0f;
  830. currentLOD = 0;
  831. jumpVelocity.Zero();
  832. jumpFXSetup = false;
  833. nodeUsed = NULL;
  834. nodeRecycle = NULL;
  835. currentRightPoof = currentLeftPoof = 0;
  836. localTextureHandle = 0xffffffff;
  837. isSmoking = -1;
  838. isWaking = false;
  839. isDusting = false;
  840. movedThisFrame = false;
  841. fallDust = false;
  842. criticalSmoke = NULL;
  843. smokeEffect = NULL;
  844. waterWake = NULL;
  845. helicopterDustCloud = NULL;
  846. isHelicopter = false;
  847. leftArm = rightArm = NULL;
  848. rightArmSmoke = leftArmSmoke = NULL;
  849. currentFlash = duration = flashDuration = 0.0f;
  850. flashColor = 0x00000000;
  851. drawFlash = false;
  852. //Default to Bright RGB.
  853. psRed = psGreen = psBlue = 0xffffffff;
  854. if (mechType)
  855. {
  856. mechShape = mechType->mechShape[0]->CreateFrom();
  857. sensorTriangleShape = GVAppearanceType::SensorTriangleShape->CreateFrom();
  858. if (mechType->leftArm)
  859. leftArm = mechType->leftArm->CreateFrom();
  860. if (mechType->rightArm)
  861. rightArm = mechType->rightArm->CreateFrom();
  862. //-------------------------------------------------
  863. // Load the texture and store its handle.
  864. for (long i=0;i<sensorTriangleShape->GetNumTextures();i++)
  865. {
  866. char txmName[1024];
  867. sensorTriangleShape->GetTextureName(i,txmName,256);
  868. char texturePath[1024];
  869. sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
  870. FullPathFileName textureName;
  871. textureName.init(texturePath,txmName,"");
  872. if (fileExists(textureName))
  873. {
  874. if (strnicmp(txmName,"a_",2) == 0)
  875. {
  876. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
  877. sensorTriangleShape->SetTextureHandle(i,gosTextureHandle);
  878. sensorTriangleShape->SetTextureAlpha(i,true);
  879. }
  880. else
  881. {
  882. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
  883. sensorTriangleShape->SetTextureHandle(i,gosTextureHandle);
  884. sensorTriangleShape->SetTextureAlpha(i,false);
  885. }
  886. }
  887. else
  888. {
  889. //PAUSE(("Warning: %s texture name not found",textureName));
  890. sensorTriangleShape->SetTextureHandle(i,0xffffffff);
  891. }
  892. }
  893. if (mechType->numJumpNodes)
  894. {
  895. sensorSquareShape = Mech3DAppearanceType::SensorSquareShape->CreateFrom();
  896. //-------------------------------------------------
  897. // Load the texture and store its handle.
  898. for (i=0;i<sensorSquareShape->GetNumTextures();i++)
  899. {
  900. char txmName[1024];
  901. sensorSquareShape->GetTextureName(i,txmName,256);
  902. char texturePath[1024];
  903. sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
  904. FullPathFileName textureName;
  905. textureName.init(texturePath,txmName,"");
  906. if (fileExists(textureName))
  907. {
  908. if (strnicmp(txmName,"a_",2) == 0)
  909. {
  910. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
  911. sensorSquareShape->SetTextureHandle(i,gosTextureHandle);
  912. sensorSquareShape->SetTextureAlpha(i,true);
  913. }
  914. else
  915. {
  916. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
  917. sensorSquareShape->SetTextureHandle(i,gosTextureHandle);
  918. sensorSquareShape->SetTextureAlpha(i,false);
  919. }
  920. }
  921. else
  922. {
  923. //PAUSE(("Warning: %s texture name not found",textureName));
  924. sensorSquareShape->SetTextureHandle(i,0xffffffff);
  925. }
  926. }
  927. }
  928. else
  929. {
  930. sensorSquareShape = GVAppearanceType::SensorCircleShape->CreateFrom();
  931. //-------------------------------------------------
  932. // Load the texture and store its handle.
  933. for (i=0;i<sensorSquareShape->GetNumTextures();i++)
  934. {
  935. char txmName[1024];
  936. sensorSquareShape->GetTextureName(i,txmName,256);
  937. char texturePath[1024];
  938. sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
  939. FullPathFileName textureName;
  940. textureName.init(texturePath,txmName,"");
  941. if (fileExists(textureName))
  942. {
  943. if (strnicmp(txmName,"a_",2) == 0)
  944. {
  945. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
  946. sensorSquareShape->SetTextureHandle(i,gosTextureHandle);
  947. sensorSquareShape->SetTextureAlpha(i,true);
  948. }
  949. else
  950. {
  951. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
  952. sensorSquareShape->SetTextureHandle(i,gosTextureHandle);
  953. sensorSquareShape->SetTextureAlpha(i,false);
  954. }
  955. }
  956. else
  957. {
  958. //PAUSE(("Warning: %s texture name not found",textureName));
  959. sensorSquareShape->SetTextureHandle(i,0xffffffff);
  960. }
  961. }
  962. }
  963. if (mechType->numWeaponNodes)
  964. {
  965. nodeUsed = (long *)AppearanceTypeList::appearanceHeap->Malloc(sizeof(long) * mechType->numWeaponNodes);
  966. gosASSERT(nodeUsed != NULL);
  967. memset(nodeUsed,0,sizeof(long) * mechType->numWeaponNodes);
  968. nodeRecycle = (float *)AppearanceTypeList::appearanceHeap->Malloc(sizeof(float) * mechType->numWeaponNodes);
  969. gosASSERT(nodeRecycle != NULL);
  970. for (long i=0;i<mechType->numWeaponNodes;i++)
  971. nodeRecycle[i] = 0.0f;
  972. }
  973. for (i=0;i<mechType->numWeaponNodes;i++)
  974. {
  975. if (mechShape->isChildOf(mechType->nodeData->nodeId,"joint_ruarm"))
  976. mechType->nodeData[i+mechType->numSmokeNodes].isRArmNode = true;
  977. else
  978. mechType->nodeData[i+mechType->numSmokeNodes].isRArmNode = false;
  979. if (mechShape->isChildOf(mechType->nodeData->nodeId,"joint_luarm"))
  980. mechType->nodeData[i+mechType->numSmokeNodes].isLArmNode = true;
  981. else
  982. mechType->nodeData[i+mechType->numSmokeNodes].isLArmNode = false;
  983. }
  984. Stuff::Vector3D boxCoords[8];
  985. Stuff::Vector3D nodeCenter = mechShape->GetRootNodeCenter();
  986. boxCoords[0].x = position.x + mechShape->GetMinBox().x + nodeCenter.x;
  987. boxCoords[0].y = position.y + mechShape->GetMinBox().z + nodeCenter.z;
  988. boxCoords[0].z = position.z + mechShape->GetMaxBox().y + nodeCenter.y;
  989. boxCoords[1].x = position.x + mechShape->GetMinBox().x + nodeCenter.x;
  990. boxCoords[1].y = position.y + mechShape->GetMaxBox().z + nodeCenter.z;
  991. boxCoords[1].z = position.z + mechShape->GetMaxBox().y + nodeCenter.y;
  992. boxCoords[2].x = position.x + mechShape->GetMaxBox().x + nodeCenter.x;
  993. boxCoords[2].y = position.y + mechShape->GetMaxBox().z + nodeCenter.z;
  994. boxCoords[2].z = position.z + mechShape->GetMaxBox().y + nodeCenter.y;
  995. boxCoords[3].x = position.x + mechShape->GetMaxBox().x + nodeCenter.x;
  996. boxCoords[3].y = position.y + mechShape->GetMinBox().z + nodeCenter.z;
  997. boxCoords[3].z = position.z + mechShape->GetMaxBox().y + nodeCenter.y;
  998. boxCoords[4].x = position.x + mechShape->GetMinBox().x + nodeCenter.x;
  999. boxCoords[4].y = position.y + mechShape->GetMinBox().z + nodeCenter.z;
  1000. boxCoords[4].z = position.z + mechShape->GetMinBox().y + nodeCenter.y;
  1001. boxCoords[5].x = position.x + mechShape->GetMaxBox().x + nodeCenter.x;
  1002. boxCoords[5].y = position.y + mechShape->GetMinBox().z + nodeCenter.z;
  1003. boxCoords[5].z = position.z + mechShape->GetMinBox().y + nodeCenter.y;
  1004. boxCoords[6].x = position.x + mechShape->GetMaxBox().x + nodeCenter.x;
  1005. boxCoords[6].y = position.y + mechShape->GetMaxBox().z + nodeCenter.z;
  1006. boxCoords[6].z = position.z + mechShape->GetMinBox().y + nodeCenter.y;
  1007. boxCoords[7].x = position.x + mechShape->GetMinBox().x + nodeCenter.x;
  1008. boxCoords[7].y = position.y + mechShape->GetMaxBox().z + nodeCenter.z;
  1009. boxCoords[7].z = position.z + mechShape->GetMinBox().y + nodeCenter.y;
  1010. float testRadius = 0.0;
  1011. for (i=0;i<8;i++)
  1012. {
  1013. testRadius = boxCoords[i].GetLength();
  1014. if (OBBRadius < testRadius)
  1015. OBBRadius = testRadius;
  1016. }
  1017. mechType->boundsUpperLeftX = (-OBBRadius);
  1018. mechType->boundsUpperLeftY = (-OBBRadius * 2.0);
  1019. mechType->boundsLowerRightX = (OBBRadius);
  1020. mechType->boundsLowerRightY = (OBBRadius);
  1021. if (!mechType->getDesignerTypeBounds())
  1022. {
  1023. mechType->typeUpperLeft.x = mechShape->GetMaxBox().x + nodeCenter.x;
  1024. mechType->typeUpperLeft.y = mechShape->GetMaxBox().z + nodeCenter.z;
  1025. mechType->typeUpperLeft.z = mechShape->GetMaxBox().y + nodeCenter.y;
  1026. mechType->typeLowerRight.x = mechShape->GetMinBox().x + nodeCenter.x;
  1027. mechType->typeLowerRight.y = mechShape->GetMinBox().z + nodeCenter.z;
  1028. mechType->typeLowerRight.z = mechShape->GetMinBox().y + nodeCenter.y;
  1029. //Now expand box by some percentage to make selection easier.
  1030. mechType->typeUpperLeft.x *= EXPAND_FACTOR;
  1031. mechType->typeUpperLeft.y *= EXPAND_FACTOR;
  1032. mechType->typeUpperLeft.z *= EXPAND_FACTOR;
  1033. mechType->typeLowerRight.x *= EXPAND_FACTOR;
  1034. mechType->typeLowerRight.y *= EXPAND_FACTOR;
  1035. mechType->typeLowerRight.z *= EXPAND_FACTOR;
  1036. }
  1037. }
  1038. mechFrameRate = 30.0f;
  1039. forceStop = atTransitionToNextGesture = inReverse = inJump = false;
  1040. inDebugMoveMode = singleStepMode = nextStep = prevStep = false;
  1041. currentStateGoal = -1; //Always start ready to change gestures
  1042. currentGestureId = 2; //Always start in Stand Mode
  1043. transitionState = 0;
  1044. oldStateGoal = 1; //Always start in Stand Mode
  1045. currentFrame = 0.0f;
  1046. pointLight = NULL;
  1047. lightId = 0xffffffff;
  1048. hitGestureId = -1;
  1049. jumpSetup = false;
  1050. jumpAirborne = inJump = false;
  1051. footPos[0].x = footPos[0].y = footPos[0].z = 1000.0f;
  1052. footPos[1].x = footPos[1].y = footPos[1].z = 1000.0f;
  1053. for (long i=0;i<MAX_DUST_POOFS;i++)
  1054. {
  1055. rightDustPoofEffect[i] = NULL;
  1056. leftDustPoofEffect[i] = NULL;
  1057. }
  1058. smokeEffect = NULL;
  1059. jumpJetEffect = NULL;
  1060. rightShoulderBoom = leftShoulderBoom = NULL;
  1061. leftFootDone0 = rightFootDone0 = leftFootDone1 = rightFootDone1 = false;
  1062. leftFootPoofDraw[0] = leftFootPoofDraw[1] = leftFootPoofDraw[2] =
  1063. rightFootPoofDraw[0] = rightFootPoofDraw[1] = rightFootPoofDraw[2] = false;
  1064. if (mechType && mechType->mechShadowShape)
  1065. {
  1066. mechShadowShape = mechType->mechShadowShape->CreateFrom();
  1067. //-------------------------------------------------
  1068. // Load the texture and store its handle.
  1069. for (long i=0;i<mechShadowShape->GetNumTextures();i++)
  1070. {
  1071. char txmName[1024];
  1072. mechShadowShape->GetTextureName(i,txmName,256);
  1073. char texturePath[1024];
  1074. sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
  1075. FullPathFileName textureName;
  1076. textureName.init(texturePath,txmName,"");
  1077. if (fileExists(textureName))
  1078. {
  1079. if (strnicmp(txmName,"a_",2) == 0)
  1080. {
  1081. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
  1082. gosASSERT(gosTextureHandle != 0xffffffff);
  1083. mechShadowShape->SetTextureHandle(i,gosTextureHandle);
  1084. mechShadowShape->SetTextureAlpha(i,true);
  1085. }
  1086. else
  1087. {
  1088. DWORD gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
  1089. gosASSERT(gosTextureHandle != 0xffffffff);
  1090. mechShadowShape->SetTextureHandle(i,gosTextureHandle);
  1091. mechShadowShape->SetTextureAlpha(i,false);
  1092. }
  1093. }
  1094. else
  1095. {
  1096. mechShadowShape->SetTextureHandle(i,0xffffffff);
  1097. }
  1098. }
  1099. }
  1100. else
  1101. {
  1102. mechShadowShape = NULL;
  1103. }
  1104. }
  1105. void Mech3DAppearance::initFX (void)
  1106. {
  1107. //-----------------------------------------------
  1108. //Create FX here so they are always ready to go!
  1109. if (!InEditor)
  1110. {
  1111. if (useNonWeaponEffects && strcmp(weaponEffects->GetEffectName(FX_POOF_ID),"NONE") != 0)
  1112. {
  1113. //--------------------------------------------
  1114. // Yes, load it on up.
  1115. unsigned flags = gosFX::Effect::ExecuteFlag;
  1116. Check_Object(gosFX::EffectLibrary::Instance);
  1117. gosFX::Effect::Specification* gosEffectSpec = gosFX::EffectLibrary::Instance->Find(weaponEffects->GetEffectName(FX_POOF_ID));
  1118. if (gosEffectSpec)
  1119. {
  1120. for (long i=0;i<MAX_DUST_POOFS;i++)
  1121. {
  1122. rightDustPoofEffect[i] = gosFX::EffectLibrary::Instance->MakeEffect(gosEffectSpec->m_effectID, flags);
  1123. gosASSERT(rightDustPoofEffect[i] != NULL);
  1124. }
  1125. MidLevelRenderer::MLRTexturePool::Instance->LoadImages();
  1126. }
  1127. }
  1128. if (useNonWeaponEffects && strcmp(weaponEffects->GetEffectName(FX_POOF_ID),"NONE") != 0)
  1129. {
  1130. //--------------------------------------------
  1131. // Yes, load it on up.
  1132. unsigned flags = gosFX::Effect::ExecuteFlag;
  1133. Check_Object(gosFX::EffectLibrary::Instance);
  1134. gosFX::Effect::Specification* gosEffectSpec = gosFX::EffectLibrary::Instance->Find(weaponEffects->GetEffectName(FX_POOF_ID));
  1135. if (gosEffectSpec)
  1136. {
  1137. for (long i=0;i<MAX_DUST_POOFS;i++)
  1138. {
  1139. leftDustPoofEffect[i] = gosFX::EffectLibrary::Instance->MakeEffect(gosEffectSpec->m_effectID, flags);
  1140. gosASSERT(leftDustPoofEffect[i] != NULL);
  1141. }
  1142. MidLevelRenderer::MLRTexturePool::Instance->LoadImages();
  1143. }
  1144. }
  1145. if (useNonWeaponEffects && strcmp(weaponEffects->GetEffectName(FX_SMOKE_ID),"NONE") != 0)
  1146. {
  1147. //--------------------------------------------
  1148. // Yes, load it on up.
  1149. unsigned flags = gosFX::Effect::ExecuteFlag|gosFX::Effect::LoopFlag;
  1150. Check_Object(gosFX::EffectLibrary::Instance);
  1151. gosFX::Effect::Specification* gosEffectSpec = gosFX::EffectLibrary::Instance->Find(weaponEffects->GetEffectName(FX_SMOKE_ID));
  1152. if (gosEffectSpec)
  1153. {
  1154. smokeEffect = gosFX::EffectLibrary::Instance->MakeEffect(gosEffectSpec->m_effectID, flags);
  1155. gosASSERT(smokeEffect != NULL);
  1156. MidLevelRenderer::MLRTexturePool::Instance->LoadImages();
  1157. }
  1158. }
  1159. if (strcmp(weaponEffects->GetEffectName(FX_JUMP_ID),"NONE") != 0)
  1160. {
  1161. //--------------------------------------------
  1162. // Yes, load it on up.
  1163. unsigned flags = gosFX::Effect::ExecuteFlag|gosFX::Effect::LoopFlag;
  1164. Check_Object(gosFX::EffectLibrary::Instance);
  1165. gosFX::Effect::Specification* gosEffectSpec = gosFX::EffectLibrary::Instance->Find(weaponEffects->GetEffectName(FX_JUMP_ID));
  1166. if (gosEffectSpec)
  1167. {
  1168. jumpJetEffect = gosFX::EffectLibrary::Instance->MakeEffect(gosEffectSpec->m_effectID, flags);
  1169. gosASSERT(jumpJetEffect != NULL);
  1170. MidLevelRenderer::MLRTexturePool::Instance->LoadImages();
  1171. }
  1172. }
  1173. }
  1174. }
  1175. //------------------------------------------------------------------------------------------
  1176. //Puts mech into hit mode IF and ONLY IF the mech is standing, walking, reversing, running or limping.
  1177. // NO OTHER GESTURE IS VALID!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1178. void Mech3DAppearance::hitFront (void)
  1179. {
  1180. if ((currentGestureId == GestureStand) ||
  1181. (currentGestureId == GestureWalk) ||
  1182. (currentGestureId == GestureReverse) ||
  1183. (currentGestureId == GestureRun) ||
  1184. (currentGestureId == GestureLimpLeft) ||
  1185. (currentGestureId == GestureLimpRight))
  1186. {
  1187. hitGestureId = currentGestureId;
  1188. currentGestureId = GestureHitFront;
  1189. long firstFrame = mechType->gestures[currentGestureId].frameStart;
  1190. atTransitionToNextGesture = false;
  1191. inReverse = false;
  1192. currentFrame = firstFrame;
  1193. }
  1194. }
  1195. //-----------------------------------------------------------------------------
  1196. void Mech3DAppearance::hitBack (void)
  1197. {
  1198. if ((currentGestureId == GestureStand) ||
  1199. (currentGestureId == GestureWalk) ||
  1200. (currentGestureId == GestureReverse) ||
  1201. (currentGestureId == GestureRun) ||
  1202. (currentGestureId == GestureLimpLeft) ||
  1203. (currentGestureId == GestureLimpRight))
  1204. {
  1205. hitGestureId = currentGestureId;
  1206. currentGestureId = GestureHitBack;
  1207. long firstFrame = mechType->gestures[currentGestureId].frameStart;
  1208. atTransitionToNextGesture = false;
  1209. inReverse = false;
  1210. currentFrame = firstFrame;
  1211. }
  1212. }
  1213. //-----------------------------------------------------------------------------
  1214. void Mech3DAppearance::hitLeft (void)
  1215. {
  1216. if ((currentGestureId == GestureStand) ||
  1217. (currentGestureId == GestureWalk) ||
  1218. (currentGestureId == GestureReverse) ||
  1219. (currentGestureId == GestureRun) ||
  1220. (currentGestureId == GestureLimpLeft) ||
  1221. (currentGestureId == GestureLimpRight))
  1222. {
  1223. hitGestureId = currentGestureId;
  1224. currentGestureId = GestureHitLeft;
  1225. long firstFrame = mechType->gestures[currentGestureId].frameStart;
  1226. atTransitionToNextGesture = false;
  1227. inReverse = false;
  1228. currentFrame = firstFrame;
  1229. }
  1230. }
  1231. //-----------------------------------------------------------------------------
  1232. void Mech3DAppearance::hitRight (void)
  1233. {
  1234. if ((currentGestureId == GestureStand) ||
  1235. (currentGestureId == GestureWalk) ||
  1236. (currentGestureId == GestureReverse) ||
  1237. (currentGestureId == GestureRun) ||
  1238. (currentGestureId == GestureLimpLeft) ||
  1239. (currentGestureId == GestureLimpRight))
  1240. {
  1241. hitGestureId = currentGestureId;
  1242. currentGestureId = GestureHitRight;
  1243. long firstFrame = mechType->gestures[currentGestureId].frameStart;
  1244. atTransitionToNextGesture = false;
  1245. inReverse = false;
  1246. currentFrame = firstFrame;
  1247. }
  1248. }
  1249. //-----------------------------------------------------------------------------
  1250. bool Mech3DAppearance::PerPolySelect (long mouseX, long mouseY)
  1251. {
  1252. return mechShape->PerPolySelect(mouseX,mouseY);
  1253. }
  1254. //-----------------------------------------------------------------------------
  1255. void Mech3DAppearance::LoadPaintSchemata (void)
  1256. {
  1257. FullPathFileName paintName;
  1258. paintName.init(tglPath,"paintSchemata",".fit");
  1259. FitIniFile paintFile;
  1260. long result = paintFile.open(paintName);
  1261. gosASSERT(result == NO_ERR);
  1262. result = paintFile.seekBlock("Main");
  1263. gosASSERT(result == NO_ERR);
  1264. result = paintFile.readIdULong("NumPaintSchemes",numPaintSchemata);
  1265. gosASSERT(result == NO_ERR);
  1266. paintSchemata = (PaintSchemataPtr)AppearanceTypeList::appearanceHeap->Malloc(numPaintSchemata * sizeof(PaintSchemata));
  1267. gosASSERT(paintSchemata != NULL);
  1268. memset(paintSchemata,0xff,numPaintSchemata * sizeof(PaintSchemata));
  1269. for (long i=0;i<numPaintSchemata;i++)
  1270. {
  1271. char blockId[512];
  1272. sprintf(blockId,"Scheme%d",i);
  1273. result = paintFile.seekBlock(blockId);
  1274. gosASSERT(result == NO_ERR);
  1275. result = paintFile.readIdULong("RedColor",paintSchemata[i].redColor);
  1276. gosASSERT(result == NO_ERR);
  1277. result = paintFile.readIdULong("GreenColor",paintSchemata[i].greenColor);
  1278. gosASSERT(result == NO_ERR);
  1279. result = paintFile.readIdULong("BlueColor",paintSchemata[i].blueColor);
  1280. gosASSERT(result == NO_ERR);
  1281. }
  1282. paintFile.close();
  1283. }
  1284. //-----------------------------------------------------------------------------
  1285. void Mech3DAppearance::setPaintScheme (void)
  1286. {
  1287. //----------------------------------------------------------------------------
  1288. // Simple really. Get the texture memory, apply the paint scheme, let it go!
  1289. DWORD gosHandle = mcTextureManager->get_gosTextureHandle(mechShape->GetTextureHandle(0));
  1290. if (gosHandle && gosHandle != 0xffffffff)
  1291. {
  1292. //-------------------
  1293. // Lock the texture.
  1294. TEXTUREPTR textureData;
  1295. gos_LockTexture(gosHandle, 0, 0, &textureData);
  1296. //-------------------------------------------------------
  1297. DWORD *textureMemory = textureData.pTexture;
  1298. for (long i=0;i<textureData.Height;i++)
  1299. {
  1300. for (long j=0;j<textureData.Height;j++)
  1301. {
  1302. //---------------------------------------------
  1303. // Make Color from PaintScheme.
  1304. DWORD baseColor = *textureMemory;
  1305. float baseColorRed = float((baseColor & 0x00ff0000)>>16);
  1306. float baseColorGreen = float((baseColor & 0x0000ff00)>>8);
  1307. float baseColorBlue = float(baseColor & 0x000000ff);
  1308. DWORD newColor = *textureMemory; //Black by default.
  1309. if ((!baseColorGreen) && (!baseColorBlue))
  1310. {
  1311. baseColorRed *= 0.00390625f; //Divide by 256;
  1312. baseColorRed = 1.0 - baseColorRed;
  1313. baseColorRed *= baseColorRed; //Log colors
  1314. baseColorRed = 1.0 - baseColorRed;
  1315. float newColorRed = float((psRed & 0x00ff0000)>>16);
  1316. newColorRed *= baseColorRed;
  1317. unsigned char red = (unsigned char)newColorRed;
  1318. float newColorGreen = float((psRed & 0x0000ff00)>>8);
  1319. newColorGreen *= baseColorRed;
  1320. unsigned char green = (unsigned char)newColorGreen;
  1321. float newColorBlue = float(psRed & 0x000000ff);
  1322. newColorBlue *= baseColorRed;
  1323. unsigned char blue = (unsigned char)newColorBlue;
  1324. newColor = (0xff<<24) + (red<<16) + (green<<8) + (blue);
  1325. }
  1326. else if ((!baseColorRed) && (!baseColorBlue))
  1327. {
  1328. baseColorGreen *= 0.00390625f; //Divide by 256;
  1329. baseColorGreen = 1.0 - baseColorGreen;
  1330. baseColorGreen *= baseColorGreen; //Log colors
  1331. baseColorGreen = 1.0 - baseColorGreen;
  1332. float newColorRed = float((psGreen & 0x00ff0000)>>16);
  1333. newColorRed *= baseColorGreen;
  1334. unsigned char red = (unsigned char)newColorRed;
  1335. float newColorGreen = float((psGreen & 0x0000ff00)>>8);
  1336. newColorGreen *= baseColorGreen;
  1337. unsigned char green = (unsigned char)newColorGreen;
  1338. float newColorBlue = float(psGreen & 0x000000ff);
  1339. newColorBlue *= baseColorGreen;
  1340. unsigned char blue = (unsigned char)newColorBlue;
  1341. newColor = (0xff<<24) + (red<<16) + (green<<8) + (blue);
  1342. }
  1343. else if ((!baseColorRed) && (!baseColorGreen))
  1344. {
  1345. baseColorBlue *= 0.00390625f; //Divide by 256;
  1346. baseColorBlue = 1.0 - baseColorBlue;
  1347. baseColorBlue *= baseColorBlue; //Log colors
  1348. baseColorBlue = 1.0 - baseColorBlue;
  1349. float newColorRed = float((psBlue & 0x00ff0000)>>16);
  1350. newColorRed *= baseColorBlue;
  1351. unsigned char red = (unsigned char)newColorRed;
  1352. float newColorGreen = float((psBlue & 0x0000ff00)>>8);
  1353. newColorGreen *= baseColorBlue;
  1354. unsigned char green = (unsigned char)newColorGreen;
  1355. float newColorBlue = float(psBlue & 0x000000ff);
  1356. newColorBlue *= baseColorBlue;
  1357. unsigned char blue = (unsigned char)newColorBlue;
  1358. newColor = (0xff<<24) + (red<<16) + (green<<8) + (blue);
  1359. }
  1360. *textureMemory = newColor;
  1361. textureMemory++;
  1362. }
  1363. }
  1364. //------------------------
  1365. // Unlock the texture
  1366. gos_UnLockTexture(gosHandle);
  1367. }
  1368. }
  1369. //---------------------------------------------------------------------------
  1370. DWORD bgrTorgb (DWORD frontRGB)
  1371. {
  1372. DWORD tmp;
  1373. tmp = (((0x00ff0000) & frontRGB)>>16) + ((0x0000ff00) & frontRGB) + (((0x000000ff) & frontRGB)<<16);
  1374. return(tmp);
  1375. }
  1376. //-----------------------------------------------------------------------------
  1377. void Mech3DAppearance::setPaintScheme (DWORD mcRed, DWORD mcGreen, DWORD mcBlue)
  1378. {
  1379. #ifdef BGR
  1380. // These come into here bgr instead of RGB. CONVERT!
  1381. psRed = bgrTorgb(mcRed);
  1382. psBlue = bgrTorgb(mcBlue);
  1383. psGreen = bgrTorgb(mcGreen);
  1384. #else /*BGR*/
  1385. psRed = mcRed;
  1386. psBlue = mcBlue;
  1387. psGreen = mcGreen;
  1388. #endif /*BGR*/
  1389. setPaintScheme();
  1390. }
  1391. //-----------------------------------------------------------------------------
  1392. void Mech3DAppearance::getPaintScheme( DWORD& red, DWORD& green, DWORD& blue )
  1393. {
  1394. #ifdef BGR
  1395. red = bgrTorgb(psRed);
  1396. blue = bgrTorgb(psBlue);
  1397. green = bgrTorgb(psGreen);
  1398. #else /*BGR*/
  1399. red = psRed;
  1400. blue = psBlue;
  1401. green = psGreen;
  1402. #endif /*BGR*/
  1403. }
  1404. //-----------------------------------------------------------------------------
  1405. void Mech3DAppearance::resetPaintScheme (DWORD red, DWORD green, DWORD blue)
  1406. {
  1407. //---------------------------------------------------------------------------------
  1408. // Simple really. Toss the current texture, reload the RGB and reapply the colors
  1409. DWORD gosHandle = mcTextureManager->get_gosTextureHandle(localTextureHandle);
  1410. mcTextureManager->removeTexture(gosHandle);
  1411. //-------------------------------------------------
  1412. // Load the texture and store its handle.
  1413. char txmName[1024];
  1414. mechShape->GetTextureName(0,txmName,256);
  1415. char texturePath[1024];
  1416. sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
  1417. FullPathFileName textureName;
  1418. textureName.init(texturePath,txmName,"");
  1419. //DWORD paintInstance = (red << 16) + (green << 8) + (blue);
  1420. /* The texture manager asks for a unique 32bit identifier for every texture instance.
  1421. However, it requires 72 bits to fully describe a mech texture (the base color (stored in
  1422. the variable "red"), highlight color1 (blue), and highlight color2 (green), each of which
  1423. is a 24bit number made up of 8bit r, g, and b components). Instead of creating a
  1424. mapping between the mech textures used (probably less than 2^32 of them) and
  1425. 32bit identifiers, for the sake of expediency I'm just taking the 3 most significant bits of
  1426. the 9 rgb components to make a 27 bit identifier. This means that two mech textures
  1427. that are close in color (i.e. all of the 3 most significant bits of the 9 rgb components are
  1428. the same) will be treated as the same texture, which is not necessarily a bad thing in
  1429. our case. LOD is never needed because if the texture is different, its NAME will be different!!*/
  1430. DWORD ccbase = ((red >> 5) & 7) + (((red >> 13) & 7) << 3) + (((red >> 21) & 7) << 6);
  1431. DWORD cchighlight1 = ((green >> 5) & 7) + (((green >> 13) & 7) << 3) + (((green >> 21) & 7) << 6);
  1432. DWORD cchighlight2 = ((blue >> 5) & 7) + (((blue >> 13) & 7) << 3) + (((blue >> 21) & 7) << 6);
  1433. DWORD paintInstance = (ccbase << 18) + (cchighlight1 << 9) + (cchighlight2);
  1434. if (fileExists(textureName))
  1435. {
  1436. DWORD textureInstanceAlreadyExists = mcTextureManager->textureInstanceExists(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink,paintInstance);
  1437. if (!textureInstanceAlreadyExists)
  1438. localTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink,paintInstance);
  1439. else
  1440. localTextureHandle = textureInstanceAlreadyExists;
  1441. mechShape->SetTextureHandle(0,localTextureHandle);
  1442. mechShape->SetTextureAlpha(0,false);
  1443. if (leftArm)
  1444. {
  1445. leftArm->SetTextureHandle(0,localTextureHandle);
  1446. leftArm->SetTextureAlpha(0,false);
  1447. }
  1448. if (rightArm)
  1449. {
  1450. rightArm->SetTextureHandle(0,localTextureHandle);
  1451. rightArm->SetTextureAlpha(0,false);
  1452. }
  1453. if (textureInstanceAlreadyExists)
  1454. {
  1455. /* In this case, the texture returned should already have the paint scheme
  1456. applied. */
  1457. //Still need to store psRed/psGreen/psBlue!!!!
  1458. psRed = red;
  1459. psGreen = green;
  1460. psBlue = blue;
  1461. return;
  1462. }
  1463. }
  1464. else
  1465. {
  1466. //PAUSE(("Warning: %s texture name not found",textureName));
  1467. mechShape->SetTextureHandle(0,0xffffffff);
  1468. if (leftArm)
  1469. leftArm->SetTextureHandle(0,0xffffffff);
  1470. if (rightArm)
  1471. rightArm->SetTextureHandle(0,0xffffffff);
  1472. }
  1473. setPaintScheme(red,green,blue);
  1474. }
  1475. //-----------------------------------------------------------------------------
  1476. void Mech3DAppearance::setObjectParameters (Stuff::Vector3D &pos, float Rot, long sel, long team, long homeRelations)
  1477. {
  1478. movedThisFrame = false;
  1479. if ((rotation != Rot) || (pos != position))
  1480. movedThisFrame = true;
  1481. if ((currentGestureId == 23) || (currentGestureId == 24) || (currentGestureId == 21) || (currentGestureId == 22) ||
  1482. (currentGestureId == 14) || (currentGestureId == 15))
  1483. {
  1484. }
  1485. else
  1486. {
  1487. rotation = Rot;
  1488. if (rotation > 180)
  1489. rotation -= 360;
  1490. if (rotation < -180)
  1491. rotation += 360;
  1492. }
  1493. position = pos;
  1494. selected = sel;
  1495. teamId = team;
  1496. homeTeamRelationship = homeRelations;
  1497. }
  1498. //-----------------------------------------------------------------------------
  1499. void Mech3DAppearance::setMoverParameters (float turretRot, float lArmRot, float rArmRot, bool isAirborne)
  1500. {
  1501. isHelicopter = isAirborne;
  1502. if ((currentGestureId == 23) || (currentGestureId == 24) || (currentGestureId == 21) || (currentGestureId == 22) ||
  1503. (currentGestureId == 14) || (currentGestureId == 15))
  1504. {
  1505. }
  1506. else
  1507. {
  1508. torsoRotation = turretRot;
  1509. leftArmRotation = lArmRot;
  1510. rightArmRotation = rArmRot;
  1511. if (torsoRotation > 180)
  1512. torsoRotation -= 360;
  1513. if (torsoRotation < -180)
  1514. torsoRotation += 360;
  1515. }
  1516. }
  1517. //-----------------------------------------------------------------------------
  1518. void Mech3DAppearance::updateFootprints (void)
  1519. {
  1520. }
  1521. //-----------------------------------------------------------------------------
  1522. void Mech3DAppearance::debugUpdate (long whichOne)
  1523. {
  1524. if (!inDebugMoveMode)
  1525. return;
  1526. //----------------------------------------
  1527. // Adjust mechDebugAngle based on Input
  1528. if (userInput->getKeyDown(KEY_LEFT) && userInput->ctrl())
  1529. {
  1530. mechDebugAngle[whichOne] += 11.25;
  1531. if (mechDebugAngle[whichOne] > 180.0)
  1532. mechDebugAngle[whichOne] -= 360;
  1533. }
  1534. if (userInput->getKeyDown(KEY_RIGHT) && userInput->ctrl())
  1535. {
  1536. mechDebugAngle[whichOne] -= 11.25;
  1537. if (mechDebugAngle[whichOne] < -180.0)
  1538. mechDebugAngle[whichOne] += 360.0;
  1539. }
  1540. //----------------------------------------
  1541. // Adjust torsoDebugAngle based on Input
  1542. if (userInput->getKeyDown(KEY_UP) && userInput->ctrl())
  1543. {
  1544. torsoDebugAngle[whichOne] += 11.25;
  1545. if (torsoDebugAngle[whichOne] > 180.0)
  1546. torsoDebugAngle[whichOne] -= 360;
  1547. }
  1548. if (userInput->getKeyDown(KEY_DOWN) && userInput->ctrl())
  1549. {
  1550. torsoDebugAngle[whichOne] -= 11.25;
  1551. if (torsoDebugAngle[whichOne] < -180.0)
  1552. torsoDebugAngle[whichOne] += 360.0;
  1553. }
  1554. //----------------------------------------
  1555. // Adjust GestureGoal based on Input
  1556. if (userInput->getKeyDown(KEY_0) && userInput->ctrl())
  1557. {
  1558. setGestureGoal(0); //PARK
  1559. }
  1560. if (userInput->getKeyDown(KEY_1) && userInput->ctrl())
  1561. {
  1562. setGestureGoal(1); //STAND
  1563. }
  1564. if (userInput->getKeyDown(KEY_2) && userInput->ctrl())
  1565. {
  1566. setGestureGoal(2); //WALK
  1567. }
  1568. if (userInput->getKeyDown(KEY_3) && userInput->ctrl())
  1569. {
  1570. setGestureGoal(3); //RUN
  1571. }
  1572. if (userInput->getKeyDown(KEY_4) && userInput->ctrl())
  1573. {
  1574. setGestureGoal(4); //REVERSE
  1575. }
  1576. if (userInput->getKeyDown(KEY_5) && userInput->ctrl())
  1577. {
  1578. setGestureGoal(5); //LIMP
  1579. }
  1580. if (userInput->getKeyDown(KEY_6) && userInput->ctrl())
  1581. {
  1582. setGestureGoal(6); //JUMP
  1583. }
  1584. if (userInput->getKeyDown(KEY_7) && userInput->ctrl())
  1585. {
  1586. setGestureGoal(7); //FALL FORWARD
  1587. }
  1588. if (userInput->getKeyDown(KEY_8) && userInput->ctrl())
  1589. {
  1590. setGestureGoal(8); //FALL BACKWARD
  1591. }
  1592. //------------------------------------------------------------------
  1593. // Adjust position based on mech Velocity which is based on gesture
  1594. Stuff::Vector3D velocity;
  1595. velocity.x = 0.7071f;
  1596. velocity.z = 0.0;
  1597. velocity.y = -0.7071f;
  1598. Rotate(velocity,-mechDebugAngle[whichOne]);
  1599. float velMag = getVelocityMagnitude();
  1600. //-----------------------------------------
  1601. // Take slope being walked on into account.
  1602. // Use for ground vehicles for sure.
  1603. /*
  1604. Stuff::Vector3D currentNormal = land->getTerrainNormal(debugMechActorPosition);
  1605. float angle = angle_from(velocity,currentNormal);
  1606. if (angle != 90.0)
  1607. {
  1608. float hillFactor = cos(angle * DEGREES_TO_RADS) * velMag;
  1609. velMag += hillFactor;
  1610. }
  1611. */
  1612. velocity *= velMag * worldUnitsPerMeter;
  1613. velocity *= frameLength;
  1614. debugMechActorPosition[whichOne] += velocity;
  1615. debugMechActorPosition[whichOne].z = land->getTerrainElevation(debugMechActorPosition[whichOne]);
  1616. setObjectParameters(debugMechActorPosition[whichOne],mechDebugAngle[whichOne],true,0,0);
  1617. update();
  1618. recalcBounds();
  1619. updateFootprints();
  1620. }
  1621. //-----------------------------------------------------------------------------
  1622. bool Mech3DAppearance::isMouseOver (float px, float py)
  1623. {
  1624. if (inView)
  1625. {
  1626. if ((px <= lowerRight.x) && (py <= lowerRight.y) &&
  1627. (px >= upperLeft.x) &&
  1628. (py >= upperLeft.y))
  1629. {
  1630. return inView;
  1631. }
  1632. else
  1633. {
  1634. return FALSE;
  1635. }
  1636. }
  1637. return(inView);
  1638. }
  1639. //-----------------------------------------------------------------------------
  1640. bool Mech3DAppearance::recalcBounds (void)
  1641. {
  1642. Stuff::Vector4D tempPos;
  1643. bool wasInView = inView;
  1644. inView = false;
  1645. float eyeDistance = 0.0f;
  1646. if (eye)
  1647. {
  1648. //ALWAYS need to do this or select is YAYA
  1649. eye->projectZ(position,screenPos);
  1650. //--------------------------------------------------
  1651. // First, if we are using perspective, figure out
  1652. // if object too far from camera. Far Clip Plane.
  1653. if (eye->usePerspective)
  1654. {
  1655. Stuff::Point3D Distance;
  1656. Stuff::Point3D objPosition;
  1657. Stuff::Point3D eyePosition(eye->getCameraOrigin());
  1658. objPosition.x = -position.x;
  1659. objPosition.y = position.z;
  1660. objPosition.z = position.y;
  1661. Distance.Subtract(objPosition,eyePosition);
  1662. eyeDistance = Distance.GetApproximateLength();
  1663. if (eyeDistance > Camera::MaxClipDistance)
  1664. {
  1665. hazeFactor = 1.0f;
  1666. inView = false;
  1667. }
  1668. else if (eyeDistance > Camera::MinHazeDistance)
  1669. {
  1670. Camera::HazeFactor = (eyeDistance - Camera::MinHazeDistance) * Camera::DistanceFactor;
  1671. inView = true;
  1672. }
  1673. else
  1674. {
  1675. Camera::HazeFactor = 0.0f;
  1676. inView = true;
  1677. }
  1678. //-----------------------------------------------------------------
  1679. // If inside farClip plane, check if behind camera.
  1680. // Find angle between lookVector of Camera and vector from camPos
  1681. // to Target. If angle is less then halfFOV, object is visible.
  1682. if (inView)
  1683. {
  1684. Stuff::Vector3D Distance;
  1685. Stuff::Point3D objPosition;
  1686. Stuff::Point3D eyePosition(eye->getCameraOrigin());
  1687. objPosition.x = -position.x;
  1688. objPosition.y = position.z;
  1689. objPosition.z = position.y;
  1690. Distance.Subtract(objPosition,eyePosition);
  1691. Distance.Normalize(Distance);
  1692. float cosine = Distance * eye->getLookVector();
  1693. if (cosine > eye->cosHalfFOV)
  1694. inView = true;
  1695. else
  1696. inView = false;
  1697. }
  1698. }
  1699. else
  1700. {
  1701. Camera::HazeFactor = 0.0f;
  1702. inView = true;
  1703. }
  1704. if (inView)
  1705. {
  1706. if (reloadBounds)
  1707. mechType->reinit();
  1708. //mechType->boundsLowerRightY = (OBBRadius * eye->getTiltFactor() * 2.0f);
  1709. //-------------------------------------------------------------------------
  1710. // do a rough check if on screen. If no where near, do NOT do the below.
  1711. // Mighty mighty slow!!!!
  1712. // Use the original check done before all this 3D madness. Dig out sourceSafe tomorrow!
  1713. tempPos = screenPos;
  1714. upperLeft.x = tempPos.x;
  1715. upperLeft.y = tempPos.y;
  1716. lowerRight.x = tempPos.x;
  1717. lowerRight.y = tempPos.y;
  1718. upperLeft.x += (mechType->boundsUpperLeftX * eye->getScaleFactor());
  1719. upperLeft.y += (mechType->boundsUpperLeftY * eye->getScaleFactor());
  1720. lowerRight.x += (mechType->boundsLowerRightX * eye->getScaleFactor());
  1721. lowerRight.y += (mechType->boundsLowerRightY * eye->getScaleFactor());
  1722. if ((lowerRight.x >= 0) && (lowerRight.y >= 0) &&
  1723. (upperLeft.x <= eye->getScreenResX()) &&
  1724. (upperLeft.y <= eye->getScreenResY()))
  1725. {
  1726. //We are on screen. Figure out selection box.
  1727. Stuff::Vector3D boxCoords[8];
  1728. Stuff::Vector4D bcsp[8];
  1729. if (rootNodeIndex == -1)
  1730. rootNodeIndex = mechShape->GetNodeNameId("joint_root");
  1731. //Gotta let the NodeIdPosition know that its matrix is valid or invalid so this actually does clip mech to screen!!
  1732. // Leave the old one in place until we are inView again!
  1733. // Should fix flickering on screen edge? It does. Must let jump flicker or he never comes down.
  1734. inView = wasInView;
  1735. if (inView || (currentGestureId == 20))
  1736. baseRootNodeDifference = (getNodeIdPosition(rootNodeIndex).z - position.z) - baseRootNodeHeight;
  1737. if (inView && isHelicopter)
  1738. baseRootNodeDifference -= HELICOPTER_FACTOR;
  1739. inView = true;
  1740. if (InEditor)
  1741. {
  1742. if (isHelicopter)
  1743. baseRootNodeDifference = 0.0f - HELICOPTER_FACTOR;
  1744. else
  1745. baseRootNodeDifference = 0.0f;
  1746. }
  1747. boxCoords[0].x = position.x + mechType->typeUpperLeft.x;
  1748. boxCoords[0].y = position.y + mechType->typeUpperLeft.y;
  1749. boxCoords[0].z = position.z + mechType->typeUpperLeft.z + baseRootNodeDifference;
  1750. boxCoords[1].x = position.x + mechType->typeUpperLeft.x;
  1751. boxCoords[1].y = position.y + mechType->typeLowerRight.y;
  1752. boxCoords[1].z = position.z + mechType->typeUpperLeft.z + baseRootNodeDifference;
  1753. boxCoords[2].x = position.x + mechType->typeLowerRight.x;
  1754. boxCoords[2].y = position.y + mechType->typeUpperLeft.y;
  1755. boxCoords[2].z = position.z + mechType->typeUpperLeft.z + baseRootNodeDifference;
  1756. boxCoords[3].x = position.x + mechType->typeLowerRight.x;
  1757. boxCoords[3].y = position.y + mechType->typeLowerRight.y;
  1758. boxCoords[3].z = position.z + mechType->typeUpperLeft.z + baseRootNodeDifference;
  1759. boxCoords[4].x = position.x + mechType->typeLowerRight.x;
  1760. boxCoords[4].y = position.y + mechType->typeLowerRight.y;
  1761. boxCoords[4].z = position.z + mechType->typeLowerRight.z + baseRootNodeDifference;
  1762. boxCoords[5].x = position.x + mechType->typeLowerRight.x;
  1763. boxCoords[5].y = position.y + mechType->typeUpperLeft.y;
  1764. boxCoords[5].z = position.z + mechType->typeLowerRight.z + baseRootNodeDifference;
  1765. boxCoords[6].x = position.x + mechType->typeUpperLeft.x;
  1766. boxCoords[6].y = position.y + mechType->typeLowerRight.y;
  1767. boxCoords[6].z = position.z + mechType->typeLowerRight.z + baseRootNodeDifference;
  1768. boxCoords[7].x = position.x + mechType->typeUpperLeft.x;
  1769. boxCoords[7].y = position.y + mechType->typeUpperLeft.y;
  1770. boxCoords[7].z = position.z + mechType->typeLowerRight.z + baseRootNodeDifference;
  1771. float maxX = 0.0f, maxY = 0.0f;
  1772. float minX = 0.0f, minY = 0.0f;
  1773. for (long i=0;i<8;i++)
  1774. {
  1775. eye->projectZ(boxCoords[i],bcsp[i]);
  1776. if (!i)
  1777. {
  1778. maxX = minX = bcsp[i].x;
  1779. maxY = minY = bcsp[i].y;
  1780. }
  1781. if (i)
  1782. {
  1783. if (bcsp[i].x > maxX)
  1784. maxX = bcsp[i].x;
  1785. if (bcsp[i].x < minX)
  1786. minX = bcsp[i].x;
  1787. if (bcsp[i].y > maxY)
  1788. maxY = bcsp[i].y;
  1789. if (bcsp[i].y < minY)
  1790. minY = bcsp[i].y;
  1791. }
  1792. }
  1793. upperLeft.x = minX;
  1794. upperLeft.y = minY;
  1795. lowerRight.x = maxX;
  1796. lowerRight.y = maxY;
  1797. if ((lowerRight.x >= 0) && (lowerRight.y >= 0) &&
  1798. (upperLeft.x <= eye->getScreenResX()) &&
  1799. (upperLeft.y <= eye->getScreenResY()))
  1800. {
  1801. inView = true;
  1802. if (status != OBJECT_STATUS_DESTROYED)
  1803. {
  1804. bool baseLOD = true;
  1805. DWORD selectLOD = 0;
  1806. if (useHighObjectDetail)
  1807. {
  1808. //-------------------------------------------------------------------------------
  1809. //Set LOD of Model here because we have the distance and we KNOW we can see it!
  1810. for (long i=1;i<MAX_LODS;i++)
  1811. {
  1812. if (mechType->mechShape[i] && mechType->mechShape[i]->GetNumShapes() && (eyeDistance > mechType->lodDistance[i]))
  1813. {
  1814. baseLOD = false;
  1815. selectLOD = i;
  1816. }
  1817. }
  1818. }
  1819. else
  1820. {
  1821. if (mechType->mechShape[1] && mechType->mechShape[1]->GetNumShapes())
  1822. {
  1823. baseLOD = false;
  1824. selectLOD = 1;
  1825. }
  1826. }
  1827. // we are at this LOD level.
  1828. if (selectLOD != currentLOD)
  1829. {
  1830. currentLOD = selectLOD;
  1831. BYTE alphaValue = mechShape->GetAlphaValue();
  1832. //mechShape->ClearAnimation(); //DO NOT do this with animating things!!
  1833. delete mechShape;
  1834. mechShape = NULL;
  1835. mechShape = mechType->mechShape[currentLOD]->CreateFrom();
  1836. mechShape->SetAlphaValue(alphaValue);
  1837. resetPaintScheme(psRed,psGreen,psBlue);
  1838. if (rightArmOff)
  1839. mechShape->StopUsing("joint_ruarm");
  1840. if (leftArmOff)
  1841. mechShape->StopUsing("joint_luarm");
  1842. }
  1843. if (currentLOD && baseLOD)
  1844. {
  1845. // we are at the Base LOD level.
  1846. currentLOD = 0;
  1847. BYTE alphaValue = mechShape->GetAlphaValue();
  1848. //treeShape->ClearAnimation();
  1849. delete mechShape;
  1850. mechShape = NULL;
  1851. mechShape = mechType->mechShape[currentLOD]->CreateFrom();
  1852. mechShape->SetAlphaValue(alphaValue);
  1853. //Automatically reloads texture and stores it.
  1854. resetPaintScheme(psRed,psGreen,psBlue);
  1855. if (rightArmOff)
  1856. mechShape->StopUsing("joint_ruarm");
  1857. if (leftArmOff)
  1858. mechShape->StopUsing("joint_luarm");
  1859. }
  1860. mechType->setAnimation(mechShape,currentGestureId);
  1861. }
  1862. }
  1863. else
  1864. {
  1865. inView = false; //Did alot of extra work checking this, but WHY draw and insult to injury?
  1866. }
  1867. }
  1868. else
  1869. {
  1870. inView = false;
  1871. }
  1872. }
  1873. }
  1874. return(inView);
  1875. }
  1876. //-----------------------------------------------------------------------------
  1877. long Mech3DAppearance::render (long depthFixup)
  1878. {
  1879. // Force textures to reload due to unique instance.
  1880. mechShape->SetTextureHandle(0,localTextureHandle);
  1881. if (rightArm)
  1882. rightArm->SetTextureHandle(0,localTextureHandle);
  1883. if (leftArm)
  1884. leftArm->SetTextureHandle(0,localTextureHandle);
  1885. if (inView)
  1886. {
  1887. if (visible)
  1888. {
  1889. long color = SD_BLUE;
  1890. unsigned long highLight = 0x007f7f7f;
  1891. if ((teamId > -1) && (teamId < 8)) {
  1892. static unsigned long highLightTable[3] = {0x00007f00, 0x0000007f, 0x007f0000};
  1893. static long colorTable[3] = {SB_GREEN | 0xff000000, SB_BLUE | 0xff000000, SB_RED | 0xff000000};
  1894. color = colorTable[homeTeamRelationship];
  1895. highLight = highLightTable[homeTeamRelationship];
  1896. }
  1897. if (selected & DRAW_COLORED && duration <= 0 )
  1898. {
  1899. mechShape->SetARGBHighLight(highLight);
  1900. }
  1901. else
  1902. {
  1903. mechShape->SetARGBHighLight(highlightColor);
  1904. }
  1905. Camera::HazeFactor = hazeFactor;
  1906. if (drawFlash)
  1907. {
  1908. mechShape->SetARGBHighLight(flashColor);
  1909. }
  1910. //---------------------------------------------
  1911. // Call Multi-shape render stuff here.
  1912. mechShape->Render(true);
  1913. if (selected & DRAW_BARS)
  1914. {
  1915. drawBars();
  1916. }
  1917. if ( selected & DRAW_BRACKETS )
  1918. {
  1919. drawSelectBrackets(color);
  1920. }
  1921. if ((objectNameId != -1) && (selected & DRAW_TEXT) && !sensorLevel )
  1922. {
  1923. drawBars();
  1924. if ( strlen( mechName ) )
  1925. {
  1926. drawTextHelp( mechName, color );
  1927. }
  1928. else
  1929. {
  1930. char tmpString[255];
  1931. cLoadString(objectNameId, tmpString, 254);
  1932. drawTextHelp(tmpString, color);
  1933. }
  1934. if ( strlen( pilotName ) )
  1935. {
  1936. drawPilotName( pilotName, color );
  1937. }
  1938. else if ( pilotNameID != -1 ) // only draw your own
  1939. {
  1940. char tmpPilotName[255];
  1941. cLoadString( pilotNameID, tmpPilotName, 254 );
  1942. drawPilotName( tmpPilotName, color );
  1943. }
  1944. }
  1945. //------------------------------------------------
  1946. // Render GOSFX
  1947. if (!InEditor)
  1948. {
  1949. gosFX::Effect::DrawInfo drawInfo;
  1950. drawInfo.m_clipper = theClipper;
  1951. MidLevelRenderer::MLRState mlrState;
  1952. mlrState.SetDitherOn();
  1953. mlrState.SetTextureCorrectionOn();
  1954. mlrState.SetZBufferCompareOn();
  1955. mlrState.SetZBufferWriteOn();
  1956. drawInfo.m_state = mlrState;
  1957. drawInfo.m_clippingFlags = 0x0;
  1958. if (!isWaking && useNonWeaponEffects)
  1959. {
  1960. for (long i=0;i<MAX_DUST_POOFS;i++)
  1961. {
  1962. if (rightFootPoofDraw[i] && rightDustPoofEffect[i] && rightDustPoofEffect[i]->IsExecuted())
  1963. {
  1964. Stuff::LinearMatrix4D shapeOrigin;
  1965. Stuff::LinearMatrix4D localToWorld;
  1966. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  1967. shapeOrigin.BuildTranslation(rFootPosition[i]);
  1968. drawInfo.m_parentToWorld = &shapeOrigin;
  1969. if (!MLRVertexLimitReached)
  1970. rightDustPoofEffect[i]->Draw(&drawInfo);
  1971. }
  1972. if (leftFootPoofDraw[i] && leftDustPoofEffect[i] && leftDustPoofEffect[i]->IsExecuted())
  1973. {
  1974. Stuff::LinearMatrix4D shapeOrigin;
  1975. Stuff::LinearMatrix4D localToWorld;
  1976. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  1977. shapeOrigin.BuildTranslation(lFootPosition[i]);
  1978. drawInfo.m_parentToWorld = &shapeOrigin;
  1979. if (!MLRVertexLimitReached)
  1980. leftDustPoofEffect[i]->Draw(&drawInfo);
  1981. }
  1982. }
  1983. }
  1984. if ((currentGestureId == GestureJump) && inJump && jumpJetEffect && jumpJetEffect->IsExecuted())
  1985. {
  1986. long jumpNodeId = mechType->numSmokeNodes + mechType->numWeaponNodes;
  1987. Stuff::Vector3D jumpNodePos = getNodePosition(jumpNodeId);
  1988. Stuff::Point3D actualPosition;
  1989. Stuff::LinearMatrix4D shapeOrigin;
  1990. Stuff::LinearMatrix4D localToWorld;
  1991. Stuff::LinearMatrix4D localResult;
  1992. actualPosition.x = -jumpNodePos.x;
  1993. actualPosition.y = jumpNodePos.z;
  1994. actualPosition.z = jumpNodePos.y;
  1995. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  1996. shapeOrigin.BuildTranslation(actualPosition);
  1997. Stuff::UnitQuaternion effectRot;
  1998. effectRot = Stuff::EulerAngles(JUMP_PITCH * DEGREES_TO_RADS,rotation * DEGREES_TO_RADS,0.0f);
  1999. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  2000. localResult.Multiply(localToWorld,shapeOrigin);
  2001. drawInfo.m_parentToWorld = &localResult;
  2002. if (!MLRVertexLimitReached)
  2003. jumpJetEffect->Draw(&drawInfo);
  2004. }
  2005. //----------------------------------------------------------------
  2006. // Arm Blown FX
  2007. if (leftShoulderBoom)
  2008. {
  2009. Stuff::LinearMatrix4D shapeOrigin;
  2010. Stuff::LinearMatrix4D localToWorld;
  2011. Stuff::LinearMatrix4D localResult;
  2012. if (leftArmNodeIndex == -1)
  2013. leftArmNodeIndex = mechShape->GetNodeNameId("joint_luarm");
  2014. Stuff::Vector3D leftNodePos = getNodeIdPosition(leftArmNodeIndex);
  2015. leftShoulderPos.x = -leftNodePos.x;
  2016. leftShoulderPos.y = leftNodePos.z;
  2017. leftShoulderPos.z = leftNodePos.y;
  2018. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2019. shapeOrigin.BuildTranslation(leftShoulderPos);
  2020. Stuff::UnitQuaternion effectRot;
  2021. effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
  2022. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  2023. localResult.Multiply(localToWorld,shapeOrigin);
  2024. drawInfo.m_parentToWorld = &localResult;
  2025. if (!MLRVertexLimitReached)
  2026. leftShoulderBoom->Draw(&drawInfo);
  2027. }
  2028. if (rightShoulderBoom)
  2029. {
  2030. Stuff::LinearMatrix4D shapeOrigin;
  2031. Stuff::LinearMatrix4D localToWorld;
  2032. Stuff::LinearMatrix4D localResult;
  2033. if (rightArmNodeIndex == -1)
  2034. rightArmNodeIndex = mechShape->GetNodeNameId("joint_ruarm");
  2035. Stuff::Vector3D rightNodePos = getNodeIdPosition(rightArmNodeIndex);
  2036. rightShoulderPos.x = -rightNodePos.x;
  2037. rightShoulderPos.y = rightNodePos.z;
  2038. rightShoulderPos.z = rightNodePos.y;
  2039. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2040. shapeOrigin.BuildTranslation(rightShoulderPos);
  2041. Stuff::UnitQuaternion effectRot;
  2042. effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
  2043. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  2044. localResult.Multiply(localToWorld,shapeOrigin);
  2045. drawInfo.m_parentToWorld = &localResult;
  2046. if (!MLRVertexLimitReached)
  2047. rightShoulderBoom->Draw(&drawInfo);
  2048. }
  2049. //------------------------------------------------
  2050. // All other FXs
  2051. if (isSmoking != -1)
  2052. {
  2053. Stuff::LinearMatrix4D shapeOrigin;
  2054. Stuff::LinearMatrix4D localToWorld;
  2055. Stuff::Vector3D smokeNodePos = getNodePosition(0);
  2056. Stuff::Point3D smokePos;
  2057. smokePos.x = -smokeNodePos.x;
  2058. smokePos.y = smokeNodePos.z;
  2059. smokePos.z = smokeNodePos.y;
  2060. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2061. shapeOrigin.BuildTranslation(smokePos);
  2062. drawInfo.m_parentToWorld = &shapeOrigin;
  2063. if (isSmoking > 0)
  2064. {
  2065. //Loops until told to stop.
  2066. if (!MLRVertexLimitReached)
  2067. criticalSmoke->Draw(&drawInfo);
  2068. }
  2069. else
  2070. {
  2071. if (!MLRVertexLimitReached)
  2072. smokeEffect->Draw(&drawInfo);
  2073. }
  2074. }
  2075. if (waterWake && isWaking && (currentGestureId != 20)) //Do NOT draw wake if we are jumping. keep calcing it, though!
  2076. {
  2077. Stuff::LinearMatrix4D shapeOrigin;
  2078. Stuff::LinearMatrix4D localToWorld;
  2079. Stuff::LinearMatrix4D localResult;
  2080. Stuff::Point3D wakePos;
  2081. wakePos.x = -position.x;
  2082. wakePos.y = Terrain::waterElevation;
  2083. wakePos.z = position.y;
  2084. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2085. shapeOrigin.BuildTranslation(wakePos);
  2086. Stuff::UnitQuaternion effectRot;
  2087. effectRot = Stuff::EulerAngles(90.0f * DEGREES_TO_RADS,rotation * DEGREES_TO_RADS,0.0f);
  2088. if (!inReverse)
  2089. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  2090. else
  2091. localToWorld.Multiply(gosFX::Effect_Into_Motion,effectRot);
  2092. localResult.Multiply(localToWorld,shapeOrigin);
  2093. drawInfo.m_parentToWorld = &localResult;
  2094. if (!MLRVertexLimitReached)
  2095. waterWake->Draw(&drawInfo);
  2096. }
  2097. if (isDusting && helicopterDustCloud)
  2098. {
  2099. Stuff::LinearMatrix4D shapeOrigin;
  2100. Stuff::LinearMatrix4D localToWorld;
  2101. Stuff::LinearMatrix4D localResult;
  2102. Stuff::Point3D wakePos;
  2103. wakePos.x = -position.x;
  2104. wakePos.y = position.z;
  2105. wakePos.z = position.y;
  2106. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2107. shapeOrigin.BuildTranslation(wakePos);
  2108. /*
  2109. Stuff::UnitQuaternion effectRot;
  2110. effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
  2111. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  2112. localResult.Multiply(localToWorld,shapeOrigin);
  2113. */
  2114. drawInfo.m_parentToWorld = &shapeOrigin;
  2115. if (!MLRVertexLimitReached)
  2116. helicopterDustCloud->Draw(&drawInfo);
  2117. }
  2118. }
  2119. #ifdef DRAW_BOX
  2120. //---------------------------------------------------------
  2121. // Render the Bounding Box to see if it is OK.
  2122. Stuff::Vector3D nodeCenter = mechShape->GetRootNodeCenter();
  2123. Stuff::Vector3D boxCoords[8];
  2124. boxCoords[0].x = position.x + mechType->typeUpperLeft.x;
  2125. boxCoords[0].y = position.y + mechType->typeUpperLeft.y;
  2126. boxCoords[0].z = position.z + mechType->typeUpperLeft.z;
  2127. boxCoords[1].x = position.x + mechType->typeUpperLeft.x;
  2128. boxCoords[1].y = position.y + mechType->typeLowerRight.y;
  2129. boxCoords[1].z = position.z + mechType->typeUpperLeft.z;
  2130. boxCoords[2].x = position.x + mechType->typeLowerRight.x;
  2131. boxCoords[2].y = position.y + mechType->typeUpperLeft.y;
  2132. boxCoords[2].z = position.z + mechType->typeUpperLeft.z;
  2133. boxCoords[3].x = position.x + mechType->typeLowerRight.x;
  2134. boxCoords[3].y = position.y + mechType->typeLowerRight.y;
  2135. boxCoords[3].z = position.z + mechType->typeUpperLeft.z;
  2136. boxCoords[4].x = position.x + mechType->typeLowerRight.x;
  2137. boxCoords[4].y = position.y + mechType->typeLowerRight.y;
  2138. boxCoords[4].z = position.z + mechType->typeLowerRight.z;
  2139. boxCoords[5].x = position.x + mechType->typeLowerRight.x;
  2140. boxCoords[5].y = position.y + mechType->typeUpperLeft.y;
  2141. boxCoords[5].z = position.z + mechType->typeLowerRight.z;
  2142. boxCoords[6].x = position.x + mechType->typeUpperLeft.x;
  2143. boxCoords[6].y = position.y + mechType->typeLowerRight.y;
  2144. boxCoords[6].z = position.z + mechType->typeLowerRight.z;
  2145. boxCoords[7].x = position.x + mechType->typeUpperLeft.x;
  2146. boxCoords[7].y = position.y + mechType->typeUpperLeft.y;
  2147. boxCoords[7].z = position.z + mechType->typeLowerRight.z;
  2148. Stuff::Vector4D screenPos[8];
  2149. for (long i=0;i<8;i++)
  2150. {
  2151. eye->projectZ(boxCoords[i],screenPos[i]);
  2152. }
  2153. {
  2154. LineElement newElement(screenPos[0],screenPos[1],XP_WHITE,NULL,-1);
  2155. newElement.draw();
  2156. }
  2157. {
  2158. LineElement newElement(screenPos[0],screenPos[4],XP_WHITE,NULL,-1);
  2159. newElement.draw();
  2160. }
  2161. {
  2162. LineElement newElement(screenPos[0],screenPos[3],XP_WHITE,NULL,-1);
  2163. newElement.draw();
  2164. }
  2165. {
  2166. LineElement newElement(screenPos[5],screenPos[4],XP_WHITE,NULL,-1);
  2167. newElement.draw();
  2168. }
  2169. {
  2170. LineElement newElement(screenPos[5],screenPos[6],XP_WHITE,NULL,-1);
  2171. newElement.draw();
  2172. }
  2173. {
  2174. LineElement newElement(screenPos[5],screenPos[3],XP_WHITE,NULL,-1);
  2175. newElement.draw();
  2176. }
  2177. {
  2178. LineElement newElement(screenPos[2],screenPos[3],XP_WHITE,NULL,-1);
  2179. newElement.draw();
  2180. }
  2181. {
  2182. LineElement newElement(screenPos[2],screenPos[6],XP_WHITE,NULL,-1);
  2183. newElement.draw();
  2184. }
  2185. {
  2186. LineElement newElement(screenPos[2],screenPos[1],XP_WHITE,NULL,-1);
  2187. newElement.draw();
  2188. }
  2189. {
  2190. LineElement newElement(screenPos[7],screenPos[1],XP_WHITE,NULL,-1);
  2191. newElement.draw();
  2192. }
  2193. {
  2194. LineElement newElement(screenPos[7],screenPos[6],XP_WHITE,NULL,-1);
  2195. newElement.draw();
  2196. }
  2197. {
  2198. LineElement newElement(screenPos[7],screenPos[4],XP_WHITE,NULL,-1);
  2199. newElement.draw();
  2200. }
  2201. #endif
  2202. }
  2203. if ((sensorLevel > 0) && (sensorLevel < 5))
  2204. {
  2205. //---------------------------------------
  2206. // Draw Sensor Contact here.
  2207. if (sensorLevel > 1)
  2208. {
  2209. sensorSquareShape->Render();
  2210. }
  2211. else
  2212. {
  2213. sensorTriangleShape->Render();
  2214. }
  2215. }
  2216. }
  2217. if (rightArmOff && rightArm && rightArmInView)
  2218. {
  2219. Camera::HazeFactor = rightArmHazeFactor;
  2220. rightArm->Render(true);
  2221. if (rightArmSmoke)
  2222. {
  2223. gosFX::Effect::DrawInfo drawInfo;
  2224. drawInfo.m_clipper = theClipper;
  2225. MidLevelRenderer::MLRState mlrState;
  2226. mlrState.SetDitherOn();
  2227. mlrState.SetTextureCorrectionOn();
  2228. mlrState.SetZBufferCompareOn();
  2229. mlrState.SetZBufferWriteOn();
  2230. drawInfo.m_state = mlrState;
  2231. drawInfo.m_clippingFlags = 0x0;
  2232. Stuff::LinearMatrix4D shapeOrigin;
  2233. Stuff::LinearMatrix4D localToWorld;
  2234. Stuff::LinearMatrix4D localResult;
  2235. rightShoulderPos.x = -rightArmPos.x;
  2236. rightShoulderPos.y = rightArmPos.z;
  2237. rightShoulderPos.z = rightArmPos.y;
  2238. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2239. shapeOrigin.BuildTranslation(rightShoulderPos);
  2240. Stuff::UnitQuaternion effectRot;
  2241. effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
  2242. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  2243. localResult.Multiply(localToWorld,shapeOrigin);
  2244. drawInfo.m_parentToWorld = &localResult;
  2245. if (!MLRVertexLimitReached)
  2246. rightArmSmoke->Draw(&drawInfo);
  2247. }
  2248. }
  2249. if (leftArmOff && leftArm && leftArmInView)
  2250. {
  2251. Camera::HazeFactor = leftArmHazeFactor;
  2252. leftArm->Render(true);
  2253. if (leftArmSmoke)
  2254. {
  2255. gosFX::Effect::DrawInfo drawInfo;
  2256. drawInfo.m_clipper = theClipper;
  2257. MidLevelRenderer::MLRState mlrState;
  2258. mlrState.SetDitherOn();
  2259. mlrState.SetTextureCorrectionOn();
  2260. mlrState.SetZBufferCompareOn();
  2261. mlrState.SetZBufferWriteOn();
  2262. drawInfo.m_state = mlrState;
  2263. drawInfo.m_clippingFlags = 0x0;
  2264. Stuff::LinearMatrix4D shapeOrigin;
  2265. Stuff::LinearMatrix4D localToWorld;
  2266. Stuff::LinearMatrix4D localResult;
  2267. leftShoulderPos.x = -leftArmPos.x;
  2268. leftShoulderPos.y = leftArmPos.z;
  2269. leftShoulderPos.z = leftArmPos.y;
  2270. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2271. shapeOrigin.BuildTranslation(leftShoulderPos);
  2272. Stuff::UnitQuaternion effectRot;
  2273. effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
  2274. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  2275. localResult.Multiply(localToWorld,shapeOrigin);
  2276. drawInfo.m_parentToWorld = &localResult;
  2277. if (!MLRVertexLimitReached)
  2278. leftArmSmoke->Draw(&drawInfo);
  2279. }
  2280. }
  2281. return NO_ERR;
  2282. }
  2283. //-----------------------------------------------------------------------------
  2284. long Mech3DAppearance::renderShadows (void)
  2285. {
  2286. mechShape->SetTextureHandle(0,localTextureHandle);
  2287. if (inView && visible)
  2288. {
  2289. //---------------------------------------------
  2290. // Call Multi-shape render stuff here.
  2291. // DONT RENDER UNTIL FINAL MECH DATA FROM MR CHOI
  2292. //---------------------------------------------
  2293. // Call Multi-shape render stuff here.
  2294. if (mechShadowShape)
  2295. mechShadowShape->RenderShadows(true);
  2296. else
  2297. mechShape->RenderShadows(true);
  2298. }
  2299. return(NO_ERR);
  2300. }
  2301. bool oneMechPlease = false;
  2302. #ifdef LAB_ONLY
  2303. __int64 MCTimeAnimationCalc = 0;
  2304. __int64 x;
  2305. #endif
  2306. //-----------------------------------------------------------------------------
  2307. void Mech3DAppearance::setObjStatus (long oStatus)
  2308. {
  2309. if ( (status != oStatus) && (!InEditor))
  2310. {
  2311. if (oStatus == OBJECT_STATUS_DESTROYED)
  2312. {
  2313. if (currentGestureId == 23)
  2314. {
  2315. if (mechType->mechForwardDmgShape)
  2316. {
  2317. mechShape->ClearAnimation();
  2318. delete mechShape;
  2319. mechShape = NULL;
  2320. mechShape = mechType->mechForwardDmgShape->CreateFrom();
  2321. }
  2322. }
  2323. else if (currentGestureId == 24)
  2324. {
  2325. if (mechType->mechBackwardDmgShape)
  2326. {
  2327. mechShape->ClearAnimation();
  2328. delete mechShape;
  2329. mechShape = NULL;
  2330. mechShape = mechType->mechBackwardDmgShape->CreateFrom();
  2331. }
  2332. }
  2333. currentLOD = 0;
  2334. //-------------------------------------------------
  2335. // Load the texture and store its handle.
  2336. for (long i=0;i<mechShape->GetNumTextures();i++)
  2337. {
  2338. char txmName[1024];
  2339. mechShape->GetTextureName(i,txmName,256);
  2340. char texturePath[1024];
  2341. sprintf(texturePath,"%s%d\\",tglPath,ObjectTextureSize);
  2342. FullPathFileName textureName;
  2343. textureName.init(texturePath,txmName,"");
  2344. if (fileExists(textureName))
  2345. {
  2346. if (strnicmp(txmName,"a_",2) == 0)
  2347. {
  2348. DWORD gosTextureHandle = 0;
  2349. if (!i)
  2350. {
  2351. localTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink,true);
  2352. mechShape->SetTextureHandle(i,localTextureHandle);
  2353. mechShape->SetTextureAlpha(i,true);
  2354. }
  2355. else
  2356. {
  2357. gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Alpha,gosHint_DisableMipmap | gosHint_DontShrink);
  2358. mechShape->SetTextureHandle(i,gosTextureHandle);
  2359. mechShape->SetTextureAlpha(i,true);
  2360. }
  2361. }
  2362. else
  2363. {
  2364. DWORD gosTextureHandle = 0;
  2365. if (!i)
  2366. {
  2367. localTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink,true);
  2368. mechShape->SetTextureHandle(i,localTextureHandle);
  2369. mechShape->SetTextureAlpha(i,false);
  2370. }
  2371. else
  2372. {
  2373. gosTextureHandle = mcTextureManager->loadTexture(textureName,gos_Texture_Solid,gosHint_DisableMipmap | gosHint_DontShrink);
  2374. mechShape->SetTextureHandle(i,gosTextureHandle);
  2375. mechShape->SetTextureAlpha(i,false);
  2376. }
  2377. }
  2378. }
  2379. else
  2380. {
  2381. //PAUSE(("Warning: %s texture name not found",textureName));
  2382. mechShape->SetTextureHandle(i,0xffffffff);
  2383. }
  2384. }
  2385. }
  2386. if (status == OBJECT_STATUS_DESTROYED && oStatus == OBJECT_STATUS_NORMAL)
  2387. {
  2388. STOP(("Destroyed Mech just came back to life!!"));
  2389. }
  2390. }
  2391. status = oStatus;
  2392. }
  2393. //-----------------------------------------------------------------------------
  2394. void Mech3DAppearance::updateGeometry (void)
  2395. {
  2396. #ifdef LAB_ONLY
  2397. x=GetCycles();
  2398. #endif
  2399. //Always override with our local instance.
  2400. mechShape->SetTextureHandle(0,localTextureHandle);
  2401. if (rightArm)
  2402. rightArm->SetTextureHandle(0,localTextureHandle);
  2403. if (leftArm)
  2404. leftArm->SetTextureHandle(0,localTextureHandle);
  2405. if ((status == OBJECT_STATUS_DESTROYED) ||
  2406. (status == OBJECT_STATUS_DISABLED) ||
  2407. (status == OBJECT_STATUS_SHUTDOWN))
  2408. {
  2409. mechShape->SetLightsOut(true);
  2410. }
  2411. else
  2412. {
  2413. mechShape->SetLightsOut(false);
  2414. }
  2415. Stuff::Point3D xlatPosition;
  2416. xlatPosition.x = -position.x;
  2417. xlatPosition.y = position.z;
  2418. xlatPosition.z = position.y;
  2419. //Update flashing regardless of view!!!
  2420. if (duration > 0.0f)
  2421. {
  2422. duration -= frameLength;
  2423. currentFlash -= frameLength;
  2424. if (currentFlash < 0.0f)
  2425. {
  2426. drawFlash ^= true;
  2427. currentFlash = flashDuration;
  2428. }
  2429. }
  2430. else
  2431. {
  2432. drawFlash = false;
  2433. }
  2434. //if (visible)
  2435. {
  2436. //-------------------------------------------
  2437. // Does math necessary to draw mech.
  2438. Stuff::UnitQuaternion qRotation;
  2439. float yaw = rotation * DEGREES_TO_RADS;
  2440. qRotation = Stuff::EulerAngles(0.0f, yaw, 0.0f);
  2441. unsigned char lightr,lightg,lightb;
  2442. float lightIntensity = 1.0f;
  2443. if ( land )
  2444. lightIntensity = land->getTerrainLight(position);
  2445. lightr = eye->getLightRed(lightIntensity);
  2446. lightg = eye->getLightGreen(lightIntensity);
  2447. lightb = eye->getLightBlue(lightIntensity);
  2448. DWORD lightRGB = (lightr<<16) + (lightg<<8) + lightb;
  2449. eye->setLightColor(0,lightRGB);
  2450. eye->setLightIntensity(0,1.0);
  2451. DWORD fogRGB = 0xff<<24;
  2452. float fogStart = eye->fogStart;
  2453. float fogFull = eye->fogFull;
  2454. if (useFog && (xlatPosition.y < fogStart))
  2455. {
  2456. float fogFactor = fogStart - xlatPosition.y;
  2457. if (fogFactor < 0.0)
  2458. fogRGB = 0xff<<24;
  2459. else
  2460. {
  2461. fogFactor /= (fogStart - fogFull);
  2462. if (fogFactor <= 1.0)
  2463. {
  2464. fogFactor *= fogFactor;
  2465. fogFactor = 1.0 - fogFactor;
  2466. fogFactor *= 256.0;
  2467. }
  2468. else
  2469. {
  2470. fogFactor = 256.0;
  2471. }
  2472. unsigned char fogResult = fogFactor;
  2473. fogRGB = fogResult << 24;
  2474. }
  2475. }
  2476. else
  2477. {
  2478. fogRGB = 0xff<<24;
  2479. }
  2480. if (useFog)
  2481. mechShape->SetFogRGB(fogRGB);
  2482. else
  2483. mechShape->SetFogRGB(0xffffffff);
  2484. //-----------------------------------
  2485. //Test of Mech as Point Light Source
  2486. if (!pointLight && eye->isNight)
  2487. {
  2488. if (lightCircleNodeIndex == -1)
  2489. lightCircleNodeIndex = mechShape->GetNodeNameId("SLCircle_anubis");
  2490. Stuff::Vector3D lightPos = getNodeIdPosition(lightCircleNodeIndex);
  2491. if (lightPos != position)
  2492. {
  2493. pointLight = (TG_LightPtr)malloc(sizeof(TG_Light));
  2494. pointLight->init(TG_LIGHT_SPOT);
  2495. lightId = eye->addWorldLight(pointLight);
  2496. pointLight->SetaRGB(0xffffff00);
  2497. pointLight->SetIntensity(0.15f);
  2498. pointLight->SetFalloffDistances(50.0f, 250.0f);
  2499. }
  2500. }
  2501. if (pointLight)
  2502. {
  2503. if (visible && (sensorLevel > 4) && !InEditor)
  2504. {
  2505. if (lightCircleNodeIndex == -1)
  2506. lightCircleNodeIndex = mechShape->GetNodeNameId("SLCircle_anubis");
  2507. Stuff::Vector3D lightPos = getNodeIdPosition(lightCircleNodeIndex);
  2508. Stuff::Point3D ourPosition;
  2509. ourPosition.x = -lightPos.x;
  2510. ourPosition.y = lightPos.z;
  2511. ourPosition.z = lightPos.y;
  2512. pointLight->direction = ourPosition;
  2513. pointLight->spotDir.x = -position.x;
  2514. pointLight->spotDir.y = position.z;
  2515. pointLight->spotDir.z = position.y;
  2516. pointLight->maxSpotLength = 50.0f;
  2517. Stuff::LinearMatrix4D lightToWorldMatrix;
  2518. lightToWorldMatrix.BuildTranslation(ourPosition);
  2519. lightToWorldMatrix.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2520. pointLight->SetLightToWorld(&lightToWorldMatrix);
  2521. pointLight->SetPosition(&lightPos);
  2522. pointLight->active = true;
  2523. }
  2524. else
  2525. {
  2526. pointLight->active = false;
  2527. }
  2528. }
  2529. //----------------------------------------------------
  2530. // Set Animation State Here.
  2531. // ONLY ONE case now:
  2532. // -We are in an art generated state, Just playback animation
  2533. // All cases covered now.
  2534. if (status != OBJECT_STATUS_DESTROYED)
  2535. {
  2536. mechType->setAnimation(mechShape,currentGestureId);
  2537. mechShape->SetFrameNum(currentFrame);
  2538. if (mechShadowShape)
  2539. {
  2540. mechType->setAnimation(mechShadowShape,currentGestureId);
  2541. mechShadowShape->SetFrameNum(currentFrame);
  2542. }
  2543. }
  2544. Stuff::UnitQuaternion torsoRot;
  2545. torsoRot = Stuff::EulerAngles(0.0f,(torsoRotation * DEGREES_TO_RADS),0.0f);
  2546. if (rotationalNodeIndex == -1)
  2547. rotationalNodeIndex = mechShape->SetNodeRotation("joint_torso",&torsoRot);
  2548. mechShape->SetNodeRotation(rotationalNodeIndex,&torsoRot);
  2549. if (mechShadowShape)
  2550. mechShape->SetUseShadow(false);
  2551. if (mechShadowShape && useShadows)
  2552. {
  2553. if (rotationalNodeIndex == -1)
  2554. rotationalNodeIndex = mechShadowShape->SetNodeRotation("joint_torso",&torsoRot);
  2555. mechShadowShape->SetNodeRotation(rotationalNodeIndex,&torsoRot);
  2556. mechShadowShape->SetNodeRotation("joint_torso",&torsoRot);
  2557. mechShadowShape->SetLightList(eye->getWorldLights(),eye->getNumLights());
  2558. mechShadowShape->TransformMultiShape (&xlatPosition,&qRotation);
  2559. }
  2560. mechShape->SetLightList(eye->getWorldLights(),eye->getNumLights());
  2561. mechShape->TransformMultiShape (&xlatPosition,&qRotation);
  2562. }
  2563. if (visible && (sensorLevel > 4) && !InEditor && useNonWeaponEffects)
  2564. {
  2565. //--------------------------------------------------------------
  2566. // Having already transformed the mech, the foot poofs go here.
  2567. Stuff::Vector3D rFootPos, lFootPos;
  2568. long footId1 = mechType->getTotalNodes() - 2;
  2569. long footId0 = mechType->getTotalNodes() - 1;
  2570. rFootPos = getNodePosition(footId1);
  2571. lFootPos = getNodePosition(footId0);
  2572. if (!rightFootDone0 &&
  2573. (currentFrame >= (mechType->gestures[currentGestureId].rightFootDownFrame0-FOOTPRINT_SLOP)) &&
  2574. (currentFrame <= (mechType->gestures[currentGestureId].rightFootDownFrame0+FOOTPRINT_SLOP)))
  2575. {
  2576. //Foot is on ground. Poof and footprint.
  2577. rightFootDone0 = true;
  2578. if (rightDustPoofEffect[currentRightPoof] && (currentGestureId != 13))
  2579. {
  2580. Stuff::Point3D actualPosition;
  2581. Stuff::LinearMatrix4D shapeOrigin;
  2582. Stuff::LinearMatrix4D localToWorld;
  2583. rFootPosition[currentRightPoof].x = -rFootPos.x;
  2584. rFootPosition[currentRightPoof].y = rFootPos.z;
  2585. rFootPosition[currentRightPoof].z = rFootPos.y;
  2586. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2587. shapeOrigin.BuildTranslation(rFootPosition[currentRightPoof]);
  2588. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,NULL);
  2589. rightDustPoofEffect[currentRightPoof]->Start(&info);
  2590. rightFootPoofDraw[currentRightPoof] = true;
  2591. currentRightPoof++;
  2592. if (currentRightPoof >= MAX_DUST_POOFS)
  2593. currentRightPoof = 0;
  2594. }
  2595. //Draw footprint here.
  2596. if (craterManager && !isWaking)
  2597. craterManager->addCrater(mechType->rightFootprintType,rFootPos,rotation);
  2598. }
  2599. if (!rightFootDone1 &&
  2600. (currentFrame >= (mechType->gestures[currentGestureId].rightFootDownFrame1-FOOTPRINT_SLOP)) &&
  2601. (currentFrame <= (mechType->gestures[currentGestureId].rightFootDownFrame1+FOOTPRINT_SLOP)))
  2602. {
  2603. //Foot is on ground. Poof and footprint.
  2604. rightFootDone1 = true;
  2605. if (rightDustPoofEffect[currentRightPoof] && (currentGestureId != 13))
  2606. {
  2607. Stuff::Point3D actualPosition;
  2608. Stuff::LinearMatrix4D shapeOrigin;
  2609. Stuff::LinearMatrix4D localToWorld;
  2610. rFootPosition[currentRightPoof].x = -rFootPos.x;
  2611. rFootPosition[currentRightPoof].y = rFootPos.z;
  2612. rFootPosition[currentRightPoof].z = rFootPos.y;
  2613. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2614. shapeOrigin.BuildTranslation(rFootPosition[currentRightPoof]);
  2615. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,NULL);
  2616. rightDustPoofEffect[currentRightPoof]->Start(&info);
  2617. rightFootPoofDraw[currentRightPoof] = true;
  2618. currentRightPoof++;
  2619. if (currentRightPoof >= MAX_DUST_POOFS)
  2620. currentRightPoof = 0;
  2621. }
  2622. //Draw footprint here.
  2623. if (craterManager && !isWaking)
  2624. craterManager->addCrater(mechType->rightFootprintType,rFootPos,rotation);
  2625. }
  2626. if (rightFootDone0 &&
  2627. (currentFrame < (mechType->gestures[currentGestureId].rightFootDownFrame0-FOOTPRINT_SLOP)) ||
  2628. (currentFrame > (mechType->gestures[currentGestureId].rightFootDownFrame0+FOOTPRINT_SLOP)))
  2629. {
  2630. rightFootDone0 = false;
  2631. }
  2632. if (rightFootDone1 &&
  2633. (currentFrame < (mechType->gestures[currentGestureId].rightFootDownFrame1-FOOTPRINT_SLOP)) ||
  2634. (currentFrame > (mechType->gestures[currentGestureId].rightFootDownFrame1+FOOTPRINT_SLOP)))
  2635. {
  2636. rightFootDone1 = false;
  2637. }
  2638. if (!leftFootDone0 &&
  2639. (currentFrame >= (mechType->gestures[currentGestureId].leftFootDownFrame0-FOOTPRINT_SLOP)) &&
  2640. (currentFrame <= (mechType->gestures[currentGestureId].leftFootDownFrame0+FOOTPRINT_SLOP)))
  2641. {
  2642. //Foot is on ground. Poof and footprint.
  2643. leftFootDone0 = true;
  2644. if (leftDustPoofEffect[currentLeftPoof] && (currentGestureId != 13))
  2645. {
  2646. Stuff::Point3D actualPosition;
  2647. Stuff::LinearMatrix4D shapeOrigin;
  2648. Stuff::LinearMatrix4D localToWorld;
  2649. lFootPosition[currentLeftPoof].x = -lFootPos.x;
  2650. lFootPosition[currentLeftPoof].y = lFootPos.z;
  2651. lFootPosition[currentLeftPoof].z = lFootPos.y;
  2652. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2653. shapeOrigin.BuildTranslation(lFootPosition[currentLeftPoof]);
  2654. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,NULL);
  2655. leftDustPoofEffect[currentLeftPoof]->Start(&info);
  2656. leftFootPoofDraw[currentLeftPoof] = true;
  2657. currentLeftPoof++;
  2658. if (currentLeftPoof >= MAX_DUST_POOFS)
  2659. currentLeftPoof = 0;
  2660. }
  2661. //Draw footprint here.
  2662. if (craterManager && !isWaking)
  2663. craterManager->addCrater(mechType->leftFootprintType,lFootPos,rotation);
  2664. }
  2665. if (!leftFootDone1 &&
  2666. (currentFrame >= (mechType->gestures[currentGestureId].leftFootDownFrame1-FOOTPRINT_SLOP)) &&
  2667. (currentFrame <= (mechType->gestures[currentGestureId].leftFootDownFrame1+FOOTPRINT_SLOP)))
  2668. {
  2669. //Foot is on ground. Poof and footprint.
  2670. leftFootDone1 = true;
  2671. if (leftDustPoofEffect[currentLeftPoof] && (currentGestureId != 13))
  2672. {
  2673. Stuff::Point3D actualPosition;
  2674. Stuff::LinearMatrix4D shapeOrigin;
  2675. Stuff::LinearMatrix4D localToWorld;
  2676. lFootPosition[currentLeftPoof].x = -lFootPos.x;
  2677. lFootPosition[currentLeftPoof].y = lFootPos.z;
  2678. lFootPosition[currentLeftPoof].z = lFootPos.y;
  2679. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2680. shapeOrigin.BuildTranslation(lFootPosition[currentLeftPoof]);
  2681. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,NULL);
  2682. leftDustPoofEffect[currentLeftPoof]->Start(&info);
  2683. leftFootPoofDraw[currentLeftPoof] = true;
  2684. currentLeftPoof++;
  2685. if (currentLeftPoof >= MAX_DUST_POOFS)
  2686. currentLeftPoof = 0;
  2687. }
  2688. //Draw footprint here.
  2689. if (craterManager && !isWaking)
  2690. craterManager->addCrater(mechType->leftFootprintType,lFootPos,rotation);
  2691. }
  2692. if (leftFootDone0 &&
  2693. (currentFrame < (mechType->gestures[currentGestureId].leftFootDownFrame0-FOOTPRINT_SLOP)) ||
  2694. (currentFrame > (mechType->gestures[currentGestureId].leftFootDownFrame0+FOOTPRINT_SLOP)))
  2695. {
  2696. leftFootDone0 = false;
  2697. }
  2698. if (leftFootDone1 &&
  2699. (currentFrame < (mechType->gestures[currentGestureId].leftFootDownFrame1-FOOTPRINT_SLOP)) ||
  2700. (currentFrame > (mechType->gestures[currentGestureId].leftFootDownFrame1+FOOTPRINT_SLOP)))
  2701. {
  2702. leftFootDone1 = false;
  2703. }
  2704. }
  2705. Stuff::UnitQuaternion totalRotation;
  2706. sensorSpin += SPIN_RATE * frameLength;
  2707. if (sensorSpin > 180)
  2708. sensorSpin -= 360;
  2709. if (sensorSpin < -180)
  2710. sensorSpin += 360;
  2711. totalRotation = Stuff::EulerAngles(0.0f,sensorSpin * DEGREES_TO_RADS,0.0f);
  2712. float baseRootNodeDifference = baseRootNodeHeight;
  2713. if (isHelicopter)
  2714. baseRootNodeDifference -= HELICOPTER_FACTOR;
  2715. xlatPosition.y += baseRootNodeDifference;
  2716. //----------------------------------------------
  2717. // Do geometry here to draw sensor contact
  2718. sensorTriangleShape->SetFogRGB(0xffffffff);
  2719. sensorTriangleShape->SetLightList(eye->getWorldLights(),eye->getNumLights());
  2720. sensorTriangleShape->TransformMultiShape(&xlatPosition,&totalRotation);
  2721. //----------------------------------------------
  2722. // Do geometry here to draw sensor contact
  2723. sensorSquareShape->SetFogRGB(0xffffffff);
  2724. sensorSquareShape->SetLightList(eye->getWorldLights(),eye->getNumLights());
  2725. sensorSquareShape->TransformMultiShape(&xlatPosition,&totalRotation);
  2726. //-----------------------------------------
  2727. // Create Jump FX Here.
  2728. if (!jumpFXSetup && (currentGestureId == GestureJump) && inJump && jumpJetEffect)
  2729. {
  2730. long jumpNodeId = mechType->numSmokeNodes + mechType->numWeaponNodes;
  2731. Stuff::Vector3D jumpNodePos = getNodePosition(jumpNodeId);
  2732. Stuff::Point3D actualPosition;
  2733. Stuff::LinearMatrix4D shapeOrigin;
  2734. Stuff::LinearMatrix4D localToWorld;
  2735. Stuff::LinearMatrix4D localResult;
  2736. actualPosition.x = -jumpNodePos.x;
  2737. actualPosition.y = jumpNodePos.z;
  2738. actualPosition.z = jumpNodePos.y;
  2739. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2740. shapeOrigin.BuildTranslation(actualPosition);
  2741. Stuff::UnitQuaternion effectRot;
  2742. effectRot = Stuff::EulerAngles(JUMP_PITCH * DEGREES_TO_RADS,rotation * DEGREES_TO_RADS,0.0f);
  2743. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  2744. localResult.Multiply(localToWorld,shapeOrigin);
  2745. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&localResult,NULL);
  2746. jumpJetEffect->Start(&info);
  2747. jumpFXSetup = true;
  2748. }
  2749. //------------------------------------------------
  2750. // Update GOSFX
  2751. for (long i=0;i<MAX_DUST_POOFS;i++)
  2752. {
  2753. if (rightFootPoofDraw[i] && rightDustPoofEffect[i] && rightDustPoofEffect[i]->IsExecuted())
  2754. {
  2755. Stuff::LinearMatrix4D shapeOrigin;
  2756. Stuff::LinearMatrix4D localToWorld;
  2757. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2758. shapeOrigin.BuildTranslation(rFootPosition[i]);
  2759. Stuff::OBB boundingBox;
  2760. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,&boundingBox);
  2761. bool result = rightDustPoofEffect[i]->Execute(&info);
  2762. if (!result)
  2763. {
  2764. rightFootPoofDraw[i] = false;
  2765. }
  2766. }
  2767. if (leftFootPoofDraw[i] && leftDustPoofEffect[i] && leftDustPoofEffect[i]->IsExecuted())
  2768. {
  2769. Stuff::LinearMatrix4D shapeOrigin;
  2770. Stuff::LinearMatrix4D localToWorld;
  2771. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2772. shapeOrigin.BuildTranslation(lFootPosition[i]);
  2773. Stuff::OBB boundingBox;
  2774. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,&boundingBox);
  2775. bool result = leftDustPoofEffect[i]->Execute(&info);
  2776. if (!result)
  2777. {
  2778. leftFootPoofDraw[i] = false;
  2779. }
  2780. }
  2781. }
  2782. if ((currentGestureId == GestureJump) && inJump && jumpJetEffect && jumpJetEffect->IsExecuted())
  2783. {
  2784. long jumpNodeId = mechType->numSmokeNodes + mechType->numWeaponNodes;
  2785. Stuff::Vector3D jumpNodePos = getNodePosition(jumpNodeId);
  2786. Stuff::Point3D actualPosition;
  2787. Stuff::LinearMatrix4D shapeOrigin;
  2788. Stuff::LinearMatrix4D localToWorld;
  2789. Stuff::LinearMatrix4D localResult;
  2790. actualPosition.x = -jumpNodePos.x;
  2791. actualPosition.y = jumpNodePos.z;
  2792. actualPosition.z = jumpNodePos.y;
  2793. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2794. shapeOrigin.BuildTranslation(actualPosition);
  2795. Stuff::UnitQuaternion effectRot;
  2796. effectRot = Stuff::EulerAngles(JUMP_PITCH * DEGREES_TO_RADS,rotation * DEGREES_TO_RADS,0.0f);
  2797. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  2798. localResult.Multiply(localToWorld,shapeOrigin);
  2799. Stuff::OBB boundingBox;
  2800. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&localResult,&boundingBox);
  2801. jumpJetEffect->Execute(&info);
  2802. }
  2803. if (!inJump && jumpFXSetup)
  2804. {
  2805. jumpJetEffect->Stop();
  2806. jumpFXSetup = false;
  2807. }
  2808. //----------------------------------------------------------------
  2809. // Arm Blown FX
  2810. if (leftShoulderBoom)
  2811. {
  2812. Stuff::LinearMatrix4D shapeOrigin;
  2813. Stuff::LinearMatrix4D localToWorld;
  2814. Stuff::LinearMatrix4D localResult;
  2815. if (leftArmNodeIndex == -1)
  2816. leftArmNodeIndex = mechShape->GetNodeNameId("joint_luarm");
  2817. Stuff::Vector3D leftNodePos = getNodeIdPosition(leftArmNodeIndex);
  2818. leftShoulderPos.x = -leftNodePos.x;
  2819. leftShoulderPos.y = leftNodePos.z;
  2820. leftShoulderPos.z = leftNodePos.y;
  2821. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2822. shapeOrigin.BuildTranslation(leftShoulderPos);
  2823. Stuff::UnitQuaternion effectRot;
  2824. effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
  2825. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  2826. localResult.Multiply(localToWorld,shapeOrigin);
  2827. Stuff::OBB boundingBox;
  2828. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&localResult,&boundingBox);
  2829. bool result = leftShoulderBoom->Execute(&info);
  2830. if (!result)
  2831. {
  2832. leftShoulderBoom->Kill();
  2833. delete leftShoulderBoom;
  2834. leftShoulderBoom = NULL;
  2835. }
  2836. }
  2837. if (rightShoulderBoom)
  2838. {
  2839. Stuff::LinearMatrix4D shapeOrigin;
  2840. Stuff::LinearMatrix4D localToWorld;
  2841. Stuff::LinearMatrix4D localResult;
  2842. if (rightArmNodeIndex == -1)
  2843. rightArmNodeIndex = mechShape->GetNodeNameId("joint_ruarm");
  2844. Stuff::Vector3D rightNodePos = getNodeIdPosition(rightArmNodeIndex);
  2845. rightShoulderPos.x = -rightNodePos.x;
  2846. rightShoulderPos.y = rightNodePos.z;
  2847. rightShoulderPos.z = rightNodePos.y;
  2848. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2849. shapeOrigin.BuildTranslation(rightShoulderPos);
  2850. Stuff::UnitQuaternion effectRot;
  2851. effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
  2852. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  2853. localResult.Multiply(localToWorld,shapeOrigin);
  2854. Stuff::OBB boundingBox;
  2855. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&localResult,&boundingBox);
  2856. bool result = rightShoulderBoom->Execute(&info);
  2857. if (!result)
  2858. {
  2859. rightShoulderBoom->Kill();
  2860. delete rightShoulderBoom;
  2861. rightShoulderBoom = NULL;
  2862. }
  2863. }
  2864. //-------------------------------------------------
  2865. // All other effects
  2866. if ((criticalSmoke && (isSmoking > 0)) || (smokeEffect && (isSmoking == 0)))
  2867. {
  2868. Stuff::LinearMatrix4D shapeOrigin;
  2869. Stuff::LinearMatrix4D localToWorld;
  2870. Stuff::Vector3D smokeNodePos = getNodePosition(0);
  2871. Stuff::Point3D smokePos;
  2872. smokePos.x = -smokeNodePos.x;
  2873. smokePos.y = smokeNodePos.z;
  2874. smokePos.z = smokeNodePos.y;
  2875. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2876. shapeOrigin.BuildTranslation(smokePos);
  2877. Stuff::OBB boundingBox;
  2878. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,&boundingBox);
  2879. if (isSmoking > 0)
  2880. {
  2881. //Loops until told to stop.
  2882. criticalSmoke->Execute(&info);
  2883. }
  2884. else
  2885. {
  2886. smokeEffect->Execute(&info);
  2887. }
  2888. }
  2889. if (waterWake && isWaking)
  2890. {
  2891. if (movedThisFrame)
  2892. {
  2893. waterWake->SetLoopOn();
  2894. waterWake->SetExecuteOn();
  2895. }
  2896. else
  2897. {
  2898. waterWake->SetLoopOff();
  2899. waterWake->SetExecuteOn();
  2900. }
  2901. Stuff::LinearMatrix4D shapeOrigin;
  2902. Stuff::LinearMatrix4D localToWorld;
  2903. Stuff::LinearMatrix4D localResult;
  2904. Stuff::Point3D wakePos;
  2905. wakePos.x = -position.x;
  2906. wakePos.y = Terrain::waterElevation;
  2907. wakePos.z = position.y;
  2908. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2909. shapeOrigin.BuildTranslation(wakePos);
  2910. Stuff::UnitQuaternion effectRot;
  2911. effectRot = Stuff::EulerAngles(90.0f * DEGREES_TO_RADS,rotation * DEGREES_TO_RADS,0.0f);
  2912. if (!inReverse)
  2913. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  2914. else
  2915. localToWorld.Multiply(gosFX::Effect_Into_Motion,effectRot);
  2916. localResult.Multiply(localToWorld,shapeOrigin);
  2917. Stuff::OBB boundingBox;
  2918. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&localResult,&boundingBox);
  2919. waterWake->Execute(&info);
  2920. }
  2921. if (helicopterDustCloud && isDusting)
  2922. {
  2923. Stuff::LinearMatrix4D shapeOrigin;
  2924. Stuff::LinearMatrix4D localToWorld;
  2925. Stuff::LinearMatrix4D localResult;
  2926. Stuff::Point3D wakePos;
  2927. wakePos.x = -position.x;
  2928. wakePos.y = position.z;
  2929. wakePos.z = position.y;
  2930. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  2931. shapeOrigin.BuildTranslation(wakePos);
  2932. /*
  2933. Stuff::UnitQuaternion effectRot;
  2934. effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
  2935. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  2936. localResult.Multiply(localToWorld,shapeOrigin);
  2937. */
  2938. Stuff::OBB boundingBox;
  2939. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,&boundingBox);
  2940. bool result = helicopterDustCloud->Execute(&info);
  2941. if (!result)
  2942. {
  2943. helicopterDustCloud->Kill();
  2944. isDusting = false;
  2945. }
  2946. }
  2947. #ifdef LAB_ONLY
  2948. x=GetCycles()-x;
  2949. MCTimeAnimationCalc += x;
  2950. #endif
  2951. }
  2952. #ifdef _DEBUG
  2953. FilePtr logFile = NULL;
  2954. #endif
  2955. //-----------------------------------------------------------------------------
  2956. bool Mech3DAppearance::setJumpParameters (Stuff::Vector3D &end)
  2957. {
  2958. if (!inJump)
  2959. {
  2960. jumpSetup = true;
  2961. jumpDestination = end;
  2962. return true;
  2963. }
  2964. return false;
  2965. }
  2966. //-----------------------------------------------------------------------------
  2967. bool Mech3DAppearance::leftArmRecalc (void)
  2968. {
  2969. if (!leftArm)
  2970. return false;
  2971. leftArmInView = false;
  2972. float eyeDistance = 0.0f;
  2973. //--------------------------------------------------
  2974. // First, if we are using perspective, figure out
  2975. // if object too far from camera. Far Clip Plane.
  2976. if (eye->usePerspective)
  2977. {
  2978. Stuff::Point3D Distance;
  2979. Stuff::Point3D objPosition;
  2980. Stuff::Point3D eyePosition(eye->getCameraOrigin());
  2981. objPosition.x = -leftArmPos.x;
  2982. objPosition.y = leftArmPos.z;
  2983. objPosition.z = leftArmPos.y;
  2984. Distance.Subtract(objPosition,eyePosition);
  2985. eyeDistance = Distance.GetApproximateLength();
  2986. if (eyeDistance > Camera::MaxClipDistance)
  2987. {
  2988. leftArmHazeFactor = 1.0f;
  2989. leftArmInView = false;
  2990. }
  2991. else if (eyeDistance > Camera::MinHazeDistance)
  2992. {
  2993. leftArmHazeFactor = (eyeDistance - Camera::MinHazeDistance) * Camera::DistanceFactor;
  2994. leftArmInView = true;
  2995. }
  2996. else
  2997. {
  2998. leftArmHazeFactor = 0.0f;
  2999. leftArmInView = true;
  3000. }
  3001. //-----------------------------------------------------------------
  3002. // If inside farClip plane, check if behind camera.
  3003. // Find angle between lookVector of Camera and vector from camPos
  3004. // to Target. If angle is less then halfFOV, object is visible.
  3005. if (inView)
  3006. {
  3007. Distance.Normalize(Distance);
  3008. float cosine = Distance * eye->getLookVector();
  3009. if (cosine > eye->cosHalfFOV)
  3010. leftArmInView = true;
  3011. else
  3012. leftArmInView = false;
  3013. }
  3014. }
  3015. return leftArmInView;
  3016. }
  3017. //-----------------------------------------------------------------------------
  3018. bool Mech3DAppearance::rightArmRecalc (void)
  3019. {
  3020. if (!rightArm)
  3021. return false;
  3022. rightArmInView = false;
  3023. float eyeDistance = 0.0f;
  3024. //--------------------------------------------------
  3025. // First, if we are using perspective, figure out
  3026. // if object too far from camera. Far Clip Plane.
  3027. if (eye->usePerspective)
  3028. {
  3029. Stuff::Point3D Distance;
  3030. Stuff::Point3D objPosition;
  3031. Stuff::Point3D eyePosition(eye->getCameraOrigin());
  3032. objPosition.x = -rightArmPos.x;
  3033. objPosition.y = rightArmPos.z;
  3034. objPosition.z = rightArmPos.y;
  3035. Distance.Subtract(objPosition,eyePosition);
  3036. eyeDistance = Distance.GetApproximateLength();
  3037. if (eyeDistance > Camera::MaxClipDistance)
  3038. {
  3039. rightArmHazeFactor = 1.0f;
  3040. rightArmInView = false;
  3041. }
  3042. else if (eyeDistance > Camera::MinHazeDistance)
  3043. {
  3044. rightArmHazeFactor = (eyeDistance - Camera::MinHazeDistance) * Camera::DistanceFactor;
  3045. rightArmInView = true;
  3046. }
  3047. else
  3048. {
  3049. rightArmHazeFactor = 0.0f;
  3050. rightArmInView = true;
  3051. }
  3052. //-----------------------------------------------------------------
  3053. // If inside farClip plane, check if behind camera.
  3054. // Find angle between lookVector of Camera and vector from camPos
  3055. // to Target. If angle is less then halfFOV, object is visible.
  3056. if (inView)
  3057. {
  3058. Distance.Normalize(Distance);
  3059. float cosine = Distance * eye->getLookVector();
  3060. if (cosine > eye->cosHalfFOV)
  3061. rightArmInView = true;
  3062. else
  3063. rightArmInView = false;
  3064. }
  3065. }
  3066. return rightArmInView;
  3067. }
  3068. //-----------------------------------------------------------------------------
  3069. long Mech3DAppearance::update (bool animate)
  3070. {
  3071. #ifdef _DEBUG
  3072. if (!logFile)
  3073. {
  3074. logFile = new File;
  3075. long result = logFile->create("gesture.log");
  3076. if (result != NO_ERR)
  3077. {
  3078. delete logFile;
  3079. logFile = NULL;
  3080. }
  3081. }
  3082. #endif
  3083. //----------------------------------------
  3084. // Recycle the weapon Nodes
  3085. if (nodeRecycle)
  3086. {
  3087. for (long i=0;i<mechType->numWeaponNodes;i++)
  3088. {
  3089. if (nodeRecycle[i] > 0.0f)
  3090. {
  3091. nodeRecycle[i] -= frameLength;
  3092. if (nodeRecycle[i] < 0.0f)
  3093. nodeRecycle[i] = 0.0f;
  3094. }
  3095. }
  3096. }
  3097. oncePerFrame = false;
  3098. bool setFirstFrame = false;
  3099. if ((currentGestureId == GestureHitFront) ||
  3100. (currentGestureId == GestureHitBack) ||
  3101. (currentGestureId == GestureHitLeft) ||
  3102. (currentGestureId == GestureHitRight))
  3103. {
  3104. if (atTransitionToNextGesture)
  3105. {
  3106. currentGestureId = hitGestureId;
  3107. hitGestureId = -1;
  3108. setFirstFrame = true;
  3109. long firstFrame = mechType->gestures[currentGestureId].frameStart;
  3110. if (firstFrame < 0) //Start at end of animation. Probably to reverse. Like StandToPark
  3111. firstFrame = mechType->getNumFrames(currentGestureId)-1;
  3112. inReverse = false;
  3113. if (mechType->getFrameRate(currentGestureId) < 0.0)
  3114. inReverse = true;
  3115. atTransitionToNextGesture = false;
  3116. currentFrame = firstFrame;
  3117. }
  3118. }
  3119. //----------------------------------------------
  3120. //If mech is in 2 and does NOT have a target.
  3121. //Fix please
  3122. if (!inCombatMode && (currentGestureId == 2))
  3123. {
  3124. idleTime += frameLength;
  3125. if (idleTime > idleMAX)
  3126. {
  3127. currentGestureId = 13;
  3128. }
  3129. }
  3130. else
  3131. {
  3132. idleTime = 0.0f;
  3133. }
  3134. if ((currentGestureId == 13) && atTransitionToNextGesture)
  3135. {
  3136. currentGestureId = 2;
  3137. currentFrame = 0;
  3138. }
  3139. //--------------------------------------------------------------
  3140. // Check to see if we need to stop NOW!!!!!!!!!
  3141. if (checkStop() && !inDebugMoveMode && !jumpSetup && (getVelocityMagnitude() != 0.0f) && (currentGestureId != GestureJump))
  3142. {
  3143. //--------------------------------
  3144. // We are at the goal. Store off
  3145. // our current gesture state.
  3146. currentGestureId = 2; //Force us to the stand gesture
  3147. oldStateGoal = 1; //We always came FROM STAND
  3148. currentStateGoal = -1; //Not going anywhere
  3149. transitionState = 0; //No Transition necessary. So be ready at beginning if we need one!
  3150. currentFrame = 0; //In the "how did this ever work file" Duh, need to reset the frame!
  3151. }
  3152. long newGestureId = -1; //Assume we do not need to transition.
  3153. //--------------------------------------------------------------
  3154. // Check if currentStateGoal is -1.
  3155. // If it is not, we need to move to a new gesture to get to our goal.
  3156. // Check if we can change gestures. If yes, go through change over.
  3157. // Combines three separate old chunks o code.
  3158. if (currentStateGoal != -1)
  3159. {
  3160. //--------------------------------------------
  3161. // Find out how we get to Goal. If result is
  3162. // -1, we are already at goal.
  3163. long arrayIdx = (oldStateGoal * GESTURE_OFFSET_SIZE) + (currentStateGoal * MAX_TRANSITION_GESTURES) + transitionState;
  3164. newGestureId = transitionArray[arrayIdx];
  3165. if (atTransitionToNextGesture) //This is only set when we are ready for the next gesture if these is one!
  3166. {
  3167. transitionState++; //Ready to go to next state. Increment the transition counter for next frame!
  3168. long firstFrame = currentFrame;
  3169. if (newGestureId == -1) //We have reached our goal.
  3170. {
  3171. //--------------------------------
  3172. // We are at the goal. Store off
  3173. // our current gesture state.
  3174. oldStateGoal = currentStateGoal;
  3175. if (oldStateGoal == MECH_STATE_JUMPING)
  3176. oldStateGoal = 1; //We are always standing AFTER a jump or a fall!
  3177. currentStateGoal = -1;
  3178. transitionState = 0;
  3179. atTransitionToNextGesture = false;
  3180. if (mechType->getFrameRate(currentGestureId) < 0.0)
  3181. inReverse = true;
  3182. }
  3183. else
  3184. //----------------------------------------------------
  3185. // reset all frames to zero for this gesture.
  3186. // NOTE: This may be a two way gesture. Most will be
  3187. // set to zero, but some may need to be set to last.
  3188. //
  3189. {
  3190. //----------------------------------------------
  3191. // Now actually reset everything and setup flags
  3192. // to facilitate the playing of the new gesture
  3193. currentGestureId = newGestureId;
  3194. setFirstFrame = true;
  3195. firstFrame = mechType->gestures[currentGestureId].frameStart;
  3196. if (currentGestureId == GestureJump)
  3197. firstFrame = 0; //We store information in the firstFrame of the jump. They always start at 0!
  3198. if (firstFrame < 0) //Start at end of animation. Probably to reverse. Like StandToPark
  3199. firstFrame = mechType->getNumFrames(currentGestureId)-1;
  3200. inReverse = false;
  3201. if (mechType->getFrameRate(currentGestureId) < 0.0)
  3202. inReverse = true;
  3203. atTransitionToNextGesture = false;
  3204. }
  3205. currentFrame = firstFrame;
  3206. }
  3207. }
  3208. if ((status == OBJECT_STATUS_DESTROYED) || (status == OBJECT_STATUS_DISABLED))
  3209. {
  3210. //----------------------------------------------------
  3211. // This will bypass animation if we go the old way.
  3212. // Just set stateGoal to 7 or 8 if its not.
  3213. if (currentStateGoal < 7)
  3214. {
  3215. if (RollDice(50))
  3216. {
  3217. setGestureGoal(7);
  3218. }
  3219. else
  3220. {
  3221. setGestureGoal(8);
  3222. }
  3223. }
  3224. }
  3225. //------------------------------------------------------------
  3226. mechFrameRate = mechType->getFrameRate(currentGestureId);
  3227. if (mechFrameRate < 0.0)
  3228. mechFrameRate = -mechFrameRate;
  3229. //---------------------
  3230. // Do jump magic here.
  3231. if ((currentGestureId == GestureJump) && !inJump)
  3232. {
  3233. inJump = true;
  3234. jumpSetup = false;
  3235. //-----------------------------------------------------
  3236. // Distance is straight line distance. This is only
  3237. // the case if the mech is FACING the correct way. If
  3238. // not, we must increase distance based on facing.
  3239. float takeoffFrame = mechType->getJumpTakeoffFrame();
  3240. float landingFrame = mechType->getJumpLandFrame();
  3241. //-----------------------------------------
  3242. // Get mech flying toward targetPosition.
  3243. Stuff::Vector3D ownerPosition = position;
  3244. Stuff::Vector3D targetPosition = jumpDestination;
  3245. jumpVelocity.Subtract(targetPosition,ownerPosition);
  3246. float velMag = jumpVelocity.GetLength() / ((landingFrame - takeoffFrame) / 30.0f);
  3247. jumpVelocity.Normalize(jumpVelocity);
  3248. jumpVelocity *= velMag;
  3249. //---------------------------------------------
  3250. // Jump Velocity is now a velocity vector which
  3251. // will move the mech WITHOUT turning to the landing point.
  3252. }
  3253. if (currentGestureId == GestureJump && inJump)
  3254. {
  3255. if (currentFrame >= mechType->getJumpTakeoffFrame())
  3256. {
  3257. jumpAirborne = true;
  3258. }
  3259. if ((currentFrame >= mechType->getJumpLandFrame()) && jumpAirborne)
  3260. {
  3261. jumpAirborne = false;
  3262. jumpVelocity.Zero();
  3263. if (jumpJetEffect)
  3264. {
  3265. jumpJetEffect->Stop(); //Done drawing it.
  3266. }
  3267. }
  3268. }
  3269. //--------------------------------------------------------
  3270. // Force frames to last frame of FALL if fallen
  3271. fallen = FALSE;
  3272. if ((currentGestureId == GestureFallenForward) || (currentGestureId == GestureFallenBackward))
  3273. {
  3274. fallen = TRUE;
  3275. if (currentStateGoal != -1)
  3276. atTransitionToNextGesture = TRUE;
  3277. //Try playing the helicopter dust cloud for grins to see how it looks!
  3278. // Only play once!!! Until they get back up.
  3279. if (!fallDust)
  3280. {
  3281. playEjection();
  3282. fallDust = true;
  3283. }
  3284. }
  3285. else if (currentGestureId == GesturePark)
  3286. {
  3287. fallDust = false;
  3288. if (currentStateGoal != -1)
  3289. atTransitionToNextGesture = TRUE;
  3290. }
  3291. else //Normal Frame Increment
  3292. {
  3293. fallDust = false;
  3294. if (animate)
  3295. {
  3296. float frameInc = 0.0f;
  3297. if (singleStepMode && nextStep)
  3298. {
  3299. frameInc = 1.0f;
  3300. }
  3301. else if (singleStepMode && prevStep)
  3302. {
  3303. frameInc = -1.0f;
  3304. }
  3305. else if (!singleStepMode)
  3306. {
  3307. //--------------------------------------------------------
  3308. // Make sure animation runs no faster than mechFrameRate fps.
  3309. frameInc = mechFrameRate * frameLength;
  3310. }
  3311. //------------------------------------------
  3312. // Always ASSUME we cannot transition yet.
  3313. // Saves myriad compares below.
  3314. atTransitionToNextGesture = FALSE;
  3315. //---------------------------------------
  3316. // Increment Frames -- Everything else!
  3317. if ((frameInc != 0.0f) || (singleStepMode))
  3318. {
  3319. if (!setFirstFrame) //DO NOT ANIMATE ON FIRST FRAME! Wait a bit!
  3320. {
  3321. if (inReverse)
  3322. currentFrame -= frameInc;
  3323. else
  3324. currentFrame += frameInc;
  3325. }
  3326. //--------------------------------------
  3327. //Check Positive overflow of gesture
  3328. if (currentFrame >= mechType->getNumFrames(currentGestureId))
  3329. {
  3330. if ((currentStateGoal == -1) && (hitGestureId == -1) && (currentGestureId != GestureIdle)) //Are we just Looping or transitioning?
  3331. {
  3332. currentFrame -= mechType->getNumFrames(currentGestureId);
  3333. }
  3334. else
  3335. {
  3336. //-------------------------------------------
  3337. // We are at the end and ready to transition
  3338. // Force us back to the previous frame so draw
  3339. // doesn't go off into lala land.
  3340. atTransitionToNextGesture = TRUE;
  3341. currentFrame = mechType->getNumFrames(currentGestureId) - 1.0f;
  3342. if (currentGestureId == GestureJump)
  3343. {
  3344. inJump = false;
  3345. jumpSetup = false;
  3346. oldStateGoal = 1; //We always started a Jump standing!
  3347. }
  3348. }
  3349. }
  3350. //--------------------------------------
  3351. //Check negative overflow of gesture
  3352. if (currentFrame < 0)
  3353. {
  3354. if ((currentStateGoal == -1) && (hitGestureId == -1))
  3355. {
  3356. currentFrame += mechType->getNumFrames(currentGestureId);
  3357. }
  3358. else
  3359. {
  3360. //-------------------------------------------
  3361. // We are at the end and ready to transition
  3362. // Force us back to the previous frame so draw
  3363. // doesn't go off into lala land.
  3364. atTransitionToNextGesture = TRUE;
  3365. currentFrame = 0.0f;
  3366. }
  3367. }
  3368. }
  3369. else //This is a single frame gesture. We are ALWAYS ready to transition in this case!
  3370. {
  3371. if (currentStateGoal != -1)
  3372. atTransitionToNextGesture = TRUE;
  3373. }
  3374. }
  3375. }
  3376. if (currentFrame < 0.0f)
  3377. currentFrame = 0.0f;
  3378. // STOP(("CurrentFrame of animation can never be less then zero. Frame %f, NumFrames %f, GestureId %d",currentFrame,mechType->getNumFrames(currentGestureId),currentGestureId));
  3379. if ((currentFrame > 0.0f) && (currentFrame >= mechType->getNumFrames(currentGestureId)))
  3380. currentFrame = 0.0f;
  3381. // STOP(("CurrentFrame is greater then numFrames. Frame %f, NumFrames %f, GestureId %d",currentFrame,mechType->getNumFrames(currentGestureId),currentGestureId));
  3382. #ifdef _DEBUG
  3383. if (logFile && (inDebugMoveMode))
  3384. {
  3385. char msg[1024];
  3386. sprintf(msg,"Gesture: %d, Frame: %f, SGoal: %d, OGoal: %d, Rot: %f",currentGestureId,currentFrame,currentStateGoal,oldStateGoal,rotation);
  3387. logFile->writeLine(msg);
  3388. }
  3389. #endif
  3390. if ((turn < 3) || inView || (currentGestureId == GestureJump)) //Gotta get the weapon nodes working!!
  3391. updateGeometry();
  3392. //----------------------------------------------------------------------
  3393. // If currentGestureId is 2 and baseRootNodeHeight is not set, set it!!
  3394. if (baseRootNodeHeight == -99999.9f)
  3395. {
  3396. if (rootNodeIndex == -1)
  3397. rootNodeIndex = mechShape->GetNodeNameId("joint_root");
  3398. bool oldInView = inView;
  3399. inView = true;
  3400. baseRootNodeHeight = (getNodeIdPosition(rootNodeIndex).z - position.z);
  3401. inView = oldInView;
  3402. }
  3403. //------------------------------------------------
  3404. // If arms are off, process their geometry here!
  3405. // MUST do every frame. We don't know where the arms are!!!
  3406. Stuff::Point3D xlatPosition;
  3407. Stuff::UnitQuaternion qRotation;
  3408. if (leftArmOff && leftArm && leftArmRecalc())
  3409. {
  3410. //--------------------------------------------------------
  3411. // Update the dynamics and position here for leftArm
  3412. float speed = dVel[1].GetLength();
  3413. if (speed)
  3414. {
  3415. Stuff::Vector3D velDiff = dAcc[1];
  3416. velDiff *= frameLength;
  3417. dVel[1].Add(dVel[1],velDiff);
  3418. speed = dVel[1].GetLength();
  3419. if (speed < Stuff::SMALL)
  3420. {
  3421. dVel[1].x = dVel[1].y = dVel[1].z = 0.0;
  3422. }
  3423. Stuff::Vector3D posDiff = dVel[1];
  3424. posDiff *= frameLength;
  3425. leftArmPos.Add(leftArmPos,posDiff);
  3426. float elev = land->getTerrainElevation(leftArmPos);
  3427. if (leftArmPos.z < elev)
  3428. {
  3429. leftArmPos.z = elev;
  3430. dRacc[1].Zero();
  3431. dRVel[1].Zero();
  3432. dTime[1] -= frameLength;
  3433. if (dTime[1] < 0.0)
  3434. dVel[1].x = dVel[1].y = dVel[1].z = 0.0;
  3435. }
  3436. Stuff::Vector3D rvDiff = dRacc[1];
  3437. rvDiff *= frameLength;
  3438. dRVel[1].Add(dRVel[1],rvDiff);
  3439. Stuff::Vector3D rotDiff = dRVel[1];
  3440. rotDiff *= frameLength;
  3441. dRot[1].Add(dRot[1],rotDiff);
  3442. }
  3443. xlatPosition.x = -leftArmPos.x;
  3444. xlatPosition.y = leftArmPos.z;
  3445. xlatPosition.z = leftArmPos.y;
  3446. qRotation = Stuff::EulerAngles(dRot[1].x * DEGREES_TO_RADS, dRot[1].y * DEGREES_TO_RADS, dRot[1].z * DEGREES_TO_RADS);
  3447. leftArm->SetFogRGB(0xffffffff);
  3448. leftArm->SetLightList(eye->getWorldLights(),eye->getNumLights());
  3449. leftArm->TransformMultiShape(&xlatPosition,&qRotation);
  3450. if (leftArmSmoke)
  3451. {
  3452. Stuff::LinearMatrix4D shapeOrigin;
  3453. Stuff::LinearMatrix4D localToWorld;
  3454. Stuff::LinearMatrix4D localResult;
  3455. leftShoulderPos.x = -leftArmPos.x;
  3456. leftShoulderPos.y = leftArmPos.z;
  3457. leftShoulderPos.z = leftArmPos.y;
  3458. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  3459. shapeOrigin.BuildTranslation(leftShoulderPos);
  3460. Stuff::UnitQuaternion effectRot;
  3461. effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
  3462. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  3463. localResult.Multiply(localToWorld,shapeOrigin);
  3464. Stuff::OBB boundingBox;
  3465. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&localResult,&boundingBox);
  3466. bool result = leftArmSmoke->Execute(&info);
  3467. if (!result)
  3468. {
  3469. leftArmSmoke->Kill();
  3470. delete leftArmSmoke;
  3471. leftArmSmoke = NULL;
  3472. }
  3473. }
  3474. }
  3475. if (rightArmOff && rightArm && rightArmRecalc())
  3476. {
  3477. //--------------------------------------------------------
  3478. // Update the dynamics and position here for leftArm
  3479. float speed = dVel[0].GetLength();
  3480. if (speed)
  3481. {
  3482. Stuff::Vector3D velDiff = dAcc[0];
  3483. velDiff *= frameLength;
  3484. dVel[0].Add(dVel[0],velDiff);
  3485. speed = dVel[0].GetLength();
  3486. if (speed < Stuff::SMALL)
  3487. {
  3488. dVel[0].x = dVel[0].y = dVel[0].z = 0.0;
  3489. }
  3490. Stuff::Vector3D posDiff = dVel[0];
  3491. posDiff *= frameLength;
  3492. rightArmPos.Add(rightArmPos,posDiff);
  3493. float elev = land->getTerrainElevation(rightArmPos);
  3494. if (rightArmPos.z < elev)
  3495. {
  3496. rightArmPos.z = elev;
  3497. dRacc[0].Zero();
  3498. dRVel[0].Zero();
  3499. dTime[0] -= frameLength;
  3500. if (dTime[0] < 0.0)
  3501. dVel[0].x = dVel[0].y = dVel[0].z = 0.0;
  3502. }
  3503. Stuff::Vector3D rvDiff = dRacc[0];
  3504. rvDiff *= frameLength;
  3505. dRVel[0].Add(dRVel[0],rvDiff);
  3506. Stuff::Vector3D rotDiff = dRVel[0];
  3507. rotDiff *= frameLength;
  3508. dRot[0].Add(dRot[0],rotDiff);
  3509. }
  3510. xlatPosition.x = -rightArmPos.x;
  3511. xlatPosition.y = rightArmPos.z;
  3512. xlatPosition.z = rightArmPos.y;
  3513. qRotation = Stuff::EulerAngles(dRot[0].x * DEGREES_TO_RADS, dRot[0].y * DEGREES_TO_RADS, dRot[0].z * DEGREES_TO_RADS);
  3514. rightArm->SetFogRGB(0xffffffff);
  3515. rightArm->SetLightList(eye->getWorldLights(),eye->getNumLights());
  3516. rightArm->TransformMultiShape(&xlatPosition,&qRotation);
  3517. if (rightArmSmoke)
  3518. {
  3519. Stuff::LinearMatrix4D shapeOrigin;
  3520. Stuff::LinearMatrix4D localToWorld;
  3521. Stuff::LinearMatrix4D localResult;
  3522. rightShoulderPos.x = -rightArmPos.x;
  3523. rightShoulderPos.y = rightArmPos.z;
  3524. rightShoulderPos.z = rightArmPos.y;
  3525. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  3526. shapeOrigin.BuildTranslation(rightShoulderPos);
  3527. Stuff::UnitQuaternion effectRot;
  3528. effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
  3529. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  3530. localResult.Multiply(localToWorld,shapeOrigin);
  3531. Stuff::OBB boundingBox;
  3532. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&localResult,&boundingBox);
  3533. bool result = rightArmSmoke->Execute(&info);
  3534. if (!result)
  3535. {
  3536. rightArmSmoke->Kill();
  3537. delete rightArmSmoke;
  3538. rightArmSmoke = NULL;
  3539. }
  3540. }
  3541. }
  3542. nextStep = prevStep = false;
  3543. return TRUE;
  3544. }
  3545. //-----------------------------------------------------------------------------
  3546. void Mech3DAppearance::blowLeftArm (void)
  3547. {
  3548. if (leftArmOff)
  3549. return;
  3550. // For now, the shoulder just gets a location which does not change.
  3551. // Can easily move to a node if a node becomes available.
  3552. //
  3553. if (strcmp(weaponEffects->GetEffectName(SHOULDER_POP_ID),"NONE") != 0)
  3554. {
  3555. //--------------------------------------------
  3556. // Yes, load it on up.
  3557. unsigned flags = gosFX::Effect::ExecuteFlag;
  3558. Check_Object(gosFX::EffectLibrary::Instance);
  3559. gosFX::Effect::Specification* gosEffectSpec = gosFX::EffectLibrary::Instance->Find(weaponEffects->GetEffectName(SHOULDER_POP_ID));
  3560. if (gosEffectSpec)
  3561. {
  3562. leftShoulderBoom = gosFX::EffectLibrary::Instance->MakeEffect(gosEffectSpec->m_effectID, flags);
  3563. gosASSERT(leftShoulderBoom != NULL);
  3564. MidLevelRenderer::MLRTexturePool::Instance->LoadImages();
  3565. }
  3566. }
  3567. if (strcmp(weaponEffects->GetEffectName(ARM_FLYING_ID),"NONE") != 0)
  3568. {
  3569. //--------------------------------------------
  3570. // Yes, load it on up.
  3571. unsigned flags = gosFX::Effect::ExecuteFlag;
  3572. Check_Object(gosFX::EffectLibrary::Instance);
  3573. gosFX::Effect::Specification* gosEffectSpec = gosFX::EffectLibrary::Instance->Find(weaponEffects->GetEffectName(ARM_FLYING_ID));
  3574. if (gosEffectSpec)
  3575. {
  3576. leftArmSmoke = gosFX::EffectLibrary::Instance->MakeEffect(gosEffectSpec->m_effectID, flags);
  3577. gosASSERT(leftArmSmoke != NULL);
  3578. MidLevelRenderer::MLRTexturePool::Instance->LoadImages();
  3579. }
  3580. }
  3581. if (leftArmNodeIndex == -1)
  3582. leftArmNodeIndex = mechShape->GetNodeNameId("joint_luarm");
  3583. Stuff::Vector3D leftNodePos = getNodeIdPosition(leftArmNodeIndex);
  3584. leftArmPos = leftNodePos;
  3585. if (leftShoulderBoom)
  3586. {
  3587. Stuff::LinearMatrix4D shapeOrigin;
  3588. Stuff::LinearMatrix4D localToWorld;
  3589. Stuff::LinearMatrix4D localResult;
  3590. leftShoulderPos.x = -leftNodePos.x;
  3591. leftShoulderPos.y = leftNodePos.z;
  3592. leftShoulderPos.z = leftNodePos.y;
  3593. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  3594. shapeOrigin.BuildTranslation(leftShoulderPos);
  3595. Stuff::UnitQuaternion effectRot;
  3596. effectRot = Stuff::EulerAngles(0.0f * DEGREES_TO_RADS,rotation * DEGREES_TO_RADS,0.0f);
  3597. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  3598. localResult.Multiply(localToWorld,shapeOrigin);
  3599. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&localResult,NULL);
  3600. leftShoulderBoom->Start(&info);
  3601. }
  3602. if (leftArmSmoke)
  3603. {
  3604. Stuff::LinearMatrix4D shapeOrigin;
  3605. Stuff::LinearMatrix4D localToWorld;
  3606. Stuff::LinearMatrix4D localResult;
  3607. leftShoulderPos.x = -leftArmPos.x;
  3608. leftShoulderPos.y = leftArmPos.z;
  3609. leftShoulderPos.z = leftArmPos.y;
  3610. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  3611. shapeOrigin.BuildTranslation(leftShoulderPos);
  3612. Stuff::UnitQuaternion effectRot;
  3613. effectRot = Stuff::EulerAngles(0.0f * DEGREES_TO_RADS,rotation * DEGREES_TO_RADS,0.0f);
  3614. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  3615. localResult.Multiply(localToWorld,shapeOrigin);
  3616. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&localResult,NULL);
  3617. leftArmSmoke->Start(&info);
  3618. }
  3619. leftArmOff = true;
  3620. //Calc initial Velocity, rotation and set Acceleration to down in World.
  3621. long xlatBase = 12.0f + 50.0 / 2.0f;
  3622. long upBase = 25.0f + 100.0;
  3623. long rotBase = 25.0f + 100.0;
  3624. dVel[1].x = RandomNumber(xlatBase * 2.0) - xlatBase;
  3625. dVel[1].y = RandomNumber(xlatBase * 2.0) - xlatBase;
  3626. dVel[1].z = RandomNumber(upBase) + upBase;
  3627. dRVel[1].x = RandomNumber(rotBase * 2.0) - rotBase;
  3628. dRVel[1].y = RandomNumber(rotBase * 2.0) - rotBase;
  3629. dRVel[1].z = RandomNumber(rotBase * 2.0) - rotBase;
  3630. dRot[1].Zero();
  3631. dAcc[1].x = dVel[1].x * 0.1f;
  3632. dAcc[1].y = dVel[1].y * 0.1f;
  3633. dAcc[1].z = dVel[1].z * 0.5f;
  3634. dAcc[1].Negate(dAcc[1]);
  3635. dRacc[1].x = dRVel[1].x * 0.1f;
  3636. dRacc[1].y = dRVel[1].y * 0.1f;
  3637. dRacc[1].z = dRVel[1].z * 0.1f;
  3638. dRacc[1].Negate(dRacc[1]);
  3639. dTime[1] = 4.0f;
  3640. mechShape->StopUsing("joint_luarm");
  3641. }
  3642. //-----------------------------------------------------------------------------
  3643. void Mech3DAppearance::blowRightArm (void)
  3644. {
  3645. if (rightArmOff)
  3646. return;
  3647. // For now, the shoulder just gets a location which does not change.
  3648. // Can easily move to a node if a node becomes available.
  3649. //
  3650. if (strcmp(weaponEffects->GetEffectName(SHOULDER_POP_ID),"NONE") != 0)
  3651. {
  3652. //--------------------------------------------
  3653. // Yes, load it on up.
  3654. unsigned flags = gosFX::Effect::ExecuteFlag;
  3655. Check_Object(gosFX::EffectLibrary::Instance);
  3656. gosFX::Effect::Specification* gosEffectSpec = gosFX::EffectLibrary::Instance->Find(weaponEffects->GetEffectName(SHOULDER_POP_ID));
  3657. if (gosEffectSpec)
  3658. {
  3659. rightShoulderBoom = gosFX::EffectLibrary::Instance->MakeEffect(gosEffectSpec->m_effectID, flags);
  3660. gosASSERT(rightShoulderBoom != NULL);
  3661. MidLevelRenderer::MLRTexturePool::Instance->LoadImages();
  3662. }
  3663. }
  3664. if (strcmp(weaponEffects->GetEffectName(ARM_FLYING_ID),"NONE") != 0)
  3665. {
  3666. //--------------------------------------------
  3667. // Yes, load it on up.
  3668. unsigned flags = gosFX::Effect::ExecuteFlag;
  3669. Check_Object(gosFX::EffectLibrary::Instance);
  3670. gosFX::Effect::Specification* gosEffectSpec = gosFX::EffectLibrary::Instance->Find(weaponEffects->GetEffectName(ARM_FLYING_ID));
  3671. if (gosEffectSpec)
  3672. {
  3673. rightArmSmoke = gosFX::EffectLibrary::Instance->MakeEffect(gosEffectSpec->m_effectID, flags);
  3674. gosASSERT(rightArmSmoke != NULL);
  3675. MidLevelRenderer::MLRTexturePool::Instance->LoadImages();
  3676. }
  3677. }
  3678. if (rightArmNodeIndex == -1)
  3679. rightArmNodeIndex = mechShape->GetNodeNameId("joint_ruarm");
  3680. Stuff::Vector3D rightNodePos = getNodeIdPosition(rightArmNodeIndex);
  3681. rightArmPos = rightNodePos;
  3682. if (rightShoulderBoom)
  3683. {
  3684. Stuff::LinearMatrix4D shapeOrigin;
  3685. Stuff::LinearMatrix4D localToWorld;
  3686. Stuff::LinearMatrix4D localResult;
  3687. rightShoulderPos.x = -rightNodePos.x;
  3688. rightShoulderPos.y = rightNodePos.z;
  3689. rightShoulderPos.z = rightNodePos.y;
  3690. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  3691. shapeOrigin.BuildTranslation(rightShoulderPos);
  3692. Stuff::UnitQuaternion effectRot;
  3693. effectRot = Stuff::EulerAngles(0.0f * DEGREES_TO_RADS,rotation * DEGREES_TO_RADS,0.0f);
  3694. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  3695. localResult.Multiply(localToWorld,shapeOrigin);
  3696. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&localResult,NULL);
  3697. rightShoulderBoom->Start(&info);
  3698. }
  3699. if (rightArmSmoke)
  3700. {
  3701. Stuff::LinearMatrix4D shapeOrigin;
  3702. Stuff::LinearMatrix4D localToWorld;
  3703. Stuff::LinearMatrix4D localResult;
  3704. rightShoulderPos.x = -rightArmPos.x;
  3705. rightShoulderPos.y = rightArmPos.z;
  3706. rightShoulderPos.z = rightArmPos.y;
  3707. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  3708. shapeOrigin.BuildTranslation(rightShoulderPos);
  3709. Stuff::UnitQuaternion effectRot;
  3710. effectRot = Stuff::EulerAngles(0.0f * DEGREES_TO_RADS,rotation * DEGREES_TO_RADS,0.0f);
  3711. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  3712. localResult.Multiply(localToWorld,shapeOrigin);
  3713. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&localResult,NULL);
  3714. rightArmSmoke->Start(&info);
  3715. }
  3716. rightArmOff = true;
  3717. //Calc initial Velocity, rotation and set Acceleration to down in World.
  3718. long xlatBase = 12.0f + 50.0 / 2.0f;
  3719. long upBase = 25.0f + 100.0;
  3720. long rotBase = 25.0f + 100.0;
  3721. dVel[0].x = RandomNumber(xlatBase * 2.0) - xlatBase;
  3722. dVel[0].y = RandomNumber(xlatBase * 2.0) - xlatBase;
  3723. dVel[0].z = RandomNumber(upBase) + upBase;
  3724. dRVel[0].x = RandomNumber(rotBase * 2.0) - rotBase;
  3725. dRVel[0].y = RandomNumber(rotBase * 2.0) - rotBase;
  3726. dRVel[0].z = RandomNumber(rotBase * 2.0) - rotBase;
  3727. dRot[0].Zero();
  3728. dAcc[0].x = dVel[0].x * 0.1f;
  3729. dAcc[0].y = dVel[0].y * 0.1f;
  3730. dAcc[0].z = dVel[0].z * 0.5f;
  3731. dAcc[0].Negate(dAcc[0]);
  3732. dRacc[0].x = dRVel[0].x * 0.1f;
  3733. dRacc[0].y = dRVel[0].y * 0.1f;
  3734. dRacc[0].z = dRVel[0].z * 0.1f;
  3735. dRacc[0].Negate(dRacc[0]);
  3736. dTime[0] = 4.0f;
  3737. mechShape->StopUsing("joint_ruarm");
  3738. }
  3739. //-----------------------------------------------------------------------------
  3740. void Mech3DAppearance::startSmoking (long smokeLvl)
  3741. {
  3742. //Check if we are already playing one. If not, smoke away
  3743. //First, check if its even loaded.
  3744. // can easily preload this. Should we? Memory?
  3745. if (!useNonWeaponEffects)
  3746. return;
  3747. if ((smokeLvl > 0) && !criticalSmoke)
  3748. {
  3749. if (strcmp(weaponEffects->GetEffectName(CRITICAL_SMOKE_ID),"NONE") != 0)
  3750. {
  3751. //--------------------------------------------
  3752. // Yes, load it on up.
  3753. unsigned flags = gosFX::Effect::ExecuteFlag|gosFX::Effect::LoopFlag;
  3754. Check_Object(gosFX::EffectLibrary::Instance);
  3755. gosFX::Effect::Specification* gosEffectSpec = gosFX::EffectLibrary::Instance->Find(weaponEffects->GetEffectName(CRITICAL_SMOKE_ID));
  3756. if (gosEffectSpec)
  3757. {
  3758. criticalSmoke = gosFX::EffectLibrary::Instance->MakeEffect(gosEffectSpec->m_effectID, flags);
  3759. gosASSERT(criticalSmoke != NULL);
  3760. MidLevelRenderer::MLRTexturePool::Instance->LoadImages();
  3761. }
  3762. }
  3763. }
  3764. if ((smokeLvl == 0) && !smokeEffect)
  3765. {
  3766. if (strcmp(weaponEffects->GetEffectName(MECH_SMOKE_ID),"NONE") != 0)
  3767. {
  3768. //--------------------------------------------
  3769. // Yes, load it on up.
  3770. unsigned flags = gosFX::Effect::ExecuteFlag|gosFX::Effect::LoopFlag;
  3771. Check_Object(gosFX::EffectLibrary::Instance);
  3772. gosFX::Effect::Specification* gosEffectSpec = gosFX::EffectLibrary::Instance->Find(weaponEffects->GetEffectName(MECH_SMOKE_ID));
  3773. if (gosEffectSpec)
  3774. {
  3775. smokeEffect = gosFX::EffectLibrary::Instance->MakeEffect(gosEffectSpec->m_effectID, flags);
  3776. gosASSERT(smokeEffect != NULL);
  3777. MidLevelRenderer::MLRTexturePool::Instance->LoadImages();
  3778. }
  3779. }
  3780. }
  3781. if (smokeLvl != -1)
  3782. {
  3783. if ((isSmoking == -1) || ((isSmoking != smokeLvl) && (smokeLvl != -1)))
  3784. {
  3785. Stuff::LinearMatrix4D shapeOrigin;
  3786. Stuff::LinearMatrix4D localToWorld;
  3787. Stuff::Vector3D smokeNodePos = getNodePosition(0); //Always SMOKE if it exists!!
  3788. Stuff::Point3D smokePos;
  3789. smokePos.x = -smokeNodePos.x;
  3790. smokePos.y = smokeNodePos.z;
  3791. smokePos.z = smokeNodePos.y;
  3792. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  3793. shapeOrigin.BuildTranslation(smokePos);
  3794. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,NULL);
  3795. if (smokeLvl > 0)
  3796. criticalSmoke->Start(&info);
  3797. else
  3798. smokeEffect->Start(&info);
  3799. }
  3800. }
  3801. else
  3802. {
  3803. if (smokeEffect)
  3804. smokeEffect->Kill();
  3805. if (criticalSmoke)
  3806. criticalSmoke->Kill();
  3807. }
  3808. isSmoking = smokeLvl;
  3809. }
  3810. //-----------------------------------------------------------------------------
  3811. void Mech3DAppearance::startWaterWake (void)
  3812. {
  3813. //Check if we are already playing one. If not, wake city.
  3814. //Check if we are a helicopter OR we are jumping. No WAKE if either is true.
  3815. if (isHelicopter || currentGestureId == 20)
  3816. return;
  3817. if (!useNonWeaponEffects)
  3818. return;
  3819. //First, check if its even loaded.
  3820. // can easily preload this. Should we? Memory?
  3821. if (useNonWeaponEffects && !waterWake)
  3822. {
  3823. if (strcmp(weaponEffects->GetEffectName(MECH_WATER_WAKE),"NONE") != 0)
  3824. {
  3825. //--------------------------------------------
  3826. // Yes, load it on up.
  3827. unsigned flags = gosFX::Effect::ExecuteFlag|gosFX::Effect::LoopFlag;
  3828. Check_Object(gosFX::EffectLibrary::Instance);
  3829. gosFX::Effect::Specification* gosEffectSpec = gosFX::EffectLibrary::Instance->Find(weaponEffects->GetEffectName(MECH_WATER_WAKE));
  3830. if (gosEffectSpec)
  3831. {
  3832. waterWake = gosFX::EffectLibrary::Instance->MakeEffect(gosEffectSpec->m_effectID, flags);
  3833. gosASSERT(waterWake != NULL);
  3834. MidLevelRenderer::MLRTexturePool::Instance->LoadImages();
  3835. }
  3836. }
  3837. }
  3838. if (waterWake && !isWaking) //Start the effect if we are not running it yet!!
  3839. {
  3840. Stuff::LinearMatrix4D shapeOrigin;
  3841. Stuff::LinearMatrix4D localToWorld;
  3842. Stuff::LinearMatrix4D localResult;
  3843. Stuff::Point3D wakePos;
  3844. wakePos.x = -position.x;
  3845. wakePos.y = Terrain::waterElevation; //Wake is at Water Level!
  3846. wakePos.z = position.y;
  3847. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  3848. shapeOrigin.BuildTranslation(wakePos);
  3849. Stuff::UnitQuaternion effectRot;
  3850. effectRot = Stuff::EulerAngles(90.0f * DEGREES_TO_RADS,rotation * DEGREES_TO_RADS,0.0f);
  3851. if (!inReverse)
  3852. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  3853. else
  3854. localToWorld.Multiply(gosFX::Effect_Into_Motion,effectRot);
  3855. localResult.Multiply(localToWorld,shapeOrigin);
  3856. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&localResult,NULL);
  3857. waterWake->Start(&info);
  3858. isWaking = true;
  3859. }
  3860. }
  3861. //-----------------------------------------------------------------------------
  3862. void Mech3DAppearance::stopWaterWake (void)
  3863. {
  3864. if (waterWake && isWaking) //Stop the effect if we are running it!!
  3865. waterWake->Kill();
  3866. isWaking = false;
  3867. }
  3868. //-----------------------------------------------------------------------------
  3869. void Mech3DAppearance::playEjection (void)
  3870. {
  3871. if (InEditor)
  3872. return;
  3873. //Check if we are already playing one. If not, dustCloud. Use for falls, too?
  3874. //First, check if its even loaded.
  3875. // can easily preload this. Should we? Memory?
  3876. if (useNonWeaponEffects && !helicopterDustCloud)
  3877. {
  3878. if (strcmp(weaponEffects->GetEffectName(HELICOPTER_DUST_CLOUD),"NONE") != 0)
  3879. {
  3880. //--------------------------------------------
  3881. // Yes, load it on up.
  3882. unsigned flags = gosFX::Effect::ExecuteFlag;
  3883. Check_Object(gosFX::EffectLibrary::Instance);
  3884. gosFX::Effect::Specification* gosEffectSpec = gosFX::EffectLibrary::Instance->Find(weaponEffects->GetEffectName(HELICOPTER_DUST_CLOUD));
  3885. if (gosEffectSpec)
  3886. {
  3887. helicopterDustCloud = gosFX::EffectLibrary::Instance->MakeEffect(gosEffectSpec->m_effectID, flags);
  3888. gosASSERT(helicopterDustCloud != NULL);
  3889. MidLevelRenderer::MLRTexturePool::Instance->LoadImages();
  3890. }
  3891. }
  3892. }
  3893. if (!isDusting && helicopterDustCloud) //Start the effect if we are not running it yet!!
  3894. {
  3895. Stuff::LinearMatrix4D shapeOrigin;
  3896. Stuff::LinearMatrix4D localToWorld;
  3897. Stuff::LinearMatrix4D localResult;
  3898. Stuff::Point3D wakePos;
  3899. wakePos.x = -position.x;
  3900. wakePos.y = position.z; //dustCloud is just centered on position.
  3901. wakePos.z = position.y;
  3902. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  3903. shapeOrigin.BuildTranslation(wakePos);
  3904. /*
  3905. Stuff::UnitQuaternion effectRot;
  3906. effectRot = Stuff::EulerAngles(0.0f,rotation * DEGREES_TO_RADS,0.0f);
  3907. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  3908. localResult.Multiply(localToWorld,shapeOrigin);
  3909. */
  3910. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&shapeOrigin,NULL);
  3911. helicopterDustCloud->Start(&info);
  3912. isDusting = true;
  3913. }
  3914. }
  3915. //-----------------------------------------------------------------------------
  3916. void Mech3DAppearance::destroy (void)
  3917. {
  3918. AppearanceTypeList::appearanceHeap->Free(paintSchemata);
  3919. paintSchemata = NULL;
  3920. if ( mechShape )
  3921. delete mechShape;
  3922. mechShape = NULL;
  3923. if (mechShadowShape)
  3924. {
  3925. delete mechShadowShape;
  3926. mechShadowShape = NULL;
  3927. }
  3928. if ( leftArm )
  3929. delete leftArm;
  3930. leftArm = NULL;
  3931. if ( rightArm )
  3932. delete rightArm;
  3933. rightArm = NULL;
  3934. #ifdef _DEBUG
  3935. if (logFile )
  3936. {
  3937. delete logFile;
  3938. logFile = NULL;
  3939. }
  3940. #endif
  3941. for (long i=0;i<MAX_DUST_POOFS;i++)
  3942. {
  3943. if (rightDustPoofEffect[i])
  3944. {
  3945. rightDustPoofEffect[i]->Kill();
  3946. delete rightDustPoofEffect[i];
  3947. rightDustPoofEffect[i] = NULL;
  3948. }
  3949. if (leftDustPoofEffect[i])
  3950. {
  3951. leftDustPoofEffect[i]->Kill();
  3952. delete leftDustPoofEffect[i];
  3953. leftDustPoofEffect[i] = NULL;
  3954. }
  3955. }
  3956. if (smokeEffect)
  3957. {
  3958. smokeEffect->Kill();
  3959. delete smokeEffect;
  3960. smokeEffect = NULL;
  3961. }
  3962. if (jumpJetEffect)
  3963. {
  3964. jumpJetEffect->Kill();
  3965. delete jumpJetEffect;
  3966. jumpJetEffect = NULL;
  3967. }
  3968. if (rightShoulderBoom)
  3969. {
  3970. rightShoulderBoom->Kill();
  3971. delete rightShoulderBoom;
  3972. rightShoulderBoom = NULL;
  3973. }
  3974. if (leftShoulderBoom)
  3975. {
  3976. leftShoulderBoom->Kill();
  3977. delete leftShoulderBoom;
  3978. leftShoulderBoom = NULL;
  3979. }
  3980. if (sensorSquareShape)
  3981. {
  3982. delete sensorSquareShape;
  3983. sensorSquareShape = NULL;
  3984. }
  3985. if (sensorTriangleShape)
  3986. {
  3987. delete sensorTriangleShape;
  3988. sensorTriangleShape = NULL;
  3989. }
  3990. appearanceTypeList->removeAppearance(mechType);
  3991. if (InEditor)
  3992. {
  3993. AppearanceTypeList::appearanceHeap->Free(nodeUsed);
  3994. nodeUsed = NULL;
  3995. AppearanceTypeList::appearanceHeap->Free(nodeRecycle);
  3996. nodeRecycle = NULL;
  3997. }
  3998. }
  3999. //*****************************************************************************
  4000. void Mech3DAppearance::copyTo (MechAppearanceData *data)
  4001. {
  4002. data->frameNum = frameNum;
  4003. data->mechFrameRate = mechFrameRate;
  4004. data->leftArmOff = leftArmOff;
  4005. data->rightArmOff = rightArmOff;
  4006. data->fallen = fallen;
  4007. data->forceStop = forceStop;
  4008. data->atTransitionToNextGesture = atTransitionToNextGesture;
  4009. data->inReverse = inReverse;
  4010. data->inJump = inJump;
  4011. data->jumpSetup = jumpSetup;
  4012. data->jumpFXSetup = jumpFXSetup;
  4013. data->jumpAirborne = jumpAirborne;
  4014. data->oncePerFrame = oncePerFrame;
  4015. data->lockRotation = lockRotation;
  4016. data->velocity = velocity;
  4017. data->status = status;
  4018. data->currentStateGoal = currentStateGoal;
  4019. data->currentGestureId = currentGestureId;
  4020. data->transitionState = transitionState;
  4021. data->oldStateGoal = oldStateGoal;
  4022. data->hitGestureId = hitGestureId;
  4023. data->currentFrame = currentFrame;
  4024. data->currentLOD = currentLOD;
  4025. if (mechType->numWeaponNodes > 10)
  4026. STOP(("Mech Has too many weapon nodes to save %d",mechType->numWeaponNodes));
  4027. memcpy(data->nodeUsed,nodeUsed,10);
  4028. memcpy(data->nodeRecycle,nodeRecycle,10);
  4029. data->isSmoking = isSmoking;
  4030. data->isWaking = isWaking;
  4031. data->isDusting = isDusting;
  4032. data->fallDust = fallDust;
  4033. data->isHelicopter = isHelicopter;
  4034. data->baseRootNodeHeight = baseRootNodeHeight;
  4035. data->jumpDestination = jumpDestination;
  4036. data->jumpVelocity = jumpVelocity;
  4037. }
  4038. //*****************************************************************************
  4039. void Mech3DAppearance::copyFrom (MechAppearanceData *data)
  4040. {
  4041. frameNum = data->frameNum;
  4042. mechFrameRate = data->mechFrameRate;
  4043. leftArmOff = data->leftArmOff;
  4044. rightArmOff = data->rightArmOff;
  4045. fallen = data->fallen;
  4046. forceStop = data->forceStop;
  4047. atTransitionToNextGesture = data->atTransitionToNextGesture;
  4048. inReverse = data->inReverse;
  4049. inJump = data->inJump;
  4050. jumpSetup = data->jumpSetup;
  4051. jumpFXSetup = data->jumpFXSetup;
  4052. jumpAirborne = data->jumpAirborne;
  4053. oncePerFrame = data->oncePerFrame;
  4054. lockRotation = data->lockRotation;
  4055. velocity = data->velocity;
  4056. //Let mech reset status when it reloads so that the destroyed shapes come up.
  4057. // status = data->status;
  4058. currentStateGoal = data->currentStateGoal;
  4059. currentGestureId = data->currentGestureId;
  4060. transitionState = data->transitionState;
  4061. oldStateGoal = data->oldStateGoal;
  4062. hitGestureId = data->hitGestureId;
  4063. currentFrame = data->currentFrame;
  4064. currentLOD = data->currentLOD;
  4065. memcpy(nodeUsed,data->nodeUsed,10);
  4066. memcpy(nodeRecycle,data->nodeRecycle,10);
  4067. isSmoking = -1;
  4068. if (data->isSmoking >= 0)
  4069. startSmoking(data->isSmoking);
  4070. isWaking = false;
  4071. if (data->isWaking)
  4072. startWaterWake();
  4073. isDusting = false;
  4074. if (data->isDusting)
  4075. playEjection();
  4076. fallDust = false;
  4077. if (data->fallDust)
  4078. playEjection();
  4079. if (data->inJump)
  4080. {
  4081. long jumpNodeId = mechType->numSmokeNodes + mechType->numWeaponNodes;
  4082. Stuff::Vector3D jumpNodePos = getNodePosition(jumpNodeId);
  4083. Stuff::Point3D actualPosition;
  4084. Stuff::LinearMatrix4D shapeOrigin;
  4085. Stuff::LinearMatrix4D localToWorld;
  4086. Stuff::LinearMatrix4D localResult;
  4087. actualPosition.x = -jumpNodePos.x;
  4088. actualPosition.y = jumpNodePos.z;
  4089. actualPosition.z = jumpNodePos.y;
  4090. shapeOrigin.BuildRotation(Stuff::EulerAngles(0.0f,0.0f,0.0f));
  4091. shapeOrigin.BuildTranslation(actualPosition);
  4092. Stuff::UnitQuaternion effectRot;
  4093. effectRot = Stuff::EulerAngles(JUMP_PITCH * DEGREES_TO_RADS,rotation * DEGREES_TO_RADS,0.0f);
  4094. localToWorld.Multiply(gosFX::Effect_Against_Motion,effectRot);
  4095. localResult.Multiply(localToWorld,shapeOrigin);
  4096. gosFX::Effect::ExecuteInfo info((Stuff::Time)scenarioTime,&localResult,NULL);
  4097. jumpJetEffect->Start(&info);
  4098. }
  4099. isHelicopter = data->isHelicopter;
  4100. baseRootNodeHeight = data->baseRootNodeHeight;
  4101. jumpDestination = data->jumpDestination;
  4102. jumpVelocity = data->jumpVelocity;
  4103. }
  4104. void Mech3DAppearance::flashBuilding (float dur, float fDuration, DWORD color)
  4105. {
  4106. duration = dur;
  4107. flashDuration = fDuration;
  4108. flashColor = color;
  4109. drawFlash = true;
  4110. currentFlash = flashDuration;
  4111. }
  4112. Stuff::Vector3D Mech3DAppearance::getHitNodeLeft (void)
  4113. {
  4114. if (hitLeftNodeIndex == -1)
  4115. hitLeftNodeIndex = mechShape->GetNodeNameId("hit_left");
  4116. Stuff::Vector3D result = position;
  4117. if (!inView)
  4118. return result;
  4119. //-------------------------------------------
  4120. // Create Matrix to conform to.
  4121. Stuff::UnitQuaternion qRotation;
  4122. float yaw = rotation * DEGREES_TO_RADS;
  4123. qRotation = Stuff::EulerAngles(0.0f, yaw, 0.0f);
  4124. Stuff::Point3D xlatPosition;
  4125. xlatPosition.x = -position.x;
  4126. xlatPosition.y = position.z;
  4127. xlatPosition.z = position.y;
  4128. Stuff::UnitQuaternion torsoRot;
  4129. torsoRot = Stuff::EulerAngles(0.0f,(torsoRotation * DEGREES_TO_RADS),0.0f);
  4130. if (rotationalNodeIndex == -1)
  4131. rotationalNodeIndex = mechShape->SetNodeRotation("joint_torso",&torsoRot);
  4132. mechShape->SetNodeRotation(rotationalNodeIndex,&torsoRot);
  4133. result = mechShape->GetTransformedNodePosition(&xlatPosition,&qRotation,hitLeftNodeIndex);
  4134. if ((result.x == 0.0f) &&
  4135. (result.y == 0.0f) &&
  4136. (result.z == 0.0f))
  4137. result = position;
  4138. return result;
  4139. }
  4140. Stuff::Vector3D Mech3DAppearance::getHitNodeRight (void)
  4141. {
  4142. if (hitRightNodeIndex == -1)
  4143. hitRightNodeIndex = mechShape->GetNodeNameId("hit_right");
  4144. Stuff::Vector3D result = position;
  4145. if (!inView)
  4146. return result;
  4147. //-------------------------------------------
  4148. // Create Matrix to conform to.
  4149. Stuff::UnitQuaternion qRotation;
  4150. float yaw = rotation * DEGREES_TO_RADS;
  4151. qRotation = Stuff::EulerAngles(0.0f, yaw, 0.0f);
  4152. Stuff::Point3D xlatPosition;
  4153. xlatPosition.x = -position.x;
  4154. xlatPosition.y = position.z;
  4155. xlatPosition.z = position.y;
  4156. Stuff::UnitQuaternion torsoRot;
  4157. torsoRot = Stuff::EulerAngles(0.0f,(torsoRotation * DEGREES_TO_RADS),0.0f);
  4158. if (rotationalNodeIndex == -1)
  4159. rotationalNodeIndex = mechShape->SetNodeRotation("joint_torso",&torsoRot);
  4160. mechShape->SetNodeRotation(rotationalNodeIndex,&torsoRot);
  4161. result = mechShape->GetTransformedNodePosition(&xlatPosition,&qRotation,hitRightNodeIndex);
  4162. if ((result.x == 0.0f) &&
  4163. (result.y == 0.0f) &&
  4164. (result.z == 0.0f))
  4165. result = position;
  4166. return result;
  4167. }
  4168. //*****************************************************************************