llagent.cpp 196 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575
  1. /**
  2. * @file llagent.cpp
  3. * @brief LLAgent class implementation
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llagent.h"
  34. #include "imageids.h"
  35. #include "llanimationstates.h"
  36. #include "llapp.h"
  37. #include "llappearancemgr.h"
  38. #include "llavatarnamecache.h"
  39. #include "llbutton.h"
  40. #include "llcallbacklist.h"
  41. #include "llconsole.h"
  42. #include "llevent.h"
  43. #include "llexperiencecache.h"
  44. #include "llimage.h" // For activateStaleTextures()
  45. #include "llmenugl.h"
  46. #include "llmd5.h"
  47. #include "llparcel.h"
  48. #include "llpermissions.h"
  49. #include "llregionhandle.h"
  50. #include "llscriptpermissions.h"
  51. #include "llsdutil.h"
  52. #include "llsys.h"
  53. #include "llteleportflags.h"
  54. #include "lltrans.h"
  55. #include "lluictrlfactory.h"
  56. #include "llmessage.h"
  57. #include "roles_constants.h"
  58. #include "llagentpilot.h"
  59. #include "llagentwearables.h"
  60. #include "llappviewer.h"
  61. #include "llavatartracker.h"
  62. #include "llchatbar.h"
  63. #include "lldrawable.h"
  64. #include "lleventpoll.h" // For LLEventPoll::getMargin()
  65. #include "llface.h"
  66. #include "llfirstuse.h"
  67. #include "llfloater.h"
  68. #include "llfloateractivespeakers.h"
  69. #include "llfloateravatarinfo.h"
  70. #include "llfloatercamera.h"
  71. #include "llfloaterchat.h"
  72. #include "llfloatercustomize.h"
  73. #include "llfloatergroupinfo.h"
  74. #include "llfloatergroups.h"
  75. #include "llfloaterland.h"
  76. #include "llfloaterminimap.h"
  77. #include "llfloatermove.h"
  78. #include "llfloaterpostcard.h"
  79. #include "llfloaterpreference.h"
  80. #include "hbfloatersearch.h"
  81. #include "llfloatersnapshot.h"
  82. #include "hbfloaterteleporthistory.h"
  83. #include "llfloatertools.h"
  84. #include "llfloaterworldmap.h"
  85. #include "llfollowcam.h"
  86. #include "llgridmanager.h"
  87. #include "llgroupmgr.h"
  88. #include "llhudeffectlookat.h"
  89. #include "llhudmanager.h"
  90. #include "llimmgr.h"
  91. #include "llinventorymodel.h"
  92. #include "lljoystickbutton.h"
  93. #include "lllandmarklist.h"
  94. #include "llmarketplacefunctions.h"
  95. #include "llmeshrepository.h"
  96. #include "llmorphview.h"
  97. #include "llpipeline.h"
  98. #include "llpuppetmotion.h"
  99. //MK
  100. #include "mkrlinterface.h"
  101. //mk
  102. #include "llselectmgr.h"
  103. #include "llsky.h"
  104. #include "llslurl.h"
  105. #include "llstatusbar.h"
  106. #include "llstartup.h"
  107. #include "lltool.h"
  108. #include "lltoolcomp.h"
  109. #include "lltoolfocus.h"
  110. #include "lltoolgrab.h"
  111. #include "lltoolmgr.h"
  112. #include "lltoolpie.h"
  113. #include "lltoolview.h"
  114. #include "hbviewerautomation.h"
  115. #include "llviewercamera.h"
  116. #include "llviewercontrol.h"
  117. #include "llviewerdisplay.h" // For gTeleportDisplay
  118. #include "llviewerinventory.h"
  119. #include "llviewerjoystick.h"
  120. #include "llviewermediafocus.h"
  121. #include "llviewermenu.h"
  122. #include "llviewerobjectlist.h"
  123. #include "llviewerparcelmgr.h"
  124. #include "llviewerparceloverlay.h"
  125. #include "llviewerregion.h"
  126. #include "llviewerstats.h"
  127. #include "llviewertexturelist.h" // For gTextureList
  128. #include "llviewerwindow.h"
  129. #include "llviewerdisplay.h"
  130. #include "llvoavatarself.h"
  131. #include "llvoiceclient.h"
  132. #include "llvosky.h"
  133. #include "llwearablelist.h"
  134. #include "llworld.h"
  135. #include "llworldmap.h"
  136. using namespace LLOldEvents;
  137. using namespace LLAvatarAppearanceDefines;
  138. LLUUID gAgentID;
  139. LLUUID gAgentSessionID;
  140. // Face editing constants
  141. const LLVector3d FACE_EDIT_CAMERA_OFFSET(0.4f, -0.05f, 0.07f);
  142. const LLVector3d FACE_EDIT_TARGET_OFFSET(0.f, 0.f, 0.05f);
  143. // Mousewheel camera zoom
  144. constexpr F32 MIN_ZOOM_FRACTION = 0.25f;
  145. constexpr F32 INITIAL_ZOOM_FRACTION = 1.f;
  146. constexpr F32 MAX_ZOOM_FRACTION = 8.f;
  147. constexpr F32 CAMERA_ZOOM_HALF_LIFE = 0.07f; // In seconds
  148. constexpr F32 FOV_ZOOM_HALF_LIFE = 0.07f; // In seconds
  149. constexpr F32 CAMERA_FOCUS_HALF_LIFE = 0.f; // 0.02f;
  150. constexpr F32 CAMERA_LAG_HALF_LIFE = 0.25f;
  151. constexpr F32 MIN_CAMERA_LAG = 0.5f;
  152. constexpr F32 MAX_CAMERA_LAG = 5.f;
  153. constexpr F32 CAMERA_COLLIDE_EPSILON = 0.1f;
  154. constexpr F32 MIN_CAMERA_DISTANCE = 0.1f;
  155. constexpr F32 AVATAR_ZOOM_MIN_X_FACTOR = 0.55f;
  156. constexpr F32 AVATAR_ZOOM_MIN_Y_FACTOR = 0.7f;
  157. constexpr F32 AVATAR_ZOOM_MIN_Z_FACTOR = 1.15f;
  158. constexpr F32 MAX_CAMERA_DISTANCE_FROM_AGENT = 50.f;
  159. constexpr F32 MAX_CAMERA_SMOOTH_DISTANCE = 50.f;
  160. constexpr F32 HEAD_BUFFER_SIZE = 0.3f;
  161. constexpr F32 CUSTOMIZE_AVATAR_CAMERA_ANIM_SLOP = 0.2f;
  162. constexpr F32 LAND_MIN_ZOOM = 0.15f;
  163. constexpr F32 AVATAR_MIN_ZOOM = 0.5f;
  164. constexpr F32 OBJECT_MIN_ZOOM = 0.02f;
  165. constexpr F32 APPEARANCE_MIN_ZOOM = 0.39f;
  166. constexpr F32 APPEARANCE_MAX_ZOOM = 8.f;
  167. // Fidget constants in seconds
  168. constexpr F32 MIN_FIDGET_TIME = 8.f;
  169. constexpr F32 MAX_FIDGET_TIME = 20.f;
  170. constexpr F32 GROUND_TO_AIR_CAMERA_TRANSITION_TIME = 0.5f;
  171. constexpr F32 GROUND_TO_AIR_CAMERA_TRANSITION_START_TIME = 0.5f;
  172. constexpr F32 MAX_VELOCITY_AUTO_LAND_SQUARED = 4.f * 4.f;
  173. constexpr F32 OBJECT_EXTENTS_PADDING = 0.5f;
  174. constexpr F64 CHAT_AGE_FAST_RATE = 3.0;
  175. // The agent instance.
  176. LLAgent gAgent;
  177. // Static member variables
  178. std::map<std::string, std::string> LLAgent::sTeleportErrorMessages;
  179. std::map<std::string, std::string> LLAgent::sTeleportProgressMessages;
  180. // Friends observer
  181. class LLAgentFriendObserver final : public LLFriendObserver
  182. {
  183. public:
  184. LLAgentFriendObserver()
  185. {
  186. }
  187. ~LLAgentFriendObserver() override
  188. {
  189. }
  190. void changed(U32 mask) override
  191. {
  192. // If there is a change we are interested in.
  193. if ((mask & LLFriendObserver::POWERS) != 0)
  194. {
  195. gAgent.friendsChanged();
  196. }
  197. }
  198. };
  199. ///////////////////////////////////////////////////////////////////////////////
  200. // This used to be a template in its own llcommon/llsmoothstep.h header, but
  201. // since it is only used here and only with F32 as a data type, I moved it here
  202. // and made it into a simple, non-template function. HB
  203. ///////////////////////////////////////////////////////////////////////////////
  204. LL_INLINE F32 llsmoothstep(F32 edge0, F32 edge1, F32 value)
  205. {
  206. if (value < edge0)
  207. {
  208. return 0.f;
  209. }
  210. if (value >= edge1)
  211. {
  212. return 1.f;
  213. }
  214. // Scale/bias into [0..1] range
  215. F32 scaled_value = (value - edge0) / (edge1 - edge0);
  216. return scaled_value * scaled_value * (3.f - 2.f * scaled_value);
  217. }
  218. //-----------------------------------------------------------------------------
  219. // LLAgent() class
  220. //-----------------------------------------------------------------------------
  221. LLAgent::LLAgent()
  222. : mDrawDistance(DEFAULT_FAR_PLANE),
  223. mGroupPowers(0),
  224. mHideGroupTitle(false),
  225. mMapOriginX(0.F),
  226. mMapOriginY(0.F),
  227. mMapWidth(0),
  228. mMapHeight(0),
  229. mLookAt(NULL),
  230. mPointAt(NULL),
  231. mHUDTargetZoom(1.f),
  232. mHUDCurZoom(1.f),
  233. mInitialized(false),
  234. mUploadedBakes(BAKED_HAIR + 1),
  235. mRebakeNeeded(false),
  236. mForceMouselook(false),
  237. mDoubleTapRunMode(DOUBLETAP_NONE),
  238. mAlwaysRun(false),
  239. mRunning(false),
  240. mAccess(SIM_ACCESS_PG),
  241. mAdminOverride(false),
  242. mGodLevel(GOD_NOT),
  243. mHttpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID),
  244. mTeleportState(TELEPORT_NONE),
  245. mRegionp(NULL),
  246. mDepartureHandle(0),
  247. mArrivalHandle(0),
  248. mLastPosGlobalSignaled(0.f),
  249. mDistanceTraveled(0.0),
  250. mRenderState(0),
  251. mCameraMode(CAMERA_MODE_THIRD_PERSON),
  252. mLastCameraMode(CAMERA_MODE_THIRD_PERSON),
  253. mViewsPushed(false),
  254. mCustomAnim(false),
  255. mShowAvatar(true),
  256. mCameraAnimating(false),
  257. mAnimationDuration(0.33f),
  258. mCameraFOVZoomFactor(0.f),
  259. mCameraCurrentFOVZoomFactor(0.f),
  260. mCurrentCameraDistance(2.f), // meters, set in init()
  261. mTargetCameraDistance(2.f),
  262. mCameraZoomFraction(1.f), // deprecated
  263. mThirdPersonHeadOffset(0.f, 0.f, 1.f),
  264. mSitCameraEnabled(false),
  265. mCameraSmoothingStop(false),
  266. mCameraUpVector(LLVector3::z_axis), // default is straight up
  267. mFocusOnAvatar(true),
  268. mFocusObject(NULL),
  269. mFocusObjectDist(0.f),
  270. mTrackFocusObject(true),
  271. mUIOffset(0.f),
  272. mIsBusy(false),
  273. mIsAutoReplying(false),
  274. mHasExtEnvironment(false),
  275. mInventorySettings(false),
  276. mInventoryMaterial(false),
  277. mAtKey(0), // Either 1, 0, or -1... indicates that movement-key is pressed
  278. mWalkKey(0), // like AtKey, but causes less forward thrust
  279. mLeftKey(0),
  280. mUpKey(0),
  281. mYawKey(0.f),
  282. mPitchKey(0),
  283. mOrbitLeftKey(0.f),
  284. mOrbitRightKey(0.f),
  285. mOrbitUpKey(0.f),
  286. mOrbitDownKey(0.f),
  287. mOrbitInKey(0.f),
  288. mOrbitOutKey(0.f),
  289. mPanUpKey(0.f),
  290. mPanDownKey(0.f),
  291. mPanLeftKey(0.f),
  292. mPanRightKey(0.f),
  293. mPanInKey(0.f),
  294. mPanOutKey(0.f),
  295. mControlFlags(0x00000000),
  296. mFlagsDirty(false),
  297. mFlagsNeedReset(false),
  298. mSittingOnGround(false),
  299. mEffectColor(0.f, 1.f, 1.f, 1.f),
  300. mHaveHomePosition(false),
  301. mHomeRegionHandle(0),
  302. mNearChatRadius(CHAT_NORMAL_RADIUS * 0.5f),
  303. mNextFidgetTime(0.f),
  304. mCurrentFidget(0),
  305. mFirstLogin(false),
  306. mGenderChosen(false),
  307. mAppearanceSerialNum(0),
  308. mTeleportKeepsLookAt(false)
  309. {
  310. for (U32 i = 0; i < TOTAL_CONTROLS; ++i)
  311. {
  312. mControlsTakenCount[i] = 0;
  313. mControlsTakenPassedOnCount[i] = 0;
  314. }
  315. mFollowCam.setMaxCameraDistantFromSubject(MAX_CAMERA_DISTANCE_FROM_AGENT);
  316. }
  317. // Requires gSavedSettings to be initialized.
  318. void LLAgent::init()
  319. {
  320. // Initialize the appearance dictionary before we need it... This saves us
  321. // having to use a slow and cumbersome LLSingleton to access the pointer to
  322. // this class.
  323. gAvatarAppDictp =
  324. new LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary();
  325. mDrawDistance = gSavedSettings.getF32("RenderFarClip");
  326. // Let's initialize the camera now...
  327. LLViewerCamera::initClass();
  328. gViewerCamera.setView(DEFAULT_FIELD_OF_VIEW);
  329. // Leave at 0.1 meters until we have real near clip management
  330. gViewerCamera.setNear(0.1f);
  331. // If you want to change camera settings, do so in camera.h
  332. gViewerCamera.setFar(mDrawDistance);
  333. // Default, overridden in LLViewerWindow::reshape
  334. gViewerCamera.setAspect(gViewerWindowp->getDisplayAspectRatio());
  335. // Default, overridden in LLViewerWindow::reshape
  336. gViewerCamera.setViewHeightInPixels(768);
  337. setFlying(gSavedPerAccountSettings.getBool("FlyingAtExit"));
  338. mCameraFocusOffsetTarget =
  339. LLVector4(gSavedSettings.getVector3("CameraOffsetBuild"));
  340. mCameraOffsetDefault = gSavedSettings.getVector3("CameraOffsetDefault");
  341. mCameraFocusOffsetDefault =
  342. gSavedSettings.getVector3("FocusOffsetDefault");
  343. mCameraCollidePlane.clear();
  344. mCurrentCameraDistance = mCameraOffsetDefault.length() *
  345. gSavedSettings.getF32("CameraOffsetScale");
  346. mTargetCameraDistance = mCurrentCameraDistance;
  347. mCameraZoomFraction = 1.f;
  348. mTrackFocusObject = gSavedSettings.getBool("TrackFocusObject");
  349. mEffectColor = gSavedSettings.getColor4("EffectColor");
  350. LLControlVariable* maturity =
  351. gSavedSettings.getControl("PreferredMaturity");
  352. if (maturity)
  353. {
  354. maturity->getValidateSignal()->connect(boost::bind(&LLAgent::validateMaturity,
  355. this, _2));
  356. maturity->getSignal()->connect(boost::bind(&LLAgent::handleMaturity,
  357. this, _2));
  358. }
  359. LLAppCoreHttp& app_core_http = gAppViewerp->getAppCoreHttp();
  360. app_core_http.getPolicy(LLAppCoreHttp::AP_AGENT);
  361. mInitialized = true;
  362. }
  363. void LLAgent::cleanup()
  364. {
  365. if (mSimFeaturesReceivedSlot.connected())
  366. {
  367. mSimFeaturesReceivedSlot.disconnect();
  368. }
  369. setSitCamera(LLUUID::null);
  370. if (mLookAt)
  371. {
  372. mLookAt->markDead();
  373. mLookAt = NULL;
  374. }
  375. if (mPointAt)
  376. {
  377. mPointAt->markDead();
  378. mPointAt = NULL;
  379. }
  380. mRegionp = NULL;
  381. setFocusObject(NULL);
  382. }
  383. LLAgent::~LLAgent()
  384. {
  385. cleanup();
  386. }
  387. // Change camera back to third person, stop the autopilot, deselect stuff, etc.
  388. void LLAgent::resetView(bool reset_camera, bool change_camera)
  389. {
  390. static bool dont_reenter = false;
  391. if (dont_reenter) return;
  392. //MK
  393. if (gRLenabled && mCameraMode != CAMERA_MODE_MOUSELOOK &&
  394. gRLInterface.mCamDistMax <= 0.f)
  395. {
  396. changeCameraToMouselook(false);
  397. return;
  398. }
  399. //mk
  400. dont_reenter = true;
  401. bool was_not_customizing = mCameraMode != CAMERA_MODE_CUSTOMIZE_AVATAR;
  402. gAgentPilot.stopAutoPilot(true);
  403. gSelectMgr.unhighlightAll();
  404. #if 0 // By popular request, keep land selection while walking around. JC
  405. gViewerParcelMgr.deselectLand();
  406. #endif
  407. // Force deselect when walking and attachment is selected; this is so
  408. // people do not wig out when their avatar moves without animating
  409. if (gSelectMgr.getSelection()->isAttachment())
  410. {
  411. gSelectMgr.deselectAll();
  412. }
  413. // Hide all popup menus
  414. if (gMenuHolderp)
  415. {
  416. gMenuHolderp->hideMenus();
  417. }
  418. if (change_camera && !LLPipeline::sFreezeTime)
  419. {
  420. changeCameraToDefault();
  421. LLViewerJoystick* joystick = LLViewerJoystick::getInstance();
  422. if (joystick->getOverrideCamera())
  423. {
  424. joystick->toggleFlycam();
  425. }
  426. // Reset avatar mode from eventual residual motion
  427. if (gToolMgr.inBuildMode())
  428. {
  429. joystick->moveAvatar(true);
  430. }
  431. if (gFloaterToolsp)
  432. {
  433. gFloaterToolsp->close();
  434. }
  435. if (gViewerWindowp)
  436. {
  437. gViewerWindowp->showCursor();
  438. }
  439. // Switch back to basic toolset
  440. gToolMgr.setCurrentToolset(gBasicToolset);
  441. }
  442. if (reset_camera && !LLPipeline::sFreezeTime &&
  443. (was_not_customizing ||
  444. gSavedSettings.getBool("AppearanceAnimation") ||
  445. gSavedSettings.getBool("AppearanceCameraMovement")))
  446. {
  447. if (gViewerWindowp && !gViewerWindowp->getLeftMouseDown() &&
  448. cameraThirdPerson())
  449. {
  450. // Leaving mouse-steer mode
  451. LLVector3 agent_at_axis = getAtAxis();
  452. agent_at_axis -= projected_vec(agent_at_axis, getReferenceUpVector());
  453. agent_at_axis.normalize();
  454. resetAxes(lerp(getAtAxis(), agent_at_axis,
  455. LLCriticalDamp::getInterpolant(0.3f)));
  456. }
  457. setFocusOnAvatar();
  458. }
  459. mHUDTargetZoom = 1.f;
  460. dont_reenter = false;
  461. }
  462. // Handle any actions that need to be performed when the main app gains focus
  463. // (such as through alt-tab).
  464. void LLAgent::onAppFocusGained()
  465. {
  466. //MK
  467. if (gRLenabled)
  468. {
  469. return;
  470. }
  471. //mk
  472. if (mCameraMode == CAMERA_MODE_MOUSELOOK)
  473. {
  474. changeCameraToDefault();
  475. gToolMgr.clearSavedTool();
  476. }
  477. }
  478. void LLAgent::ageChat()
  479. {
  480. if (isAgentAvatarValid())
  481. {
  482. // Get amount of time since I last chatted
  483. F64 elapsed_time = (F64)gAgentAvatarp->mChatTimer.getElapsedTimeF32();
  484. // Add in frame time * 3 (so it ages 4x)
  485. gAgentAvatarp->mChatTimer.setAge(elapsed_time +
  486. (F64)gFrameDT *
  487. (CHAT_AGE_FAST_RATE - 1.0));
  488. }
  489. }
  490. // Allow camera to be moved somewhere other than behind avatar.
  491. void LLAgent::unlockView()
  492. {
  493. //MK
  494. if (gRLenabled &&
  495. (gRLInterface.contains("camunlock") ||
  496. gRLInterface.contains("setcam_unlock")))
  497. {
  498. return;
  499. }
  500. //mk
  501. if (getFocusOnAvatar())
  502. {
  503. if (isAgentAvatarValid())
  504. {
  505. setFocusGlobal(LLVector3d::zero, gAgentAvatarp->mID);
  506. }
  507. setFocusOnAvatar(false, false); // No animation
  508. }
  509. }
  510. void LLAgent::moveAt(S32 direction, bool reset)
  511. {
  512. // Age chat timer so it fades more quickly when you are intentionally
  513. // moving
  514. ageChat();
  515. setKey(direction, mAtKey);
  516. if (direction > 0)
  517. {
  518. setControlFlags(AGENT_CONTROL_AT_POS | AGENT_CONTROL_FAST_AT);
  519. }
  520. else if (direction < 0)
  521. {
  522. setControlFlags(AGENT_CONTROL_AT_NEG | AGENT_CONTROL_FAST_AT);
  523. }
  524. if (reset)
  525. {
  526. resetView();
  527. }
  528. }
  529. void LLAgent::moveAtNudge(S32 direction)
  530. {
  531. // Age chat timer so it fades quicker when you are intentionally moving
  532. ageChat();
  533. setKey(direction, mWalkKey);
  534. if (direction > 0)
  535. {
  536. setControlFlags(AGENT_CONTROL_NUDGE_AT_POS);
  537. }
  538. else if (direction < 0)
  539. {
  540. setControlFlags(AGENT_CONTROL_NUDGE_AT_NEG);
  541. }
  542. resetView();
  543. }
  544. void LLAgent::moveLeft(S32 direction)
  545. {
  546. // Age chat timer so it fades quicker when you are intentionally moving
  547. ageChat();
  548. setKey(direction, mLeftKey);
  549. if (direction > 0)
  550. {
  551. setControlFlags(AGENT_CONTROL_LEFT_POS | AGENT_CONTROL_FAST_LEFT);
  552. }
  553. else if (direction < 0)
  554. {
  555. setControlFlags(AGENT_CONTROL_LEFT_NEG | AGENT_CONTROL_FAST_LEFT);
  556. }
  557. resetView();
  558. }
  559. void LLAgent::moveLeftNudge(S32 direction)
  560. {
  561. // Age chat timer so it fades quicker when you are intentionally moving
  562. ageChat();
  563. setKey(direction, mLeftKey);
  564. if (direction > 0)
  565. {
  566. setControlFlags(AGENT_CONTROL_NUDGE_LEFT_POS);
  567. }
  568. else if (direction < 0)
  569. {
  570. setControlFlags(AGENT_CONTROL_NUDGE_LEFT_NEG);
  571. }
  572. resetView();
  573. }
  574. void LLAgent::moveUp(S32 direction)
  575. {
  576. // Age chat timer so it fades quicker when you are intentionally moving
  577. ageChat();
  578. setKey(direction, mUpKey);
  579. if (direction > 0)
  580. {
  581. setControlFlags(AGENT_CONTROL_UP_POS | AGENT_CONTROL_FAST_UP);
  582. }
  583. else if (direction < 0)
  584. {
  585. setControlFlags(AGENT_CONTROL_UP_NEG | AGENT_CONTROL_FAST_UP);
  586. }
  587. resetView();
  588. }
  589. void LLAgent::moveYaw(F32 mag, bool reset_view)
  590. {
  591. mYawKey = mag;
  592. if (mag > 0.f)
  593. {
  594. setControlFlags(AGENT_CONTROL_YAW_POS);
  595. }
  596. else if (mag < 0.f)
  597. {
  598. setControlFlags(AGENT_CONTROL_YAW_NEG);
  599. }
  600. if (reset_view)
  601. {
  602. resetView();
  603. }
  604. }
  605. void LLAgent::movePitch(S32 direction)
  606. {
  607. setKey(direction, mPitchKey);
  608. if (direction > 0)
  609. {
  610. setControlFlags(AGENT_CONTROL_PITCH_POS);
  611. }
  612. else if (direction < 0)
  613. {
  614. setControlFlags(AGENT_CONTROL_PITCH_NEG);
  615. }
  616. }
  617. // Does this parcel allow you to fly ?
  618. bool LLAgent::canFly()
  619. {
  620. //MK
  621. if (gRLenabled && gRLInterface.mContainsFly)
  622. {
  623. return false;
  624. }
  625. //mk
  626. if (isGodlike())
  627. {
  628. return true;
  629. }
  630. if (mRegionp && mRegionp->getBlockFly())
  631. {
  632. return false;
  633. }
  634. LLParcel* parcel = gViewerParcelMgr.getAgentParcel();
  635. if (!parcel)
  636. {
  637. return false;
  638. }
  639. return parcel->getAllowFly() ||
  640. // Allow owners to fly on their own land.
  641. LLViewerParcelMgr::isParcelOwnedByAgent(parcel, GP_LAND_ALLOW_FLY);
  642. }
  643. void LLAgent::setFlying(bool fly, bool play_failed_sound)
  644. {
  645. if (fly)
  646. {
  647. if (isAgentAvatarValid() && gAgentAvatarp->mIsSitting)
  648. {
  649. // Do not allow taking off while sitting
  650. return;
  651. }
  652. //MK
  653. if (gRLenabled && gRLInterface.mContainsFly)
  654. {
  655. return;
  656. }
  657. //mk
  658. bool was_flying = getFlying();
  659. if (!was_flying && !canFly())
  660. {
  661. // Parcel does not let you start fly, gods can always fly and it is
  662. // OK if you are already flying
  663. if (play_failed_sound)
  664. {
  665. make_ui_sound("UISndBadKeystroke");
  666. }
  667. return;
  668. }
  669. if (!was_flying)
  670. {
  671. gViewerStats.incStat(LLViewerStats::ST_FLY_COUNT);
  672. }
  673. setControlFlags(AGENT_CONTROL_FLY);
  674. gSavedSettings.setBool("FlyBtnState", true);
  675. }
  676. else
  677. {
  678. clearControlFlags(AGENT_CONTROL_FLY);
  679. gSavedSettings.setBool("FlyBtnState", false);
  680. }
  681. mFlagsDirty = true;
  682. }
  683. // UI based mechanism of setting fly state
  684. void LLAgent::toggleFlying()
  685. {
  686. bool fly = !(mControlFlags & AGENT_CONTROL_FLY);
  687. setFlying(fly);
  688. resetView();
  689. }
  690. boost::signals2::connection LLAgent::addRegionChangedCB(const region_change_cb_t::slot_type& cb)
  691. {
  692. return mRegionChangeSignal.connect(cb);
  693. }
  694. // Deals with baked textures uploads in OpenSIM (limit them to BAKED_HAIR
  695. // unless the region advertizes bake on mesh support (actually Universal
  696. // additional/mesh-only bakes) and the user accepts breaking their avatar
  697. // look for users around them using older viewers).
  698. bool LLAgent::setUploadedBakesLimit()
  699. {
  700. static LLCachedControl<bool> os_bom(gSavedSettings,
  701. "OSAllowBakeOnMeshUploads");
  702. U8 old_num_bakes = mUploadedBakes;
  703. if ((gIsInSecondLife || os_bom) &&
  704. mRegionp && mRegionp->bakesOnMeshEnabled())
  705. {
  706. mUploadedBakes = BAKED_NUM_INDICES;
  707. }
  708. else
  709. {
  710. mUploadedBakes = BAKED_HAIR + 1;
  711. }
  712. if (!gIsInSecondLife && mUploadedBakes != old_num_bakes &&
  713. isAgentAvatarValid())
  714. {
  715. llinfos << "Detected change in uploaded bakes number, scheduling a rebake..."
  716. << llendl;
  717. mRebakeNeeded = false;
  718. doAfterInterval(boost::bind(&LLVOAvatarSelf::forceBakeAllTextures,
  719. gAgentAvatarp.get(), true), 5.f);
  720. return true;
  721. }
  722. return false;
  723. }
  724. void LLAgent::onSimFeaturesReceived(const LLUUID& region_id)
  725. {
  726. if (!mRegionp)
  727. {
  728. return;
  729. }
  730. if (mRegionp->getRegionID() != region_id)
  731. {
  732. // Region changed, we do not care any more...
  733. return;
  734. }
  735. if (!mRegionp->getFeaturesReceived())
  736. {
  737. mSimFeaturesReceivedSlot =
  738. mRegionp->setFeaturesReceivedCB(boost::bind(&LLAgent::onSimFeaturesReceived,
  739. this, _1));
  740. return;
  741. }
  742. // Vivox to WebRTC voice transition. HB
  743. gVoiceClient.handleSimFeaturesReceived(mRegionp->getSimulatorFeatures());
  744. }
  745. void LLAgent::handleServerFeaturesTransition()
  746. {
  747. if (!mRegionp)
  748. {
  749. mHasExtEnvironment = mInventorySettings = mInventoryMaterial = false;
  750. return;
  751. }
  752. // Some capabilities must be passed to library classes for the agent
  753. // region.
  754. const std::string& cap1 = mRegionp->getCapability("GetDisplayNames");
  755. LLAvatarNameCache::setNameLookupURL(cap1);
  756. llinfos << "Avatar names lookup URL set to: "
  757. << (cap1.empty() ? "none" : cap1) << llendl;
  758. // Make sure the name tags will be refreshed, using the (possibly new)
  759. // avatar name cache capability.
  760. LLVOAvatar::invalidateNameTags();
  761. const std::string& cap2 = mRegionp->getCapability("GetExperienceInfo");
  762. LLExperienceCache::setLookupURL(cap2);
  763. llinfos << "Experiences lookup URL set to: "
  764. << (cap2.empty() ? "none" : cap2) << llendl;
  765. #if LL_PUPPETRY
  766. LLPuppetMotion::requestPuppetryStatus(mRegionp);
  767. #endif
  768. mHasExtEnvironment = hasRegionCapability("ExtEnvironment");
  769. mInventorySettings = hasRegionCapability("UpdateSettingsTaskInventory") &&
  770. hasRegionCapability("UpdateSettingsAgentInventory");
  771. mInventoryMaterial = hasRegionCapability("UpdateMaterialTaskInventory") &&
  772. hasRegionCapability("UpdateMaterialAgentInventory");
  773. #if 0 // Not needed any more since now the whole grid should have it (SL) or
  774. // not at all (OpenSim).
  775. // See if the Marketplace Listings folder is supported in this region
  776. LLMarketplace::checkMerchantStatus();
  777. #endif
  778. // Vivox to WebRTC voice transition. HB
  779. onSimFeaturesReceived(mRegionp->getRegionID());
  780. // NOTE: the avatar is not yet fully rezzed when logging in and the
  781. // capabilities are received and trigger a first call to this method...
  782. if (!isAgentAvatarValid()) return;
  783. // Make sure to use the proper method to account for the Z-Offset: using
  784. // the new Avatar Hover Offset capability/feature if available or, in
  785. // non-SSB sims, as a simple offset added to the size sent by
  786. // sendAgentSetAppearance().
  787. gAgentAvatarp->scheduleHoverUpdate();
  788. // Deal with baked textures uploads in OpenSim
  789. if (setUploadedBakesLimit())
  790. {
  791. // If a rebake has been scheduled, skip the rest...
  792. return;
  793. }
  794. // We needed a rebake just after the region capabilities were received, so
  795. // we can do it now.
  796. if (mRebakeNeeded)
  797. {
  798. mRebakeNeeded = false;
  799. gAppearanceMgr.incrementCofVersion();
  800. gAppearanceMgr.resetCOFUpdateTimer();
  801. return;
  802. }
  803. // SSB transition: not needed any more in SL, but I kept it in case OpenSim
  804. // would implement SSB, sometime in the future. HB
  805. bool server_baked = gAgentAvatarp->isUsingServerBakes();
  806. if (LLVOAvatarSelf::canUseServerBaking())
  807. {
  808. if (!server_baked)
  809. {
  810. // Old-style appearance entering a server-bake region.
  811. llinfos << "Rebake requested due to region transition" << llendl;
  812. gAppearanceMgr.requestServerAppearanceUpdate();
  813. }
  814. }
  815. else if (server_baked)
  816. {
  817. // New-style appearance entering a non-bake region: force a rebake.
  818. // Trying to rebake immediately after crossing region boundary seems to
  819. // be failure prone; adding a delay factor. Yes, this fix is ad-hoc and
  820. // not guaranteed to work in all cases.
  821. gAppearanceMgr.setRebaking();
  822. doAfterInterval(boost::bind(&LLVOAvatarSelf::forceBakeAllTextures,
  823. gAgentAvatarp.get(), true), 5.f);
  824. llinfos << "Rebake requested due to region transition" << llendl;
  825. }
  826. }
  827. void LLAgent::setRegion(LLViewerRegion* regionp)
  828. {
  829. if (regionp && mRegionp != regionp)
  830. {
  831. //MK
  832. if (!gRLenabled || !gRLInterface.mContainsShowloc)
  833. //mk
  834. {
  835. llinfos << "Moving agent into region: " << regionp->getIdentity()
  836. << llendl;
  837. }
  838. // Clear all ban lines
  839. gViewerParcelMgr.resetCollisionSegments();
  840. // We have changed region and we are now going to change our agent
  841. // coordinate frame.
  842. mAgentOriginGlobal = regionp->getOriginGlobal();
  843. LLViewerCamera* camera = &gViewerCamera;
  844. LLVector3 camera_position_agent = camera->getOrigin();
  845. LLVector3 delta;
  846. LLVector3d agent_offset_global;
  847. if (mRegionp)
  848. {
  849. // Force the interest list mode back to "default" for the region we
  850. // are leaving... HB
  851. mRegionp->setInterestListMode(true);
  852. // Set departure and arrival handle, used to detect far TPs. HB
  853. mDepartureHandle = mRegionp->getHandle();
  854. mArrivalHandle = regionp->getHandle();
  855. LL_DEBUGS("Teleport") << "Set departure handle to "
  856. << mDepartureHandle
  857. << ", and arrival handle to "
  858. << mArrivalHandle << LL_ENDL;
  859. // Start afresh for textures loading in the new place. HB
  860. if (mArrivalHandle != mDepartureHandle)
  861. {
  862. LLViewerTexture::resetLowMemCondition();
  863. }
  864. agent_offset_global = mRegionp->getOriginGlobal();
  865. delta.set(regionp->getOriginGlobal() - agent_offset_global);
  866. // Hack to keep sky in the agent's region, otherwise it may get
  867. // deleted - DJS 08/02/02
  868. // *TODO: possibly refactor into gSky->setAgentRegion(regionp) ?
  869. if (gSky.mVOSkyp)
  870. {
  871. gSky.mVOSkyp->setRegion(regionp);
  872. }
  873. }
  874. else
  875. {
  876. // First time initialization.
  877. LLViewerTexture::resetLowMemCondition();
  878. agent_offset_global = mAgentOriginGlobal;
  879. delta.set(agent_offset_global);
  880. }
  881. setPositionAgent(getPositionAgent() - delta);
  882. camera->setOrigin(camera_position_agent - delta);
  883. // When automatic stale GL textures cleanup is disabled, do clean them
  884. // up once after each arrival in a new simulator. HB
  885. if (gSavedSettings.getU32("StaleGLImageCleanupMinDelay") == 0)
  886. {
  887. LLImageGL::activateStaleTextures();
  888. }
  889. }
  890. else if (regionp && regionp == mRegionp)
  891. {
  892. llinfos << "Region unchanged" << llendl;
  893. mDepartureHandle = mArrivalHandle = regionp->getHandle();
  894. LL_DEBUGS("Teleport") << "Departure and arrival handle set to "
  895. << mArrivalHandle << LL_ENDL;
  896. }
  897. else if (mRegionp && !regionp && !LLApp::isQuitting())
  898. {
  899. llwarns << "Setting agent region to NULL." << llendl;
  900. }
  901. mRegionp = regionp;
  902. if (regionp)
  903. {
  904. regionp->setInterestListMode();
  905. // Must shift hole-covering water object locations because local
  906. // coordinate frame changed.
  907. gWorld.updateWaterObjects();
  908. // Keep a list of regions we have been to. This is just an interesting
  909. // stat, logged at the dataserver we could trake this at the dataserver
  910. // side, but this is harder.
  911. U64 handle = regionp->getHandle();
  912. mRegionsVisited.insert(handle);
  913. if (mDepartureHandle == 0) // If never initialized
  914. {
  915. LL_DEBUGS("Teleport") << "Set departure handle to: " << handle
  916. << LL_ENDL;
  917. mDepartureHandle = handle;
  918. }
  919. gSelectMgr.updateSelectionCenter();
  920. // Let interested parties know agent region has been changed.
  921. mRegionChangeSignal();
  922. LLHUDEffectLookAt::updateSettings();
  923. // Check for transitional features changes between regions
  924. if (regionp->capabilitiesReceived())
  925. {
  926. handleServerFeaturesTransition();
  927. }
  928. else
  929. {
  930. // Need to handle via callback after caps arrive.
  931. regionp->setCapsReceivedCB(boost::bind(&LLAgent::handleServerFeaturesTransition,
  932. this));
  933. }
  934. // Play the default/idle Bento animation, if desired.
  935. if (gSavedSettings.getBool("PlayDefaultBentoAnimation"))
  936. {
  937. sendAnimationRequest(ANIM_AGENT_BENTO_IDLE, ANIM_REQUEST_START);
  938. }
  939. // *HACK: make sure all objects get rezzed in the region of arrival. HB
  940. U32 sim_change_type =
  941. mTeleportState == TELEPORT_NONE ? AFTER_CROSS_BORDER
  942. : AFTER_FAR_TP;
  943. schedule_objects_visibility_refresh(sim_change_type);
  944. }
  945. }
  946. U64 LLAgent::getRegionHandle() const
  947. {
  948. return mRegionp ? mRegionp->getHandle() : 0;
  949. }
  950. const LLHost& LLAgent::getRegionHost() const
  951. {
  952. return mRegionp ? mRegionp->getHost() : LLHost::invalid;
  953. }
  954. // Returns empty() if mRegionp == NULL
  955. std::string LLAgent::getSLURL() const
  956. {
  957. if (mRegionp)
  958. {
  959. LLVector3 pos = ((LLAgent*)this)->getPositionAgent();
  960. LLSLURL slurl(mRegionp->getName(), pos);
  961. return slurl.getSLURLString();
  962. }
  963. return LLStringUtil::null;
  964. }
  965. const std::string& LLAgent::getRegionCapability(const char* cap)
  966. {
  967. return mRegionp ? mRegionp->getCapability(cap) : LLStringUtil::null;
  968. }
  969. bool LLAgent::regionCapabilitiesReceived() const
  970. {
  971. return mRegionp && mRegionp->capabilitiesReceived();
  972. }
  973. bool LLAgent::hasRegionCapability(const char* cap) const
  974. {
  975. return mRegionp && !mRegionp->getCapability(cap).empty();
  976. }
  977. bool LLAgent::regionHasExportPermSupport() const
  978. {
  979. return mRegionp && mRegionp->isOSExportPermSupported();
  980. }
  981. S32 LLAgent::getRegionMaxTextureSize() const
  982. {
  983. return mRegionp ? mRegionp->getMaxTextureSize() : 1024;
  984. }
  985. bool LLAgent::inPrelude()
  986. {
  987. return mRegionp && mRegionp->isPrelude();
  988. }
  989. bool LLAgent::canManageEstate() const
  990. {
  991. return mRegionp && mRegionp->canManageEstate();
  992. }
  993. void LLAgent::sendMessage()
  994. {
  995. if (gDisconnected)
  996. {
  997. llwarns << "Trying to send message when disconnected !" << llendl;
  998. return;
  999. }
  1000. if (!mRegionp)
  1001. {
  1002. llwarns << "No region for agent yet !" << llendl;
  1003. llassert(false);
  1004. return;
  1005. }
  1006. LLMessageSystem* msg = gMessageSystemp;
  1007. if (msg)
  1008. {
  1009. msg->sendMessage(mRegionp->getHost());
  1010. }
  1011. else
  1012. {
  1013. llwarns << "Message system pointer is NULL !" << llendl;
  1014. }
  1015. }
  1016. void LLAgent::sendReliableMessage(U32 retries_factor)
  1017. {
  1018. if (gDisconnected)
  1019. {
  1020. LL_DEBUGS("Agent") << "Trying to send message when disconnected !"
  1021. << LL_ENDL;
  1022. return;
  1023. }
  1024. if (!mRegionp)
  1025. {
  1026. LL_DEBUGS("Agent") << "No region for agent yet, not sending message !"
  1027. << LL_ENDL;
  1028. return;
  1029. }
  1030. LLMessageSystem* msg = gMessageSystemp;
  1031. if (!msg)
  1032. {
  1033. llwarns << "Message system pointer is NULL !" << llendl;
  1034. return;
  1035. }
  1036. msg->sendReliable(mRegionp->getHost(), retries_factor);
  1037. }
  1038. LLVector3 LLAgent::getVelocity() const
  1039. {
  1040. if (!isAgentAvatarValid())
  1041. {
  1042. return LLVector3::zero;
  1043. }
  1044. return gAgentAvatarp->getVelocity();
  1045. }
  1046. void LLAgent::setPositionAgent(const LLVector3& pos_agent)
  1047. {
  1048. if (!pos_agent.isFinite())
  1049. {
  1050. llwarns << "Got an infinite position. Ignoring." << llendl;
  1051. llassert(false);
  1052. return;
  1053. }
  1054. LLViewerObject* parentp = NULL;
  1055. if (isAgentAvatarValid())
  1056. {
  1057. parentp = (LLViewerObject*)gAgentAvatarp->getParent();
  1058. }
  1059. if (parentp)
  1060. {
  1061. LLVector3 pos_agent_sitting;
  1062. LLVector3d pos_agent_d;
  1063. pos_agent_sitting = gAgentAvatarp->getPosition() *
  1064. parentp->getRotation() +
  1065. parentp->getPositionAgent();
  1066. pos_agent_d.set(pos_agent_sitting);
  1067. mFrameAgent.setOrigin(pos_agent_sitting);
  1068. mPositionGlobal = pos_agent_d + mAgentOriginGlobal;
  1069. }
  1070. else
  1071. {
  1072. mFrameAgent.setOrigin(pos_agent);
  1073. LLVector3d pos_agent_d;
  1074. pos_agent_d.set(pos_agent);
  1075. mPositionGlobal = pos_agent_d + mAgentOriginGlobal;
  1076. }
  1077. }
  1078. void LLAgent::slamLookAt(const LLVector3& look_at)
  1079. {
  1080. LLVector3 look_at_norm = look_at;
  1081. look_at_norm.mV[VZ] = 0.f;
  1082. look_at_norm.normalize();
  1083. resetAxes(look_at_norm);
  1084. }
  1085. boost::signals2::connection LLAgent::setPosChangeCallback(const pos_change_signal_t::slot_type& cb)
  1086. {
  1087. return mPosChangeSignal.connect(cb);
  1088. }
  1089. const LLVector3d& LLAgent::getPositionGlobal() const
  1090. {
  1091. if (isAgentAvatarValid() && gAgentAvatarp->mDrawable.notNull())
  1092. {
  1093. mPositionGlobal =
  1094. getPosGlobalFromAgent(gAgentAvatarp->getRenderPosition());
  1095. }
  1096. else
  1097. {
  1098. mPositionGlobal = getPosGlobalFromAgent(mFrameAgent.getOrigin());
  1099. }
  1100. return mPositionGlobal;
  1101. }
  1102. const LLVector3& LLAgent::getPositionAgent()
  1103. {
  1104. if (isAgentAvatarValid())
  1105. {
  1106. if (gAgentAvatarp->mDrawable.notNull())
  1107. {
  1108. mFrameAgent.setOrigin(gAgentAvatarp->getPositionAgent());
  1109. }
  1110. else
  1111. {
  1112. mFrameAgent.setOrigin(gAgentAvatarp->getRenderPosition());
  1113. }
  1114. }
  1115. return mFrameAgent.getOrigin();
  1116. }
  1117. S32 LLAgent::getRegionsVisited() const
  1118. {
  1119. return mRegionsVisited.size();
  1120. }
  1121. LLVector3 LLAgent::getPosAgentFromGlobal(const LLVector3d &pos_global) const
  1122. {
  1123. LLVector3 pos_agent;
  1124. pos_agent.set(pos_global - mAgentOriginGlobal);
  1125. return pos_agent;
  1126. }
  1127. LLVector3d LLAgent::getPosGlobalFromAgent(const LLVector3& pos_agent) const
  1128. {
  1129. LLVector3d pos_agent_d;
  1130. pos_agent_d.set(pos_agent);
  1131. return pos_agent_d + mAgentOriginGlobal;
  1132. }
  1133. void LLAgent::resetAxes()
  1134. {
  1135. mFrameAgent.resetAxes();
  1136. }
  1137. // Copied from LLCamera::setOriginAndLookAt; look_at must be unit vector.
  1138. void LLAgent::resetAxes(const LLVector3& look_at)
  1139. {
  1140. LLVector3 skyward = getReferenceUpVector();
  1141. // If look_at has zero length or if look_at and skyward are parallel, fail.
  1142. // Test both of these conditions with a cross product.
  1143. LLVector3 cross(look_at % skyward);
  1144. if (cross.isNull())
  1145. {
  1146. LL_DEBUGS("Agent") << "Cross-product is zero. Skipped." << LL_ENDL;
  1147. return;
  1148. }
  1149. // Make sure look_at and skyward are not parallel and neither are 0 length
  1150. LLVector3 left(skyward % look_at);
  1151. LLVector3 up(look_at % left);
  1152. mFrameAgent.setAxes(look_at, left, up);
  1153. }
  1154. void LLAgent::rotate(F32 angle, const LLVector3& axis)
  1155. {
  1156. mFrameAgent.rotate(angle, axis);
  1157. }
  1158. void LLAgent::rotate(F32 angle, F32 x, F32 y, F32 z)
  1159. {
  1160. mFrameAgent.rotate(angle, x, y, z);
  1161. }
  1162. void LLAgent::rotate(const LLMatrix3& matrix)
  1163. {
  1164. mFrameAgent.rotate(matrix);
  1165. }
  1166. void LLAgent::rotate(const LLQuaternion& quaternion)
  1167. {
  1168. mFrameAgent.rotate(quaternion);
  1169. }
  1170. // Returns vector is in the coordinate frame of the avatar's parent object, or
  1171. // the world if none
  1172. LLVector3 LLAgent::getReferenceUpVector()
  1173. {
  1174. LLVector3 up_vector = LLVector3::z_axis;
  1175. LLViewerObject* parentp = NULL;
  1176. if (isAgentAvatarValid() && gAgentAvatarp->mDrawable.notNull())
  1177. {
  1178. parentp = (LLViewerObject*)gAgentAvatarp->getParent();
  1179. }
  1180. if (parentp)
  1181. {
  1182. U32 camera_mode = mCameraAnimating ? mLastCameraMode : mCameraMode;
  1183. // And in third person...
  1184. if (camera_mode == CAMERA_MODE_THIRD_PERSON)
  1185. {
  1186. // Make the up vector point to the absolute +z axis
  1187. up_vector = up_vector * ~(parentp->getRenderRotation());
  1188. }
  1189. else if (camera_mode == CAMERA_MODE_MOUSELOOK)
  1190. {
  1191. // Make the up vector point to the avatar's +z axis
  1192. up_vector = up_vector * gAgentAvatarp->mDrawable->getRotation();
  1193. }
  1194. }
  1195. return up_vector;
  1196. }
  1197. // Radians, positive is forward into ground
  1198. void LLAgent::pitch(F32 angle)
  1199. {
  1200. // Do not let the user pitch if pointed almost all the way down or up
  1201. mFrameAgent.pitch(clampPitchToLimits(angle));
  1202. }
  1203. // Radians, positive is forward into ground
  1204. F32 LLAgent::clampPitchToLimits(F32 angle)
  1205. {
  1206. // A dot B = mag(A) * mag(B) * cosf(angle between A and B)
  1207. // so... cosf(angle between A and B) = A dot B / mag(A) / mag(B)
  1208. // = A dot B for unit vectors
  1209. LLVector3 skyward = getReferenceUpVector();
  1210. F32 look_down_limit;
  1211. F32 look_up_limit = 10.f * DEG_TO_RAD;
  1212. F32 angle_from_skyward = acosf(mFrameAgent.getAtAxis() * skyward);
  1213. if (isAgentAvatarValid() && gAgentAvatarp->mIsSitting)
  1214. {
  1215. look_down_limit = 130.f * DEG_TO_RAD;
  1216. }
  1217. else
  1218. {
  1219. look_down_limit = 170.f * DEG_TO_RAD;
  1220. }
  1221. // Clamp pitch to limits
  1222. if (angle >= 0.f && angle_from_skyward + angle > look_down_limit)
  1223. {
  1224. angle = look_down_limit - angle_from_skyward;
  1225. }
  1226. else if (angle < 0.f && angle_from_skyward + angle < look_up_limit)
  1227. {
  1228. angle = look_up_limit - angle_from_skyward;
  1229. }
  1230. return angle;
  1231. }
  1232. void LLAgent::roll(F32 angle)
  1233. {
  1234. mFrameAgent.roll(angle);
  1235. }
  1236. void LLAgent::yaw(F32 angle)
  1237. {
  1238. if (!rotateGrabbed())
  1239. {
  1240. mFrameAgent.rotate(angle, getReferenceUpVector());
  1241. }
  1242. }
  1243. bool LLAgent::noCameraConstraints()
  1244. {
  1245. static LLCachedControl<bool> no_constraints(gSavedSettings,
  1246. "DisableCameraConstraints");
  1247. return no_constraints
  1248. //MK
  1249. && !(gRLenabled &&
  1250. (gRLInterface.mCamDistMax < EXTREMUM ||
  1251. gRLInterface.mCamDistMin > -EXTREMUM ||
  1252. gRLInterface.mCamZoomMax < EXTREMUM ||
  1253. gRLInterface.mCamZoomMin > -EXTREMUM));
  1254. //mk
  1255. }
  1256. LLVector3 LLAgent::calcFocusOffset(LLViewerObject* object,
  1257. LLVector3 original_focus_point,
  1258. S32 x, S32 y)
  1259. {
  1260. LLVector3 obj_pos = object->getRenderPosition();
  1261. // If it is an avatar or an animesh object, do not do any funky heuristics
  1262. // to position the focal point. See DEV-30589.
  1263. if (!gViewerWindowp || object->isAvatar() ||
  1264. (object->isAnimatedObject() && object->getPuppetAvatar()))
  1265. {
  1266. return original_focus_point - obj_pos;
  1267. }
  1268. const LLMatrix4& obj_matrix = object->getRenderMatrix();
  1269. LLQuaternion obj_rot = object->getRenderRotation();
  1270. LLViewerCamera* camera = &gViewerCamera;
  1271. LLQuaternion inv_obj_rot = ~obj_rot; // get inverse of rotation
  1272. LLVector3 object_extents = object->getScale();
  1273. // Make sure they object extents are non-zero
  1274. object_extents.clamp(0.001f, F32_MAX);
  1275. // obj_to_cam_ray is unit vector pointing from object center to camera, in
  1276. // the coordinate frame of the object
  1277. LLVector3 obj_to_cam_ray = obj_pos - camera->getOrigin();
  1278. obj_to_cam_ray.rotVec(inv_obj_rot);
  1279. obj_to_cam_ray.normalize();
  1280. // obj_to_cam_ray_proportions are the (positive) ratios of
  1281. // the obj_to_cam_ray x,y,z components with the x,y,z object dimensions.
  1282. LLVector3 obj_to_cam_ray_proportions;
  1283. obj_to_cam_ray_proportions.mV[VX] = fabsf(obj_to_cam_ray.mV[VX] /
  1284. object_extents.mV[VX]);
  1285. obj_to_cam_ray_proportions.mV[VY] = fabsf(obj_to_cam_ray.mV[VY] /
  1286. object_extents.mV[VY]);
  1287. obj_to_cam_ray_proportions.mV[VZ] = fabsf(obj_to_cam_ray.mV[VZ] /
  1288. object_extents.mV[VZ]);
  1289. // Find the largest ratio stored in obj_to_cam_ray_proportions.
  1290. // This corresponds to the object's local axial plane (XY, YZ, XZ) that is
  1291. // *most* facing the camera
  1292. LLVector3 longest_object_axis;
  1293. // Is x-axis longest ?
  1294. if (obj_to_cam_ray_proportions.mV[VX] > obj_to_cam_ray_proportions.mV[VY] &&
  1295. obj_to_cam_ray_proportions.mV[VX] > obj_to_cam_ray_proportions.mV[VZ])
  1296. {
  1297. // Then grab it
  1298. longest_object_axis.set(obj_matrix.getFwdRow4());
  1299. }
  1300. // Is y-axis longest ?
  1301. else if (obj_to_cam_ray_proportions.mV[VY] > obj_to_cam_ray_proportions.mV[VZ])
  1302. {
  1303. // Then grab it
  1304. longest_object_axis.set(obj_matrix.getLeftRow4());
  1305. }
  1306. // Otherwise, use z axis
  1307. else
  1308. {
  1309. longest_object_axis.set(obj_matrix.getUpRow4());
  1310. }
  1311. // Use this axis as the normal to project mouse click on to plane with that
  1312. // normal, at the object center.
  1313. // This generates a point behind the mouse cursor that is approximately in
  1314. // the middle of the object in terms of depth.
  1315. // We do this to allow the camera rotation tool to "tumble" the object by
  1316. // rotating the camera.
  1317. // If the focus point were the object surface under the mouse, camera
  1318. // rotation would introduce an undesirable eccentricity to the object
  1319. // orientation
  1320. LLVector3 focus_plane_normal(longest_object_axis);
  1321. focus_plane_normal.normalize();
  1322. LLVector3d focus_pt_global;
  1323. gViewerWindowp->mousePointOnPlaneGlobal(focus_pt_global, x, y,
  1324. getPosGlobalFromAgent(obj_pos),
  1325. focus_plane_normal);
  1326. LLVector3 focus_pt = getPosAgentFromGlobal(focus_pt_global);
  1327. // Find vector from camera to focus point in object space
  1328. LLVector3 camera_to_focus_vec = focus_pt - camera->getOrigin();
  1329. camera_to_focus_vec.rotVec(inv_obj_rot);
  1330. // Find vector from object origin to focus point in object coordinates
  1331. LLVector3 focus_offset_from_object_center = focus_pt - obj_pos;
  1332. // convert to object-local space
  1333. focus_offset_from_object_center.rotVec(inv_obj_rot);
  1334. // We need to project the focus point back into the bounding box of the
  1335. // focused object.
  1336. // Do this by calculating the XYZ scale factors needed to get focus offset
  1337. // back in bounds along the camera_focus axis
  1338. LLVector3 clip_fraction;
  1339. // For each axis...
  1340. for (U32 axis = VX; axis <= VZ; ++axis)
  1341. {
  1342. // Calculate distance that focus offset sits outside of bounding box
  1343. // along that axis. NOTE: dist_out_of_bounds keeps the sign of
  1344. // focus_offset_from_object_center
  1345. F32 dist_out_of_bounds;
  1346. if (focus_offset_from_object_center.mV[axis] > 0.f)
  1347. {
  1348. dist_out_of_bounds = llmax(0.f,
  1349. focus_offset_from_object_center.mV[axis] -
  1350. object_extents.mV[axis] * 0.5f);
  1351. }
  1352. else
  1353. {
  1354. dist_out_of_bounds = llmin(0.f,
  1355. focus_offset_from_object_center.mV[axis] +
  1356. object_extents.mV[axis] * 0.5f);
  1357. }
  1358. // Then calculate the scale factor needed to push camera_to_focus_vec
  1359. // back in bounds along current axis
  1360. if (fabsf(camera_to_focus_vec.mV[axis]) < 0.0001f)
  1361. {
  1362. // don't divide by very small number
  1363. clip_fraction.mV[axis] = 0.f;
  1364. }
  1365. else
  1366. {
  1367. clip_fraction.mV[axis] = dist_out_of_bounds / camera_to_focus_vec.mV[axis];
  1368. }
  1369. }
  1370. LLVector3 abs_clip_fraction = clip_fraction;
  1371. abs_clip_fraction.abs();
  1372. // Find axis of focus offset that is *most* outside the bounding box and
  1373. // use that to rescale focus offset to inside object extents
  1374. if (abs_clip_fraction.mV[VX] > abs_clip_fraction.mV[VY] &&
  1375. abs_clip_fraction.mV[VX] > abs_clip_fraction.mV[VZ])
  1376. {
  1377. focus_offset_from_object_center -= clip_fraction.mV[VX] * camera_to_focus_vec;
  1378. }
  1379. else if (abs_clip_fraction.mV[VY] > abs_clip_fraction.mV[VZ])
  1380. {
  1381. focus_offset_from_object_center -= clip_fraction.mV[VY] * camera_to_focus_vec;
  1382. }
  1383. else
  1384. {
  1385. focus_offset_from_object_center -= clip_fraction.mV[VZ] * camera_to_focus_vec;
  1386. }
  1387. // Convert back to world space
  1388. focus_offset_from_object_center.rotVec(obj_rot);
  1389. // Now, based on distance of camera from object relative to object size
  1390. // push the focus point towards the near surface of the object when
  1391. // (relatively) close to the object or keep the focus point in the object
  1392. // middle when (relatively) far.
  1393. // NOTE: leave focus point in middle of avatars, since the behavior you
  1394. // want when alt-zooming on avatars is almost always "tumble about middle"
  1395. // and not "spin around surface point"
  1396. LLVector3 obj_rel = original_focus_point - object->getRenderPosition();
  1397. // Now that we have the object relative position, we should bias toward the
  1398. // center of the object based on the distance of the camera to the focus
  1399. // point vs. the distance of the camera to the focus.
  1400. F32 relDist = fabsf(obj_rel * camera->getAtAxis());
  1401. F32 viewDist = dist_vec(obj_pos + obj_rel, camera->getOrigin());
  1402. LLBBox obj_bbox = object->getBoundingBoxAgent();
  1403. F32 bias = 0.f;
  1404. // virtual_camera_pos is the camera position we are simulating by backing
  1405. // the camera off and adjusting the FOV
  1406. LLVector3 virtual_camera_pos;
  1407. virtual_camera_pos = getPosAgentFromGlobal(mFocusTargetGlobal +
  1408. (getCameraPositionGlobal() -
  1409. mFocusTargetGlobal) /
  1410. (1.f + mCameraFOVZoomFactor));
  1411. // If the camera is inside the object (large, hollow objects, for example)
  1412. // leave focus point all the way to destination depth, away from object
  1413. // center
  1414. if (!obj_bbox.containsPointAgent(virtual_camera_pos))
  1415. {
  1416. // Perform magic number biasing of focus point towards surface versus
  1417. // planar center
  1418. bias = clamp_rescale(relDist/viewDist, 0.1f, 0.7f, 0.f, 1.f);
  1419. obj_rel = lerp(focus_offset_from_object_center, obj_rel, bias);
  1420. }
  1421. return obj_rel;
  1422. }
  1423. bool LLAgent::calcCameraMinDistance(F32& obj_min_distance)
  1424. {
  1425. if (noCameraConstraints() ||
  1426. !mFocusObject || mFocusObject->isDead() || mFocusObject->isMesh())
  1427. {
  1428. obj_min_distance = 0.f;
  1429. return true;
  1430. }
  1431. // Tells whether the bounding box is to be treated literally (volumes) or
  1432. // as an approximation (avatars)
  1433. bool soft_limit = false;
  1434. if (mFocusObject->mDrawable.isNull())
  1435. {
  1436. llwarns << "Focus object with no drawable !" << llendl;
  1437. #if LL_DEBUG
  1438. mFocusObject->dump();
  1439. llassert(false);
  1440. #endif
  1441. obj_min_distance = 0.f;
  1442. return true;
  1443. }
  1444. LLQuaternion inv_object_rot = ~mFocusObject->getRenderRotation();
  1445. LLVector3 target_offset_origin = mFocusObjectOffset;
  1446. LLVector3 camera_offset_target(getCameraPositionAgent() -
  1447. getPosAgentFromGlobal(mFocusTargetGlobal));
  1448. // convert offsets into object local space
  1449. camera_offset_target.rotVec(inv_object_rot);
  1450. target_offset_origin.rotVec(inv_object_rot);
  1451. // push around object extents based on target offset
  1452. LLVector3 object_extents = mFocusObject->getScale();
  1453. if (mFocusObject->isAvatar())
  1454. {
  1455. // Fudge factors that lets you zoom in on avatars a bit more (which
  1456. // do not do FOV zoom)
  1457. object_extents.mV[VX] *= AVATAR_ZOOM_MIN_X_FACTOR;
  1458. object_extents.mV[VY] *= AVATAR_ZOOM_MIN_Y_FACTOR;
  1459. object_extents.mV[VZ] *= AVATAR_ZOOM_MIN_Z_FACTOR;
  1460. soft_limit = true;
  1461. }
  1462. LLVector3 abs_target_offset = target_offset_origin;
  1463. abs_target_offset.abs();
  1464. LLVector3 target_offset_dir = target_offset_origin;
  1465. bool target_outside_object_extents = false;
  1466. for (U32 i = VX; i <= VZ; ++i)
  1467. {
  1468. if (abs_target_offset.mV[i] * 2.f >
  1469. object_extents.mV[i] + OBJECT_EXTENTS_PADDING)
  1470. {
  1471. target_outside_object_extents = true;
  1472. }
  1473. if (camera_offset_target.mV[i] > 0.f)
  1474. {
  1475. object_extents.mV[i] -= target_offset_origin.mV[i] * 2.f;
  1476. }
  1477. else
  1478. {
  1479. object_extents.mV[i] += target_offset_origin.mV[i] * 2.f;
  1480. }
  1481. }
  1482. // Do not shrink the object extents so far that the object inverts
  1483. object_extents.clamp(0.001f, F32_MAX);
  1484. // Move into first octant
  1485. LLVector3 camera_offset_target_abs_norm = camera_offset_target;
  1486. camera_offset_target_abs_norm.abs();
  1487. // make sure offset is non-zero
  1488. camera_offset_target_abs_norm.clamp(0.001f, F32_MAX);
  1489. camera_offset_target_abs_norm.normalize();
  1490. // Find camera position relative to normalized object extents
  1491. LLVector3 camera_offset_target_scaled = camera_offset_target_abs_norm;
  1492. camera_offset_target_scaled.mV[VX] /= object_extents.mV[VX];
  1493. camera_offset_target_scaled.mV[VY] /= object_extents.mV[VY];
  1494. camera_offset_target_scaled.mV[VZ] /= object_extents.mV[VZ];
  1495. if (camera_offset_target_scaled.mV[VX] > camera_offset_target_scaled.mV[VY] &&
  1496. camera_offset_target_scaled.mV[VX] > camera_offset_target_scaled.mV[VZ])
  1497. {
  1498. if (camera_offset_target_abs_norm.mV[VX] < 0.001f)
  1499. {
  1500. obj_min_distance = object_extents.mV[VX] * 0.5f;
  1501. }
  1502. else
  1503. {
  1504. obj_min_distance = object_extents.mV[VX] *
  1505. 0.5f / camera_offset_target_abs_norm.mV[VX];
  1506. }
  1507. }
  1508. else if (camera_offset_target_scaled.mV[VY] > camera_offset_target_scaled.mV[VZ])
  1509. {
  1510. if (camera_offset_target_abs_norm.mV[VY] < 0.001f)
  1511. {
  1512. obj_min_distance = object_extents.mV[VY] * 0.5f;
  1513. }
  1514. else
  1515. {
  1516. obj_min_distance = object_extents.mV[VY] *
  1517. 0.5f / camera_offset_target_abs_norm.mV[VY];
  1518. }
  1519. }
  1520. else
  1521. {
  1522. if (camera_offset_target_abs_norm.mV[VZ] < 0.001f)
  1523. {
  1524. obj_min_distance = object_extents.mV[VZ] * 0.5f;
  1525. }
  1526. else
  1527. {
  1528. obj_min_distance = object_extents.mV[VZ] *
  1529. 0.5f / camera_offset_target_abs_norm.mV[VZ];
  1530. }
  1531. }
  1532. LLVector3 object_split_axis;
  1533. LLVector3 target_offset_scaled = target_offset_origin;
  1534. target_offset_scaled.abs();
  1535. target_offset_scaled.normalize();
  1536. target_offset_scaled.mV[VX] /= object_extents.mV[VX];
  1537. target_offset_scaled.mV[VY] /= object_extents.mV[VY];
  1538. target_offset_scaled.mV[VZ] /= object_extents.mV[VZ];
  1539. if (target_offset_scaled.mV[VX] > target_offset_scaled.mV[VY] &&
  1540. target_offset_scaled.mV[VX] > target_offset_scaled.mV[VZ])
  1541. {
  1542. object_split_axis = LLVector3::x_axis;
  1543. }
  1544. else if (target_offset_scaled.mV[VY] > target_offset_scaled.mV[VZ])
  1545. {
  1546. object_split_axis = LLVector3::y_axis;
  1547. }
  1548. else
  1549. {
  1550. object_split_axis = LLVector3::z_axis;
  1551. }
  1552. LLVector3 camera_offset_object(getCameraPositionAgent() -
  1553. mFocusObject->getPositionAgent());
  1554. F32 camera_offset_clip = camera_offset_object * object_split_axis;
  1555. F32 target_offset_clip = target_offset_dir * object_split_axis;
  1556. // Target has moved outside of object extents. Check to see if camera and
  1557. // target are on same side.
  1558. if (target_outside_object_extents &&
  1559. ((camera_offset_clip > 0.f && target_offset_clip > 0.f) ||
  1560. (camera_offset_clip < 0.f && target_offset_clip < 0.f)))
  1561. {
  1562. return false;
  1563. }
  1564. // Clamp obj distance to diagonal of 10 by 10 cube
  1565. obj_min_distance = llmin(obj_min_distance, 10.f * F_SQRT3);
  1566. obj_min_distance += gViewerCamera.getNear() + (soft_limit ? 0.1f : 0.2f);
  1567. return true;
  1568. }
  1569. F32 LLAgent::getCameraZoomFraction()
  1570. {
  1571. // 0.f: camera zoomed all the way out; 1.f: camera zoomed all the way in
  1572. LLObjectSelectionHandle selection = gSelectMgr.getSelection();
  1573. if (selection->getObjectCount() &&
  1574. selection->getSelectType() == SELECT_TYPE_HUD)
  1575. {
  1576. // Already [0,1]
  1577. return mHUDTargetZoom;
  1578. }
  1579. if (mFocusOnAvatar && cameraThirdPerson())
  1580. {
  1581. return clamp_rescale(mCameraZoomFraction, MIN_ZOOM_FRACTION,
  1582. MAX_ZOOM_FRACTION, 1.f, 0.f);
  1583. }
  1584. if (cameraCustomizeAvatar())
  1585. {
  1586. F32 distance = (F32)mCameraFocusOffsetTarget.length();
  1587. return clamp_rescale(distance, APPEARANCE_MIN_ZOOM,
  1588. APPEARANCE_MAX_ZOOM, 1.f, 0.f);
  1589. }
  1590. F32 distance = (F32)mCameraFocusOffsetTarget.length();
  1591. constexpr F32 DIST_FUDGE = 16.f; // In meters
  1592. F32 region_with = mRegionp ? mRegionp->getWidth() : REGION_WIDTH_METERS;
  1593. F32 max_zoom = llmin(mDrawDistance - DIST_FUDGE, region_with - DIST_FUDGE,
  1594. MAX_CAMERA_DISTANCE_FROM_AGENT);
  1595. F32 min_zoom;
  1596. if (mFocusObject.notNull())
  1597. {
  1598. if (mFocusObject->isAvatar())
  1599. {
  1600. min_zoom = AVATAR_MIN_ZOOM;
  1601. }
  1602. else
  1603. {
  1604. min_zoom = OBJECT_MIN_ZOOM;
  1605. }
  1606. }
  1607. else
  1608. {
  1609. min_zoom = LAND_MIN_ZOOM;
  1610. }
  1611. return clamp_rescale(distance, min_zoom, max_zoom, 1.f, 0.f);
  1612. }
  1613. // fraction == 0.f for camera zoomed all the way out, 1.f for camera zoomed all
  1614. // the way in
  1615. void LLAgent::setCameraZoomFraction(F32 fraction)
  1616. {
  1617. LLObjectSelectionHandle selection = gSelectMgr.getSelection();
  1618. if (selection->getObjectCount() &&
  1619. selection->getSelectType() == SELECT_TYPE_HUD)
  1620. {
  1621. mHUDTargetZoom = fraction;
  1622. // Clamp target zoom level to reasonable values
  1623. //MK
  1624. if (gRLenabled && gRLInterface.mHasLockedHuds)
  1625. {
  1626. mHUDTargetZoom = llclamp(mHUDTargetZoom, 0.85f, 1.f);
  1627. }
  1628. else
  1629. //mk
  1630. {
  1631. mHUDTargetZoom = llclamp(mHUDTargetZoom, 0.1f, 1.f);
  1632. }
  1633. }
  1634. else if (mFocusOnAvatar && cameraThirdPerson())
  1635. {
  1636. mCameraZoomFraction = rescale(fraction, 0.f, 1.f,
  1637. MAX_ZOOM_FRACTION, MIN_ZOOM_FRACTION);
  1638. }
  1639. else if (cameraCustomizeAvatar())
  1640. {
  1641. LLVector3d camera_offset_dir = mCameraFocusOffsetTarget;
  1642. camera_offset_dir.normalize();
  1643. mCameraFocusOffsetTarget = camera_offset_dir *
  1644. rescale(fraction, 0.f, 1.f,
  1645. APPEARANCE_MAX_ZOOM,
  1646. APPEARANCE_MIN_ZOOM);
  1647. }
  1648. else
  1649. {
  1650. constexpr F32 DIST_FUDGE = 16.f; // meters
  1651. F32 region_with = mRegionp ? mRegionp->getWidth()
  1652. : REGION_WIDTH_METERS;
  1653. F32 max_zoom = llmin(mDrawDistance - DIST_FUDGE,
  1654. region_with - DIST_FUDGE,
  1655. MAX_CAMERA_DISTANCE_FROM_AGENT);
  1656. F32 min_zoom = LAND_MIN_ZOOM;
  1657. if (noCameraConstraints())
  1658. {
  1659. min_zoom = 0.f;
  1660. }
  1661. else if (mFocusObject.notNull())
  1662. {
  1663. if (mFocusObject->isAvatar())
  1664. {
  1665. min_zoom = AVATAR_MIN_ZOOM;
  1666. }
  1667. else
  1668. {
  1669. min_zoom = OBJECT_MIN_ZOOM;
  1670. }
  1671. }
  1672. LLVector3d camera_offset_dir = mCameraFocusOffsetTarget;
  1673. camera_offset_dir.normalize();
  1674. mCameraFocusOffsetTarget = camera_offset_dir *
  1675. rescale(fraction, 0.f, 1.f, max_zoom,
  1676. min_zoom);
  1677. }
  1678. startCameraAnimation();
  1679. }
  1680. void LLAgent::cameraOrbitAround(F32 radians)
  1681. {
  1682. LLObjectSelectionHandle selection = gSelectMgr.getSelection();
  1683. if (selection->getObjectCount() &&
  1684. selection->getSelectType() == SELECT_TYPE_HUD)
  1685. {
  1686. // Do nothing for hud selection
  1687. return;
  1688. }
  1689. if (mFocusOnAvatar &&
  1690. (mCameraMode == CAMERA_MODE_THIRD_PERSON ||
  1691. mCameraMode == CAMERA_MODE_FOLLOW))
  1692. {
  1693. mFrameAgent.rotate(radians, getReferenceUpVector());
  1694. }
  1695. else
  1696. {
  1697. mCameraFocusOffsetTarget.rotVec(radians, 0.f, 0.f, 1.f);
  1698. cameraZoomIn(1.f);
  1699. }
  1700. }
  1701. void LLAgent::cameraOrbitOver(F32 angle)
  1702. {
  1703. LLObjectSelectionHandle selection = gSelectMgr.getSelection();
  1704. if (selection->getObjectCount() &&
  1705. selection->getSelectType() == SELECT_TYPE_HUD)
  1706. {
  1707. // Do nothing for hud selection
  1708. }
  1709. else if (mFocusOnAvatar && mCameraMode == CAMERA_MODE_THIRD_PERSON)
  1710. {
  1711. pitch(angle);
  1712. }
  1713. else
  1714. {
  1715. LLVector3 camera_offset_unit(mCameraFocusOffsetTarget);
  1716. camera_offset_unit.normalize();
  1717. F32 angle_from_up = acosf(camera_offset_unit * getReferenceUpVector());
  1718. LLVector3d left_axis;
  1719. left_axis.set(gViewerCamera.getLeftAxis());
  1720. F32 new_angle = llclamp(angle_from_up - angle, 1.f * DEG_TO_RAD,
  1721. 179.f * DEG_TO_RAD);
  1722. mCameraFocusOffsetTarget.rotVec(angle_from_up - new_angle, left_axis);
  1723. cameraZoomIn(1.f);
  1724. }
  1725. }
  1726. void LLAgent::cameraZoomIn(F32 fraction)
  1727. {
  1728. if (gDisconnected)
  1729. {
  1730. return;
  1731. }
  1732. LLObjectSelectionHandle selection = gSelectMgr.getSelection();
  1733. if (selection->getObjectCount() &&
  1734. selection->getSelectType() == SELECT_TYPE_HUD &&
  1735. gToolMgr.inBuildMode())
  1736. {
  1737. // Just update hud zoom level
  1738. mHUDTargetZoom /= fraction;
  1739. return;
  1740. }
  1741. LLVector3d camera_offset_unit(mCameraFocusOffsetTarget);
  1742. F32 min_zoom = LAND_MIN_ZOOM;
  1743. F32 current_distance = (F32)camera_offset_unit.normalize();
  1744. F32 new_distance = current_distance * fraction;
  1745. bool camera_constraints = !noCameraConstraints();
  1746. if (camera_constraints)
  1747. {
  1748. // Do not move through focus point
  1749. if (mFocusObject)
  1750. {
  1751. min_zoom = OBJECT_MIN_ZOOM;
  1752. if (mFocusObject->isAvatar())
  1753. {
  1754. calcCameraMinDistance(min_zoom);
  1755. }
  1756. }
  1757. new_distance = llmax(new_distance, min_zoom);
  1758. }
  1759. // Do not zoom too far back
  1760. F32 max_distance;
  1761. if (camera_constraints)
  1762. {
  1763. F32 region_with = mRegionp ? mRegionp->getWidth()
  1764. : REGION_WIDTH_METERS;
  1765. max_distance = llmin(mDrawDistance, region_with);
  1766. }
  1767. else
  1768. {
  1769. max_distance = 4096.f;
  1770. }
  1771. if (new_distance > max_distance)
  1772. {
  1773. new_distance = max_distance;
  1774. }
  1775. if (cameraCustomizeAvatar())
  1776. {
  1777. new_distance = llclamp(new_distance, APPEARANCE_MIN_ZOOM,
  1778. APPEARANCE_MAX_ZOOM);
  1779. }
  1780. mCameraFocusOffsetTarget = new_distance * camera_offset_unit;
  1781. }
  1782. void LLAgent::cameraOrbitIn(F32 meters)
  1783. {
  1784. //MK
  1785. // If we have to force the camera distance because of RLV restrictions,
  1786. // don't do anything else
  1787. if (gRLenabled && !gRLInterface.checkCameraLimits(true))
  1788. {
  1789. return;
  1790. }
  1791. //mk
  1792. if (mFocusOnAvatar && mCameraMode == CAMERA_MODE_THIRD_PERSON)
  1793. {
  1794. static LLCachedControl<F32> camera_offset_scale(gSavedSettings,
  1795. "CameraOffsetScale");
  1796. F32 camera_offset_dist = llmax(0.001f,
  1797. mCameraOffsetDefault.length() *
  1798. (F32)camera_offset_scale);
  1799. mCameraZoomFraction = (mTargetCameraDistance - meters) /
  1800. camera_offset_dist;
  1801. if (!LLPipeline::sFreezeTime &&
  1802. mCameraZoomFraction < MIN_ZOOM_FRACTION && meters > 0.f)
  1803. {
  1804. // No need to animate, camera is already there.
  1805. changeCameraToMouselook(false);
  1806. }
  1807. mCameraZoomFraction = llclamp(mCameraZoomFraction,
  1808. MIN_ZOOM_FRACTION, MAX_ZOOM_FRACTION);
  1809. }
  1810. else
  1811. {
  1812. LLVector3d camera_offset_unit(mCameraFocusOffsetTarget);
  1813. F32 current_distance = (F32)camera_offset_unit.normalize();
  1814. F32 new_distance = current_distance - meters;
  1815. F32 min_zoom = LAND_MIN_ZOOM;
  1816. // Do not move through focus point
  1817. if (mFocusObject.notNull())
  1818. {
  1819. if (mFocusObject->isAvatar())
  1820. {
  1821. min_zoom = AVATAR_MIN_ZOOM;
  1822. }
  1823. else
  1824. {
  1825. min_zoom = OBJECT_MIN_ZOOM;
  1826. }
  1827. }
  1828. new_distance = llmax(new_distance, min_zoom);
  1829. // Unless camera is unconstrained
  1830. if (!noCameraConstraints())
  1831. {
  1832. // Do not zoom too far back
  1833. constexpr F32 DIST_FUDGE = 16.f; // meters
  1834. F32 region_with = mRegionp ? mRegionp->getWidth()
  1835. : REGION_WIDTH_METERS;
  1836. F32 max_distance = llmin(mDrawDistance - DIST_FUDGE,
  1837. region_with - DIST_FUDGE);
  1838. if (new_distance > max_distance)
  1839. {
  1840. new_distance = max_distance;
  1841. }
  1842. // Appearance editing mode constraints
  1843. if (mCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR)
  1844. {
  1845. new_distance = llclamp(new_distance, APPEARANCE_MIN_ZOOM,
  1846. APPEARANCE_MAX_ZOOM);
  1847. }
  1848. }
  1849. // Compute new camera offset
  1850. mCameraFocusOffsetTarget = new_distance * camera_offset_unit;
  1851. cameraZoomIn(1.f);
  1852. }
  1853. }
  1854. void LLAgent::cameraPanIn(F32 meters)
  1855. {
  1856. LLVector3d at_axis;
  1857. at_axis.set(gViewerCamera.getAtAxis());
  1858. mFocusTargetGlobal += meters * at_axis;
  1859. mFocusGlobal = mFocusTargetGlobal;
  1860. // Do not enforce zoom constraints as this is the only way for users to get
  1861. // past them easily
  1862. updateFocusOffset();
  1863. // NOTE: panning movements expect the camera to move exactly with the focus
  1864. // target, not animated behind -Nyx
  1865. mCameraSmoothingLastPositionGlobal = calcCameraPositionTargetGlobal();
  1866. }
  1867. void LLAgent::cameraPanLeft(F32 meters)
  1868. {
  1869. LLVector3d left_axis;
  1870. left_axis.set(gViewerCamera.getLeftAxis());
  1871. mFocusTargetGlobal += meters * left_axis;
  1872. mFocusGlobal = mFocusTargetGlobal;
  1873. // Disable smoothing for camera pan
  1874. mCameraSmoothingStop = true;
  1875. cameraZoomIn(1.f);
  1876. updateFocusOffset();
  1877. // NOTE: panning movements expect the camera to move exactly with the focus
  1878. // target, not animated behind - Nyx
  1879. mCameraSmoothingLastPositionGlobal = calcCameraPositionTargetGlobal();
  1880. }
  1881. void LLAgent::cameraPanUp(F32 meters)
  1882. {
  1883. LLVector3d up_axis;
  1884. up_axis.set(gViewerCamera.getUpAxis());
  1885. mFocusTargetGlobal += meters * up_axis;
  1886. mFocusGlobal = mFocusTargetGlobal;
  1887. // Disable smoothing for camera pan
  1888. mCameraSmoothingStop = true;
  1889. cameraZoomIn(1.f);
  1890. updateFocusOffset();
  1891. // NOTE: panning movements expect the camera to move exactly with the focus
  1892. // target, not animated behind -Nyx
  1893. mCameraSmoothingLastPositionGlobal = calcCameraPositionTargetGlobal();
  1894. }
  1895. void LLAgent::setKey(S32 direction, S32& key)
  1896. {
  1897. if (direction > 0)
  1898. {
  1899. key = 1;
  1900. }
  1901. else if (direction < 0)
  1902. {
  1903. key = -1;
  1904. }
  1905. else
  1906. {
  1907. key = 0;
  1908. }
  1909. }
  1910. void LLAgent::setControlFlags(U32 mask)
  1911. {
  1912. U32 old_flags = mControlFlags;
  1913. mControlFlags |= mask;
  1914. mFlagsDirty = mControlFlags != old_flags;
  1915. if (mask & AGENT_CONTROL_SIT_ON_GROUND)
  1916. {
  1917. mSittingOnGround = true;
  1918. }
  1919. else if (mask & AGENT_CONTROL_STAND_UP)
  1920. {
  1921. mSittingOnGround = false;
  1922. }
  1923. }
  1924. void LLAgent::clearControlFlags(U32 mask)
  1925. {
  1926. U32 old_flags = mControlFlags;
  1927. mControlFlags &= ~mask;
  1928. if (old_flags != mControlFlags)
  1929. {
  1930. mFlagsDirty = true;
  1931. }
  1932. }
  1933. void LLAgent::resetControlFlags()
  1934. {
  1935. if (mFlagsNeedReset)
  1936. {
  1937. mFlagsNeedReset = false;
  1938. mFlagsDirty = false;
  1939. // Reset all of the ephemeral flags; some flags are managed elsewhere
  1940. mControlFlags &= AGENT_CONTROL_AWAY | AGENT_CONTROL_FLY |
  1941. AGENT_CONTROL_MOUSELOOK;
  1942. }
  1943. }
  1944. void LLAgent::setAFK()
  1945. {
  1946. if (!mRegionp)
  1947. {
  1948. // Do not set AFK if we are not talking to a region yet.
  1949. return;
  1950. }
  1951. if (!(mControlFlags & AGENT_CONTROL_AWAY))
  1952. {
  1953. sendAnimationRequest(ANIM_AGENT_AWAY, ANIM_REQUEST_START);
  1954. setControlFlags(AGENT_CONTROL_AWAY | AGENT_CONTROL_STOP);
  1955. gAwayTimer.start();
  1956. if (gAutomationp)
  1957. {
  1958. gAutomationp->onAgentOccupationChange(1);
  1959. }
  1960. }
  1961. }
  1962. void LLAgent::clearAFK()
  1963. {
  1964. gAwayTriggerTimer.reset();
  1965. // Gods can sometimes get into away state (via gestures) without setting
  1966. // the appropriate control flag. JC
  1967. if (mControlFlags & AGENT_CONTROL_AWAY ||
  1968. (isAgentAvatarValid() &&
  1969. gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AWAY) !=
  1970. gAgentAvatarp->mSignaledAnimations.end()))
  1971. {
  1972. sendAnimationRequest(ANIM_AGENT_AWAY, ANIM_REQUEST_STOP);
  1973. clearControlFlags(AGENT_CONTROL_AWAY);
  1974. if (gAutomationp && !mIsBusy && !mIsAutoReplying)
  1975. {
  1976. gAutomationp->onAgentOccupationChange(0);
  1977. }
  1978. }
  1979. }
  1980. void LLAgent::setBusy()
  1981. {
  1982. mIsBusy = true;
  1983. sendAnimationRequest(ANIM_AGENT_BUSY, ANIM_REQUEST_START);
  1984. clearAutoReply();
  1985. if (gAutomationp)
  1986. {
  1987. gAutomationp->onAgentOccupationChange(2);
  1988. }
  1989. }
  1990. void LLAgent::clearBusy()
  1991. {
  1992. mIsBusy = false;
  1993. sendAnimationRequest(ANIM_AGENT_BUSY, ANIM_REQUEST_STOP);
  1994. if (gAutomationp && !mIsAutoReplying && !getAFK())
  1995. {
  1996. gAutomationp->onAgentOccupationChange(0);
  1997. }
  1998. }
  1999. void LLAgent::setAutoReply()
  2000. {
  2001. mIsAutoReplying = true;
  2002. clearBusy();
  2003. if (gAutomationp)
  2004. {
  2005. gAutomationp->onAgentOccupationChange(3);
  2006. }
  2007. }
  2008. void LLAgent::clearAutoReply()
  2009. {
  2010. mIsAutoReplying = false;
  2011. if (gAutomationp && !mIsBusy && !getAFK())
  2012. {
  2013. gAutomationp->onAgentOccupationChange(0);
  2014. }
  2015. }
  2016. void LLAgent::propagate(F32 dt)
  2017. {
  2018. // Update UI based on agent motion
  2019. LLFloaterMove* floaterp = LLFloaterMove::getInstance();
  2020. if (floaterp)
  2021. {
  2022. floaterp->mForwardButton->setToggleState(mAtKey > 0 || mWalkKey > 0);
  2023. floaterp->mBackwardButton->setToggleState(mAtKey < 0 || mWalkKey < 0);
  2024. floaterp->mSlideLeftButton->setToggleState(mLeftKey > 0);
  2025. floaterp->mSlideRightButton->setToggleState(mLeftKey < 0);
  2026. floaterp->mTurnLeftButton->setToggleState(mYawKey > 0.f);
  2027. floaterp->mTurnRightButton->setToggleState(mYawKey < 0.f);
  2028. floaterp->mMoveUpButton->setToggleState(mUpKey > 0);
  2029. floaterp->mMoveDownButton->setToggleState(mUpKey < 0);
  2030. }
  2031. // Handle rotation based on keyboard levels
  2032. constexpr F32 YAW_RATE = 90.f * DEG_TO_RAD; // Radians per second
  2033. yaw(YAW_RATE * mYawKey * dt);
  2034. constexpr F32 PITCH_RATE = 90.f * DEG_TO_RAD; // Radians per second
  2035. pitch(PITCH_RATE * (F32) mPitchKey * dt);
  2036. // Handle auto-land behavior
  2037. static LLCachedControl<bool> automatic_fly(gSavedSettings, "AutomaticFly");
  2038. if (automatic_fly && mUpKey < 0 && isAgentAvatarValid() &&
  2039. !gAgentAvatarp->mInAir)
  2040. {
  2041. LLVector3 land_vel = getVelocity();
  2042. land_vel.mV[VZ] = 0.f;
  2043. if (land_vel.lengthSquared() < MAX_VELOCITY_AUTO_LAND_SQUARED)
  2044. {
  2045. // Land automatically
  2046. setFlying(false);
  2047. }
  2048. }
  2049. // Clear keys
  2050. mAtKey = mWalkKey = mLeftKey = mUpKey = mPitchKey = 0;
  2051. mYawKey = 0.f;
  2052. }
  2053. void LLAgent::checkPositionChanged()
  2054. {
  2055. LLVector3d global_pos = getPositionGlobal();
  2056. if (!mLastPositionGlobal.isExactlyZero())
  2057. {
  2058. LLVector3d delta = global_pos - mLastPositionGlobal;
  2059. // Update the travel distance stat.
  2060. mDistanceTraveled += delta.length();
  2061. // Send the "position changed signal" if the position changed
  2062. // by more than 3 meters, and throttle the signals by limiting
  2063. // them to one every 10 seconds.
  2064. if ((mLastPosGlobalTest - global_pos).lengthSquared() > 9.0 &&
  2065. gFrameTimeSeconds - mLastPosGlobalSignaled > 10.f)
  2066. {
  2067. mLastPosGlobalSignaled = gFrameTimeSeconds;
  2068. mLastPosGlobalTest = mPositionGlobal;
  2069. // Send the signal to registered callbacks.
  2070. mPosChangeSignal(mFrameAgent.getOrigin(), global_pos);
  2071. // Not registered as a signal, because we want to update the
  2072. // history regardless of an automation script usage (e.g. to
  2073. // get it from LSL scripts). We call it on purpose *after* we
  2074. // called the signals, which may include the signal callback used
  2075. // to trigger in its turn the OnPositionChange() Lua callback (see
  2076. // this callback documentation in the viewer Lua manual). HB
  2077. HBViewerAutomation::addToAgentPosHistory(global_pos);
  2078. }
  2079. }
  2080. mLastPositionGlobal = global_pos;
  2081. }
  2082. void LLAgent::updateAgentPosition(F32 dt, F32 yaw_radians, S32 mouse_x,
  2083. S32 mouse_y)
  2084. {
  2085. propagate(dt);
  2086. rotate(yaw_radians, 0.f, 0.f, 1.f);
  2087. // Check for water and land collision, set underwater flag
  2088. updateLookAt(mouse_x, mouse_y);
  2089. // When agent has no parent, position updates come from setPositionAgent()
  2090. // but when agent is seated (i.e. it is parented to the seat object), the
  2091. // position remains unchanged relative to parent and no parent's position
  2092. // update trigger setPositionAgent(); in this case we therefore need to
  2093. // check for a change in position here.
  2094. if (isAgentAvatarValid() && gAgentAvatarp->getParent())
  2095. {
  2096. checkPositionChanged();
  2097. }
  2098. }
  2099. void LLAgent::updateLookAt(S32 mouse_x, S32 mouse_y)
  2100. {
  2101. static LLVector3 last_at_axis;
  2102. if (!isAgentAvatarValid()) // Also true when gViewerWindowp is NULL
  2103. {
  2104. return;
  2105. }
  2106. LLVector3 root_at = LLVector3::x_axis *
  2107. gAgentAvatarp->mRoot->getWorldRotation();
  2108. if (LLViewerWindow::getMouseVelocityStat().getCurrent() < 0.01f &&
  2109. root_at * last_at_axis > 0.95f)
  2110. {
  2111. LLQuaternion av_inv_rot = ~gAgentAvatarp->mRoot->getWorldRotation();
  2112. LLVector3 vel = gAgentAvatarp->getVelocity();
  2113. if (vel.lengthSquared() > 4.f)
  2114. {
  2115. setLookAt(LOOKAT_TARGET_IDLE, gAgentAvatarp, vel * av_inv_rot);
  2116. }
  2117. else
  2118. {
  2119. // *FIX: rotate mFrameAgent by sit object's rotation ?
  2120. // Use the camera current rotation
  2121. LLQuaternion look_rotation =
  2122. gAgentAvatarp->mIsSitting ? gAgentAvatarp->getRenderRotation()
  2123. : mFrameAgent.getQuaternion();
  2124. LLVector3 look_offset = LLVector3(2.f, 0.f, 0.f) *
  2125. look_rotation * av_inv_rot;
  2126. setLookAt(LOOKAT_TARGET_IDLE, gAgentAvatarp, look_offset);
  2127. }
  2128. last_at_axis = root_at;
  2129. return;
  2130. }
  2131. last_at_axis = root_at;
  2132. if (mCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR)
  2133. {
  2134. setLookAt(LOOKAT_TARGET_NONE, gAgentAvatarp,
  2135. LLVector3(-2.f, 0.f, 0.f));
  2136. }
  2137. else
  2138. {
  2139. // Move head based on cursor position
  2140. ELookAtType lookat_type = LOOKAT_TARGET_NONE;
  2141. LLCoordFrame cam_frame = (LLCoordFrame)gViewerCamera;
  2142. if (cameraMouselook())
  2143. {
  2144. lookat_type = LOOKAT_TARGET_MOUSELOOK;
  2145. }
  2146. else if (cameraThirdPerson())
  2147. {
  2148. // Range from -.5 to .5
  2149. F32 x_from_center = (F32)mouse_x /
  2150. (F32)gViewerWindowp->getWindowWidth() - 0.5f;
  2151. F32 y_from_center = (F32)mouse_y /
  2152. (F32)gViewerWindowp->getWindowHeight() - 0.5f;
  2153. static LLCachedControl<bool> eyes_follow_mouse(gSavedSettings,
  2154. "EyesFollowMousePointer");
  2155. static LLCachedControl<F32> yaw_from_mouse_position(gSavedSettings,
  2156. "YawFromMousePosition");
  2157. static LLCachedControl<F32> pitch_from_mouse_position(gSavedSettings,
  2158. "PitchFromMousePosition");
  2159. if (eyes_follow_mouse)
  2160. {
  2161. cam_frame.yaw(-x_from_center * yaw_from_mouse_position *
  2162. DEG_TO_RAD);
  2163. cam_frame.pitch(-y_from_center * pitch_from_mouse_position *
  2164. DEG_TO_RAD);
  2165. }
  2166. lookat_type = LOOKAT_TARGET_FREELOOK;
  2167. }
  2168. LLVector3 head_look_axis = cam_frame.getAtAxis();
  2169. #if 0 // RN: we use world-space offset for mouselook and freelook
  2170. LLQuaternion av_inv_rot = ~gAgentAvatarp->mRoot->getWorldRotation();
  2171. head_look_axis = head_look_axis * av_inv_rot;
  2172. #endif
  2173. setLookAt(lookat_type, gAgentAvatarp, head_look_axis);
  2174. }
  2175. }
  2176. std::ostream& operator<<(std::ostream& s, const LLAgent& agent)
  2177. {
  2178. // This is unfinished, but might never be used. We will just leave it for
  2179. // now; we can always delete it.
  2180. s << " { " << " Frame = " << agent.mFrameAgent << "\n" << " }";
  2181. return s;
  2182. }
  2183. void LLAgent::setAvatarObject(LLVOAvatarSelf* avatar)
  2184. {
  2185. if (!avatar)
  2186. {
  2187. llinfos << "NULL agent pointer passed: ignoring." << llendl;
  2188. return;
  2189. }
  2190. if (!mLookAt)
  2191. {
  2192. mLookAt =
  2193. (LLHUDEffectLookAt*)LLHUDManager::createEffect(LLHUDObject::LL_HUD_EFFECT_LOOKAT);
  2194. }
  2195. if (!mPointAt)
  2196. {
  2197. mPointAt =
  2198. (LLHUDEffectPointAt*)LLHUDManager::createEffect(LLHUDObject::LL_HUD_EFFECT_POINTAT);
  2199. }
  2200. if (mLookAt.notNull())
  2201. {
  2202. mLookAt->setSourceObject(avatar);
  2203. }
  2204. if (mPointAt.notNull())
  2205. {
  2206. mPointAt->setSourceObject(avatar);
  2207. }
  2208. }
  2209. // Returns true if your own avatar needs to be rendered. Usually only in third
  2210. // person and build.
  2211. bool LLAgent::needsRenderAvatar()
  2212. {
  2213. if (cameraMouselook() && !LLVOAvatar::sVisibleInFirstPerson)
  2214. {
  2215. return false;
  2216. }
  2217. return mShowAvatar && mGenderChosen;
  2218. }
  2219. bool LLAgent::needsRenderHead()
  2220. {
  2221. return (mShowAvatar && !cameraMouselook()) ||
  2222. (LLVOAvatar::sVisibleInFirstPerson &&
  2223. LLPipeline::sReflectionRender);
  2224. }
  2225. void LLAgent::startTyping()
  2226. {
  2227. mTypingTimer.reset();
  2228. if (getRenderState() & AGENT_STATE_TYPING)
  2229. {
  2230. // Already typing, so do not trigger a different animation
  2231. return;
  2232. }
  2233. setRenderState(AGENT_STATE_TYPING);
  2234. if (mChatTimer.getElapsedTimeF32() < 2.f)
  2235. {
  2236. LLVOAvatar* chatter = gObjectList.findAvatar(mLastChatterID);
  2237. if (chatter)
  2238. {
  2239. setLookAt(LOOKAT_TARGET_RESPOND, chatter, LLVector3::zero);
  2240. }
  2241. }
  2242. if (gSavedSettings.getBool("PlayTypingAnim"))
  2243. {
  2244. sendAnimationRequest(ANIM_AGENT_TYPE, ANIM_REQUEST_START);
  2245. }
  2246. if (gChatBarp)
  2247. {
  2248. gChatBarp->sendChatFromViewer("", CHAT_TYPE_START, false);
  2249. }
  2250. }
  2251. void LLAgent::stopTyping()
  2252. {
  2253. if (mRenderState & AGENT_STATE_TYPING)
  2254. {
  2255. clearRenderState(AGENT_STATE_TYPING);
  2256. sendAnimationRequest(ANIM_AGENT_TYPE, ANIM_REQUEST_STOP);
  2257. if (gChatBarp)
  2258. {
  2259. gChatBarp->sendChatFromViewer("", CHAT_TYPE_STOP, false);
  2260. }
  2261. }
  2262. }
  2263. void LLAgent::setRenderState(U8 newstate)
  2264. {
  2265. mRenderState |= newstate;
  2266. }
  2267. void LLAgent::clearRenderState(U8 clearstate)
  2268. {
  2269. mRenderState &= ~clearstate;
  2270. }
  2271. U8 LLAgent::getRenderState()
  2272. {
  2273. if (!gKeyboardp)
  2274. {
  2275. return 0;
  2276. }
  2277. // *FIX: do not do stuff in a getter ! This is infinite loop city !
  2278. if (mTypingTimer.getElapsedTimeF32() > TYPING_TIMEOUT_SECS &&
  2279. (mRenderState & AGENT_STATE_TYPING))
  2280. {
  2281. stopTyping();
  2282. }
  2283. if ((!gSelectMgr.getSelection()->isEmpty() &&
  2284. gSelectMgr.shouldShowSelection()) ||
  2285. gToolMgr.getCurrentTool()->isEditing())
  2286. {
  2287. setRenderState(AGENT_STATE_EDITING);
  2288. }
  2289. else
  2290. {
  2291. clearRenderState(AGENT_STATE_EDITING);
  2292. }
  2293. return mRenderState;
  2294. }
  2295. static const LLFloaterView::skip_list_t& get_skip_list()
  2296. {
  2297. static LLFloaterView::skip_list_t skip_list;
  2298. skip_list.insert(LLFloaterMiniMap::getInstance());
  2299. return skip_list;
  2300. }
  2301. void LLAgent::endAnimationUpdateUI()
  2302. {
  2303. if (mCameraMode == mLastCameraMode)
  2304. {
  2305. // We are already done endAnimationUpdateUI for this transition.
  2306. return;
  2307. }
  2308. // Clean up UI from mode we are leaving
  2309. if (mLastCameraMode == CAMERA_MODE_MOUSELOOK)
  2310. {
  2311. // Show mouse cursor
  2312. if (gViewerWindowp)
  2313. {
  2314. gViewerWindowp->showCursor();
  2315. }
  2316. // Show menus
  2317. if (gMenuBarViewp)
  2318. {
  2319. gMenuBarViewp->setVisible(true);
  2320. }
  2321. if (gStatusBarp)
  2322. {
  2323. gStatusBarp->setVisibleForMouselook(true);
  2324. }
  2325. gToolMgr.setCurrentToolset(gBasicToolset);
  2326. // Only pop if we have pushed...
  2327. if (mViewsPushed)
  2328. {
  2329. mViewsPushed = false;
  2330. if (gFloaterViewp)
  2331. {
  2332. gFloaterViewp->popVisibleAll(get_skip_list());
  2333. }
  2334. }
  2335. setLookAt(LOOKAT_TARGET_CLEAR);
  2336. if (gMorphViewp)
  2337. {
  2338. gMorphViewp->setVisible(false);
  2339. }
  2340. // Disable mouselook-specific animations
  2341. if (isAgentAvatarValid() &&
  2342. gAgentAvatarp->isAnyAnimationSignaled(AGENT_GUN_AIM_ANIMS,
  2343. NUM_AGENT_GUN_AIM_ANIMS))
  2344. {
  2345. const LLVOAvatar::anim_map_t& anims =
  2346. gAgentAvatarp->mSignaledAnimations;
  2347. LLVOAvatar::anim_it_t end =
  2348. gAgentAvatarp->mSignaledAnimations.end();
  2349. if (anims.find(ANIM_AGENT_AIM_RIFLE_R) != end)
  2350. {
  2351. sendAnimationRequest(ANIM_AGENT_AIM_RIFLE_R,
  2352. ANIM_REQUEST_STOP);
  2353. sendAnimationRequest(ANIM_AGENT_HOLD_RIFLE_R,
  2354. ANIM_REQUEST_START);
  2355. }
  2356. if (anims.find(ANIM_AGENT_AIM_HANDGUN_R) != end)
  2357. {
  2358. sendAnimationRequest(ANIM_AGENT_AIM_HANDGUN_R,
  2359. ANIM_REQUEST_STOP);
  2360. sendAnimationRequest(ANIM_AGENT_HOLD_HANDGUN_R,
  2361. ANIM_REQUEST_START);
  2362. }
  2363. if (anims.find(ANIM_AGENT_AIM_BAZOOKA_R) != end)
  2364. {
  2365. sendAnimationRequest(ANIM_AGENT_AIM_BAZOOKA_R,
  2366. ANIM_REQUEST_STOP);
  2367. sendAnimationRequest(ANIM_AGENT_HOLD_BAZOOKA_R,
  2368. ANIM_REQUEST_START);
  2369. }
  2370. if (anims.find(ANIM_AGENT_AIM_BOW_L) != end)
  2371. {
  2372. sendAnimationRequest(ANIM_AGENT_AIM_BOW_L,
  2373. ANIM_REQUEST_STOP);
  2374. sendAnimationRequest(ANIM_AGENT_HOLD_BOW_L,
  2375. ANIM_REQUEST_START);
  2376. }
  2377. }
  2378. }
  2379. else if (mLastCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR)
  2380. {
  2381. // Make sure we ask to save changes
  2382. gToolMgr.setCurrentToolset(gBasicToolset);
  2383. // *HACK: If we are quitting and we were in customize avatar, do not
  2384. // let the mini-map go visible again. JC
  2385. if (!gAppViewerp->quitRequested())
  2386. {
  2387. LLFloaterMiniMap::getInstance()->popVisible();
  2388. }
  2389. if (gMorphViewp)
  2390. {
  2391. gMorphViewp->setVisible(false);
  2392. }
  2393. if (isAgentAvatarValid() && mCustomAnim)
  2394. {
  2395. sendAnimationRequest(ANIM_AGENT_CUSTOMIZE, ANIM_REQUEST_STOP);
  2396. sendAnimationRequest(ANIM_AGENT_CUSTOMIZE_DONE,
  2397. ANIM_REQUEST_START);
  2398. mCustomAnim = false;
  2399. }
  2400. setLookAt(LOOKAT_TARGET_CLEAR);
  2401. }
  2402. //---------------------------------------------------------------------
  2403. // Set up UI for mode we're entering
  2404. //---------------------------------------------------------------------
  2405. if (mCameraMode == CAMERA_MODE_MOUSELOOK)
  2406. {
  2407. // Hide menus
  2408. if (gMenuBarViewp)
  2409. {
  2410. gMenuBarViewp->setVisible(false);
  2411. }
  2412. if (gStatusBarp)
  2413. {
  2414. gStatusBarp->setVisibleForMouselook(false);
  2415. }
  2416. // Clear out camera lag effect
  2417. mCameraLag.clear();
  2418. // JC - Added for always chat in third person option
  2419. gFocusMgr.setKeyboardFocus(NULL);
  2420. gToolMgr.setCurrentToolset(gMouselookToolset);
  2421. mViewsPushed = true;
  2422. if (gFloaterViewp)
  2423. {
  2424. gFloaterViewp->pushVisibleAll(false, get_skip_list());
  2425. }
  2426. if (gMorphViewp)
  2427. {
  2428. gMorphViewp->setVisible(false);
  2429. }
  2430. if (gConsolep)
  2431. {
  2432. gConsolep->setVisible(true);
  2433. }
  2434. if (isAgentAvatarValid())
  2435. {
  2436. // Trigger mouselook-specific animations
  2437. if (gAgentAvatarp->isAnyAnimationSignaled(AGENT_GUN_HOLD_ANIMS,
  2438. NUM_AGENT_GUN_HOLD_ANIMS))
  2439. {
  2440. const LLVOAvatar::anim_map_t& anims =
  2441. gAgentAvatarp->mSignaledAnimations;
  2442. LLVOAvatar::anim_it_t end =
  2443. gAgentAvatarp->mSignaledAnimations.end();
  2444. if (anims.find(ANIM_AGENT_HOLD_RIFLE_R) != end)
  2445. {
  2446. sendAnimationRequest(ANIM_AGENT_HOLD_RIFLE_R,
  2447. ANIM_REQUEST_STOP);
  2448. sendAnimationRequest(ANIM_AGENT_AIM_RIFLE_R,
  2449. ANIM_REQUEST_START);
  2450. }
  2451. if (anims.find(ANIM_AGENT_HOLD_HANDGUN_R) != end)
  2452. {
  2453. sendAnimationRequest(ANIM_AGENT_HOLD_HANDGUN_R,
  2454. ANIM_REQUEST_STOP);
  2455. sendAnimationRequest(ANIM_AGENT_AIM_HANDGUN_R,
  2456. ANIM_REQUEST_START);
  2457. }
  2458. if (anims.find(ANIM_AGENT_HOLD_BAZOOKA_R) != end)
  2459. {
  2460. sendAnimationRequest(ANIM_AGENT_HOLD_BAZOOKA_R,
  2461. ANIM_REQUEST_STOP);
  2462. sendAnimationRequest(ANIM_AGENT_AIM_BAZOOKA_R,
  2463. ANIM_REQUEST_START);
  2464. }
  2465. if (anims.find(ANIM_AGENT_HOLD_BOW_L) != end)
  2466. {
  2467. sendAnimationRequest(ANIM_AGENT_HOLD_BOW_L,
  2468. ANIM_REQUEST_STOP);
  2469. sendAnimationRequest(ANIM_AGENT_AIM_BOW_L,
  2470. ANIM_REQUEST_START);
  2471. }
  2472. }
  2473. LLViewerObject* parentp =
  2474. (LLViewerObject*)gAgentAvatarp->getParent();
  2475. if (parentp)
  2476. {
  2477. LLVector3 at_axis = gViewerCamera.getAtAxis();
  2478. LLViewerObject* root_object =
  2479. (LLViewerObject*)gAgentAvatarp->getRoot();
  2480. if (root_object->flagCameraDecoupled())
  2481. {
  2482. resetAxes(at_axis);
  2483. }
  2484. else
  2485. {
  2486. resetAxes(at_axis * ~(parentp->getRenderRotation()));
  2487. }
  2488. }
  2489. }
  2490. }
  2491. else if (mCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR)
  2492. {
  2493. gToolMgr.setCurrentToolset(gFaceEditToolset);
  2494. LLFloaterMiniMap::getInstance()->pushVisible(false);
  2495. if (gMorphViewp)
  2496. {
  2497. gMorphViewp->setVisible(true);
  2498. }
  2499. // Freeze avatar
  2500. if (isAgentAvatarValid())
  2501. {
  2502. mPauseRequest = gAgentAvatarp->requestPause();
  2503. }
  2504. }
  2505. if (isAgentAvatarValid())
  2506. {
  2507. gAgentAvatarp->updateAttachmentVisibility(mCameraMode);
  2508. }
  2509. if (gFloaterToolsp)
  2510. {
  2511. gFloaterToolsp->dirty();
  2512. }
  2513. // Do not let this be called more than once if the camera mode has not
  2514. // changed. - JC
  2515. mLastCameraMode = mCameraMode;
  2516. }
  2517. void LLAgent::updateCamera()
  2518. {
  2519. if (gCubeSnapshot)
  2520. {
  2521. return;
  2522. }
  2523. mCameraUpVector = LLVector3::z_axis;
  2524. U32 camera_mode = mCameraAnimating ? mLastCameraMode : mCameraMode;
  2525. validateFocusObject();
  2526. if (isAgentAvatarValid() && gAgentAvatarp->mIsSitting &&
  2527. camera_mode == CAMERA_MODE_MOUSELOOK)
  2528. {
  2529. mCameraUpVector = mCameraUpVector * gAgentAvatarp->getRenderRotation();
  2530. }
  2531. if (cameraThirdPerson() && mFocusOnAvatar &&
  2532. LLFollowCamMgr::getActiveFollowCamParams())
  2533. {
  2534. changeCameraToFollow();
  2535. }
  2536. // NOTE: this needs to be integrated into a general upVector system here
  2537. // within llAgent.
  2538. if (camera_mode == CAMERA_MODE_FOLLOW && mFocusOnAvatar)
  2539. {
  2540. mCameraUpVector = mFollowCam.getUpVector();
  2541. }
  2542. if (mSitCameraEnabled && mSitCameraReferenceObject->isDead())
  2543. {
  2544. setSitCamera(LLUUID::null);
  2545. }
  2546. // Update UI with our camera inputs
  2547. LLFloaterCamera* floater_camera = LLFloaterCamera::getInstance();
  2548. floater_camera->mRotate->setToggleState(mOrbitRightKey > 0.f, // left
  2549. mOrbitUpKey > 0.f, // top
  2550. mOrbitLeftKey > 0.f, // right
  2551. mOrbitDownKey > 0.f); // bottom
  2552. floater_camera->mZoom->setToggleState(mOrbitInKey > 0.f, // top
  2553. mOrbitOutKey > 0.f); // bottom
  2554. floater_camera->mTrack->setToggleState(mPanLeftKey > 0.f, // left
  2555. mPanUpKey > 0.f, // top
  2556. mPanRightKey > 0.f, // right
  2557. mPanDownKey > 0.f); // bottom
  2558. // Handle camera movement based on keyboard.
  2559. constexpr F32 ORBIT_OVER_RATE = 90.f * DEG_TO_RAD; // Rad/s
  2560. constexpr F32 ORBIT_AROUND_RATE = 90.f * DEG_TO_RAD; // Rad/s
  2561. constexpr F32 PAN_RATE = 5.f; // M/s
  2562. LLViewerCamera* camera = &gViewerCamera;
  2563. if (mOrbitUpKey || mOrbitDownKey)
  2564. {
  2565. F32 input_rate = mOrbitUpKey - mOrbitDownKey;
  2566. cameraOrbitOver(input_rate * ORBIT_OVER_RATE / gFPSClamped);
  2567. }
  2568. if (mOrbitLeftKey || mOrbitRightKey)
  2569. {
  2570. F32 input_rate = mOrbitLeftKey - mOrbitRightKey;
  2571. cameraOrbitAround(input_rate * ORBIT_AROUND_RATE / gFPSClamped);
  2572. }
  2573. if (mOrbitInKey || mOrbitOutKey)
  2574. {
  2575. F32 input_rate = mOrbitInKey - mOrbitOutKey;
  2576. LLVector3d to_focus = getPosGlobalFromAgent(camera->getOrigin()) -
  2577. calcFocusPositionTargetGlobal();
  2578. F32 distance_to_focus = (F32)to_focus.length();
  2579. // Move at distance (in meters) meters per second
  2580. cameraOrbitIn(input_rate * distance_to_focus / gFPSClamped);
  2581. }
  2582. if (mPanInKey || mPanOutKey)
  2583. {
  2584. F32 input_rate = mPanInKey - mPanOutKey;
  2585. cameraPanIn(input_rate * PAN_RATE / gFPSClamped);
  2586. }
  2587. if (mPanRightKey || mPanLeftKey)
  2588. {
  2589. F32 input_rate = mPanRightKey - mPanLeftKey;
  2590. cameraPanLeft(input_rate * -PAN_RATE / gFPSClamped);
  2591. }
  2592. if (mPanUpKey || mPanDownKey)
  2593. {
  2594. F32 input_rate = mPanUpKey - mPanDownKey;
  2595. cameraPanUp(input_rate * PAN_RATE / gFPSClamped);
  2596. }
  2597. // Clear camera keyboard keys.
  2598. mOrbitLeftKey = mOrbitRightKey = mOrbitUpKey = mOrbitDownKey =
  2599. mOrbitInKey = mOrbitOutKey = 0.f;
  2600. mPanRightKey = mPanLeftKey = mPanUpKey = mPanDownKey = mPanInKey =
  2601. mPanOutKey = 0.f;
  2602. // lerp camera focus offset
  2603. mCameraFocusOffset =
  2604. lerp(mCameraFocusOffset, mCameraFocusOffsetTarget,
  2605. LLCriticalDamp::getInterpolant(CAMERA_FOCUS_HALF_LIFE));
  2606. if (mCameraMode == CAMERA_MODE_FOLLOW && isAgentAvatarValid())
  2607. {
  2608. // This is where the avatar's position and rotation are given to
  2609. // followCam, and where it is updated. All three of its attributes are
  2610. // updated: (1) position, (2) focus, and (3) upvector. They can then be
  2611. // queried elsewhere in llAgent.
  2612. LLFollowCamParams* curr_cam = LLFollowCamMgr::getActiveFollowCamParams();
  2613. if (curr_cam)
  2614. {
  2615. mFollowCam.copyParams(*curr_cam);
  2616. // *TODO: use combined rotation of frame agent and sit object
  2617. LLQuaternion av_rot =
  2618. gAgentAvatarp->mIsSitting ? gAgentAvatarp->getRenderRotation()
  2619. : mFrameAgent.getQuaternion();
  2620. mFollowCam.setSubjectPositionAndRotation(gAgentAvatarp->getRenderPosition(),
  2621. av_rot);
  2622. mFollowCam.update();
  2623. }
  2624. else
  2625. {
  2626. changeCameraToThirdPerson(true);
  2627. }
  2628. }
  2629. LLVector3d camera_pos_global;
  2630. LLVector3d camera_target_global = calcCameraPositionTargetGlobal();
  2631. mCameraVirtualPositionAgent = getPosAgentFromGlobal(camera_target_global);
  2632. LLVector3d focus_target_global = calcFocusPositionTargetGlobal();
  2633. // Perform field of view correction
  2634. mCameraFOVZoomFactor = calcCameraFOVZoomFactor();
  2635. //MK
  2636. if (!gRLenabled || gRLInterface.mCamDistMax >= EXTREMUM * 0.75)
  2637. //mk
  2638. {
  2639. camera_target_global = focus_target_global +
  2640. (camera_target_global - focus_target_global) *
  2641. (1.f + mCameraFOVZoomFactor);
  2642. }
  2643. mShowAvatar = true; // can see avatar by default
  2644. // Adjust position for animation
  2645. if (mCameraAnimating)
  2646. {
  2647. F32 time = mAnimationTimer.getElapsedTimeF32();
  2648. #if 0
  2649. // Yet another instance of critically damped motion, hooray !
  2650. F32 fraction_of_animation = 1.f - powf(2.f,
  2651. -time / CAMERA_ZOOM_HALF_LIFE);
  2652. #else
  2653. // Linear interpolation
  2654. F32 fraction_of_animation = time / mAnimationDuration;
  2655. #endif
  2656. F32 fraction_animation_to_skip = 0.f;
  2657. if (mAnimationCameraStartGlobal != camera_target_global)
  2658. {
  2659. LLVector3d cam_delta = mAnimationCameraStartGlobal -
  2660. camera_target_global;
  2661. fraction_animation_to_skip = HEAD_BUFFER_SIZE /
  2662. (F32)cam_delta.length();
  2663. }
  2664. F32 animation_start_fraction =
  2665. mLastCameraMode == CAMERA_MODE_MOUSELOOK ?
  2666. fraction_animation_to_skip : 0.f;
  2667. F32 animation_finish_fraction =
  2668. mCameraMode == CAMERA_MODE_MOUSELOOK ?
  2669. 1.f - fraction_animation_to_skip : 1.f;
  2670. if (fraction_of_animation < animation_finish_fraction)
  2671. {
  2672. if (fraction_of_animation < animation_start_fraction ||
  2673. fraction_of_animation > animation_finish_fraction)
  2674. {
  2675. mShowAvatar = false;
  2676. }
  2677. // Adjust position for animation
  2678. F32 smooth_fraction_of_animation =
  2679. llsmoothstep(0.f, 1.f, fraction_of_animation);
  2680. camera_pos_global = lerp(mAnimationCameraStartGlobal,
  2681. camera_target_global,
  2682. smooth_fraction_of_animation);
  2683. mFocusGlobal = lerp(mAnimationFocusStartGlobal,
  2684. focus_target_global,
  2685. smooth_fraction_of_animation);
  2686. }
  2687. else
  2688. {
  2689. // Animation complete
  2690. mCameraAnimating = false;
  2691. camera_pos_global = camera_target_global;
  2692. mFocusGlobal = focus_target_global;
  2693. endAnimationUpdateUI();
  2694. mShowAvatar = true;
  2695. }
  2696. if (isAgentAvatarValid() && mCameraMode != CAMERA_MODE_MOUSELOOK)
  2697. {
  2698. gAgentAvatarp->updateAttachmentVisibility(mCameraMode);
  2699. }
  2700. }
  2701. else
  2702. {
  2703. camera_pos_global = camera_target_global;
  2704. mFocusGlobal = focus_target_global;
  2705. mShowAvatar = true;
  2706. }
  2707. // Smoothing
  2708. LLVector3d agent_pos = getPositionGlobal();
  2709. LLVector3d camera_pos_agent = camera_pos_global - agent_pos;
  2710. // Sitting on what you're manipulating can cause camera jitter with
  2711. // smoothing. This turns off smoothing while editing. -MG
  2712. mCameraSmoothingStop = mCameraSmoothingStop || gToolMgr.inBuildMode();
  2713. if (cameraThirdPerson() && !mCameraSmoothingStop)
  2714. {
  2715. constexpr F32 SMOOTHING_HALF_LIFE = 0.02f;
  2716. static LLCachedControl<F32> camera_position_smoothing(gSavedSettings,
  2717. "CameraPositionSmoothing");
  2718. F32 smoothing =
  2719. LLCriticalDamp::getInterpolant(camera_position_smoothing *
  2720. SMOOTHING_HALF_LIFE,
  2721. false);
  2722. if (mFocusOnAvatar && !mFocusObject) // We differentiate on avatar mode
  2723. {
  2724. // For avatar-relative focus, we smooth in avatar space; the
  2725. // avatar moves too jerkily w/r/t global space to smooth there.
  2726. LLVector3d delta = camera_pos_agent - mCameraSmoothingLastPositionAgent;
  2727. // Only smooth over short distances please
  2728. if (delta.length() < MAX_CAMERA_SMOOTH_DISTANCE)
  2729. {
  2730. camera_pos_agent = lerp(mCameraSmoothingLastPositionAgent,
  2731. camera_pos_agent, smoothing);
  2732. camera_pos_global = camera_pos_agent + agent_pos;
  2733. }
  2734. }
  2735. else
  2736. {
  2737. LLVector3d delta = camera_pos_global -
  2738. mCameraSmoothingLastPositionGlobal;
  2739. // Only smooth over short distances please
  2740. if (delta.length() < MAX_CAMERA_SMOOTH_DISTANCE)
  2741. {
  2742. camera_pos_global = lerp(mCameraSmoothingLastPositionGlobal,
  2743. camera_pos_global, smoothing);
  2744. }
  2745. }
  2746. }
  2747. mCameraSmoothingLastPositionGlobal = camera_pos_global;
  2748. mCameraSmoothingLastPositionAgent = camera_pos_agent;
  2749. mCameraSmoothingStop = false;
  2750. mCameraCurrentFOVZoomFactor =
  2751. lerp(mCameraCurrentFOVZoomFactor, mCameraFOVZoomFactor,
  2752. LLCriticalDamp::getInterpolant(FOV_ZOOM_HALF_LIFE));
  2753. #if 0 // Too spammy...
  2754. LL_DEBUGS("Agent") << "Current FOV Zoom: " << mCameraCurrentFOVZoomFactor
  2755. << " - Target FOV Zoom: " << mCameraFOVZoomFactor
  2756. << " - Object penetration: " << mFocusObjectDist
  2757. << LL_ENDL;
  2758. #endif
  2759. F32 ui_offset = 0.f;
  2760. if (mCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR)
  2761. {
  2762. ui_offset = calcCustomizeAvatarUIOffset(camera_pos_global);
  2763. }
  2764. LLVector3 focus_agent = getPosAgentFromGlobal(mFocusGlobal);
  2765. mCameraPositionAgent = getPosAgentFromGlobal(camera_pos_global);
  2766. // Move the camera
  2767. camera->updateCameraLocation(mCameraPositionAgent, mCameraUpVector,
  2768. focus_agent);
  2769. // RN: translate UI offset after camera is oriented properly
  2770. camera->translate(camera->getLeftAxis() * ui_offset);
  2771. // Change FOV
  2772. camera->setView(camera->getDefaultFOV() /
  2773. (1.f + mCameraCurrentFOVZoomFactor));
  2774. // Follow camera when in customize mode
  2775. if (cameraCustomizeAvatar())
  2776. {
  2777. setLookAt(LOOKAT_TARGET_FOCUS, NULL, mCameraPositionAgent);
  2778. }
  2779. checkPositionChanged();
  2780. if (LLVOAvatar::sVisibleInFirstPerson && isAgentAvatarValid() &&
  2781. !gAgentAvatarp->mIsSitting && cameraMouselook())
  2782. {
  2783. LLVector3 head_pos = gAgentAvatarp->mHeadp->getWorldPosition() +
  2784. LLVector3(0.08f, 0.f, 0.05f) *
  2785. gAgentAvatarp->mHeadp->getWorldRotation() +
  2786. LLVector3(0.1f, 0.f, 0.f) *
  2787. gAgentAvatarp->mPelvisp->getWorldRotation();
  2788. LLVector3 diff = mCameraPositionAgent - head_pos;
  2789. diff = diff * ~gAgentAvatarp->mRoot->getWorldRotation();
  2790. LLJoint* torso_joint = gAgentAvatarp->mTorsop;
  2791. LLJoint* chest_joint = gAgentAvatarp->mChestp;
  2792. LLVector3 torso_scale = torso_joint->getScale();
  2793. LLVector3 chest_scale = chest_joint->getScale();
  2794. // Shorten avatar skeleton to avoid foot interpenetration
  2795. if (!gAgentAvatarp->mInAir)
  2796. {
  2797. LLVector3 chest_offset =
  2798. LLVector3(0.f, 0.f, chest_joint->getPosition().mV[VZ]) *
  2799. torso_joint->getWorldRotation();
  2800. F32 z_compensate = llclamp(-diff.mV[VZ], -0.2f, 1.f);
  2801. F32 scale_factor = llclamp(1.f - (z_compensate * 0.5f /
  2802. chest_offset.mV[VZ]),
  2803. 0.5f, 1.2f);
  2804. torso_joint->setScale(LLVector3(1.f, 1.f, scale_factor));
  2805. LLJoint* neck_joint = gAgentAvatarp->mNeckp;
  2806. LLVector3 neck_offset =
  2807. LLVector3(0.f, 0.f, neck_joint->getPosition().mV[VZ]) *
  2808. chest_joint->getWorldRotation();
  2809. scale_factor = llclamp(1.f - (z_compensate * 0.5f /
  2810. neck_offset.mV[VZ]),
  2811. 0.5f, 1.2f);
  2812. chest_joint->setScale(LLVector3(1.f, 1.f, scale_factor));
  2813. diff.mV[VZ] = 0.f;
  2814. }
  2815. gAgentAvatarp->mPelvisp->setPosition(gAgentAvatarp->mPelvisp->getPosition() +
  2816. diff);
  2817. gAgentAvatarp->mRoot->updateWorldMatrixChildren();
  2818. for (S32 i = 0, count = gAgentAvatarp->mAttachedObjectsVector.size();
  2819. i < count; ++i)
  2820. {
  2821. LLViewerObject* object =
  2822. gAgentAvatarp->mAttachedObjectsVector[i].first;
  2823. if (object && !object->isDead() && object->mDrawable.notNull())
  2824. {
  2825. // Clear any existing "early" movements of attachment
  2826. object->mDrawable->clearState(LLDrawable::EARLY_MOVE);
  2827. gPipeline.updateMoveNormalAsync(object->mDrawable);
  2828. object->updateText();
  2829. }
  2830. }
  2831. torso_joint->setScale(torso_scale);
  2832. chest_joint->setScale(chest_scale);
  2833. }
  2834. //MK
  2835. if (gRLenabled && mCameraMode != CAMERA_MODE_FOLLOW)
  2836. {
  2837. bool is_first_person = mCameraMode == CAMERA_MODE_MOUSELOOK;
  2838. if (is_first_person && gRLInterface.mCamDistMin > 0.f)
  2839. {
  2840. changeCameraToDefault();
  2841. }
  2842. else if (!is_first_person && gRLInterface.mCamDistMax <= 0.f)
  2843. {
  2844. changeCameraToMouselook();
  2845. }
  2846. }
  2847. //mk
  2848. }
  2849. void LLAgent::updateFocusOffset()
  2850. {
  2851. validateFocusObject();
  2852. if (mFocusObject.notNull())
  2853. {
  2854. LLVector3d obj_pos =
  2855. getPosGlobalFromAgent(mFocusObject->getRenderPosition());
  2856. mFocusObjectOffset.set(mFocusTargetGlobal - obj_pos);
  2857. }
  2858. }
  2859. void LLAgent::validateFocusObject()
  2860. {
  2861. if (mFocusObject.notNull() && mFocusObject->isDead())
  2862. {
  2863. mFocusObjectOffset.clear();
  2864. clearFocusObject();
  2865. mCameraFOVZoomFactor = 0.f;
  2866. }
  2867. }
  2868. F32 LLAgent::calcCustomizeAvatarUIOffset(const LLVector3d& camera_pos_global)
  2869. {
  2870. F32 ui_offset = 0.f;
  2871. if (gFloaterCustomizep && gViewerWindowp)
  2872. {
  2873. const LLRect& rect = gFloaterCustomizep->getRect();
  2874. // Move the camera so that the avatar is not covered up by this floater
  2875. F32 ratio = (F32)rect.getWidth() /
  2876. (F32)gViewerWindowp->getWindowWidth();
  2877. F32 fraction_of_fov = 0.5f - (0.5f * (1.f - llmin(1.f, ratio)));
  2878. F32 apparent_angle = fraction_of_fov * gViewerCamera.getView() *
  2879. gViewerCamera.getAspect(); // in radians
  2880. F32 offset = tanf(apparent_angle);
  2881. if (rect.mLeft < gViewerWindowp->getWindowWidth() - rect.mRight)
  2882. {
  2883. // Move the avatar to the right (camera to the left)
  2884. ui_offset = offset;
  2885. }
  2886. else
  2887. {
  2888. // Move the avatar to the left (camera to the right)
  2889. ui_offset = -offset;
  2890. }
  2891. }
  2892. F32 range = (F32)dist_vec(camera_pos_global, getFocusGlobal());
  2893. mUIOffset = lerp(mUIOffset, ui_offset,
  2894. LLCriticalDamp::getInterpolant(0.05f));
  2895. return mUIOffset * range;
  2896. }
  2897. LLVector3d LLAgent::calcFocusPositionTargetGlobal()
  2898. {
  2899. if (mFocusObject.notNull() && mFocusObject->isDead())
  2900. {
  2901. clearFocusObject();
  2902. }
  2903. if (mCameraMode == CAMERA_MODE_FOLLOW && mFocusOnAvatar)
  2904. {
  2905. mFocusTargetGlobal =
  2906. getPosGlobalFromAgent(mFollowCam.getSimulatedFocus());
  2907. return mFocusTargetGlobal;
  2908. }
  2909. if (mCameraMode == CAMERA_MODE_MOUSELOOK)
  2910. {
  2911. LLVector3d at_axis(1.0, 0.0, 0.0);
  2912. LLQuaternion agent_rot = mFrameAgent.getQuaternion();
  2913. if (isAgentAvatarValid())
  2914. {
  2915. LLViewerObject* parentp =
  2916. (LLViewerObject*)gAgentAvatarp->getParent();
  2917. if (parentp)
  2918. {
  2919. LLViewerObject* root_object =
  2920. (LLViewerObject*)gAgentAvatarp->getRoot();
  2921. if (!root_object->flagCameraDecoupled())
  2922. {
  2923. agent_rot *= parentp->getRenderRotation();
  2924. }
  2925. }
  2926. }
  2927. at_axis = at_axis * agent_rot;
  2928. mFocusTargetGlobal = calcCameraPositionTargetGlobal() + at_axis;
  2929. return mFocusTargetGlobal;
  2930. }
  2931. if (mCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR)
  2932. {
  2933. return mFocusTargetGlobal;
  2934. }
  2935. if (!mFocusOnAvatar)
  2936. {
  2937. if (mFocusObject.notNull() && !mFocusObject->isDead() &&
  2938. mFocusObject->mDrawable.notNull())
  2939. {
  2940. LLDrawable* drawablep = mFocusObject->mDrawable;
  2941. if (mTrackFocusObject && drawablep && drawablep->isActive())
  2942. {
  2943. if (!mFocusObject->isAvatar())
  2944. {
  2945. if (mFocusObject->isSelected())
  2946. {
  2947. gPipeline.updateMoveNormalAsync(drawablep);
  2948. }
  2949. else if (drawablep->isState(LLDrawable::MOVE_UNDAMPED))
  2950. {
  2951. gPipeline.updateMoveNormalAsync(drawablep);
  2952. }
  2953. else
  2954. {
  2955. gPipeline.updateMoveDampedAsync(drawablep);
  2956. }
  2957. }
  2958. }
  2959. else
  2960. {
  2961. // If not tracking object, update offset based on new object
  2962. // position
  2963. updateFocusOffset();
  2964. }
  2965. LLVector3 focus_agent = mFocusObject->getRenderPosition() +
  2966. mFocusObjectOffset;
  2967. mFocusTargetGlobal.set(getPosGlobalFromAgent(focus_agent));
  2968. }
  2969. return mFocusTargetGlobal;
  2970. }
  2971. if (mSitCameraEnabled && isAgentAvatarValid() &&
  2972. gAgentAvatarp->mIsSitting && mSitCameraReferenceObject.notNull())
  2973. {
  2974. // Sit camera
  2975. LLVector3 object_pos = mSitCameraReferenceObject->getRenderPosition();
  2976. LLQuaternion object_rot = mSitCameraReferenceObject->getRenderRotation();
  2977. LLVector3 target_pos = object_pos + (mSitCameraFocus * object_rot);
  2978. return getPosGlobalFromAgent(target_pos);
  2979. }
  2980. return getPositionGlobal() + calcThirdPersonFocusOffset();
  2981. }
  2982. LLVector3d LLAgent::calcThirdPersonFocusOffset()
  2983. {
  2984. // Offset from avatar
  2985. LLVector3d focus_offset;
  2986. focus_offset.set(mCameraFocusOffsetDefault);
  2987. LLQuaternion agent_rot = mFrameAgent.getQuaternion();
  2988. if (isAgentAvatarValid())
  2989. {
  2990. LLViewerObject* parentp = (LLViewerObject*)gAgentAvatarp->getParent();
  2991. if (parentp)
  2992. {
  2993. agent_rot *= parentp->getRenderRotation();
  2994. }
  2995. }
  2996. return focus_offset * agent_rot;
  2997. }
  2998. void LLAgent::setupSitCamera()
  2999. {
  3000. if (!isAgentAvatarValid()) return;
  3001. // Agent frame entering this function is in world coordinates
  3002. LLViewerObject* parentp = (LLViewerObject*)gAgentAvatarp->getParent();
  3003. if (parentp)
  3004. {
  3005. LLQuaternion parent_rot = parentp->getRenderRotation();
  3006. // Slam agent coordinate frame to proper parent local version
  3007. LLVector3 at_axis = mFrameAgent.getAtAxis();
  3008. at_axis.mV[VZ] = 0.f;
  3009. at_axis.normalize();
  3010. resetAxes(at_axis * ~parent_rot);
  3011. }
  3012. }
  3013. void LLAgent::setupCameraView(bool reset)
  3014. {
  3015. static bool rear_view = false;
  3016. bool new_rear_view = gSavedSettings.getBool("CameraFrontView");
  3017. if (new_rear_view &&
  3018. (mCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR ||
  3019. mCameraMode == CAMERA_MODE_MOUSELOOK || reset))
  3020. {
  3021. gSavedSettings.setBool("CameraFrontView", false);
  3022. new_rear_view = false;
  3023. }
  3024. if (new_rear_view)
  3025. {
  3026. mCameraFocusOffsetDefault =
  3027. gSavedSettings.getVector3("FocusOffsetFrontView");
  3028. mCameraOffsetDefault =
  3029. gSavedSettings.getVector3("CameraOffsetFrontView");
  3030. }
  3031. else
  3032. {
  3033. mCameraFocusOffsetDefault =
  3034. gSavedSettings.getVector3("FocusOffsetDefault");
  3035. mCameraOffsetDefault =
  3036. gSavedSettings.getVector3("CameraOffsetDefault");
  3037. }
  3038. if (rear_view != new_rear_view)
  3039. {
  3040. rear_view = new_rear_view;
  3041. updateCamera();
  3042. }
  3043. }
  3044. const LLVector3& LLAgent::getCameraPositionAgent() const
  3045. {
  3046. return gViewerCamera.getOrigin();
  3047. }
  3048. LLVector3d LLAgent::getCameraPositionGlobal() const
  3049. {
  3050. return getPosGlobalFromAgent(gViewerCamera.getOrigin());
  3051. }
  3052. F32 LLAgent::getHUDTargetZoom() const
  3053. {
  3054. static LLCachedControl<F32> scale(gSavedSettings, "HUDScaleFactor");
  3055. F32 zoom = llmax(0.5f, scale);
  3056. LLObjectSelectionHandle sel = gSelectMgr.getSelection();
  3057. if (sel->getObjectCount() && sel->getSelectType() == SELECT_TYPE_HUD)
  3058. {
  3059. zoom *= mHUDTargetZoom;
  3060. }
  3061. return zoom;
  3062. }
  3063. F32 LLAgent::calcCameraFOVZoomFactor()
  3064. {
  3065. LLVector3 camera_offset_dir;
  3066. camera_offset_dir.set(mCameraFocusOffset);
  3067. if (mCameraMode == CAMERA_MODE_MOUSELOOK)
  3068. {
  3069. return 0.f;
  3070. }
  3071. // If not focusing on avatar or land
  3072. if (!mFocusOnAvatar && mFocusObject.notNull() && !mFocusObject->isAvatar())
  3073. {
  3074. // Do not FOV zoom on mostly transparent objects
  3075. F32 obj_min_dist = 0.f;
  3076. if (!noCameraConstraints())
  3077. {
  3078. calcCameraMinDistance(obj_min_dist);
  3079. }
  3080. F32 current_distance = llmax(0.001f, camera_offset_dir.length());
  3081. mFocusObjectDist = obj_min_dist - current_distance;
  3082. F32 new_fov_zoom = llclamp(mFocusObjectDist / current_distance,
  3083. 0.f, 1000.f);
  3084. return new_fov_zoom;
  3085. }
  3086. // Keep old field of view until user changes focus explicitly
  3087. return mCameraFOVZoomFactor;
  3088. }
  3089. LLVector3d LLAgent::calcCameraPositionTargetGlobal(bool* hit_limit)
  3090. {
  3091. // Compute base camera position and look-at points.
  3092. F32 camera_land_height;
  3093. LLVector3d frame_center_global;
  3094. if (isAgentAvatarValid())
  3095. {
  3096. frame_center_global =
  3097. getPosGlobalFromAgent(gAgentAvatarp->mRoot->getWorldPosition());
  3098. }
  3099. else
  3100. {
  3101. frame_center_global = getPositionGlobal();
  3102. }
  3103. bool constrained = false;
  3104. LLVector3d head_offset;
  3105. head_offset.set(mThirdPersonHeadOffset);
  3106. LLVector3d camera_position_global;
  3107. if (mCameraMode == CAMERA_MODE_FOLLOW && mFocusOnAvatar)
  3108. {
  3109. camera_position_global =
  3110. getPosGlobalFromAgent(mFollowCam.getSimulatedPosition());
  3111. }
  3112. else if (mCameraMode == CAMERA_MODE_MOUSELOOK)
  3113. {
  3114. if (!isAgentAvatarValid() || gAgentAvatarp->mDrawable.isNull())
  3115. {
  3116. llwarns << "Null avatar drawable !" << llendl;
  3117. return LLVector3d::zero;
  3118. }
  3119. head_offset.clear();
  3120. F32 fixup = 0.f;
  3121. if (gAgentAvatarp->mIsSitting)
  3122. {
  3123. head_offset.mdV[VZ] += 0.1;
  3124. }
  3125. else if (gAgentAvatarp->hasPelvisFixup(fixup))
  3126. {
  3127. head_offset.mdV[VZ] -= fixup;
  3128. }
  3129. LLViewerObject* parentp = (LLViewerObject*)gAgentAvatarp->getParent();
  3130. if (gAgentAvatarp->mIsSitting && parentp)
  3131. {
  3132. gAgentAvatarp->updateHeadOffset();
  3133. head_offset.mdV[VX] = gAgentAvatarp->mHeadOffset.mV[VX];
  3134. head_offset.mdV[VY] = gAgentAvatarp->mHeadOffset.mV[VY];
  3135. head_offset.mdV[VZ] += gAgentAvatarp->mHeadOffset.mV[VZ];
  3136. const LLMatrix4& mat = parentp->getRenderMatrix();
  3137. camera_position_global =
  3138. getPosGlobalFromAgent((gAgentAvatarp->getPosition() +
  3139. LLVector3(head_offset) *
  3140. gAgentAvatarp->getRotation()) * mat);
  3141. }
  3142. else
  3143. {
  3144. head_offset.mdV[VZ] += gAgentAvatarp->mHeadOffset.mV[VZ];
  3145. camera_position_global =
  3146. getPosGlobalFromAgent(gAgentAvatarp->getRenderPosition());
  3147. head_offset = head_offset * gAgentAvatarp->getRenderRotation();
  3148. camera_position_global = camera_position_global + head_offset;
  3149. }
  3150. }
  3151. else if (mCameraMode == CAMERA_MODE_THIRD_PERSON && mFocusOnAvatar)
  3152. {
  3153. LLVector3 local_camera_offset;
  3154. F32 camera_distance = 0.f;
  3155. if (mSitCameraEnabled && isAgentAvatarValid() &&
  3156. gAgentAvatarp->mIsSitting && mSitCameraReferenceObject.notNull())
  3157. {
  3158. // sit camera
  3159. LLVector3 object_pos =
  3160. mSitCameraReferenceObject->getRenderPosition();
  3161. LLQuaternion object_rot =
  3162. mSitCameraReferenceObject->getRenderRotation();
  3163. LLVector3 target_pos = object_pos + mSitCameraPos * object_rot;
  3164. camera_position_global = getPosGlobalFromAgent(target_pos);
  3165. }
  3166. else
  3167. {
  3168. static LLCachedControl<F32> camera_offset_scale(gSavedSettings,
  3169. "CameraOffsetScale");
  3170. local_camera_offset = mCameraZoomFraction *
  3171. mCameraOffsetDefault * camera_offset_scale;
  3172. LLViewerObject* parentp = NULL;
  3173. if (isAgentAvatarValid())
  3174. {
  3175. parentp = (LLViewerObject*)gAgentAvatarp->getParent();
  3176. }
  3177. // Are we sitting down ?
  3178. if (parentp)
  3179. {
  3180. LLQuaternion parent_rot = parentp->getRenderRotation();
  3181. // Slam agent coordinate frame to proper parent local version
  3182. LLVector3 at_axis = mFrameAgent.getAtAxis() * parent_rot;
  3183. at_axis.mV[VZ] = 0.f;
  3184. at_axis.normalize();
  3185. resetAxes(at_axis * ~parent_rot);
  3186. local_camera_offset = local_camera_offset *
  3187. mFrameAgent.getQuaternion() * parent_rot;
  3188. }
  3189. else
  3190. {
  3191. local_camera_offset =
  3192. mFrameAgent.rotateToAbsolute(local_camera_offset);
  3193. }
  3194. static LLCachedControl<bool> ignore_collisions(gSavedSettings,
  3195. "CameraIgnoreCollisions");
  3196. if (!ignore_collisions && !mCameraCollidePlane.isExactlyZero() &&
  3197. !(isAgentAvatarValid() && gAgentAvatarp->mIsSitting))
  3198. {
  3199. LLVector3 plane_normal;
  3200. plane_normal.set(mCameraCollidePlane.mV);
  3201. F32 offset_dot_norm = local_camera_offset * plane_normal;
  3202. if (fabsf(offset_dot_norm) < 0.001f)
  3203. {
  3204. offset_dot_norm = 0.001f;
  3205. }
  3206. camera_distance = local_camera_offset.normalize();
  3207. F32 pos_dot_norm = getPosAgentFromGlobal(frame_center_global +
  3208. head_offset) *
  3209. plane_normal;
  3210. // If agent is outside the colliding half-plane
  3211. if (pos_dot_norm > mCameraCollidePlane.mV[VW])
  3212. {
  3213. // Check to see if camera is on the opposite side (inside)
  3214. // the half-plane
  3215. if (offset_dot_norm + pos_dot_norm <
  3216. mCameraCollidePlane.mV[VW])
  3217. {
  3218. // Diminish offset by factor to push it back outside
  3219. // the half-plane
  3220. camera_distance *= (pos_dot_norm -
  3221. mCameraCollidePlane.mV[VW] -
  3222. CAMERA_COLLIDE_EPSILON) /
  3223. -offset_dot_norm;
  3224. }
  3225. }
  3226. else if (offset_dot_norm + pos_dot_norm >
  3227. mCameraCollidePlane.mV[VW])
  3228. {
  3229. camera_distance *= (mCameraCollidePlane.mV[VW] -
  3230. pos_dot_norm -
  3231. CAMERA_COLLIDE_EPSILON) /
  3232. offset_dot_norm;
  3233. }
  3234. }
  3235. else
  3236. {
  3237. camera_distance = local_camera_offset.normalize();
  3238. }
  3239. mTargetCameraDistance = llmax(camera_distance,
  3240. MIN_CAMERA_DISTANCE);
  3241. if (mTargetCameraDistance != mCurrentCameraDistance)
  3242. {
  3243. F32 camera_lerp_amt =
  3244. LLCriticalDamp::getInterpolant(CAMERA_ZOOM_HALF_LIFE);
  3245. mCurrentCameraDistance = lerp(mCurrentCameraDistance,
  3246. mTargetCameraDistance,
  3247. camera_lerp_amt);
  3248. }
  3249. // Make the camera distance current
  3250. local_camera_offset *= mCurrentCameraDistance;
  3251. // Set the global camera position
  3252. LLVector3d camera_offset;
  3253. camera_offset.set(local_camera_offset);
  3254. camera_position_global = frame_center_global + head_offset +
  3255. camera_offset;
  3256. if (isAgentAvatarValid())
  3257. {
  3258. LLVector3d camera_lag_d;
  3259. F32 lag_interp =
  3260. LLCriticalDamp::getInterpolant(CAMERA_LAG_HALF_LIFE);
  3261. LLVector3 target_lag;
  3262. LLVector3 vel = getVelocity();
  3263. // Lag by appropriate amount for flying
  3264. F32 time_in_air =
  3265. gAgentAvatarp->mTimeInAir.getElapsedTimeF32();
  3266. if (!mCameraAnimating && gAgentAvatarp->mInAir &&
  3267. time_in_air > GROUND_TO_AIR_CAMERA_TRANSITION_START_TIME)
  3268. {
  3269. LLVector3 frame_at_axis = mFrameAgent.getAtAxis();
  3270. frame_at_axis -= projected_vec(frame_at_axis,
  3271. getReferenceUpVector());
  3272. frame_at_axis.normalize();
  3273. // Transition smoothly in air mode, to avoid camera pop
  3274. F32 u = (time_in_air -
  3275. GROUND_TO_AIR_CAMERA_TRANSITION_START_TIME) /
  3276. GROUND_TO_AIR_CAMERA_TRANSITION_TIME;
  3277. u = llclamp(u, 0.f, 1.f);
  3278. lag_interp *= u;
  3279. if (gViewerWindowp->getLeftMouseDown() &&
  3280. gViewerWindowp->getLastPick().mObjectID ==
  3281. gAgentAvatarp->getID())
  3282. {
  3283. // Disable camera lag when using mouse-directed
  3284. // steering
  3285. target_lag.clear();
  3286. }
  3287. else
  3288. {
  3289. static LLCachedControl<F32> strength(gSavedSettings,
  3290. "DynamicCameraStrength");
  3291. target_lag = vel * strength / 30.f;
  3292. }
  3293. mCameraLag = lerp(mCameraLag, target_lag, lag_interp);
  3294. F32 lag_dist = mCameraLag.length();
  3295. if (lag_dist > MAX_CAMERA_LAG)
  3296. {
  3297. mCameraLag = mCameraLag * MAX_CAMERA_LAG / lag_dist;
  3298. }
  3299. // Clamp camera lag so that avatar is always in front
  3300. F32 dot = (mCameraLag - frame_at_axis *
  3301. MIN_CAMERA_LAG * u) * frame_at_axis;
  3302. if (dot < -(MIN_CAMERA_LAG * u))
  3303. {
  3304. mCameraLag -= (dot + MIN_CAMERA_LAG * u) *
  3305. frame_at_axis;
  3306. }
  3307. }
  3308. else
  3309. {
  3310. mCameraLag = lerp(mCameraLag, LLVector3::zero,
  3311. LLCriticalDamp::getInterpolant(0.15f));
  3312. }
  3313. camera_lag_d.set(mCameraLag);
  3314. camera_position_global = camera_position_global - camera_lag_d;
  3315. }
  3316. }
  3317. }
  3318. else
  3319. {
  3320. LLVector3d focusPosGlobal = calcFocusPositionTargetGlobal();
  3321. // Camera gets pushed out later WRT mCameraFOVZoomFactor... this is
  3322. // "raw" value
  3323. camera_position_global = focusPosGlobal + mCameraFocusOffset;
  3324. }
  3325. if (!noCameraConstraints() && !isGodlike())
  3326. {
  3327. LLViewerRegion* regionp =
  3328. gWorld.getRegionFromPosGlobal(camera_position_global);
  3329. bool constrain = true;
  3330. if (regionp && regionp->canManageEstate())
  3331. {
  3332. constrain = false;
  3333. }
  3334. if (constrain)
  3335. {
  3336. F32 max_dist = mCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR ?
  3337. APPEARANCE_MAX_ZOOM : mDrawDistance;
  3338. LLVector3d camera_offset = camera_position_global -
  3339. getPositionGlobal();
  3340. F32 camera_distance = (F32)camera_offset.length();
  3341. if (camera_distance > max_dist)
  3342. {
  3343. camera_position_global = getPositionGlobal() +
  3344. max_dist / camera_distance *
  3345. camera_offset;
  3346. constrained = true;
  3347. }
  3348. }
  3349. }
  3350. // Do not let camera go underground
  3351. F32 camera_min_off_ground = getCameraMinOffGround();
  3352. camera_land_height = gWorld.resolveLandHeightGlobal(camera_position_global);
  3353. if (camera_position_global.mdV[VZ] < camera_land_height +
  3354. camera_min_off_ground)
  3355. {
  3356. camera_position_global.mdV[VZ] = camera_land_height +
  3357. camera_min_off_ground;
  3358. constrained = true;
  3359. }
  3360. //MK
  3361. // Constrain the distance by RLV restrictions here. Do not do it for
  3362. // mouse-look because it would force the camera to the crotch.
  3363. if (gRLenabled && mCameraMode != CAMERA_MODE_MOUSELOOK &&
  3364. (gRLInterface.mCamDistMax < EXTREMUM ||
  3365. gRLInterface.mCamDistMin > -EXTREMUM))
  3366. {
  3367. LLJoint* ref_joint = gRLInterface.getCamDistDrawFromJoint();
  3368. if (ref_joint)
  3369. {
  3370. LLVector3 joint_pos = ref_joint->getWorldPosition();
  3371. LLVector3d joint_pos_3d = getPosGlobalFromAgent(joint_pos);
  3372. LLVector3d camera_offset = camera_position_global - joint_pos_3d;
  3373. F32 camera_distance = (F32)camera_offset.length();
  3374. if (camera_distance != 0.f)
  3375. {
  3376. if (camera_distance > gRLInterface.mCamDistMax)
  3377. {
  3378. camera_position_global = joint_pos_3d +
  3379. (gRLInterface.mCamDistMax /
  3380. camera_distance) * camera_offset;
  3381. constrained = true;
  3382. }
  3383. else if (camera_distance < gRLInterface.mCamDistMin)
  3384. {
  3385. camera_position_global = joint_pos_3d +
  3386. (gRLInterface.mCamDistMin /
  3387. camera_distance) * camera_offset;
  3388. constrained = true;
  3389. }
  3390. }
  3391. }
  3392. }
  3393. //mk
  3394. if (hit_limit)
  3395. {
  3396. *hit_limit = constrained;
  3397. }
  3398. return camera_position_global;
  3399. }
  3400. void LLAgent::handleScrollWheel(S32 clicks)
  3401. {
  3402. if (mCameraMode == CAMERA_MODE_FOLLOW && getFocusOnAvatar())
  3403. {
  3404. // Not if the followCam position is locked in place
  3405. if (!mFollowCam.getPositionLocked())
  3406. {
  3407. mFollowCam.zoom(clicks);
  3408. if (mFollowCam.isZoomedToMinimumDistance())
  3409. {
  3410. changeCameraToMouselook(false);
  3411. }
  3412. }
  3413. }
  3414. else
  3415. {
  3416. LLObjectSelectionHandle selection = gSelectMgr.getSelection();
  3417. // gcc accepts constexpr here, but not clang...
  3418. static const F32 ROOT_ROOT_TWO = sqrtf(F_SQRT2);
  3419. // Block if camera is animating
  3420. if (mCameraAnimating)
  3421. {
  3422. return;
  3423. }
  3424. if (selection->getObjectCount() &&
  3425. selection->getSelectType() == SELECT_TYPE_HUD)
  3426. {
  3427. F32 zoom_factor = powf(0.8f, -clicks);
  3428. cameraZoomIn(zoom_factor);
  3429. }
  3430. else if (mFocusOnAvatar && mCameraMode == CAMERA_MODE_THIRD_PERSON)
  3431. {
  3432. static LLCachedControl<F32> camera_offset_scale(gSavedSettings,
  3433. "CameraOffsetScale");
  3434. F32 current_zoom_fraction = mTargetCameraDistance /
  3435. (mCameraOffsetDefault.length() *
  3436. camera_offset_scale);
  3437. current_zoom_fraction *= 1.f - powf(ROOT_ROOT_TWO, clicks);
  3438. cameraOrbitIn(current_zoom_fraction *
  3439. mCameraOffsetDefault.length() * camera_offset_scale);
  3440. }
  3441. else
  3442. {
  3443. F32 current_zoom_fraction = (F32)mCameraFocusOffsetTarget.length();
  3444. cameraOrbitIn(current_zoom_fraction *
  3445. (1.f - powf(ROOT_ROOT_TWO, clicks)));
  3446. }
  3447. }
  3448. }
  3449. F32 LLAgent::getCameraMinOffGround()
  3450. {
  3451. if (mCameraMode == CAMERA_MODE_MOUSELOOK)
  3452. {
  3453. return 0.f;
  3454. }
  3455. if (noCameraConstraints())
  3456. {
  3457. return -1000.f;
  3458. }
  3459. return 0.5f;
  3460. }
  3461. void LLAgent::resetCamera()
  3462. {
  3463. // Remove any pitch from the avatar
  3464. LLVector3 at = mFrameAgent.getAtAxis();
  3465. at.mV[VZ] = 0.f;
  3466. at.normalize();
  3467. resetAxes(at);
  3468. // Have to explicitly clear field of view zoom now
  3469. mCameraFOVZoomFactor = 0.f;
  3470. updateCamera();
  3471. }
  3472. bool LLAgent::changeCameraToMouselook(bool animate)
  3473. {
  3474. if (!gViewerWindowp)
  3475. {
  3476. return false;
  3477. }
  3478. if (LLViewerJoystick::getInstance()->getOverrideCamera()
  3479. //MK
  3480. && (!gRLenabled || gRLInterface.mCamDistMax > 0.f))
  3481. //mk
  3482. {
  3483. return false;
  3484. }
  3485. // Visibility changes at end of animation
  3486. gWindowp->resetBusyCount();
  3487. // Menus should not remain open on switching to mouselook...
  3488. gMenuHolderp->hideMenus();
  3489. // Unpause avatar animation
  3490. mPauseRequest = NULL;
  3491. gToolMgr.setCurrentToolset(gMouselookToolset);
  3492. if (LLFloaterTools::isVisible())
  3493. {
  3494. gFloaterToolsp->close();
  3495. }
  3496. // Reset the view to rear view.
  3497. setupCameraView(true);
  3498. if (isAgentAvatarValid())
  3499. {
  3500. gAgentAvatarp->stopMotion(ANIM_AGENT_BODY_NOISE);
  3501. gAgentAvatarp->stopMotion(ANIM_AGENT_BREATHE_ROT);
  3502. }
  3503. #if 0
  3504. gViewerWindowp->stopGrab();
  3505. #endif
  3506. gSelectMgr.deselectAll();
  3507. gViewerWindowp->hideCursor();
  3508. gViewerWindowp->moveCursorToCenter();
  3509. if (mCameraMode != CAMERA_MODE_MOUSELOOK)
  3510. {
  3511. gFocusMgr.setKeyboardFocus(NULL);
  3512. mLastCameraMode = mCameraMode;
  3513. mCameraMode = CAMERA_MODE_MOUSELOOK;
  3514. U32 old_flags = mControlFlags;
  3515. setControlFlags(AGENT_CONTROL_MOUSELOOK);
  3516. if (old_flags != mControlFlags)
  3517. {
  3518. mFlagsDirty = true;
  3519. }
  3520. if (animate)
  3521. {
  3522. startCameraAnimation();
  3523. }
  3524. else
  3525. {
  3526. mCameraAnimating = false;
  3527. endAnimationUpdateUI();
  3528. }
  3529. gViewerWindowp->resetMouselookFadeTimer();
  3530. if (gAutomationp)
  3531. {
  3532. gAutomationp->onCameraModeChange(mCameraMode);
  3533. }
  3534. }
  3535. return true;
  3536. }
  3537. bool LLAgent::changeCameraToDefault(bool animate)
  3538. {
  3539. if (LLViewerJoystick::getInstance()->getOverrideCamera()
  3540. //MK
  3541. && (!gRLenabled || gRLInterface.mCamDistMax > 0.f))
  3542. //mk
  3543. {
  3544. return false;
  3545. }
  3546. if (LLFollowCamMgr::getActiveFollowCamParams())
  3547. {
  3548. return changeCameraToFollow(animate);
  3549. }
  3550. return changeCameraToThirdPerson(animate);
  3551. }
  3552. bool LLAgent::changeCameraToFollow(bool animate)
  3553. {
  3554. if (LLViewerJoystick::getInstance()->getOverrideCamera()
  3555. //MK
  3556. && (!gRLenabled || gRLInterface.mCamDistMax > 0.f))
  3557. //mk
  3558. {
  3559. return false;
  3560. }
  3561. if (mCameraMode != CAMERA_MODE_FOLLOW)
  3562. {
  3563. if (mCameraMode == CAMERA_MODE_MOUSELOOK)
  3564. {
  3565. animate = false;
  3566. }
  3567. startCameraAnimation();
  3568. mLastCameraMode = mCameraMode;
  3569. mCameraMode = CAMERA_MODE_FOLLOW;
  3570. // Bang-in the current focus, position, and up vector of the follow cam
  3571. mFollowCam.reset(mCameraPositionAgent,
  3572. gViewerCamera.getPointOfInterest(),
  3573. LLVector3::z_axis);
  3574. if (gBasicToolset)
  3575. {
  3576. gToolMgr.setCurrentToolset(gBasicToolset);
  3577. }
  3578. if (isAgentAvatarValid())
  3579. {
  3580. gAgentAvatarp->mPelvisp->setPosition(LLVector3::zero);
  3581. gAgentAvatarp->startMotion(ANIM_AGENT_BODY_NOISE);
  3582. gAgentAvatarp->startMotion(ANIM_AGENT_BREATHE_ROT);
  3583. }
  3584. if (LLFloaterTools::isVisible())
  3585. {
  3586. gFloaterToolsp->close();
  3587. }
  3588. // Unpause avatar animation
  3589. mPauseRequest = NULL;
  3590. clearControlFlags(AGENT_CONTROL_MOUSELOOK);
  3591. if (animate)
  3592. {
  3593. startCameraAnimation();
  3594. }
  3595. else
  3596. {
  3597. mCameraAnimating = false;
  3598. endAnimationUpdateUI();
  3599. }
  3600. if (gAutomationp)
  3601. {
  3602. gAutomationp->onCameraModeChange(mCameraMode);
  3603. }
  3604. }
  3605. return true;
  3606. }
  3607. bool LLAgent::changeCameraToThirdPerson(bool animate)
  3608. {
  3609. if (!gViewerWindowp)
  3610. {
  3611. return false;
  3612. }
  3613. if (LLViewerJoystick::getInstance()->getOverrideCamera()
  3614. //MK
  3615. && (!gRLenabled || gRLInterface.mCamDistMax > 0.f))
  3616. //mk
  3617. {
  3618. return false;
  3619. }
  3620. gWindowp->resetBusyCount();
  3621. mCameraZoomFraction = INITIAL_ZOOM_FRACTION;
  3622. if (isAgentAvatarValid())
  3623. {
  3624. if (!gAgentAvatarp->mIsSitting)
  3625. {
  3626. gAgentAvatarp->mPelvisp->setPosition(LLVector3::zero);
  3627. }
  3628. gAgentAvatarp->startMotion(ANIM_AGENT_BODY_NOISE);
  3629. gAgentAvatarp->startMotion(ANIM_AGENT_BREATHE_ROT);
  3630. }
  3631. // Unpause avatar animation
  3632. mPauseRequest = NULL;
  3633. if (mCameraMode != CAMERA_MODE_THIRD_PERSON)
  3634. {
  3635. if (gBasicToolset)
  3636. {
  3637. gToolMgr.setCurrentToolset(gBasicToolset);
  3638. }
  3639. if (LLFloaterTools::isVisible())
  3640. {
  3641. gFloaterToolsp->close();
  3642. }
  3643. mCameraLag.clear();
  3644. if (mCameraMode == CAMERA_MODE_MOUSELOOK)
  3645. {
  3646. mCurrentCameraDistance = MIN_CAMERA_DISTANCE;
  3647. mTargetCameraDistance = MIN_CAMERA_DISTANCE;
  3648. animate = false;
  3649. }
  3650. mLastCameraMode = mCameraMode;
  3651. mCameraMode = CAMERA_MODE_THIRD_PERSON;
  3652. clearControlFlags(AGENT_CONTROL_MOUSELOOK);
  3653. if (gAutomationp)
  3654. {
  3655. gAutomationp->onCameraModeChange(mCameraMode);
  3656. }
  3657. }
  3658. LLViewerObject* parentp = NULL;
  3659. if (isAgentAvatarValid())
  3660. {
  3661. parentp = (LLViewerObject*)gAgentAvatarp->getParent();
  3662. }
  3663. // Remove any pitch from the avatar
  3664. if (parentp)
  3665. {
  3666. LLVector3 at_axis = gViewerCamera.getAtAxis();
  3667. at_axis.mV[VZ] = 0.f;
  3668. at_axis.normalize();
  3669. LLQuaternion obj_rot = parentp->getRenderRotation();
  3670. resetAxes(at_axis * ~obj_rot);
  3671. }
  3672. else
  3673. {
  3674. LLVector3 at_axis = mFrameAgent.getAtAxis();
  3675. at_axis.mV[VZ] = 0.f;
  3676. at_axis.normalize();
  3677. resetAxes(at_axis);
  3678. }
  3679. if (animate)
  3680. {
  3681. startCameraAnimation();
  3682. }
  3683. else
  3684. {
  3685. mCameraAnimating = false;
  3686. endAnimationUpdateUI();
  3687. }
  3688. //MK
  3689. if (gRLenabled && gRLInterface.mCamDistMax <= 0.f)
  3690. {
  3691. // Make sure we stay in mouselook
  3692. changeCameraToMouselook(false);
  3693. return false;
  3694. }
  3695. //mk
  3696. return true;
  3697. }
  3698. void LLAgent::changeCameraToCustomizeAvatar()
  3699. {
  3700. if (!gViewerWindowp)
  3701. {
  3702. return;
  3703. }
  3704. if (LLViewerJoystick::getInstance()->getOverrideCamera()
  3705. //MK
  3706. && (!gRLenabled || gRLInterface.mCamDistMax > 0.f))
  3707. //mk
  3708. {
  3709. return;
  3710. }
  3711. bool animate = gSavedSettings.getBool("AppearanceAnimation");
  3712. //MK
  3713. if (animate && gRLenabled && gAgentAvatarp->mIsSitting &&
  3714. (gRLInterface.mContainsUnsit || gRLInterface.mContainsStandtp))
  3715. {
  3716. // We are not allowed to stand up, so do not animate !
  3717. animate = false;
  3718. }
  3719. //mk
  3720. if (animate && gAgentAvatarp->mIsSitting)
  3721. {
  3722. // Force stand up
  3723. LL_DEBUGS("AgentSit") << "Sending agent unsit request" << LL_ENDL;
  3724. setControlFlags(AGENT_CONTROL_STAND_UP);
  3725. }
  3726. gWindowp->resetBusyCount();
  3727. if (LLFloaterTools::isVisible())
  3728. {
  3729. gFloaterToolsp->close();
  3730. }
  3731. gToolMgr.setCurrentToolset(gFaceEditToolset);
  3732. if (mCameraMode != CAMERA_MODE_CUSTOMIZE_AVATAR)
  3733. {
  3734. startCameraAnimation();
  3735. if (animate || gSavedSettings.getBool("AppearanceCameraMovement"))
  3736. {
  3737. setupCameraView(true); // Reset the view to rear view.
  3738. }
  3739. mLastCameraMode = mCameraMode;
  3740. mCameraMode = CAMERA_MODE_CUSTOMIZE_AVATAR;
  3741. clearControlFlags(AGENT_CONTROL_MOUSELOOK);
  3742. gFocusMgr.setKeyboardFocus(NULL);
  3743. gFocusMgr.setMouseCapture(NULL);
  3744. if (animate)
  3745. {
  3746. // Remove any pitch or rotation from the avatar
  3747. LLVector3 at = mFrameAgent.getAtAxis();
  3748. at.mV[VZ] = 0.f;
  3749. at.normalize();
  3750. resetAxes(at);
  3751. sendAnimationRequest(ANIM_AGENT_CUSTOMIZE, ANIM_REQUEST_START);
  3752. mCustomAnim = true;
  3753. gAgentAvatarp->startMotion(ANIM_AGENT_CUSTOMIZE);
  3754. LLMotion* turn_motion =
  3755. gAgentAvatarp->findMotion(ANIM_AGENT_CUSTOMIZE);
  3756. if (turn_motion)
  3757. {
  3758. mAnimationDuration = turn_motion->getDuration() +
  3759. CUSTOMIZE_AVATAR_CAMERA_ANIM_SLOP;
  3760. }
  3761. else
  3762. {
  3763. mAnimationDuration = gSavedSettings.getF32("ZoomTime");
  3764. }
  3765. }
  3766. setFocusGlobal(LLVector3d::zero);
  3767. if (gAutomationp)
  3768. {
  3769. gAutomationp->onCameraModeChange(mCameraMode);
  3770. }
  3771. }
  3772. }
  3773. //
  3774. // Focus point management
  3775. //
  3776. void LLAgent::startCameraAnimation()
  3777. {
  3778. mAnimationCameraStartGlobal = getCameraPositionGlobal();
  3779. mAnimationFocusStartGlobal = mFocusGlobal;
  3780. mAnimationTimer.reset();
  3781. mCameraAnimating = true;
  3782. static LLCachedControl<F32> zoom_time(gSavedSettings, "ZoomTime");
  3783. mAnimationDuration = zoom_time;
  3784. }
  3785. void LLAgent::clearFocusObject()
  3786. {
  3787. if (mFocusObject.notNull())
  3788. {
  3789. startCameraAnimation();
  3790. setFocusObject(NULL);
  3791. mFocusObjectOffset.clear();
  3792. }
  3793. }
  3794. void LLAgent::setFocusObject(LLViewerObject* object)
  3795. {
  3796. mFocusObject = object;
  3797. }
  3798. // Focus on a point, but try to keep camera position stable.
  3799. void LLAgent::setFocusGlobal(const LLPickInfo& pick)
  3800. {
  3801. LLViewerObject* objectp = gObjectList.findObject(pick.mObjectID);
  3802. if (objectp && !objectp->isRiggedMesh() && pick.mGLTFNodeIndex == -1)
  3803. {
  3804. // Focus on object plus designated offset which may or may not be same
  3805. // as pick.mPosGlobal, excepted for rigged items to prevent wrong focus
  3806. // position
  3807. setFocusGlobal(objectp->getPositionGlobal() +
  3808. LLVector3d(pick.mObjectOffset),
  3809. pick.mObjectID);
  3810. }
  3811. else
  3812. {
  3813. // Focus directly on point where user clicked
  3814. setFocusGlobal(pick.mPosGlobal, pick.mObjectID);
  3815. }
  3816. }
  3817. void LLAgent::setFocusGlobal(const LLVector3d& focus, const LLUUID& object_id)
  3818. {
  3819. setFocusObject(gObjectList.findObject(object_id));
  3820. LLVector3d old_focus = mFocusTargetGlobal;
  3821. LLViewerObject* focus_obj = mFocusObject;
  3822. if (focus.isExactlyZero())
  3823. {
  3824. if (isAgentAvatarValid())
  3825. {
  3826. mFocusTargetGlobal =
  3827. getPosGlobalFromAgent(gAgentAvatarp->mHeadp->getWorldPosition());
  3828. }
  3829. else
  3830. {
  3831. mFocusTargetGlobal = getPositionGlobal();
  3832. }
  3833. }
  3834. // If focus has changed
  3835. if (old_focus != focus)
  3836. {
  3837. if (focus.isExactlyZero())
  3838. {
  3839. mCameraFocusOffsetTarget = getCameraPositionGlobal() -
  3840. mFocusTargetGlobal;
  3841. mCameraFocusOffset = mCameraFocusOffsetTarget;
  3842. setLookAt(LOOKAT_TARGET_CLEAR);
  3843. }
  3844. else
  3845. {
  3846. mFocusTargetGlobal = focus;
  3847. if (!focus_obj)
  3848. {
  3849. mCameraFOVZoomFactor = 0.f;
  3850. }
  3851. mCameraFocusOffsetTarget =
  3852. getPosGlobalFromAgent(mCameraVirtualPositionAgent) -
  3853. mFocusTargetGlobal;
  3854. startCameraAnimation();
  3855. if (focus_obj)
  3856. {
  3857. if (focus_obj->isAvatar())
  3858. {
  3859. setLookAt(LOOKAT_TARGET_FOCUS, focus_obj);
  3860. }
  3861. else
  3862. {
  3863. setLookAt(LOOKAT_TARGET_FOCUS, focus_obj,
  3864. (getPosAgentFromGlobal(focus) -
  3865. focus_obj->getRenderPosition()) *
  3866. ~focus_obj->getRenderRotation());
  3867. }
  3868. }
  3869. else
  3870. {
  3871. setLookAt(LOOKAT_TARGET_FOCUS, NULL,
  3872. getPosAgentFromGlobal(mFocusTargetGlobal));
  3873. }
  3874. }
  3875. }
  3876. else // focus == mFocusTargetGlobal
  3877. {
  3878. mCameraFocusOffsetTarget = (getCameraPositionGlobal() -
  3879. mFocusTargetGlobal) /
  3880. (1.f + mCameraFOVZoomFactor);
  3881. mCameraFocusOffset = mCameraFocusOffsetTarget;
  3882. }
  3883. if (mFocusObject.notNull())
  3884. {
  3885. // For attachments, make offset relative to avatar, not the attachment
  3886. if (mFocusObject->isAttachment())
  3887. {
  3888. while (mFocusObject.notNull() && !mFocusObject->isAvatar())
  3889. {
  3890. mFocusObject = (LLViewerObject*)mFocusObject->getParent();
  3891. }
  3892. setFocusObject((LLViewerObject*)mFocusObject);
  3893. }
  3894. updateFocusOffset();
  3895. }
  3896. }
  3897. // Used for avatar customization
  3898. void LLAgent::setCameraPosAndFocusGlobal(const LLVector3d& camera_pos,
  3899. const LLVector3d& focus,
  3900. const LLUUID& object_id)
  3901. {
  3902. LLVector3d old_focus = mFocusTargetGlobal.isExactlyZero() ?
  3903. focus : mFocusTargetGlobal;
  3904. F64 focus_delta_squared = (old_focus - focus).lengthSquared();
  3905. constexpr F64 ANIM_EPSILON_SQUARED = 0.0001;
  3906. if (focus_delta_squared > ANIM_EPSILON_SQUARED)
  3907. {
  3908. startCameraAnimation();
  3909. if (mCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR)
  3910. {
  3911. // Compensate for the fact that the camera has already been offset
  3912. // to make room for LLFloaterCustomize.
  3913. mAnimationCameraStartGlobal -=
  3914. LLVector3d(gViewerCamera.getLeftAxis() *
  3915. calcCustomizeAvatarUIOffset(mAnimationCameraStartGlobal));
  3916. }
  3917. }
  3918. #if 0
  3919. gViewerCamera.setOrigin(getPosAgentFromGlobal(camera_pos));
  3920. #endif
  3921. setFocusObject(gObjectList.findObject(object_id));
  3922. mFocusTargetGlobal = focus;
  3923. mCameraFocusOffsetTarget = camera_pos - focus;
  3924. mCameraFocusOffset = mCameraFocusOffsetTarget;
  3925. if (mFocusObject)
  3926. {
  3927. if (mFocusObject->isAvatar())
  3928. {
  3929. setLookAt(LOOKAT_TARGET_FOCUS, mFocusObject);
  3930. }
  3931. else
  3932. {
  3933. setLookAt(LOOKAT_TARGET_FOCUS, mFocusObject,
  3934. (getPosAgentFromGlobal(focus) -
  3935. mFocusObject->getRenderPosition()) *
  3936. ~mFocusObject->getRenderRotation());
  3937. }
  3938. }
  3939. else
  3940. {
  3941. setLookAt(LOOKAT_TARGET_FOCUS, NULL,
  3942. getPosAgentFromGlobal(mFocusTargetGlobal));
  3943. }
  3944. if (mCameraAnimating)
  3945. {
  3946. constexpr F64 ANIM_METERS_PER_SECOND = 10.0;
  3947. constexpr F64 MIN_ANIM_SECONDS = 0.5;
  3948. constexpr F64 MAX_ANIM_SECONDS = 10.0;
  3949. F64 anim_duration = llmax(MIN_ANIM_SECONDS,
  3950. sqrt(focus_delta_squared) /
  3951. ANIM_METERS_PER_SECOND);
  3952. anim_duration = llmin(anim_duration, MAX_ANIM_SECONDS);
  3953. setAnimationDuration((F32)anim_duration);
  3954. }
  3955. updateFocusOffset();
  3956. }
  3957. void LLAgent::setSitCamera(const LLUUID& object_id,
  3958. const LLVector3& camera_pos,
  3959. const LLVector3& camera_focus)
  3960. {
  3961. if (object_id.notNull())
  3962. {
  3963. LLViewerObject* reference_object = gObjectList.findObject(object_id);
  3964. if (reference_object)
  3965. {
  3966. // Convert to root object relative ?
  3967. mSitCameraPos = camera_pos;
  3968. mSitCameraFocus = camera_focus;
  3969. mSitCameraReferenceObject = reference_object;
  3970. mSitCameraEnabled = true;
  3971. }
  3972. }
  3973. else
  3974. {
  3975. mSitCameraPos.clear();
  3976. mSitCameraFocus.clear();
  3977. mSitCameraReferenceObject = NULL;
  3978. mSitCameraEnabled = false;
  3979. }
  3980. }
  3981. void LLAgent::setFocusOnAvatar(bool focus_on_avatar, bool animate)
  3982. {
  3983. if (focus_on_avatar != mFocusOnAvatar)
  3984. {
  3985. if (animate)
  3986. {
  3987. startCameraAnimation();
  3988. }
  3989. else
  3990. {
  3991. stopCameraAnimation();
  3992. }
  3993. }
  3994. if (!mFocusOnAvatar && focus_on_avatar)
  3995. {
  3996. setFocusGlobal(LLVector3d::zero);
  3997. mCameraFOVZoomFactor = 0.f;
  3998. if (mCameraMode == CAMERA_MODE_THIRD_PERSON)
  3999. {
  4000. LLVector3 at_axis =
  4001. gSavedSettings.getBool("ResetViewRotatesAvatar") ?
  4002. gViewerCamera.getAtAxis() : mFrameAgent.getAtAxis();
  4003. at_axis.mV[VZ] = 0.f;
  4004. at_axis.normalize();
  4005. if (isAgentAvatarValid())
  4006. {
  4007. LLViewerObject* parentp =
  4008. (LLViewerObject*)gAgentAvatarp->getParent();
  4009. if (parentp)
  4010. {
  4011. LLQuaternion obj_rot = parentp->getRenderRotation();
  4012. at_axis = at_axis * ~obj_rot;
  4013. }
  4014. }
  4015. resetAxes(at_axis);
  4016. }
  4017. }
  4018. // Unlocking camera from avatar
  4019. else if (mFocusOnAvatar && !focus_on_avatar)
  4020. {
  4021. // Keep camera focus point consistent, even though it is now unlocked
  4022. setFocusGlobal(getPositionGlobal() + calcThirdPersonFocusOffset(),
  4023. gAgentID);
  4024. }
  4025. mFocusOnAvatar = focus_on_avatar;
  4026. }
  4027. void LLAgent::heardChat(const LLUUID& id)
  4028. {
  4029. // Log text and voice chat to speaker manager for keeping track of active
  4030. // speakers, etc.
  4031. LLLocalSpeakerMgr::getInstance()->speakerChatted(id);
  4032. // Do not respond to our own voice
  4033. if (id == gAgentID) return;
  4034. if (ll_rand(2) == 0)
  4035. {
  4036. LLViewerObject* chatter = gObjectList.findObject(mLastChatterID);
  4037. setLookAt(LOOKAT_TARGET_AUTO_LISTEN, chatter, LLVector3::zero);
  4038. }
  4039. mLastChatterID = id;
  4040. mChatTimer.reset();
  4041. }
  4042. void LLAgent::lookAtLastChat()
  4043. {
  4044. // Block if camera is animating or not in normal third person camera mode
  4045. if (mCameraAnimating || !cameraThirdPerson())
  4046. {
  4047. return;
  4048. }
  4049. LLViewerObject* chatter = gObjectList.findObject(mLastChatterID);
  4050. if (!chatter)
  4051. {
  4052. return;
  4053. }
  4054. LLVector3 delta_pos;
  4055. if (chatter->isAvatar())
  4056. {
  4057. LLVOAvatar* avatarp = (LLVOAvatar*)chatter;
  4058. if (isAgentAvatarValid() && avatarp->mHeadp)
  4059. {
  4060. delta_pos = avatarp->mHeadp->getWorldPosition() -
  4061. gAgentAvatarp->mHeadp->getWorldPosition();
  4062. }
  4063. else
  4064. {
  4065. delta_pos = chatter->getPositionAgent() - getPositionAgent();
  4066. }
  4067. delta_pos.normalize();
  4068. setControlFlags(AGENT_CONTROL_STOP);
  4069. changeCameraToThirdPerson();
  4070. LLVector3 new_camera_pos = gAgentAvatarp->mHeadp->getWorldPosition();
  4071. LLVector3 left = delta_pos % LLVector3::z_axis;
  4072. left.normalize();
  4073. LLVector3 up = left % delta_pos;
  4074. up.normalize();
  4075. new_camera_pos -= delta_pos * 0.4f;
  4076. new_camera_pos += left * 0.3f;
  4077. new_camera_pos += up * 0.2f;
  4078. setFocusOnAvatar(false, false);
  4079. if (avatarp->mHeadp)
  4080. {
  4081. setFocusGlobal(getPosGlobalFromAgent(avatarp->mHeadp->getWorldPosition()),
  4082. mLastChatterID);
  4083. mCameraFocusOffsetTarget =
  4084. getPosGlobalFromAgent(new_camera_pos) -
  4085. getPosGlobalFromAgent(avatarp->mHeadp->getWorldPosition());
  4086. }
  4087. else
  4088. {
  4089. setFocusGlobal(chatter->getPositionGlobal(), mLastChatterID);
  4090. mCameraFocusOffsetTarget = getPosGlobalFromAgent(new_camera_pos) -
  4091. chatter->getPositionGlobal();
  4092. }
  4093. }
  4094. else if (!chatter->isHUDAttachment())
  4095. {
  4096. delta_pos = chatter->getRenderPosition() - getPositionAgent();
  4097. delta_pos.normalize();
  4098. setControlFlags(AGENT_CONTROL_STOP);
  4099. changeCameraToThirdPerson();
  4100. LLVector3 new_camera_pos = gAgentAvatarp->mHeadp->getWorldPosition();
  4101. LLVector3 left = delta_pos % LLVector3::z_axis;
  4102. left.normalize();
  4103. LLVector3 up = left % delta_pos;
  4104. up.normalize();
  4105. new_camera_pos -= delta_pos * 0.4f;
  4106. new_camera_pos += left * 0.3f;
  4107. new_camera_pos += up * 0.2f;
  4108. setFocusOnAvatar(false, false);
  4109. setFocusGlobal(chatter->getPositionGlobal(), mLastChatterID);
  4110. mCameraFocusOffsetTarget = getPosGlobalFromAgent(new_camera_pos) -
  4111. chatter->getPositionGlobal();
  4112. }
  4113. }
  4114. void LLAgent::lookAtObject(LLUUID object_id, ECameraPosition camera_pos)
  4115. {
  4116. // Block if camera is animating or not in normal third person camera mode
  4117. if (mCameraAnimating || !cameraThirdPerson())
  4118. {
  4119. return;
  4120. }
  4121. LLViewerObject* objectp = gObjectList.findObject(object_id);
  4122. if (!objectp) return;
  4123. LLVector3 delta_pos;
  4124. if (objectp->isAvatar())
  4125. {
  4126. setFocusOnAvatar(false, false);
  4127. LLVOAvatar* avatarp = (LLVOAvatar*)objectp;
  4128. if (isAgentAvatarValid() && avatarp->mHeadp)
  4129. {
  4130. delta_pos = avatarp->mHeadp->getWorldPosition() -
  4131. gAgentAvatarp->mHeadp->getWorldPosition();
  4132. }
  4133. else
  4134. {
  4135. delta_pos = objectp->getPositionAgent() - getPositionAgent();
  4136. }
  4137. delta_pos.normalize();
  4138. setControlFlags(AGENT_CONTROL_STOP);
  4139. changeCameraToThirdPerson();
  4140. LLVector3 new_camera_pos = gAgentAvatarp->mHeadp->getWorldPosition();
  4141. LLVector3 left = delta_pos % LLVector3::z_axis;
  4142. left.normalize();
  4143. LLVector3 up = left % delta_pos;
  4144. up.normalize();
  4145. new_camera_pos -= delta_pos * 0.4f;
  4146. new_camera_pos += left * 0.3f;
  4147. new_camera_pos += up * 0.2f;
  4148. F32 radius = avatarp->getVObjRadius();
  4149. LLVector3d view_dist(radius, radius, 0.f);
  4150. if (avatarp->mHeadp)
  4151. {
  4152. setFocusGlobal(getPosGlobalFromAgent(avatarp->mHeadp->getWorldPosition()),
  4153. object_id);
  4154. mCameraFocusOffsetTarget =
  4155. getPosGlobalFromAgent(new_camera_pos) -
  4156. getPosGlobalFromAgent(avatarp->mHeadp->getWorldPosition());
  4157. if (camera_pos == CAMERA_POSITION_SELF)
  4158. {
  4159. mCameraFocusOffsetTarget =
  4160. getPosGlobalFromAgent(new_camera_pos) -
  4161. getPosGlobalFromAgent(avatarp->mHeadp->getWorldPosition());
  4162. }
  4163. else // CAMERA_POSITION_OBJECT
  4164. {
  4165. mCameraFocusOffsetTarget = view_dist;
  4166. }
  4167. }
  4168. else
  4169. {
  4170. setFocusGlobal(objectp->getPositionGlobal(), object_id);
  4171. mCameraFocusOffsetTarget = getPosGlobalFromAgent(new_camera_pos) -
  4172. objectp->getPositionGlobal();
  4173. if (camera_pos == CAMERA_POSITION_SELF)
  4174. {
  4175. mCameraFocusOffsetTarget = getPosGlobalFromAgent(new_camera_pos) -
  4176. objectp->getPositionGlobal();
  4177. }
  4178. else // CAMERA_POSITION_OBJECT
  4179. {
  4180. mCameraFocusOffsetTarget = view_dist;
  4181. }
  4182. }
  4183. setFocusOnAvatar(false);
  4184. }
  4185. else if (!objectp->isHUDAttachment())
  4186. {
  4187. setFocusOnAvatar(false, false);
  4188. delta_pos = objectp->getRenderPosition() - getPositionAgent();
  4189. delta_pos.normalize();
  4190. setControlFlags(AGENT_CONTROL_STOP);
  4191. changeCameraToThirdPerson();
  4192. LLVector3 new_camera_pos = gAgentAvatarp->mHeadp->getWorldPosition();
  4193. LLVector3 left = delta_pos % LLVector3::z_axis;
  4194. left.normalize();
  4195. LLVector3 up = left % delta_pos;
  4196. up.normalize();
  4197. new_camera_pos -= delta_pos * 0.4f;
  4198. new_camera_pos += left * 0.3f;
  4199. new_camera_pos += up * 0.2f;
  4200. setFocusGlobal(objectp->getPositionGlobal(), object_id);
  4201. if (camera_pos == CAMERA_POSITION_SELF)
  4202. {
  4203. mCameraFocusOffsetTarget = getPosGlobalFromAgent(new_camera_pos) -
  4204. objectp->getPositionGlobal();
  4205. }
  4206. else // CAMERA_POSITION_OBJECT
  4207. {
  4208. F32 radius = objectp->getVObjRadius();
  4209. LLVector3d view_dist(radius, radius, 0.f);
  4210. mCameraFocusOffsetTarget = view_dist;
  4211. }
  4212. setFocusOnAvatar(false);
  4213. }
  4214. }
  4215. LLSD ll_sdmap_from_vector3(const LLVector3& vec)
  4216. {
  4217. LLSD ret;
  4218. ret["X"] = vec.mV[VX];
  4219. ret["Y"] = vec.mV[VY];
  4220. ret["Z"] = vec.mV[VZ];
  4221. return ret;
  4222. }
  4223. void LLAgent::setStartPosition(U32 location_id)
  4224. {
  4225. if (gAgentID.isNull() || !gObjectList.findAvatar(gAgentID))
  4226. {
  4227. llwarns << "Cannot find agent viewer object id " << gAgentID
  4228. << ". Operation aborted." << llendl;
  4229. return;
  4230. }
  4231. if (!mRegionp)
  4232. {
  4233. llwarns << "Undefined agent region. Operation aborted." << llendl;
  4234. return;
  4235. }
  4236. // We have got the viewer object. Sometimes the agent can be velocity
  4237. // interpolated off of this simulator. Clamp it to the region the agent is
  4238. // in, a little bit in on each side.
  4239. constexpr F32 INSET = 0.5f; //meters
  4240. const F32 region_width = mRegionp->getWidth();
  4241. LLVector3 agent_pos = getPositionAgent();
  4242. if (isAgentAvatarValid())
  4243. {
  4244. // The z height is at the agent's feet
  4245. agent_pos.mV[VZ] -= 0.5f * (gAgentAvatarp->mBodySize.mV[VZ] +
  4246. gAgentAvatarp->mAvatarOffset.mV[VZ]);
  4247. }
  4248. agent_pos.mV[VX] = llclamp(agent_pos.mV[VX], INSET, region_width - INSET);
  4249. agent_pos.mV[VY] = llclamp(agent_pos.mV[VY], INSET, region_width - INSET);
  4250. // Don't let them go below ground, or too high.
  4251. agent_pos.mV[VZ] = llclamp(agent_pos.mV[VZ],
  4252. mRegionp->getLandHeightRegion(agent_pos),
  4253. MAX_OBJECT_Z);
  4254. const std::string& url = getRegionCapability("HomeLocation");
  4255. if (!url.empty())
  4256. {
  4257. // Send the capability request
  4258. LLSD loc;
  4259. loc["LocationId"] = LLSD::Integer(location_id);
  4260. loc["LocationPos"] = ll_sdmap_from_vector3(agent_pos);
  4261. loc["LocationLookAt"] = ll_sdmap_from_vector3(mFrameAgent.getAtAxis());
  4262. LLSD body;
  4263. body["HomeLocation"] = loc;
  4264. LLCoreHttpUtil::HttpCoroutineAdapter::callbackHttpPost(url,
  4265. mHttpPolicy,
  4266. body,
  4267. setStartPositionSuccess,
  4268. NULL);
  4269. return;
  4270. }
  4271. // Old UDP message based method
  4272. LLMessageSystem* msg = gMessageSystemp;
  4273. if (!msg) return;
  4274. msg->newMessageFast(_PREHASH_SetStartLocationRequest);
  4275. msg->nextBlockFast(_PREHASH_AgentData);
  4276. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  4277. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  4278. msg->nextBlockFast(_PREHASH_StartLocationData);
  4279. // Corrected by the sim
  4280. msg->addStringFast(_PREHASH_SimName, "");
  4281. msg->addU32Fast(_PREHASH_LocationID, location_id);
  4282. msg->addVector3Fast(_PREHASH_LocationPos, agent_pos);
  4283. msg->addVector3Fast(_PREHASH_LocationLookAt, mFrameAgent.getAtAxis());
  4284. // Reliable only helps when setting home location. Last location is sent on
  4285. // quit, and we do not have time to ack the packets.
  4286. msg->sendReliable(mRegionp->getHost());
  4287. // With the old UDP method, we suppose the request to set home to here will
  4288. // be granted... Which might not even be true !
  4289. if (location_id == START_LOCATION_ID_HOME)
  4290. {
  4291. setHomePosRegion(mRegionp->getHandle(), getPositionAgent());
  4292. std::string name = gViewerParcelMgr.getAgentParcelName() + "|" +
  4293. mRegionp->getName();
  4294. LLStringUtil::trim(name);
  4295. gSavedPerAccountSettings.setString("AgentHomeParcel", name);
  4296. }
  4297. }
  4298. //static
  4299. void LLAgent::setStartPositionSuccess(const LLSD& result)
  4300. {
  4301. // Check for a valid server response
  4302. if (!result.has("success") || !result["success"].asBoolean() ||
  4303. !result.has("HomeLocation") ||
  4304. !result["HomeLocation"].has("LocationPos") ||
  4305. !result["HomeLocation"]["LocationPos"].has("X") ||
  4306. !result["HomeLocation"]["LocationPos"].has("Y") ||
  4307. !result["HomeLocation"]["LocationPos"].has("Z"))
  4308. {
  4309. llwarns << "Invalid server response for home location" << llendl;
  4310. return;
  4311. }
  4312. LLVector3 agent_pos;
  4313. agent_pos.mV[VX] = result["HomeLocation"]["LocationPos"]["X"].asInteger();
  4314. agent_pos.mV[VY] = result["HomeLocation"]["LocationPos"]["Y"].asInteger();
  4315. agent_pos.mV[VZ] = result["HomeLocation"]["LocationPos"]["Z"].asInteger();
  4316. LLViewerRegion* regionp = gAgent.mRegionp;
  4317. if (regionp)
  4318. {
  4319. llinfos << "Setting home position." << llendl;
  4320. gAgent.setHomePosRegion(regionp->getHandle(), agent_pos);
  4321. std::string name = gViewerParcelMgr.getAgentParcelName() + "|" +
  4322. regionp->getName();
  4323. LLStringUtil::trim(name);
  4324. gSavedPerAccountSettings.setString("AgentHomeParcel", name);
  4325. }
  4326. else
  4327. {
  4328. llwarns << "No region for agent; disconnected ? Aborted." << llendl;
  4329. }
  4330. }
  4331. void LLAgent::requestStopMotion(LLMotion* motion)
  4332. {
  4333. // Notify all avatars that a motion has stopped. This is needed to clear
  4334. // the animation state bits
  4335. LLUUID anim_state_id = motion->getID();
  4336. onAnimStop(anim_state_id);
  4337. // If motion is not looping, it could have stopped by running out of time
  4338. // so we need to tell the server this
  4339. sendAnimationRequest(anim_state_id, ANIM_REQUEST_STOP);
  4340. }
  4341. void LLAgent::onAnimStop(const LLUUID& id)
  4342. {
  4343. // Handle automatic state transitions (based on completion of animation
  4344. // playback)
  4345. if (id == ANIM_AGENT_STAND)
  4346. {
  4347. stopFidget();
  4348. }
  4349. else if (id == ANIM_AGENT_AWAY)
  4350. {
  4351. clearAFK();
  4352. }
  4353. else if (id == ANIM_AGENT_STANDUP)
  4354. {
  4355. // Send stand up command
  4356. setControlFlags(AGENT_CONTROL_FINISH_ANIM);
  4357. // Now trigger dusting self off animation
  4358. if (isAgentAvatarValid() && !gAgentAvatarp->mBelowWater && rand() % 3 == 0)
  4359. {
  4360. sendAnimationRequest(ANIM_AGENT_BRUSH, ANIM_REQUEST_START);
  4361. }
  4362. }
  4363. else if (id == ANIM_AGENT_PRE_JUMP || id == ANIM_AGENT_LAND ||
  4364. id == ANIM_AGENT_MEDIUM_LAND)
  4365. {
  4366. setControlFlags(AGENT_CONTROL_FINISH_ANIM);
  4367. }
  4368. //MK
  4369. else if (gRLenabled && gRLInterface.mSitGroundOnStandUp &&
  4370. (id == ANIM_AGENT_SIT || id == ANIM_AGENT_SIT_FEMALE ||
  4371. id == ANIM_AGENT_SIT_GENERIC || id == ANIM_AGENT_SIT_TO_STAND))
  4372. {
  4373. // We are now standing up from an object, if we did this following a
  4374. // @sitground command, immediately sit down on the ground.
  4375. gRLInterface.mSitGroundOnStandUp = false;
  4376. gAgent.setFlying(false);
  4377. gAgent.clearControlFlags(AGENT_CONTROL_STAND_UP);
  4378. gAgent.setControlFlags(AGENT_CONTROL_SIT_ON_GROUND);
  4379. gRLInterface.storeLastStandingLoc(true);
  4380. }
  4381. //mk
  4382. }
  4383. bool LLAgent::wantsPGOnly() const
  4384. {
  4385. return (prefersPG() || isTeen()) && !isGodlike();
  4386. }
  4387. bool LLAgent::canAccessMature() const
  4388. {
  4389. // If you prefer mature, you're either mature or adult, and therefore can
  4390. // access all mature content
  4391. return isGodlike() || (prefersMature() && !isTeen());
  4392. }
  4393. bool LLAgent::canAccessAdult() const
  4394. {
  4395. // If you prefer adult, you must BE adult.
  4396. return isGodlike() || (prefersAdult() && isAdult());
  4397. }
  4398. // Note: this is for now only used in llviewermessage.cpp to allow playing the
  4399. // TP sound whenever we can TP to a region. In case of a more "serious" usage
  4400. // in the future, we might want to implement the "TODO" item... HB
  4401. bool LLAgent::canAccessMaturityInRegion(U64 region_handle) const
  4402. {
  4403. LLViewerRegion* regionp = gWorld.getRegionFromHandle(region_handle);
  4404. if (!regionp)
  4405. {
  4406. // Region not yet connected and instance not yet created in the viewer:
  4407. // its maturity rating is unknown, just yet... *TODO: use sim info from
  4408. // the world map, if available ? HB
  4409. return true;
  4410. }
  4411. U8 access = regionp->getSimAccess();
  4412. if (access == SIM_ACCESS_MATURE && !canAccessMature())
  4413. {
  4414. return false;
  4415. }
  4416. if (access == SIM_ACCESS_ADULT && !canAccessAdult())
  4417. {
  4418. return false;
  4419. }
  4420. return true;
  4421. }
  4422. bool LLAgent::canAccessMaturityAtGlobal(LLVector3d pos_global) const
  4423. {
  4424. U64 region_handle = to_region_handle_global(pos_global.mdV[0],
  4425. pos_global.mdV[1]);
  4426. return canAccessMaturityInRegion(region_handle);
  4427. }
  4428. bool LLAgent::prefersPG() const
  4429. {
  4430. static LLCachedControl<U32> maturity(gSavedSettings, "PreferredMaturity");
  4431. return maturity < SIM_ACCESS_MATURE;
  4432. }
  4433. bool LLAgent::prefersMature() const
  4434. {
  4435. static LLCachedControl<U32> maturity(gSavedSettings, "PreferredMaturity");
  4436. return maturity >= SIM_ACCESS_MATURE;
  4437. }
  4438. bool LLAgent::prefersAdult() const
  4439. {
  4440. static LLCachedControl<U32> maturity(gSavedSettings, "PreferredMaturity");
  4441. return maturity >= SIM_ACCESS_ADULT;
  4442. }
  4443. void LLAgent::setTeen(bool teen)
  4444. {
  4445. mAccess = teen ? SIM_ACCESS_PG : SIM_ACCESS_MATURE;
  4446. }
  4447. //static
  4448. U8 LLAgent::convertTextToMaturity(char text)
  4449. {
  4450. if ('A' == text)
  4451. {
  4452. return SIM_ACCESS_ADULT;
  4453. }
  4454. else if ('M' == text)
  4455. {
  4456. return SIM_ACCESS_MATURE;
  4457. }
  4458. else if ('P' == text)
  4459. {
  4460. return SIM_ACCESS_PG;
  4461. }
  4462. return SIM_ACCESS_MIN;
  4463. }
  4464. bool LLAgent::sendMaturityPreferenceToServer(U8 maturity)
  4465. {
  4466. // Update agent access preference on the server
  4467. const std::string url = getRegionCapability("UpdateAgentInformation");
  4468. if (url.empty()) return false;
  4469. // Set new access preference
  4470. std::string matstr = LLViewerRegion::accessToShortString(maturity);
  4471. LLSD access_prefs = LLSD::emptyMap();
  4472. access_prefs["max"] = matstr;
  4473. LLSD body = LLSD::emptyMap();
  4474. body["access_prefs"] = access_prefs;
  4475. llinfos << "Sending access prefs update to "
  4476. << (access_prefs["max"].asString()) << " via capability to: "
  4477. << url << llendl;
  4478. httpCallback_t cbsucc = boost::bind(&LLAgent::processMaturityPreferenceFromServer,
  4479. _1, matstr);
  4480. httpCallback_t cbfail = boost::bind(&LLAgent::handlePreferredMaturityError,
  4481. maturity);
  4482. LLCoreHttpUtil::HttpCoroutineAdapter::callbackHttpPost(url, mHttpPolicy,
  4483. body, cbsucc,
  4484. cbfail);
  4485. return true;
  4486. }
  4487. //static
  4488. void LLAgent::processMaturityPreferenceFromServer(const LLSD& result,
  4489. std::string reqmatstr)
  4490. {
  4491. std::string matstr;
  4492. if (result.isDefined() && result.isMap() && result.has("access_prefs") &&
  4493. result.get("access_prefs").isMap() &&
  4494. result.get("access_prefs").has("max") &&
  4495. result.get("access_prefs").get("max").isString())
  4496. {
  4497. matstr = result.get("access_prefs").get("max").asString();
  4498. LLStringUtil::trim(matstr);
  4499. }
  4500. if (matstr == reqmatstr)
  4501. {
  4502. llinfos << "Maturity successfully set to: " << matstr << llendl;
  4503. }
  4504. else
  4505. {
  4506. llwarns << "While attempting to change maturity preference to '"
  4507. << reqmatstr << "', the server responded with '" << matstr
  4508. << llendl;
  4509. }
  4510. #if 0 // Response ignored. *TODO: backport v3's maturity responder.
  4511. gAgent.handlePreferredMaturityResult(matstr);
  4512. #endif
  4513. }
  4514. //static
  4515. void LLAgent::handlePreferredMaturityError(U8 requested_maturity)
  4516. {
  4517. llwarns << "Error while attempting to change maturity preference to: "
  4518. << LLViewerRegion::accessToString(requested_maturity) << llendl;
  4519. // Response ignored. *TODO: backport v3's maturity responder.
  4520. }
  4521. bool LLAgent::requestPostCapability(const char* cap_name, LLSD& data,
  4522. httpCallback_t cbsucc,
  4523. httpCallback_t cbfail)
  4524. {
  4525. const std::string& url = getRegionCapability(cap_name);
  4526. if (url.empty())
  4527. {
  4528. llinfos << "No region capability: " << cap_name << llendl;
  4529. return false;
  4530. }
  4531. LLCoreHttpUtil::HttpCoroutineAdapter::callbackHttpPost(url, mHttpPolicy,
  4532. data,
  4533. cbsucc, cbfail);
  4534. return true;
  4535. }
  4536. bool LLAgent::requestGetCapability(const char* cap_name,
  4537. httpCallback_t cbsucc,
  4538. httpCallback_t cbfail)
  4539. {
  4540. const std::string& url = getRegionCapability(cap_name);
  4541. if (url.empty())
  4542. {
  4543. llinfos << "No region capability: " << cap_name << llendl;
  4544. return false;
  4545. }
  4546. LLCoreHttpUtil::HttpCoroutineAdapter::callbackHttpGet(url, mHttpPolicy,
  4547. cbsucc, cbfail);
  4548. return true;
  4549. }
  4550. bool LLAgent::canSetMaturity(U8 maturity)
  4551. {
  4552. if (isAdult() || isGodlike())
  4553. {
  4554. // Adults and "gods" can always set their Maturity level
  4555. return true;
  4556. }
  4557. return maturity == SIM_ACCESS_PG ||
  4558. (maturity == SIM_ACCESS_MATURE && isMature());
  4559. }
  4560. void LLAgent::setMaturity(char text)
  4561. {
  4562. mAccess = convertTextToMaturity(text);
  4563. U8 preferred_access = (U8)gSavedSettings.getU32("PreferredMaturity");
  4564. while (!canSetMaturity(preferred_access))
  4565. {
  4566. if (preferred_access == SIM_ACCESS_ADULT)
  4567. {
  4568. preferred_access = SIM_ACCESS_MATURE;
  4569. }
  4570. else
  4571. {
  4572. // Mature or invalid access gets set to PG
  4573. preferred_access = SIM_ACCESS_PG;
  4574. }
  4575. }
  4576. gSavedSettings.setU32("PreferredMaturity", preferred_access);
  4577. }
  4578. void LLAgent::setGodLevel(U8 god_level)
  4579. {
  4580. mGodLevel = god_level;
  4581. mGodLevelChangeSignal(god_level);
  4582. }
  4583. LLAgent::god_level_change_slot_t LLAgent::registerGodLevelChanageListener(god_level_change_callback_t callback)
  4584. {
  4585. return mGodLevelChangeSignal.connect(callback);
  4586. }
  4587. bool LLAgent::validateMaturity(const LLSD& newvalue)
  4588. {
  4589. return canSetMaturity(newvalue.asInteger());
  4590. }
  4591. void LLAgent::handleMaturity(const LLSD& newvalue)
  4592. {
  4593. sendMaturityPreferenceToServer(newvalue.asInteger());
  4594. }
  4595. void LLAgent::buildFullname(std::string& name) const
  4596. {
  4597. if (isAgentAvatarValid())
  4598. {
  4599. name = gAgentAvatarp->getFullname();
  4600. }
  4601. }
  4602. void LLAgent::buildFullnameAndTitle(std::string& name) const
  4603. {
  4604. if (isGroupMember())
  4605. {
  4606. name = mGroupTitle;
  4607. name += ' ';
  4608. }
  4609. else
  4610. {
  4611. name.erase(0, name.length());
  4612. }
  4613. if (isAgentAvatarValid())
  4614. {
  4615. name += gAgentAvatarp->getFullname();
  4616. }
  4617. }
  4618. bool LLAgent::isInGroup(const LLUUID& group_id, bool ignore_god_mode) const
  4619. {
  4620. if (!ignore_god_mode && isGodlikeWithoutAdminMenuFakery())
  4621. {
  4622. return true;
  4623. }
  4624. for (S32 i = 0, count = mGroups.size(); i < count; ++i)
  4625. {
  4626. if (mGroups[i].mID == group_id)
  4627. {
  4628. return true;
  4629. }
  4630. }
  4631. return false;
  4632. }
  4633. bool LLAgent::setGroup(const LLUUID& group_id)
  4634. {
  4635. if (group_id == mGroupID)
  4636. {
  4637. return true;
  4638. }
  4639. //MK
  4640. if (gRLenabled && gRLInterface.contains("setgroup"))
  4641. {
  4642. return false;
  4643. }
  4644. //mk
  4645. if (group_id.notNull() && !isInGroup(group_id, true))
  4646. {
  4647. return false;
  4648. }
  4649. LLMessageSystem* msg = gMessageSystemp;
  4650. msg->newMessageFast(_PREHASH_ActivateGroup);
  4651. msg->nextBlockFast(_PREHASH_AgentData);
  4652. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  4653. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  4654. msg->addUUIDFast(_PREHASH_GroupID, group_id);
  4655. gAgent.sendReliableMessage();
  4656. return true;
  4657. }
  4658. // This implementation should mirror LLAgentInfo::hasPowerInGroup
  4659. bool LLAgent::hasPowerInGroup(const LLUUID& group_id, U64 power) const
  4660. {
  4661. if (isGodlikeWithoutAdminMenuFakery())
  4662. {
  4663. return true;
  4664. }
  4665. // GP_NO_POWERS can also mean no power is enough to grant an ability.
  4666. if (power == GP_NO_POWERS)
  4667. {
  4668. return false;
  4669. }
  4670. for (S32 i = 0, count = mGroups.size(); i < count; ++i)
  4671. {
  4672. if (mGroups[i].mID == group_id)
  4673. {
  4674. return (mGroups[i].mPowers & power) > 0;
  4675. }
  4676. }
  4677. return false;
  4678. }
  4679. bool LLAgent::hasPowerInActiveGroup(U64 power) const
  4680. {
  4681. return mGroupID.notNull() && hasPowerInGroup(mGroupID, power);
  4682. }
  4683. U64 LLAgent::getPowerInGroup(const LLUUID& group_id) const
  4684. {
  4685. if (isGodlike())
  4686. {
  4687. return GP_ALL_POWERS;
  4688. }
  4689. for (S32 i = 0, count = mGroups.size(); i < count; ++i)
  4690. {
  4691. if (mGroups[i].mID == group_id)
  4692. {
  4693. return mGroups[i].mPowers;
  4694. }
  4695. }
  4696. return GP_NO_POWERS;
  4697. }
  4698. bool LLAgent::getGroupData(const LLUUID& group_id, LLGroupData& data) const
  4699. {
  4700. for (S32 i = 0, count = mGroups.size(); i < count; ++i)
  4701. {
  4702. if (mGroups[i].mID == group_id)
  4703. {
  4704. data = mGroups[i];
  4705. return true;
  4706. }
  4707. }
  4708. return false;
  4709. }
  4710. S32 LLAgent::getGroupContribution(const LLUUID& group_id) const
  4711. {
  4712. for (S32 i = 0, count = mGroups.size(); i < count; ++i)
  4713. {
  4714. if (mGroups[i].mID == group_id)
  4715. {
  4716. S32 contribution = mGroups[i].mContribution;
  4717. return contribution;
  4718. }
  4719. }
  4720. return 0;
  4721. }
  4722. bool LLAgent::setGroupContribution(const LLUUID& group_id, S32 contribution)
  4723. {
  4724. for (S32 i = 0, count = mGroups.size(); i < count; ++i)
  4725. {
  4726. if (mGroups[i].mID == group_id)
  4727. {
  4728. mGroups[i].mContribution = contribution;
  4729. LLMessageSystem* msg = gMessageSystemp;
  4730. if (!msg) return false;
  4731. msg->newMessage(_PREHASH_SetGroupContribution);
  4732. msg->nextBlock(_PREHASH_AgentData);
  4733. msg->addUUID(_PREHASH_AgentID, gAgentID);
  4734. msg->addUUID(_PREHASH_SessionID, gAgentSessionID);
  4735. msg->nextBlock(_PREHASH_Data);
  4736. msg->addUUID(_PREHASH_GroupID, group_id);
  4737. msg->addS32(_PREHASH_Contribution, contribution);
  4738. sendReliableMessage();
  4739. return true;
  4740. }
  4741. }
  4742. return false;
  4743. }
  4744. bool LLAgent::setUserGroupFlags(const LLUUID& group_id, bool accept_notices,
  4745. bool list_in_profile)
  4746. {
  4747. for (S32 i = 0, count = mGroups.size(); i < count; ++i)
  4748. {
  4749. if (mGroups[i].mID == group_id)
  4750. {
  4751. mGroups[i].mAcceptNotices = accept_notices;
  4752. mGroups[i].mListInProfile = list_in_profile;
  4753. LLMessageSystem* msg = gMessageSystemp;
  4754. if (!msg) return false;
  4755. msg->newMessage(_PREHASH_SetGroupAcceptNotices);
  4756. msg->nextBlock(_PREHASH_AgentData);
  4757. msg->addUUID(_PREHASH_AgentID, gAgentID);
  4758. msg->addUUID(_PREHASH_SessionID, gAgentSessionID);
  4759. msg->nextBlock(_PREHASH_Data);
  4760. msg->addUUID(_PREHASH_GroupID, group_id);
  4761. msg->addBool(_PREHASH_AcceptNotices, accept_notices);
  4762. msg->nextBlock(_PREHASH_NewData);
  4763. msg->addBool(_PREHASH_ListInProfile, list_in_profile);
  4764. sendReliableMessage();
  4765. update_group_floaters(group_id);
  4766. return true;
  4767. }
  4768. }
  4769. return false;
  4770. }
  4771. void LLAgent::updateLanguage()
  4772. {
  4773. LLSD body;
  4774. body["language"] = LLUI::getLanguage();
  4775. body["language_is_public"] = gSavedSettings.getBool("LanguageIsPublic");
  4776. if (!requestPostCapability("UpdateAgentLanguage", body))
  4777. {
  4778. llwarns << "Cannot post language choice to server." << llendl;
  4779. }
  4780. }
  4781. // Utility to build a location string
  4782. void LLAgent::buildLocationString(std::string& str)
  4783. {
  4784. const LLVector3& agent_pos_region = getPositionAgent();
  4785. S32 pos_x = S32(agent_pos_region.mV[VX]);
  4786. S32 pos_y = S32(agent_pos_region.mV[VY]);
  4787. S32 pos_z = S32(agent_pos_region.mV[VZ]);
  4788. // Round the numbers based on the velocity
  4789. LLVector3 agent_velocity = getVelocity();
  4790. F32 velocity_mag_sq = agent_velocity.lengthSquared();
  4791. constexpr F32 FLY_CUTOFF = 6.f; // meters/sec
  4792. constexpr F32 FLY_CUTOFF_SQ = FLY_CUTOFF * FLY_CUTOFF;
  4793. constexpr F32 WALK_CUTOFF = 1.5f; // meters/sec
  4794. constexpr F32 WALK_CUTOFF_SQ = WALK_CUTOFF * WALK_CUTOFF;
  4795. if (velocity_mag_sq > FLY_CUTOFF_SQ)
  4796. {
  4797. pos_x -= pos_x % 4;
  4798. pos_y -= pos_y % 4;
  4799. }
  4800. else if (velocity_mag_sq > WALK_CUTOFF_SQ)
  4801. {
  4802. pos_x -= pos_x % 2;
  4803. pos_y -= pos_y % 2;
  4804. }
  4805. // Create a defult name and description for the landmark
  4806. std::string buffer;
  4807. if (gViewerParcelMgr.getAgentParcelName().empty())
  4808. {
  4809. // The parcel does not have a name
  4810. buffer = llformat("%.32s (%d, %d, %d)", mRegionp->getName().c_str(),
  4811. pos_x, pos_y, pos_z);
  4812. }
  4813. else
  4814. {
  4815. // The parcel has a name, so include it in the landmark name
  4816. buffer = llformat("%.32s, %.32s (%d, %d, %d)",
  4817. gViewerParcelMgr.getAgentParcelName().c_str(),
  4818. mRegionp->getName().c_str(), pos_x, pos_y, pos_z);
  4819. }
  4820. str = buffer;
  4821. }
  4822. LLQuaternion LLAgent::getHeadRotation()
  4823. {
  4824. if (!isAgentAvatarValid() || !gAgentAvatarp->mPelvisp ||
  4825. !gAgentAvatarp->mHeadp)
  4826. {
  4827. return LLQuaternion::DEFAULT;
  4828. }
  4829. if (!cameraMouselook())
  4830. {
  4831. return gAgentAvatarp->getRotation();
  4832. }
  4833. // We must be in mouselook
  4834. LLVector3 look_dir(gViewerCamera.getAtAxis());
  4835. LLVector3 up = look_dir % mFrameAgent.getLeftAxis();
  4836. LLVector3 left = up % look_dir;
  4837. LLQuaternion rot(look_dir, left, up);
  4838. if (gAgentAvatarp->getParent())
  4839. {
  4840. rot = rot * ~gAgentAvatarp->getParent()->getRotation();
  4841. }
  4842. return rot;
  4843. }
  4844. void LLAgent::sendAnimationRequests(uuid_vec_t& anim_ids, EAnimRequest request)
  4845. {
  4846. LLMessageSystem* msg = gMessageSystemp;
  4847. if (gAgentID.isNull() || !msg)
  4848. {
  4849. return;
  4850. }
  4851. msg->newMessageFast(_PREHASH_AgentAnimation);
  4852. msg->nextBlockFast(_PREHASH_AgentData);
  4853. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  4854. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  4855. bool has_valid_anims = false;
  4856. bool start_anim = request == ANIM_REQUEST_START;
  4857. for (S32 i = 0, count = anim_ids.size(); i < count; ++i)
  4858. {
  4859. const LLUUID& anim_id = anim_ids[i];
  4860. if (anim_id.notNull())
  4861. {
  4862. has_valid_anims = true;
  4863. msg->nextBlockFast(_PREHASH_AnimationList);
  4864. msg->addUUIDFast(_PREHASH_AnimID, anim_id);
  4865. msg->addBoolFast(_PREHASH_StartAnim, start_anim);
  4866. }
  4867. }
  4868. if (has_valid_anims)
  4869. {
  4870. msg->nextBlockFast(_PREHASH_PhysicalAvatarEventList);
  4871. msg->addBinaryDataFast(_PREHASH_TypeData, NULL, 0);
  4872. sendReliableMessage();
  4873. }
  4874. else
  4875. {
  4876. // Nothing to send: we *must* clear the message (else, the next message
  4877. // will retain our unsent message header, resulting in a crash in
  4878. // LLTemplateMessageBuilder::nextBlock() at some point, due to invalid
  4879. // block name/data).
  4880. msg->clearMessage();
  4881. }
  4882. }
  4883. void LLAgent::sendAnimationRequest(const LLUUID& anim_id, EAnimRequest request)
  4884. {
  4885. LLMessageSystem* msg = gMessageSystemp;
  4886. if (gAgentID.isNull() || anim_id.isNull() || !mRegionp || !msg)
  4887. {
  4888. return;
  4889. }
  4890. msg->newMessageFast(_PREHASH_AgentAnimation);
  4891. msg->nextBlockFast(_PREHASH_AgentData);
  4892. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  4893. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  4894. msg->nextBlockFast(_PREHASH_AnimationList);
  4895. msg->addUUIDFast(_PREHASH_AnimID, anim_id);
  4896. msg->addBoolFast(_PREHASH_StartAnim, request == ANIM_REQUEST_START);
  4897. msg->nextBlockFast(_PREHASH_PhysicalAvatarEventList);
  4898. msg->addBinaryDataFast(_PREHASH_TypeData, NULL, 0);
  4899. sendReliableMessage();
  4900. }
  4901. // Send a message to the region to stop the NULL animation state. This will
  4902. // reset animation state overrides for the agent.
  4903. void LLAgent::sendAnimationStateReset()
  4904. {
  4905. LLMessageSystem* msg = gMessageSystemp;
  4906. if (msg && gAgentID.notNull())
  4907. {
  4908. msg->newMessageFast(_PREHASH_AgentAnimation);
  4909. msg->nextBlockFast(_PREHASH_AgentData);
  4910. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  4911. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  4912. msg->nextBlockFast(_PREHASH_AnimationList);
  4913. msg->addUUIDFast(_PREHASH_AnimID, LLUUID::null);
  4914. msg->addBoolFast(_PREHASH_StartAnim, false);
  4915. msg->nextBlockFast(_PREHASH_PhysicalAvatarEventList);
  4916. msg->addBinaryDataFast(_PREHASH_TypeData, NULL, 0);
  4917. sendReliableMessage();
  4918. }
  4919. }
  4920. // Send a message to the region to revoke sepecified permissions on ALL scripts
  4921. // in the region. If the target is an object in the region, permissions in
  4922. // scripts on that object are cleared. If it is the region ID, all scripts
  4923. // clear the permissions for this agent.
  4924. void LLAgent::sendRevokePermissions(const LLUUID& target, U32 permissions)
  4925. {
  4926. // Currently, in SL, only the bits for SCRIPT_PERMISSION_TRIGGER_ANIMATION
  4927. // and SCRIPT_PERMISSION_OVERRIDE_ANIMATIONS are supported by the servers.
  4928. // Sending any other bits will cause the message to be dropped without
  4929. // changing any permission.
  4930. LLMessageSystem* msg = gMessageSystemp;
  4931. if (msg && gAgentID.notNull())
  4932. {
  4933. msg->newMessageFast(_PREHASH_RevokePermissions);
  4934. msg->nextBlockFast(_PREHASH_AgentData);
  4935. msg->addUUIDFast(_PREHASH_AgentID, gAgentID); // Must be our ID
  4936. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  4937. msg->nextBlockFast(_PREHASH_Data);
  4938. msg->addUUIDFast(_PREHASH_ObjectID, target); // Must be in the region
  4939. msg->addU32Fast(_PREHASH_ObjectPermissions, permissions);
  4940. sendReliableMessage();
  4941. }
  4942. }
  4943. void LLAgent::sendWalkRun(bool running)
  4944. {
  4945. LLMessageSystem* msg = gMessageSystemp;
  4946. if (msg)
  4947. {
  4948. msg->newMessageFast(_PREHASH_SetAlwaysRun);
  4949. msg->nextBlockFast(_PREHASH_AgentData);
  4950. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  4951. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  4952. msg->addBoolFast(_PREHASH_AlwaysRun, running);
  4953. sendReliableMessage();
  4954. }
  4955. }
  4956. void LLAgent::friendsChanged()
  4957. {
  4958. LLCollectProxyBuddies collector;
  4959. gAvatarTracker.applyFunctor(collector);
  4960. mProxyForAgents = collector.mProxy;
  4961. }
  4962. bool LLAgent::isGrantedProxy(const LLPermissions& perm)
  4963. {
  4964. return mProxyForAgents.count(perm.getOwner()) > 0;
  4965. }
  4966. bool LLAgent::allowOperation(PermissionBit op, const LLPermissions& perm,
  4967. U64 group_proxy_power, U8 god_minimum)
  4968. {
  4969. // Check god level.
  4970. if (getGodLevel() >= god_minimum) return true;
  4971. if (!perm.isOwned()) return false;
  4972. // A group member with group_proxy_power can act as owner.
  4973. bool is_group_owned;
  4974. LLUUID owner_id;
  4975. perm.getOwnership(owner_id, is_group_owned);
  4976. LLUUID group_id(perm.getGroup());
  4977. LLUUID agent_proxy(gAgentID);
  4978. if (is_group_owned)
  4979. {
  4980. if (hasPowerInGroup(group_id, group_proxy_power))
  4981. {
  4982. // Let the member assume the group's id for permission requests.
  4983. agent_proxy = owner_id;
  4984. }
  4985. }
  4986. // Check for granted mod permissions.
  4987. else if (op != PERM_OWNER && isGrantedProxy(perm))
  4988. {
  4989. agent_proxy = owner_id;
  4990. }
  4991. // This is the group id to use for permission requests. Only group members
  4992. // may use this field.
  4993. LLUUID group_proxy;
  4994. if (group_id.notNull() && isInGroup(group_id))
  4995. {
  4996. group_proxy = group_id;
  4997. }
  4998. // We now have max ownership information.
  4999. if (PERM_OWNER == op)
  5000. {
  5001. // This this was just a check for ownership, we can now return the
  5002. // answer.
  5003. return (agent_proxy == owner_id);
  5004. }
  5005. return perm.allowOperationBy(op, agent_proxy, group_proxy);
  5006. }
  5007. void LLAgent::getName(std::string& name)
  5008. {
  5009. name.clear();
  5010. if (isAgentAvatarValid())
  5011. {
  5012. LLNameValue* first_nv = gAgentAvatarp->getNVPair("FirstName");
  5013. LLNameValue* last_nv = gAgentAvatarp->getNVPair("LastName");
  5014. if (first_nv && last_nv)
  5015. {
  5016. name = first_nv->printData() + " " + last_nv->printData();
  5017. }
  5018. else
  5019. {
  5020. llwarns << "Agent is missing FirstName and/or LastName nv pair."
  5021. << llendl;
  5022. }
  5023. }
  5024. else
  5025. {
  5026. name = gLoginFirstName + " " + gLoginLastName;
  5027. }
  5028. }
  5029. void update_group_floaters(const LLUUID& group_id)
  5030. {
  5031. LLFloaterGroupInfo::refreshGroup(group_id);
  5032. // Update avatar info
  5033. LLFloaterAvatarInfo* floaterp = LLFloaterAvatarInfo::getInstance(gAgentID);
  5034. if (floaterp)
  5035. {
  5036. floaterp->listAgentGroups();
  5037. }
  5038. if (gIMMgrp)
  5039. {
  5040. // Update the talk view
  5041. gIMMgrp->refresh();
  5042. }
  5043. gAgent.fireEvent(new LLEvent(&gAgent, "new group"), "");
  5044. }
  5045. //static
  5046. void LLAgent::processAgentDropGroup(LLMessageSystem* msg, void**)
  5047. {
  5048. LLUUID agent_id;
  5049. msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
  5050. if (agent_id != gAgentID)
  5051. {
  5052. llwarns << "Received drop group for agent other than me" << llendl;
  5053. return;
  5054. }
  5055. LLUUID group_id;
  5056. msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_GroupID, group_id);
  5057. // Remove the group if it already exists remove it and add the new data to
  5058. // pick up changes.
  5059. LLGroupData gd;
  5060. gd.mID = group_id;
  5061. std::vector<LLGroupData>::iterator end = gAgent.mGroups.end();
  5062. std::vector<LLGroupData>::iterator it =
  5063. std::find(gAgent.mGroups.begin(), end, gd);
  5064. if (it != end)
  5065. {
  5066. gAgent.mGroups.erase(it);
  5067. if (gAgent.mGroupID == group_id)
  5068. {
  5069. gAgent.mGroupID.setNull();
  5070. gAgent.mGroupPowers = 0;
  5071. gAgent.mGroupName.clear();
  5072. gAgent.mGroupTitle.clear();
  5073. }
  5074. // Refresh all group information
  5075. gAgent.sendAgentDataUpdateRequest();
  5076. gGroupMgr.clearGroupData(group_id);
  5077. // Close the floater for this group, if any.
  5078. LLFloaterGroupInfo::closeGroup(group_id);
  5079. // Refresh the group panel of the search window, if necessary.
  5080. HBFloaterSearch::refreshGroup(group_id);
  5081. }
  5082. else
  5083. {
  5084. llwarns << "Agent is not part of group " << group_id << llendl;
  5085. }
  5086. }
  5087. class LLAgentDropGroupViewerNode final : public LLHTTPNode
  5088. {
  5089. void post(LLHTTPNode::ResponsePtr response, const LLSD& context,
  5090. const LLSD& input) const override
  5091. {
  5092. if (!input.isMap() || !input.has("body"))
  5093. {
  5094. // What to do with badly formed message ?
  5095. response->extendedResult(HTTP_BAD_REQUEST,
  5096. LLSD("Invalid message parameters"));
  5097. }
  5098. LLSD body = input["body"];
  5099. if (body.has("body"))
  5100. {
  5101. // Stupid message system doubles up the "body"s
  5102. body = body["body"];
  5103. }
  5104. if (body.has("AgentData") && body["AgentData"].isArray() &&
  5105. body["AgentData"][0].isMap())
  5106. {
  5107. llinfos << "VALID DROP GROUP" << llendl;
  5108. // There is only one set of data in the AgentData block
  5109. const LLSD& agent_data = body["AgentData"][0];
  5110. LLUUID agent_id = agent_data["AgentID"].asUUID();
  5111. if (agent_id != gAgentID)
  5112. {
  5113. llwarns << "AgentDropGroup for agent other than me" << llendl;
  5114. response->notFound();
  5115. return;
  5116. }
  5117. LLUUID group_id = agent_data["GroupID"].asUUID();
  5118. // Remove the group if it already exists remove it and add the new
  5119. // data to pick up changes.
  5120. LLGroupData gd;
  5121. gd.mID = group_id;
  5122. std::vector<LLGroupData>::iterator end = gAgent.mGroups.end();
  5123. std::vector<LLGroupData>::iterator it =
  5124. std::find(gAgent.mGroups.begin(), end, gd);
  5125. if (it != end)
  5126. {
  5127. gAgent.mGroups.erase(it);
  5128. if (gAgent.mGroupID == group_id)
  5129. {
  5130. gAgent.mGroupID.setNull();
  5131. gAgent.mGroupPowers = 0;
  5132. gAgent.mGroupName.clear();
  5133. gAgent.mGroupTitle.clear();
  5134. }
  5135. // Refresh all group information
  5136. gAgent.sendAgentDataUpdateRequest();
  5137. gGroupMgr.clearGroupData(group_id);
  5138. // Close the floater for this group, if any.
  5139. LLFloaterGroupInfo::closeGroup(group_id);
  5140. // Refresh the group panel of the search window, if necessary
  5141. HBFloaterSearch::refreshGroup(group_id);
  5142. }
  5143. else
  5144. {
  5145. llwarns << "AgentDropGroup, agent is not part of group "
  5146. << group_id << llendl;
  5147. }
  5148. response->result(LLSD());
  5149. }
  5150. else
  5151. {
  5152. // What to do with badly formed message ?
  5153. response->extendedResult(HTTP_BAD_REQUEST,
  5154. LLSD("Invalid message parameters"));
  5155. }
  5156. }
  5157. };
  5158. LLHTTPRegistration<LLAgentDropGroupViewerNode>
  5159. gHTTPRegistrationAgentDropGroupViewerNode("/message/AgentDropGroup");
  5160. //static
  5161. void LLAgent::processAgentGroupDataUpdate(LLMessageSystem* msg, void**)
  5162. {
  5163. LLUUID agent_id;
  5164. msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
  5165. if (agent_id != gAgentID)
  5166. {
  5167. return; // Not for us !... Ignore.
  5168. }
  5169. S32 count = msg->getNumberOfBlocksFast(_PREHASH_GroupData);
  5170. LLGroupData group;
  5171. bool need_floater_update = false;
  5172. for (S32 i = 0; i < count; ++i)
  5173. {
  5174. msg->getUUIDFast(_PREHASH_GroupData, _PREHASH_GroupID, group.mID, i);
  5175. msg->getUUIDFast(_PREHASH_GroupData, _PREHASH_GroupInsigniaID,
  5176. group.mInsigniaID, i);
  5177. msg->getU64(_PREHASH_GroupData, _PREHASH_GroupPowers, group.mPowers,
  5178. i);
  5179. msg->getBool(_PREHASH_GroupData, _PREHASH_AcceptNotices,
  5180. group.mAcceptNotices, i);
  5181. msg->getS32(_PREHASH_GroupData, _PREHASH_Contribution,
  5182. group.mContribution, i);
  5183. msg->getStringFast(_PREHASH_GroupData, _PREHASH_GroupName,
  5184. group.mName, i);
  5185. if (group.mID.notNull())
  5186. {
  5187. need_floater_update = true;
  5188. // Remove the group if it already exists and add the new data to
  5189. // pick up changes.
  5190. std::vector<LLGroupData>::iterator end = gAgent.mGroups.end();
  5191. std::vector<LLGroupData>::iterator it =
  5192. std::find(gAgent.mGroups.begin(), end, group);
  5193. if (it != end)
  5194. {
  5195. gAgent.mGroups.erase(it);
  5196. }
  5197. gAgent.mGroups.emplace_back(group);
  5198. }
  5199. if (need_floater_update)
  5200. {
  5201. update_group_floaters(group.mID);
  5202. }
  5203. }
  5204. }
  5205. class LLAgentGroupDataUpdateViewerNode final : public LLHTTPNode
  5206. {
  5207. void post(LLHTTPNode::ResponsePtr response, const LLSD& context,
  5208. const LLSD& input) const override
  5209. {
  5210. LLSD body = input["body"];
  5211. if (body.has("body"))
  5212. {
  5213. body = body["body"];
  5214. }
  5215. LLUUID agent_id = body["AgentData"][0]["AgentID"].asUUID();
  5216. if (agent_id != gAgentID)
  5217. {
  5218. llwarns << "Received agent group data update for agent other than me"
  5219. << llendl;
  5220. return;
  5221. }
  5222. const LLSD& group_data = body["GroupData"];
  5223. S32 group_idx = 0;
  5224. for (LLSD::array_const_iterator it = group_data.beginArray(),
  5225. end = group_data.endArray();
  5226. it != end; ++it)
  5227. {
  5228. LLGroupData group;
  5229. group.mID = (*it)["GroupID"].asUUID();
  5230. group.mPowers = ll_U64_from_sd((*it)["GroupPowers"]);
  5231. group.mAcceptNotices = (*it)["AcceptNotices"].asBoolean();
  5232. group.mListInProfile =
  5233. body["NewGroupData"][group_idx++]["ListInProfile"].asBoolean();
  5234. group.mInsigniaID = (*it)["GroupInsigniaID"].asUUID();
  5235. group.mName = (*it)["GroupName"].asString();
  5236. group.mContribution = (*it)["Contribution"].asInteger();
  5237. if (group.mID.notNull())
  5238. {
  5239. // Remove the group if it already exists and add the new data
  5240. // to pick up changes.
  5241. std::vector<LLGroupData>::iterator end2 = gAgent.mGroups.end();
  5242. std::vector<LLGroupData>::iterator it2 =
  5243. std::find(gAgent.mGroups.begin(), end2, group);
  5244. if (it2 != end2)
  5245. {
  5246. gAgent.mGroups.erase(it2);
  5247. }
  5248. gAgent.mGroups.emplace_back(group);
  5249. update_group_floaters(group.mID);
  5250. }
  5251. }
  5252. }
  5253. };
  5254. LLHTTPRegistration<LLAgentGroupDataUpdateViewerNode >
  5255. gHTTPRegistrationAgentGroupDataUpdateViewerNode ("/message/AgentGroupDataUpdate");
  5256. //static
  5257. void LLAgent::processAgentDataUpdate(LLMessageSystem* msg, void**)
  5258. {
  5259. LLUUID agent_id;
  5260. msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
  5261. if (agent_id != gAgentID)
  5262. {
  5263. return; // Not for us !... Ignore.
  5264. }
  5265. msg->getStringFast(_PREHASH_AgentData, _PREHASH_GroupTitle,
  5266. gAgent.mGroupTitle);
  5267. LLUUID active_id;
  5268. msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_ActiveGroupID, active_id);
  5269. if (active_id.notNull())
  5270. {
  5271. gAgent.mGroupID = active_id;
  5272. msg->getU64(_PREHASH_AgentData, _PREHASH_GroupPowers,
  5273. gAgent.mGroupPowers);
  5274. msg->getString(_PREHASH_AgentData, _PREHASH_GroupName,
  5275. gAgent.mGroupName);
  5276. }
  5277. else
  5278. {
  5279. gAgent.mGroupID.setNull();
  5280. gAgent.mGroupPowers = 0;
  5281. gAgent.mGroupName.clear();
  5282. }
  5283. update_group_floaters(active_id);
  5284. }
  5285. //static
  5286. void LLAgent::processScriptControlChange(LLMessageSystem* msg, void**)
  5287. {
  5288. S32 block_count = msg->getNumberOfBlocks(_PREHASH_Data);
  5289. for (S32 block_index = 0; block_index < block_count; ++block_index)
  5290. {
  5291. bool take_controls, passon;
  5292. U32 controls;
  5293. msg->getBool(_PREHASH_Data, _PREHASH_TakeControls, take_controls,
  5294. block_index);
  5295. if (take_controls)
  5296. {
  5297. // Take controls
  5298. msg->getU32(_PREHASH_Data, _PREHASH_Controls, controls,
  5299. block_index);
  5300. msg->getBool(_PREHASH_Data, _PREHASH_PassToAgent, passon,
  5301. block_index);
  5302. U32 total_count = 0;
  5303. for (U32 i = 0; i < TOTAL_CONTROLS; ++i)
  5304. {
  5305. if (controls & (1 << i))
  5306. {
  5307. if (passon)
  5308. {
  5309. ++gAgent.mControlsTakenPassedOnCount[i];
  5310. }
  5311. else
  5312. {
  5313. ++gAgent.mControlsTakenCount[i];
  5314. }
  5315. ++total_count;
  5316. }
  5317. }
  5318. // Any control taken ? If so, might be first time.
  5319. if (total_count > 0)
  5320. {
  5321. LLFirstUse::useOverrideKeys();
  5322. }
  5323. }
  5324. else
  5325. {
  5326. // Release controls
  5327. msg->getU32(_PREHASH_Data, _PREHASH_Controls, controls,
  5328. block_index);
  5329. msg->getBool(_PREHASH_Data, _PREHASH_PassToAgent, passon,
  5330. block_index);
  5331. for (U32 i = 0; i < TOTAL_CONTROLS; ++i)
  5332. {
  5333. if (controls & (1 << i))
  5334. {
  5335. if (passon)
  5336. {
  5337. --gAgent.mControlsTakenPassedOnCount[i];
  5338. if (gAgent.mControlsTakenPassedOnCount[i] < 0)
  5339. {
  5340. gAgent.mControlsTakenPassedOnCount[i] = 0;
  5341. }
  5342. }
  5343. else
  5344. {
  5345. --gAgent.mControlsTakenCount[i];
  5346. if (gAgent.mControlsTakenCount[i] < 0)
  5347. {
  5348. gAgent.mControlsTakenCount[i] = 0;
  5349. }
  5350. }
  5351. }
  5352. }
  5353. }
  5354. }
  5355. }
  5356. //static
  5357. void LLAgent::processAgentCachedTextureResponse(LLMessageSystem* mesgsys,
  5358. void** user_data)
  5359. {
  5360. if (--gAgentQueryManager.mNumPendingQueries < 0)
  5361. {
  5362. LL_DEBUGS("Agent") << "Negative pending queries, resetting to 0."
  5363. << LL_ENDL;
  5364. gAgentQueryManager.mNumPendingQueries = 0;
  5365. }
  5366. else
  5367. {
  5368. LL_DEBUGS("Agent") << "Remaining pending queries: "
  5369. << gAgentQueryManager.mNumPendingQueries << LL_ENDL;
  5370. }
  5371. if (!isAgentAvatarValid())
  5372. {
  5373. llwarns << "No avatar for user in cached texture update!" << llendl;
  5374. return;
  5375. }
  5376. if (gAgentAvatarp->isEditingAppearance())
  5377. {
  5378. // Ignore baked textures when in customize mode
  5379. LL_DEBUGS("Agent") << "Agent in customize mode, not uploading baked textures."
  5380. << LL_ENDL;
  5381. return;
  5382. }
  5383. S32 query_id;
  5384. mesgsys->getS32Fast(_PREHASH_AgentData, _PREHASH_SerialNum, query_id);
  5385. S32 num_texture_blocks =
  5386. mesgsys->getNumberOfBlocksFast(_PREHASH_WearableData);
  5387. S32 num_results = 0;
  5388. U8 texture_index;
  5389. LLUUID texture_id;
  5390. for (S32 texture_block = 0; texture_block < num_texture_blocks;
  5391. ++texture_block)
  5392. {
  5393. mesgsys->getUUIDFast(_PREHASH_WearableData, _PREHASH_TextureID,
  5394. texture_id, texture_block);
  5395. mesgsys->getU8Fast(_PREHASH_WearableData, _PREHASH_TextureIndex,
  5396. texture_index, texture_block);
  5397. if ((S32)texture_index >= TEX_NUM_INDICES)
  5398. {
  5399. continue;
  5400. }
  5401. const LLAvatarAppearanceDictionary::TextureEntry* te =
  5402. gAvatarAppDictp->getTexture((ETextureIndex)texture_index);
  5403. if (!te)
  5404. {
  5405. LL_DEBUGS("Agent") << "No texture entry found for index "
  5406. << (U32)texture_index << " !!!"<< LL_ENDL;
  5407. continue;
  5408. }
  5409. EBakedTextureIndex baked_index = te->mBakedTextureIndex;
  5410. if (gAgentQueryManager.mActiveCacheQueries[baked_index] != query_id)
  5411. {
  5412. continue;
  5413. }
  5414. if (texture_id.notNull())
  5415. {
  5416. LL_DEBUGS("Agent") << "Received cached texture "
  5417. << (U32)texture_index << ": "
  5418. << texture_id << LL_ENDL;
  5419. gAgentAvatarp->setCachedBakedTexture((ETextureIndex)texture_index,
  5420. texture_id);
  5421. #if 0
  5422. gAgentAvatarp->setTETexture(LLVOAvatar::sBakedTextureIndices[texture_index],
  5423. texture_id);
  5424. #endif
  5425. gAgentQueryManager.mActiveCacheQueries[baked_index] = 0;
  5426. ++num_results;
  5427. }
  5428. else if ((U8)baked_index >= gAgent.mUploadedBakes)
  5429. {
  5430. LL_DEBUGS("Agent") << "No cache for baked index "
  5431. << (U32)baked_index
  5432. << ", which is a BoM-only bake. Ignoring."
  5433. << LL_ENDL;
  5434. }
  5435. else
  5436. {
  5437. // No cache of this bake. Request upload.
  5438. LL_DEBUGS("Agent") << "No cache for baked index "
  5439. << (U32)baked_index
  5440. << ", invalidating composite to trigger rebake..."
  5441. << LL_ENDL;
  5442. gAgentAvatarp->invalidateComposite(gAgentAvatarp->getLayerSet(baked_index),
  5443. true);
  5444. }
  5445. }
  5446. llinfos << "Received cached texture response for " << num_results
  5447. << " textures." << llendl;
  5448. gAgentAvatarp->updateMeshTextures();
  5449. if (gAgentQueryManager.mNumPendingQueries <= 0)
  5450. {
  5451. // RN: not sure why composites are disabled at this point
  5452. gAgentAvatarp->setCompositeUpdatesEnabled(true);
  5453. gAgent.sendAgentSetAppearance();
  5454. }
  5455. }
  5456. bool LLAgent::anyControlGrabbed() const
  5457. {
  5458. for (U32 i = 0; i < TOTAL_CONTROLS; ++i)
  5459. {
  5460. if (mControlsTakenCount[i] > 0 || mControlsTakenPassedOnCount[i] > 0)
  5461. {
  5462. return true;
  5463. }
  5464. }
  5465. return false;
  5466. }
  5467. void LLAgent::forceReleaseControls()
  5468. {
  5469. LLMessageSystem* msg = gMessageSystemp;
  5470. if (msg)
  5471. {
  5472. msg->newMessage(_PREHASH_ForceScriptControlRelease);
  5473. msg->nextBlock(_PREHASH_AgentData);
  5474. msg->addUUID(_PREHASH_AgentID, gAgentID);
  5475. msg->addUUID(_PREHASH_SessionID, gAgentSessionID);
  5476. sendReliableMessage();
  5477. }
  5478. }
  5479. void LLAgent::setHomePosRegion(const U64& region_handle,
  5480. const LLVector3& pos_region)
  5481. {
  5482. mHaveHomePosition = true;
  5483. mHomeRegionHandle = region_handle;
  5484. mHomePosRegion = pos_region;
  5485. }
  5486. bool LLAgent::getHomePosGlobal(LLVector3d* pos_global)
  5487. {
  5488. if (!mHaveHomePosition)
  5489. {
  5490. return false;
  5491. }
  5492. F32 x = 0;
  5493. F32 y = 0;
  5494. from_region_handle(mHomeRegionHandle, &x, &y);
  5495. pos_global->set(x + mHomePosRegion.mV[VX], y + mHomePosRegion.mV[VY],
  5496. mHomePosRegion.mV[VZ]);
  5497. return true;
  5498. }
  5499. void LLAgent::clearVisualParams(void* data)
  5500. {
  5501. if (isAgentAvatarValid())
  5502. {
  5503. gAgentAvatarp->clearVisualParamWeights();
  5504. gAgentAvatarp->updateVisualParams();
  5505. }
  5506. }
  5507. void LLAgent::setNearChatRadius(F32 radius)
  5508. {
  5509. mNearChatRadius = radius;
  5510. LLHUDEffectLookAt::updateSettings();
  5511. }
  5512. //---------------------------------------------------------------------------
  5513. // Teleport
  5514. //---------------------------------------------------------------------------
  5515. void LLAgent::setTeleportedSimHandle(const LLVector3d& pos_global)
  5516. {
  5517. if (!pos_global.isExactlyZero())
  5518. {
  5519. LLSimInfo* info = gWorldMap.simInfoFromPosGlobal(pos_global);
  5520. if (info)
  5521. {
  5522. mTeleportedPosGlobal = pos_global;
  5523. mTeleportedSimHandle = info->mHandle;
  5524. // Also force an update of the number of agents in this sim ASAP
  5525. info->mAgentsUpdateTime = 0.0;
  5526. LL_DEBUGS("Teleport") << "Set teleported sim handle: "
  5527. << mTeleportedSimHandle << ". Position: "
  5528. << mTeleportedPosGlobal << LL_ENDL;
  5529. return;
  5530. }
  5531. }
  5532. resetTeleportedSimHandle();
  5533. }
  5534. void LLAgent::resetTeleportedSimHandle()
  5535. {
  5536. LL_DEBUGS("Teleport") << "Resetting teleported sim handle and position"
  5537. << LL_ENDL;
  5538. mTeleportedSimHandle = 0;
  5539. mTeleportedPosGlobal.setZero();
  5540. }
  5541. // Stuff to do on any teleport
  5542. bool LLAgent::teleportCore(const LLVector3d& pos_global)
  5543. {
  5544. LL_DEBUGS("Teleport") << "Destination global position: " << pos_global
  5545. << LL_ENDL;
  5546. if (mTeleportState != TELEPORT_NONE)
  5547. {
  5548. llwarns << "Attempt to teleport when already teleporting." << llendl;
  5549. return false;
  5550. }
  5551. if (!mRegionp)
  5552. {
  5553. llwarns << "Current region undefined !" << llendl;
  5554. return false;
  5555. }
  5556. // Force stand up and stop a sitting animation (if any), see MAINT-3969
  5557. if (isAgentAvatarValid() && gAgentAvatarp->mIsSitting &&
  5558. gAgentAvatarp->getParent())
  5559. {
  5560. LL_DEBUGS("AgentSit") << "Unsitting agent for TP" << LL_ENDL;
  5561. gAgentAvatarp->getOffObject();
  5562. }
  5563. // Hide the land floater since it will get out of date...
  5564. LLFloaterLand::hideInstance();
  5565. gViewerParcelMgr.deselectLand();
  5566. LLViewerMediaFocus::getInstance()->setFocusFace(false, NULL, 0, NULL);
  5567. // Close all pie menus, deselect land, etc, but do not change the camera
  5568. // until we know teleport succeeded.
  5569. resetView(false);
  5570. gViewerStats.incStat(LLViewerStats::ST_TELEPORT_COUNT);
  5571. bool is_local = false;
  5572. if (!pos_global.isExactlyZero())
  5573. {
  5574. F32 region_x = (F32)pos_global.mdV[VX];
  5575. F32 region_y = (F32)pos_global.mdV[VY];
  5576. U64 region_handle = to_region_handle_global(region_x, region_y);
  5577. is_local = mRegionp->getHandle() == region_handle;
  5578. LL_DEBUGS("Teleport") << "Current region handle: "
  5579. << mRegionp->getHandle()
  5580. << " - Destination region handle: "
  5581. << region_handle << " - Local TP = " << is_local
  5582. << LL_ENDL;
  5583. }
  5584. if (is_local)
  5585. {
  5586. setTeleportState(TELEPORT_LOCAL);
  5587. }
  5588. else
  5589. {
  5590. // When the event poll for the agent region is not within a safe window
  5591. // for the TP to happen while it is active on the server side, wait for
  5592. // sending the TP until the next poll request is started and has
  5593. // settled. HB
  5594. static LLCachedControl<bool> tp_race_fix(gSavedSettings,
  5595. "TPRaceWorkAroundInSL");
  5596. static LLCachedControl<bool> restart_poll(gSavedSettings,
  5597. "TPRaceRestartPoll");
  5598. if (gIsInSecondLife && tp_race_fix && !mRegionp->isEventPollInFlight())
  5599. {
  5600. llinfos << "Queuing the teleport request to let the agent region event poll fire."
  5601. << llendl;
  5602. setTeleportState(TELEPORT_QUEUED);
  5603. if (restart_poll)
  5604. {
  5605. // *HACK: re-launch the event poll for our region to try and
  5606. // avoid the race condition server-side.
  5607. const std::string& url =
  5608. mRegionp->getCapability("EventQueueGet");
  5609. if (!url.empty())
  5610. {
  5611. mRegionp->setCapability("EventQueueGet", url);
  5612. }
  5613. }
  5614. }
  5615. else
  5616. {
  5617. setTeleportState(TELEPORT_START);
  5618. }
  5619. setTeleportedSimHandle(pos_global);
  5620. if (gSavedSettings.getBool("SpeedRez"))
  5621. {
  5622. F32 draw_distance = gSavedSettings.getF32("RenderFarClip");
  5623. if (gSavedDrawDistance < draw_distance)
  5624. {
  5625. gSavedDrawDistance = draw_distance;
  5626. }
  5627. gSavedSettings.setF32("SavedRenderFarClip", gSavedDrawDistance);
  5628. gSavedSettings.setF32("RenderFarClip", 32.f);
  5629. }
  5630. make_ui_sound("UISndTeleportOut");
  5631. }
  5632. return true;
  5633. }
  5634. class HBQueuedTeleport
  5635. {
  5636. protected:
  5637. LOG_CLASS(HBQueuedTeleport);
  5638. public:
  5639. enum eTPType : U32
  5640. {
  5641. TP_NONE,
  5642. TP_LOCATION,
  5643. TP_LANDMARK,
  5644. TP_LURE,
  5645. };
  5646. HBQueuedTeleport()
  5647. : mType(TP_NONE),
  5648. mRegionhandle(0),
  5649. mTeleportFlags(0)
  5650. {
  5651. }
  5652. void queueLocation(U64 handle, const LLVector3& pos_local,
  5653. const LLVector3& look_at)
  5654. {
  5655. mType = TP_LOCATION;
  5656. mRegionhandle = handle;
  5657. mPosLocal = pos_local;
  5658. bool keep_look_at = gAgent.getTeleportKeepsLookAt();
  5659. mLookAtAxis = keep_look_at ? gViewerCamera.getAtAxis() : look_at;
  5660. resetGuardTimer();
  5661. }
  5662. void queueLandmark(const LLUUID& lm_asset_id)
  5663. {
  5664. mType = TP_LANDMARK;
  5665. mLandmarkAssetId = lm_asset_id;
  5666. resetGuardTimer();
  5667. }
  5668. void queueLure(const LLUUID& lure_id, U32 teleport_flags)
  5669. {
  5670. mType = TP_LURE;
  5671. mLureId = lure_id;
  5672. mTeleportFlags = teleport_flags;
  5673. resetGuardTimer();
  5674. }
  5675. void fire();
  5676. bool expired()
  5677. {
  5678. return mGuardTimer.hasExpired();
  5679. }
  5680. private:
  5681. void resetGuardTimer()
  5682. {
  5683. // Set the guard timer to encompass the maximum delay after which the
  5684. // LLViewerRegion::isEventPollInFlight() call for the agent region
  5685. // should return true.
  5686. mGuardTimer.reset();
  5687. mGuardTimer.setTimerExpirySec(2.f * LLEventPoll::getMargin() + 0.5f);
  5688. }
  5689. private:
  5690. LLUUID mLandmarkAssetId;
  5691. LLUUID mLureId;
  5692. U64 mRegionhandle;
  5693. LLVector3 mPosLocal;
  5694. LLVector3 mLookAtAxis;
  5695. U32 mTeleportFlags;
  5696. U32 mType;
  5697. LLTimer mGuardTimer;
  5698. };
  5699. void HBQueuedTeleport::fire()
  5700. {
  5701. LLMessageSystem* msg = gMessageSystemp;
  5702. if (!msg || mType == TP_NONE) return;
  5703. if (mType == TP_LOCATION)
  5704. {
  5705. LL_DEBUGS("Teleport") << "Sending TeleportLocationRequest" << LL_ENDL;
  5706. msg->newMessage(_PREHASH_TeleportLocationRequest);
  5707. msg->nextBlockFast(_PREHASH_AgentData);
  5708. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  5709. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  5710. msg->nextBlockFast(_PREHASH_Info);
  5711. msg->addU64(_PREHASH_RegionHandle, mRegionhandle);
  5712. msg->addVector3(_PREHASH_Position, mPosLocal);
  5713. msg->addVector3(_PREHASH_LookAt, mLookAtAxis);
  5714. }
  5715. else if (mType == TP_LANDMARK)
  5716. {
  5717. // When when teleporting home, reset the camera view before requesting
  5718. // the TP, so that the camera will point in the right direction on
  5719. // arrival.
  5720. if (mLandmarkAssetId.isNull())
  5721. {
  5722. gAgent.resetView(true, true);
  5723. }
  5724. LL_DEBUGS("Teleport") << "Sending TeleportLandmarkRequest" << LL_ENDL;
  5725. msg->newMessageFast(_PREHASH_TeleportLandmarkRequest);
  5726. msg->nextBlockFast(_PREHASH_Info);
  5727. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  5728. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  5729. msg->addUUIDFast(_PREHASH_LandmarkID, mLandmarkAssetId);
  5730. }
  5731. else if (mType == TP_LURE)
  5732. {
  5733. LL_DEBUGS("Teleport") << "Sending TeleportLureRequest" << LL_ENDL;
  5734. msg->newMessageFast(_PREHASH_TeleportLureRequest);
  5735. msg->nextBlockFast(_PREHASH_Info);
  5736. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  5737. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  5738. msg->addUUIDFast(_PREHASH_LureID, mLureId);
  5739. // Note: TeleportFlags is a legacy field, now derived sim-side.
  5740. msg->addU32(_PREHASH_TeleportFlags, mTeleportFlags);
  5741. }
  5742. else
  5743. {
  5744. llerrs << "Invalid TP request type" << llendl;
  5745. }
  5746. gAgent.setTeleportState(LLAgent::TELEPORT_START);
  5747. gAgent.sendReliableMessage();
  5748. mType = TP_NONE;
  5749. llinfos << "Teleport request sent." << llendl;
  5750. }
  5751. static HBQueuedTeleport sQueuedTeleport;
  5752. void LLAgent::fireQueuedTeleport()
  5753. {
  5754. static LLCachedControl<bool> tp_race_fix(gSavedSettings,
  5755. "TPRaceWorkAroundInSL");
  5756. if (!gIsInSecondLife || !tp_race_fix ||
  5757. (mRegionp && mRegionp->isEventPollInFlight()) ||
  5758. sQueuedTeleport.expired())
  5759. {
  5760. sQueuedTeleport.fire();
  5761. }
  5762. }
  5763. // lm_asset_id = LLUUID::null means teleport home
  5764. void LLAgent::teleportViaLandmark(const LLUUID& lm_asset_id)
  5765. {
  5766. LL_DEBUGS("Teleport") << "Landmark asset Id: " << lm_asset_id << LL_ENDL;
  5767. //MK
  5768. if (gRLenabled &&
  5769. (!LLStartUp::isLoggedIn() ||
  5770. (gViewerWindowp && gViewerWindowp->getShowProgress()) ||
  5771. gRLInterface.contains("tplm") ||
  5772. (gRLInterface.mContainsUnsit &&
  5773. isAgentAvatarValid() && gAgentAvatarp->mIsSitting)))
  5774. {
  5775. return;
  5776. }
  5777. //mk
  5778. LLVector3d pos_global;
  5779. if (lm_asset_id.notNull() &&
  5780. lm_asset_id != LLFloaterWorldMap::getHomeID())
  5781. {
  5782. LLLandmark* landmark = gLandmarkList.getAsset(lm_asset_id);
  5783. if (landmark)
  5784. {
  5785. landmark->getGlobalPos(pos_global);
  5786. }
  5787. }
  5788. if (teleportCore(pos_global))
  5789. {
  5790. sQueuedTeleport.queueLandmark(lm_asset_id);
  5791. if (mTeleportState != TELEPORT_QUEUED)
  5792. {
  5793. sQueuedTeleport.fire();
  5794. }
  5795. }
  5796. }
  5797. void LLAgent::teleportViaLure(const LLUUID& lure_id, bool godlike)
  5798. {
  5799. LL_DEBUGS("Teleport") << "Lure Id: " << lure_id
  5800. << " - God-like: " << (godlike ? "true" : "false")
  5801. << LL_ENDL;
  5802. if (teleportCore())
  5803. {
  5804. U32 teleport_flags = 0x0;
  5805. if (godlike)
  5806. {
  5807. teleport_flags |= TELEPORT_FLAGS_VIA_GODLIKE_LURE;
  5808. teleport_flags |= TELEPORT_FLAGS_DISABLE_CANCEL;
  5809. }
  5810. else
  5811. {
  5812. teleport_flags |= TELEPORT_FLAGS_VIA_LURE;
  5813. }
  5814. sQueuedTeleport.queueLure(lure_id, teleport_flags);
  5815. if (mTeleportState != TELEPORT_QUEUED)
  5816. {
  5817. sQueuedTeleport.fire();
  5818. }
  5819. }
  5820. }
  5821. void LLAgent::teleportCancel()
  5822. {
  5823. if (mRegionp)
  5824. {
  5825. // Send the message
  5826. LLMessageSystem* msg = gMessageSystemp;
  5827. if (!msg) return;
  5828. msg->newMessage(_PREHASH_TeleportCancel);
  5829. msg->nextBlockFast(_PREHASH_Info);
  5830. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  5831. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  5832. sendReliableMessage();
  5833. }
  5834. gTeleportDisplay = false;
  5835. LL_DEBUGS("Teleport") << "Resetting to TELEPORT_NONE" << LL_ENDL;
  5836. setTeleportState(TELEPORT_NONE);
  5837. gPipeline.resetVertexBuffers();
  5838. }
  5839. void LLAgent::teleportRequest(U64 region_handle, const LLVector3d& pos_global,
  5840. const LLVector3& pos_local,
  5841. const LLVector3& look_at)
  5842. {
  5843. LL_DEBUGS("Teleport") << "Region handle: " << region_handle
  5844. << " - Global position: " << pos_global
  5845. << " - Local position: " << pos_local
  5846. << " - Look-at vector: " << look_at << LL_ENDL;
  5847. if (teleportCore(pos_global))
  5848. {
  5849. llinfos << "TeleportLocationRequest. Region handle: " << region_handle
  5850. << " - Local position: " << pos_local << llendl;
  5851. mTeleportKeepsLookAt = look_at.isExactlyZero();
  5852. if (mTeleportKeepsLookAt)
  5853. {
  5854. // Detach camera from avatar, so it keeps direction
  5855. setFocusOnAvatar(false);
  5856. }
  5857. sQueuedTeleport.queueLocation(region_handle, pos_local, look_at);
  5858. if (mTeleportState != TELEPORT_QUEUED)
  5859. {
  5860. sQueuedTeleport.fire();
  5861. }
  5862. }
  5863. }
  5864. void LLAgent::teleportViaLocation(const LLVector3d& pos_global)
  5865. {
  5866. LL_DEBUGS("Teleport") << "Global position: " << pos_global << LL_ENDL;
  5867. //MK
  5868. if (gRLenabled &&
  5869. (!LLStartUp::isLoggedIn() ||
  5870. (gViewerWindowp && gViewerWindowp->getShowProgress()) ||
  5871. gRLInterface.contains("tploc") ||
  5872. (gRLInterface.mContainsUnsit &&
  5873. isAgentAvatarValid() && gAgentAvatarp->mIsSitting)))
  5874. {
  5875. return;
  5876. }
  5877. //mk
  5878. if (!mRegionp)
  5879. {
  5880. llwarns << "NULL region pointer. Teleport aborted." << llendl;
  5881. return;
  5882. }
  5883. LLVector3 pos_local;
  5884. F32 width = REGION_WIDTH_METERS;
  5885. U64 handle = to_region_handle(pos_global);
  5886. LLSimInfo* info = gWorldMap.simInfoFromHandle(handle);
  5887. if (info)
  5888. {
  5889. LLVector3d region_origin = info->getGlobalOrigin();
  5890. pos_local.set(pos_global.mdV[VX] - region_origin.mdV[VX],
  5891. pos_global.mdV[VY] - region_origin.mdV[VY],
  5892. pos_global.mdV[VZ]);
  5893. // Variable region size support
  5894. handle = info->getHandle(); // Actual handle
  5895. width = mRegionp->getWidth(); // Actual width
  5896. }
  5897. else
  5898. {
  5899. // Note: when we do not know about the actual region size (which we
  5900. // pretend here to be 256m), let the server fix the region handle and
  5901. // local coordinates by itself. Yes, this is totally bogus and the
  5902. // result of the dirty hack that is OpenSim variable size region... HB
  5903. F32 region_x = pos_global.mdV[VX];
  5904. F32 region_y = pos_global.mdV[VY];
  5905. handle = to_region_handle_global(region_x, region_y);
  5906. pos_local.set(fmodf(region_x, width), fmodf(region_y, width),
  5907. pos_global.mdV[VZ]);
  5908. }
  5909. LLVector3 look_at = pos_local;
  5910. look_at.mV[VX] += look_at.mV[VX] < width * 0.5f ? 1.f : -1.f;
  5911. teleportRequest(handle, pos_global, pos_local, look_at);
  5912. }
  5913. // Teleport to global position, but keep facing in the same direction
  5914. void LLAgent::teleportViaLocationLookAt(const LLVector3d& pos_global)
  5915. {
  5916. LL_DEBUGS("Teleport") << "Global position: " << pos_global << LL_ENDL;
  5917. //MK
  5918. if (gRLenabled)
  5919. {
  5920. // Do not perform these checks if we are automatically snapping back to
  5921. // the last standing location
  5922. if (!gRLInterface.mSnappingBackToLastStandingLocation)
  5923. {
  5924. // Cannot TP if we cannot sittp, unsit, tp to a location or when
  5925. // the forward control is taken (and not passed), and something is
  5926. // locked
  5927. if (gRLInterface.contains("tploc") ||
  5928. (forwardGrabbed() && gRLInterface.mContainsDetach) ||
  5929. gRLInterface.mSittpMax < EXTREMUM ||
  5930. (gRLInterface.mContainsUnsit &&
  5931. isAgentAvatarValid() && gAgentAvatarp->mIsSitting))
  5932. {
  5933. return;
  5934. }
  5935. }
  5936. }
  5937. //mk
  5938. U64 handle = to_region_handle(pos_global);
  5939. //MK
  5940. // If we are teleporting within the region (local teleport), check @tplocal
  5941. if (gRLenabled && handle == to_region_handle(getPositionGlobal()))
  5942. {
  5943. LLVector3d pos_relative =
  5944. (LLVector3d)(pos_global - getPositionGlobal());
  5945. if (pos_relative.length() > gRLInterface.mTplocalMax)
  5946. {
  5947. return;
  5948. }
  5949. }
  5950. //mk
  5951. LLVector3 pos_local;
  5952. LLSimInfo* info = gWorldMap.simInfoFromHandle(handle);
  5953. if (info)
  5954. {
  5955. // Variable region size support
  5956. handle = info->getHandle(); // Actual handle
  5957. pos_local.set(pos_global - from_region_handle(handle)); // Actual pos
  5958. }
  5959. else
  5960. {
  5961. // Note: when we do not know about the actual region size (which we
  5962. // pretend here to be 256m), let the server fix the region handle and
  5963. // local coordinates by itself. Yes, this is totally bogus and the
  5964. // result of the dirty hack that is OpenSim variable size region... HB
  5965. F32 region_x = pos_global.mdV[VX];
  5966. F32 region_y = pos_global.mdV[VY];
  5967. handle = to_region_handle_global(region_x, region_y);
  5968. pos_local.set(fmod(region_x, REGION_WIDTH_METERS),
  5969. fmod(region_y, REGION_WIDTH_METERS),
  5970. (F32)pos_global.mdV[VZ]);
  5971. }
  5972. teleportRequest(handle, pos_global, pos_local);
  5973. }
  5974. void LLAgent::setTeleportState(ETeleportState state, const std::string& reason)
  5975. {
  5976. ETeleportState old_state = mTeleportState;
  5977. mTeleportState = state;
  5978. if (state > TELEPORT_NONE && LLPipeline::sFreezeTime)
  5979. {
  5980. LLFloaterSnapshot::hide(NULL);
  5981. }
  5982. switch (state)
  5983. {
  5984. case TELEPORT_NONE:
  5985. LL_DEBUGS("Teleport") << "Switched to state TELEPORT_NONE.";
  5986. if (!reason.empty())
  5987. {
  5988. LL_CONT << " Reason: " << reason;
  5989. }
  5990. LL_CONT << LL_ENDL;
  5991. mTeleportKeepsLookAt = false;
  5992. // *HACK: make sure we refresh objects visibility when we jumped
  5993. // in position by a distance greater than the draw distance in the
  5994. // same simulator (different simulators case is already dealt with
  5995. // in LLVOAvatarSelf::updateRegion()). HB
  5996. // NOTE: 'reason' is empty when the TP succeeded, so by checking it
  5997. // we are sure that this call is not the result of a failed TP
  5998. // (where distance == 0.f, just like a successful LM TPs). HB
  5999. if (mArrivalHandle == mDepartureHandle && reason.empty() &&
  6000. // Exclude the login case and spurious TELEPORT_NONE. HB
  6001. !mPosGlobalTPdeparture.isNull())
  6002. {
  6003. static LLCachedControl<F32> draw_distance(gSavedSettings,
  6004. "RenderFarClip");
  6005. F32 distance = (mPosGlobalTPdeparture -
  6006. getPositionGlobal()).lengthSquared();
  6007. LL_DEBUGS("Teleport") << "Local teleport distance: "
  6008. << (S32)sqrtf(distance) << "m"
  6009. << LL_ENDL;
  6010. if (distance > (F32)(draw_distance * draw_distance) ||
  6011. // Special case for a successful TP via landmark from the
  6012. // same sim; the actual agent position is then received
  6013. // much later from the sim, so we saddly cannot check the
  6014. // travelled distance in this case...
  6015. distance == 0.f)
  6016. {
  6017. schedule_objects_visibility_refresh(AFTER_FAR_TP);
  6018. }
  6019. }
  6020. // Reset, in case we get spurious TELEPORT_NONE later... HB
  6021. mPosGlobalTPdeparture.setZero();
  6022. break;
  6023. case TELEPORT_START:
  6024. LL_DEBUGS("Teleport") << "Switched to state TELEPORT_START"
  6025. << LL_ENDL;
  6026. // Remember we started the TP process at this position. HB
  6027. mPosGlobalTPdeparture = getPositionGlobal();
  6028. // Store the departure region URL.
  6029. mTeleportSourceSLURL = getSLURL();
  6030. // Store the departure region handle
  6031. mDepartureHandle = getRegionHandle();
  6032. // Make sure these are equal on TP start
  6033. mArrivalHandle = mDepartureHandle;
  6034. // Enable the TP progress screen
  6035. gTeleportDisplay = true;
  6036. break;
  6037. case TELEPORT_REQUESTED:
  6038. LL_DEBUGS("Teleport") << "Switched to state TELEPORT_REQUESTED"
  6039. << LL_ENDL;
  6040. break;
  6041. case TELEPORT_MOVING:
  6042. // TELEPORT_MOVING is set before we arrive in the new region, but
  6043. // after we got the destination region handle and host (so we are
  6044. // sure, at this point, that the TP is actually possible and in
  6045. // progress).
  6046. LL_DEBUGS("Teleport") << "Switched to state TELEPORT_MOVING"
  6047. << LL_ENDL;
  6048. resetTeleportedSimHandle();
  6049. break;
  6050. case TELEPORT_START_ARRIVAL:
  6051. // TELEPORT_START_ARRIVAL is set just as we are arriving in the new
  6052. // region and at this point setRegion() has been called (with both
  6053. // the arrival and departure sim handles properly set).
  6054. LL_DEBUGS("Teleport") << "Switched to state TELEPORT_START_ARRIVAL"
  6055. << LL_ENDL;
  6056. if (mArrivalHandle != mDepartureHandle)
  6057. {
  6058. #if !LL_PENDING_MESH_REQUEST_SORTING
  6059. if (gSavedSettings.getBool("DelayPendingMeshFetchesOnTP"))
  6060. {
  6061. LL_DEBUGS("Teleport") << "Delaying pending mesh fetches"
  6062. << LL_ENDL;
  6063. gMeshRepo.delayCurrentRequests();
  6064. }
  6065. #endif
  6066. if (gSavedSettings.getBool("ClearStaleTextureFetchesOnTP"))
  6067. {
  6068. LL_DEBUGS("Teleport") << "Clearing old texture fetches"
  6069. << LL_ENDL;
  6070. // Clear old texture fetches, rebuild groups and old images
  6071. gTextureList.clearFetchingRequests();
  6072. gPipeline.clearRebuildGroups();
  6073. gTextureList.flushOldImages();
  6074. // To force-release the freed memory to the OS
  6075. LLMemory::updateMemoryInfo(true);
  6076. }
  6077. LLViewerTexture::resetLowMemCondition(true);
  6078. // Used to boost texture fetches after far TPs
  6079. LLViewerTextureList::sLastTeleportTime = gFrameTimeSeconds;
  6080. }
  6081. break;
  6082. case TELEPORT_ARRIVING:
  6083. LL_DEBUGS("Teleport") << "Switched to state TELEPORT_ARRIVING"
  6084. << LL_ENDL;
  6085. // In case of a race condition between TELEPORT_START and
  6086. // TELEPORT_MOVING:
  6087. resetTeleportedSimHandle();
  6088. gTextureList.mForceResetTextureStats = true;
  6089. resetView(true, true);
  6090. // Let the interested parties know we have teleported.
  6091. gViewerParcelMgr.onTeleportFinished(false, getPositionGlobal());
  6092. // Remove focus from any floater to allow moving around with keys
  6093. // on arrival. HB
  6094. gFocusMgr.setKeyboardFocus(NULL);
  6095. break;
  6096. case TELEPORT_LOCAL:
  6097. LL_DEBUGS("Teleport") << "Switched to state TELEPORT_LOCAL"
  6098. << LL_ENDL;
  6099. // Remember we started the TP process at this position. HB
  6100. mPosGlobalTPdeparture = getPositionGlobal();
  6101. mDepartureHandle = getRegionHandle();
  6102. mArrivalHandle = mDepartureHandle;
  6103. resetTeleportedSimHandle();
  6104. // Remove focus from any floater to allow moving around with keys
  6105. // on arrival. HB
  6106. gFocusMgr.setKeyboardFocus(NULL);
  6107. break;
  6108. case TELEPORT_QUEUED:
  6109. LL_DEBUGS("Teleport") << "Switched to state TELEPORT_QUEUED"
  6110. << LL_ENDL;
  6111. // Enable the TP progress screen
  6112. gTeleportDisplay = true;
  6113. }
  6114. gViewerStats.resetAvatarStats();
  6115. if (old_state != state && gAutomationp)
  6116. {
  6117. gAutomationp->onTPStateChange(state, reason);
  6118. }
  6119. }
  6120. // Stops all current overriding animations on this avatar, propagating this
  6121. // change back to the server.
  6122. void LLAgent::stopCurrentAnimations()
  6123. {
  6124. if (!isAgentAvatarValid())
  6125. {
  6126. return;
  6127. }
  6128. uuid_vec_t anim_ids;
  6129. for (LLVOAvatar::anim_it_t
  6130. it = gAgentAvatarp->mPlayingAnimations.begin(),
  6131. end = gAgentAvatarp->mPlayingAnimations.end();
  6132. it != end; ++it)
  6133. {
  6134. const LLUUID& id = it->first;
  6135. // Do not cancel a ground-sit anim, as viewers use this animation's
  6136. // status in determining whether we are sitting.
  6137. if (id != ANIM_AGENT_SIT_GROUND_CONSTRAINED)
  6138. {
  6139. // Stop this animation locally
  6140. gAgentAvatarp->stopMotion(id, true);
  6141. // ...and ask to the server to tell everyone.
  6142. anim_ids.emplace_back(id);
  6143. }
  6144. }
  6145. sendAnimationRequests(anim_ids, ANIM_REQUEST_STOP);
  6146. if (gSavedSettings.getBool("ResetAnimOverrideOnStopAnimation"))
  6147. {
  6148. // Tell the region to clear any animation state overrides
  6149. sendAnimationStateReset();
  6150. }
  6151. // Revoke all animation permissions
  6152. if (mRegionp && gSavedSettings.getBool("RevokePermsOnStopAnimation"))
  6153. {
  6154. U32 permissions =
  6155. LSCRIPTRunTimePermissionBits[SCRIPT_PERMISSION_TRIGGER_ANIMATION] |
  6156. LSCRIPTRunTimePermissionBits[SCRIPT_PERMISSION_OVERRIDE_ANIMATIONS];
  6157. sendRevokePermissions(mRegionp->getRegionID(), permissions);
  6158. if (gAgentAvatarp->mIsSitting)
  6159. {
  6160. // Also stand up, since auto-granted sit animation permission
  6161. // has been revoked
  6162. LL_DEBUGS("AgentSit") << "Sending agent unsit request" << LL_ENDL;
  6163. setControlFlags(AGENT_CONTROL_STAND_UP);
  6164. }
  6165. }
  6166. // Re-assert at least the default standing animation because viewers
  6167. // get confused by avatars without associated anims.
  6168. sendAnimationRequest(ANIM_AGENT_STAND, ANIM_REQUEST_START);
  6169. // Reassert default/idle Bento animation, if desired.
  6170. if (gSavedSettings.getBool("PlayDefaultBentoAnimation"))
  6171. {
  6172. sendAnimationRequest(ANIM_AGENT_BENTO_IDLE, ANIM_REQUEST_START);
  6173. }
  6174. }
  6175. void LLAgent::fidget()
  6176. {
  6177. F32 cur_time = mFidgetTimer.getElapsedTimeF32();
  6178. if (cur_time < mNextFidgetTime || getAFK())
  6179. {
  6180. return;
  6181. }
  6182. // Calculate next fidget time
  6183. mNextFidgetTime = cur_time + MIN_FIDGET_TIME +
  6184. ll_frand(MAX_FIDGET_TIME - MIN_FIDGET_TIME);
  6185. // Pick a random fidget anim here
  6186. S32 old_fidget = mCurrentFidget;
  6187. mCurrentFidget = ll_rand(NUM_AGENT_STAND_ANIMS);
  6188. if (mCurrentFidget == old_fidget)
  6189. {
  6190. return;
  6191. }
  6192. stopFidget();
  6193. switch (mCurrentFidget)
  6194. {
  6195. case 0:
  6196. break;
  6197. case 1:
  6198. sendAnimationRequest(ANIM_AGENT_STAND_1, ANIM_REQUEST_START);
  6199. break;
  6200. case 2:
  6201. sendAnimationRequest(ANIM_AGENT_STAND_2, ANIM_REQUEST_START);
  6202. break;
  6203. case 3:
  6204. sendAnimationRequest(ANIM_AGENT_STAND_3, ANIM_REQUEST_START);
  6205. break;
  6206. case 4:
  6207. sendAnimationRequest(ANIM_AGENT_STAND_4, ANIM_REQUEST_START);
  6208. }
  6209. }
  6210. //static
  6211. void LLAgent::stopFidget()
  6212. {
  6213. uuid_vec_t anims;
  6214. anims.emplace_back(ANIM_AGENT_STAND_1);
  6215. anims.emplace_back(ANIM_AGENT_STAND_2);
  6216. anims.emplace_back(ANIM_AGENT_STAND_3);
  6217. anims.emplace_back(ANIM_AGENT_STAND_4);
  6218. gAgent.sendAnimationRequests(anims, ANIM_REQUEST_STOP);
  6219. }
  6220. void LLAgent::requestEnterGodMode()
  6221. {
  6222. LLMessageSystem* msg = gMessageSystemp;
  6223. if (!msg) return;
  6224. msg->newMessageFast(_PREHASH_RequestGodlikePowers);
  6225. msg->nextBlockFast(_PREHASH_AgentData);
  6226. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  6227. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  6228. msg->nextBlockFast(_PREHASH_RequestBlock);
  6229. msg->addBoolFast(_PREHASH_Godlike, true);
  6230. msg->addUUIDFast(_PREHASH_Token, LLUUID::null);
  6231. // Simulators need to know about your request
  6232. sendReliableMessage();
  6233. }
  6234. void LLAgent::requestLeaveGodMode()
  6235. {
  6236. LLMessageSystem* msg = gMessageSystemp;
  6237. if (!msg) return;
  6238. msg->newMessageFast(_PREHASH_RequestGodlikePowers);
  6239. msg->nextBlockFast(_PREHASH_AgentData);
  6240. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  6241. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  6242. msg->nextBlockFast(_PREHASH_RequestBlock);
  6243. msg->addBoolFast(_PREHASH_Godlike, false);
  6244. msg->addUUIDFast(_PREHASH_Token, LLUUID::null);
  6245. // Simulator needs to know about your request
  6246. sendReliableMessage();
  6247. }
  6248. void LLAgent::sendAgentSetAppearance()
  6249. {
  6250. LLMessageSystem* msg = gMessageSystemp;
  6251. if (!msg || !isAgentAvatarValid() || gAgentWearables.isSettingOutfit() ||
  6252. LLVOAvatarSelf::canUseServerBaking() ||
  6253. (gAgentQueryManager.mNumPendingQueries > 0 &&
  6254. !gAgentAvatarp->isEditingAppearance()))
  6255. {
  6256. return;
  6257. }
  6258. #if 0
  6259. // *FIXME: At this point we have a complete appearance to send and are in a
  6260. // non-baking region.
  6261. gAgentAvatarp->setIsUsingServerBakes(false);
  6262. #endif
  6263. S32 sb_count, host_count, both_count, neither_count;
  6264. gAgentAvatarp->bakedTextureOriginCounts(sb_count, host_count, both_count,
  6265. neither_count);
  6266. if (both_count != 0 || neither_count != 0)
  6267. {
  6268. llwarns << "Bad bake texture state. Baked count: " << sb_count
  6269. << " - Host count: " << host_count
  6270. << " - Both count: " << both_count
  6271. << " - Neither count: " << neither_count << llendl;
  6272. }
  6273. if (sb_count != 0 && host_count == 0)
  6274. {
  6275. gAgentAvatarp->setIsUsingServerBakes(true);
  6276. }
  6277. else if (sb_count == 0 && host_count != 0)
  6278. {
  6279. gAgentAvatarp->setIsUsingServerBakes(false);
  6280. }
  6281. else if (sb_count + host_count > 0)
  6282. {
  6283. llwarns << "Unclear baked texture state: not sending appearance."
  6284. << llendl;
  6285. return;
  6286. }
  6287. llinfos << "TAT: Sent AgentSetAppearance: "
  6288. << gAgentAvatarp->getBakedStatusForPrintout() << llendl;
  6289. msg->newMessageFast(_PREHASH_AgentSetAppearance);
  6290. msg->nextBlockFast(_PREHASH_AgentData);
  6291. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  6292. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  6293. // Correct for the collision tolerance (to make it look like the agent is
  6294. // actually walking on the ground/object).
  6295. LLVector3 body_size = gAgentAvatarp->mBodySize;
  6296. body_size.mV[VZ] += gSavedSettings.getF32("AvatarOffsetZ");
  6297. body_size += gAgentAvatarp->mAvatarOffset;
  6298. msg->addVector3Fast(_PREHASH_Size, body_size);
  6299. // To guard against out of order packets.
  6300. // Note: always start by sending 1. This resets the server's count. 0 on
  6301. // the server means "uninitialized"
  6302. msg->addU32Fast(_PREHASH_SerialNum, ++mAppearanceSerialNum);
  6303. // Is texture data current relative to wearables ?
  6304. // KLW - TAT this will probably need to check the local queue.
  6305. bool textures_current = gAgentAvatarp->areTexturesCurrent();
  6306. bool wearing_skirt =
  6307. gAgentAvatarp->isWearingWearableType(LLWearableType::WT_SKIRT);
  6308. bool wearing_universal =
  6309. gAgentAvatarp->isWearingWearableType(LLWearableType::WT_UNIVERSAL);
  6310. for (U8 i = 0; i < mUploadedBakes; ++i)
  6311. {
  6312. const ETextureIndex texture_index =
  6313. LLAvatarAppearanceDictionary::bakedToLocalTextureIndex((EBakedTextureIndex)i);
  6314. // If we are not wearing a skirt, we do not need its texture baked
  6315. if (texture_index == TEX_SKIRT_BAKED && !wearing_skirt)
  6316. {
  6317. continue;
  6318. }
  6319. // If we are not wearing an universal, we do not need the corresponding
  6320. // textures baked
  6321. if (!wearing_universal && texture_index >= TEX_LEFT_ARM_BAKED &&
  6322. texture_index <= TEX_AUX3_BAKED)
  6323. {
  6324. continue;
  6325. }
  6326. // IMG_DEFAULT_AVATAR means not baked. 0 index should be ignored for
  6327. // baked textures
  6328. if (!gAgentAvatarp->isTextureDefined(texture_index, 0))
  6329. {
  6330. LL_DEBUGS("Avatar") << "Texture not current for baked: " << i
  6331. << " - local: " << (S32)texture_index
  6332. << LL_ENDL;
  6333. textures_current = false;
  6334. break;
  6335. }
  6336. }
  6337. // Only update cache entries if we have all our baked textures.
  6338. // *FIXME: need additional check for not in appearance editing mode, if
  6339. // still using local composites need to set using local composites to
  6340. // false, and update mesh textures.
  6341. if (textures_current)
  6342. {
  6343. llinfos << "TAT: Sending cached texture data" << llendl;
  6344. for (U8 i = 0; i < mUploadedBakes; ++i)
  6345. {
  6346. bool generate_valid_hash = true;
  6347. if (!gAgentAvatarp->isBakedTextureFinal((EBakedTextureIndex)i))
  6348. {
  6349. generate_valid_hash = false;
  6350. llinfos << "Not caching baked texture upload for " << i
  6351. << " due to being uploaded at low resolution."
  6352. << llendl;
  6353. }
  6354. const LLUUID hash =
  6355. gAgentWearables.computeBakedTextureHash((EBakedTextureIndex)i,
  6356. generate_valid_hash);
  6357. if (hash.notNull())
  6358. {
  6359. ETextureIndex texture_index =
  6360. LLAvatarAppearanceDictionary::bakedToLocalTextureIndex((EBakedTextureIndex)i);
  6361. msg->nextBlockFast(_PREHASH_WearableData);
  6362. msg->addUUIDFast(_PREHASH_CacheID, hash);
  6363. msg->addU8Fast(_PREHASH_TextureIndex, (U8)texture_index);
  6364. }
  6365. }
  6366. msg->nextBlockFast(_PREHASH_ObjectData);
  6367. gAgentAvatarp->sendAppearanceMessage(msg);
  6368. }
  6369. else
  6370. {
  6371. // If the textures are not baked, send NULL for texture IDs. This means
  6372. // the baked texture IDs on the server will be untouched. Once all
  6373. // textures are baked, another AvatarAppearance message will be sent to
  6374. // update the TEs.
  6375. msg->nextBlockFast(_PREHASH_ObjectData);
  6376. msg->addBinaryDataFast(_PREHASH_TextureEntry, NULL, 0);
  6377. }
  6378. for (LLViewerVisualParam* param =
  6379. (LLViewerVisualParam*)gAgentAvatarp->getFirstVisualParam(); param;
  6380. param = (LLViewerVisualParam*)gAgentAvatarp->getNextVisualParam())
  6381. {
  6382. // Do not transmit params of group
  6383. // VISUAL_PARAM_GROUP_TWEAKABLE_NO_TRANSMIT
  6384. if (param->getGroup() == VISUAL_PARAM_GROUP_TWEAKABLE)
  6385. {
  6386. msg->nextBlockFast(_PREHASH_VisualParam);
  6387. // We do not send the param ids. Instead, we assume that the
  6388. // receiver has the same params in the same sequence.
  6389. const F32 param_value = param->getWeight();
  6390. const U8 new_weight = F32_to_U8(param_value, param->getMinWeight(),
  6391. param->getMaxWeight());
  6392. msg->addU8Fast(_PREHASH_ParamValue, new_weight);
  6393. }
  6394. }
  6395. sendReliableMessage();
  6396. }
  6397. void LLAgent::sendAgentDataUpdateRequest()
  6398. {
  6399. LLMessageSystem* msg = gMessageSystemp;
  6400. if (!msg) return;
  6401. msg->newMessageFast(_PREHASH_AgentDataUpdateRequest);
  6402. msg->nextBlockFast(_PREHASH_AgentData);
  6403. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  6404. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  6405. sendReliableMessage();
  6406. }
  6407. //static
  6408. void LLAgent::userInfoRequestCallback(const LLSD& result, bool success)
  6409. {
  6410. if (success && result.isMap() && result.has("success") &&
  6411. result["success"].asBoolean())
  6412. {
  6413. // Note: support for setting the IM to email redirection with the
  6414. // viewer has been removed from SL in November 2021... Kept only for
  6415. // OpenSim. HB
  6416. bool im_via_email = result.has("im_via_email") &&
  6417. result["im_via_email"].asBoolean();
  6418. bool verified = result["is_verified"].asBoolean();
  6419. std::string email = result["email"].asString();
  6420. std::string dir_vis = result["directory_visibility"].asString();
  6421. LLFloaterPreference::updateUserInfo(dir_vis, im_via_email, email,
  6422. verified ? 1 : 0);
  6423. LLFloaterPostcard::updateUserInfo(email);
  6424. }
  6425. else
  6426. {
  6427. llwarns << "Failed to get user info via capability, falling back to UDP message."
  6428. << llendl;
  6429. gAgent.sendAgentUserInfoRequestMessage();
  6430. }
  6431. }
  6432. void LLAgent::sendAgentUserInfoRequest()
  6433. {
  6434. if (gAgentID.notNull())
  6435. {
  6436. httpCallback_t succ = boost::bind(&LLAgent::userInfoRequestCallback,
  6437. _1, true);
  6438. httpCallback_t fail = boost::bind(&LLAgent::userInfoRequestCallback,
  6439. _1, false);
  6440. if (!gAgent.requestGetCapability("UserInfo", succ, fail))
  6441. {
  6442. sendAgentUserInfoRequestMessage();
  6443. }
  6444. }
  6445. }
  6446. void LLAgent::sendAgentUserInfoRequestMessage()
  6447. {
  6448. LLMessageSystem* msg = gMessageSystemp;
  6449. if (msg && gAgentID.notNull())
  6450. {
  6451. msg->newMessageFast(_PREHASH_UserInfoRequest);
  6452. msg->nextBlockFast(_PREHASH_AgentData);
  6453. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  6454. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  6455. sendReliableMessage();
  6456. }
  6457. }
  6458. //static
  6459. void LLAgent::userInfoUpdateCallback(const LLSD& result, bool success,
  6460. bool im_via_email, std::string dir_vis)
  6461. {
  6462. if (!success || !result.isMap() || !result.has("success") ||
  6463. !result["success"].asBoolean())
  6464. {
  6465. llwarns << "Failed to set user info via capability, falling back to UDP message."
  6466. << llendl;
  6467. gAgent.sendAgentUserInfoRequestMessage(im_via_email, dir_vis);
  6468. }
  6469. }
  6470. void LLAgent::sendAgentUpdateUserInfo(bool im_via_email,
  6471. const std::string& dir_visibility)
  6472. {
  6473. if (gAgentID.isNull())
  6474. {
  6475. return; // Not logged in ?
  6476. }
  6477. LLSD body;
  6478. body["dir_visibility"] = LLSD::String(dir_visibility);
  6479. // Note: support for setting the IM to email redirection with the viewer
  6480. // has been removed from SL in November 2021... Kept only for OpenSim. HB
  6481. if (!gIsInSecondLife)
  6482. {
  6483. body["im_via_email"] = LLSD::Boolean(im_via_email);
  6484. }
  6485. httpCallback_t succ = boost::bind(&LLAgent::userInfoUpdateCallback, _1,
  6486. true, im_via_email, dir_visibility);
  6487. httpCallback_t fail = boost::bind(&LLAgent::userInfoUpdateCallback, _1,
  6488. false, im_via_email, dir_visibility);
  6489. if (!gAgent.requestPostCapability("UserInfo", body, succ, fail))
  6490. {
  6491. sendAgentUserInfoRequestMessage(im_via_email, dir_visibility);
  6492. }
  6493. }
  6494. // Note: support for setting the IM to email redirection with the viewer has
  6495. // been removed from SL in November 2021... Kept only for OpenSim. HB
  6496. void LLAgent::sendAgentUserInfoRequestMessage(bool im_via_email,
  6497. const std::string& dir_vis)
  6498. {
  6499. LLMessageSystem* msg = gMessageSystemp;
  6500. if (!gIsInSecondLife && msg && gAgentID.notNull())
  6501. {
  6502. msg->newMessageFast(_PREHASH_UpdateUserInfo);
  6503. msg->nextBlockFast(_PREHASH_AgentData);
  6504. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  6505. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  6506. msg->nextBlockFast(_PREHASH_UserData);
  6507. msg->addBoolFast(_PREHASH_IMViaEMail, im_via_email);
  6508. msg->addString(_PREHASH_DirectoryVisibility, dir_vis);
  6509. sendReliableMessage();
  6510. }
  6511. }
  6512. void LLAgent::observeFriends()
  6513. {
  6514. if (!mFriendObserver)
  6515. {
  6516. mFriendObserver = new LLAgentFriendObserver;
  6517. gAvatarTracker.addObserver(mFriendObserver);
  6518. friendsChanged();
  6519. }
  6520. }
  6521. void LLAgent::parseTeleportMessages(const std::string& xml_filename)
  6522. {
  6523. LLXMLNodePtr root;
  6524. bool success = LLUICtrlFactory::getLayeredXMLNode(xml_filename, root);
  6525. if (!success || !root || !root->hasName("teleport_messages"))
  6526. {
  6527. llerrs << "Problem reading teleport string XML file: "
  6528. << xml_filename << llendl;
  6529. return;
  6530. }
  6531. for (LLXMLNode* message_set = root->getFirstChild();
  6532. message_set != NULL;
  6533. message_set = message_set->getNextSibling())
  6534. {
  6535. if (!message_set->hasName("message_set")) continue;
  6536. std::map<std::string, std::string>* teleport_msg_map = NULL;
  6537. std::string message_set_name;
  6538. if (message_set->getAttributeString("name", message_set_name))
  6539. {
  6540. // Now we loop over all the string in the set and add them to the
  6541. // appropriate set
  6542. if (message_set_name == "errors")
  6543. {
  6544. teleport_msg_map = &sTeleportErrorMessages;
  6545. }
  6546. else if (message_set_name == "progress")
  6547. {
  6548. teleport_msg_map = &sTeleportProgressMessages;
  6549. }
  6550. }
  6551. if (!teleport_msg_map) continue;
  6552. std::string message_name;
  6553. for (LLXMLNode* message_node = message_set->getFirstChild();
  6554. message_node != NULL;
  6555. message_node = message_node->getNextSibling())
  6556. {
  6557. if (message_node->hasName("message") &&
  6558. message_node->getAttributeString("name", message_name))
  6559. {
  6560. (*teleport_msg_map)[message_name] = message_node->getTextContents();
  6561. }
  6562. }
  6563. }
  6564. }
  6565. //MK
  6566. //static
  6567. bool LLAgent::canWear(LLWearableType::EType type)
  6568. {
  6569. return gRLenabled ? gRLInterface.canWear(type) : true;
  6570. }
  6571. //static
  6572. bool LLAgent::canUnwear(LLWearableType::EType type)
  6573. {
  6574. return gRLenabled ? gRLInterface.canUnwear(type) : true;
  6575. }
  6576. //mk
  6577. /*****************************************************************************/
  6578. // Methods that used to be in llglsandbox.cpp
  6579. bool LLAgent::setLookAt(ELookAtType target_type, LLViewerObject* object,
  6580. LLVector3 position)
  6581. {
  6582. // No look at for far objects when PrivateLookAt is true
  6583. static LLCachedControl<bool> private_look_at(gSavedSettings,
  6584. "PrivateLookAt");
  6585. static LLCachedControl<U32> look_at_limit(gSavedSettings,
  6586. "PrivateLookAtLimit");
  6587. if (private_look_at && object && target_type != LOOKAT_TARGET_NONE)
  6588. {
  6589. if ((object->getPositionGlobal() -
  6590. gAgent.getPositionGlobal()).length() > look_at_limit)
  6591. {
  6592. target_type = LOOKAT_TARGET_NONE;
  6593. object = gAgentAvatarp;
  6594. position.clear();
  6595. }
  6596. }
  6597. if (object && object->isAttachment())
  6598. {
  6599. LLViewerObject* parentp = object;
  6600. while (parentp)
  6601. {
  6602. if (parentp == gAgentAvatarp)
  6603. {
  6604. // looking at an attachment on ourselves, which we don't want
  6605. // to do
  6606. object = gAgentAvatarp;
  6607. position.clear();
  6608. }
  6609. parentp = (LLViewerObject*)parentp->getParent();
  6610. }
  6611. }
  6612. if (!mLookAt || mLookAt->isDead())
  6613. {
  6614. mLookAt =
  6615. (LLHUDEffectLookAt*)LLHUDManager::createEffect(LLHUDObject::LL_HUD_EFFECT_LOOKAT);
  6616. mLookAt->setSourceObject(gAgentAvatarp);
  6617. }
  6618. return mLookAt->setLookAt(target_type, object, position);
  6619. }
  6620. bool LLAgent::setPointAt(EPointAtType target_type, LLViewerObject* object,
  6621. LLVector3 position)
  6622. {
  6623. // Disallow pointing at attachments and avatars
  6624. if (object && (object->isAttachment() || object->isAvatar()))
  6625. {
  6626. return false;
  6627. }
  6628. // No point at for far objects when PrivatePointAt is true
  6629. static LLCachedControl<bool> private_point_at(gSavedSettings,
  6630. "PrivatePointAt");
  6631. static LLCachedControl<U32> point_at_limit(gSavedSettings,
  6632. "PrivatePointAtLimit");
  6633. if (private_point_at && object &&
  6634. target_type != POINTAT_TARGET_NONE &&
  6635. target_type != POINTAT_TARGET_CLEAR)
  6636. {
  6637. if ((object->getPositionGlobal() -
  6638. gAgent.getPositionGlobal()).length() > point_at_limit)
  6639. {
  6640. target_type = POINTAT_TARGET_NONE;
  6641. object = NULL;
  6642. position.clear();
  6643. }
  6644. }
  6645. if (!mPointAt || mPointAt->isDead())
  6646. {
  6647. mPointAt = (LLHUDEffectPointAt*)LLHUDManager::createEffect(LLHUDObject::LL_HUD_EFFECT_POINTAT);
  6648. mPointAt->setSourceObject(gAgentAvatarp);
  6649. }
  6650. return mPointAt->setPointAt(target_type, object, position);
  6651. }
  6652. /*****************************************************************************/
  6653. LLAgentQueryManager gAgentQueryManager;
  6654. LLAgentQueryManager::LLAgentQueryManager()
  6655. : mWearablesCacheQueryID(0),
  6656. mNumPendingQueries(0),
  6657. mUpdateSerialNum(0)
  6658. {
  6659. for (U32 i = 0; i < BAKED_NUM_INDICES; ++i)
  6660. {
  6661. mActiveCacheQueries[i] = 0;
  6662. }
  6663. }