llmaniptranslate.cpp 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758
  1. /**
  2. * @file llmaniptranslate.cpp
  3. * @brief LLManipTranslate class implementation
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewergpl$
  6. *
  7. * Copyright (c) 2002-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. // "error: 'get_temporary_buffer<...>' is deprecated" seen with clang 18 and
  34. // gcc 12.3 libstdc++ implementation of std::stable_sort(). HB
  35. #if CLANG_VERSION >= 180000
  36. # pragma clang diagnostic ignored "-Wdeprecated-declarations"
  37. #endif
  38. #include "llmaniptranslate.h"
  39. #include "llgl.h"
  40. #include "llrender.h"
  41. #include "llrenderutils.h" // For gCone
  42. #include "llagent.h"
  43. #include "llappviewer.h" // For gFPSClamped
  44. #include "lldrawable.h"
  45. #include "llfloatertools.h"
  46. #include "llpipeline.h"
  47. //MK
  48. #include "mkrlinterface.h"
  49. //mk
  50. #include "llselectmgr.h"
  51. #include "llstatusbar.h"
  52. #include "lltoolmgr.h"
  53. #include "llviewercamera.h"
  54. #include "llviewercontrol.h"
  55. #include "llviewerdisplay.h" // For hud_render_text()
  56. #include "llviewerjoint.h"
  57. #include "llviewerobject.h"
  58. #include "llviewershadermgr.h"
  59. #include "llviewerwindow.h"
  60. #include "llvoavatarself.h"
  61. #include "llworld.h"
  62. constexpr S32 NUM_AXES = 3;
  63. constexpr S32 MOUSE_DRAG_SLOP = 2; // In pixels
  64. constexpr F32 SELECTED_ARROW_SCALE = 1.3f;
  65. constexpr F32 MANIP_HOTSPOT_START = 0.2f;
  66. constexpr F32 MANIP_HOTSPOT_END = 1.2f;
  67. constexpr F32 SNAP_GUIDE_SCREEN_SIZE = 0.7f;
  68. constexpr F32 MIN_PLANE_MANIP_DOT_PRODUCT = 0.25f;
  69. constexpr F32 PLANE_TICK_SIZE = 0.4f;
  70. constexpr F32 QUARTER_TICK_SIZE = PLANE_TICK_SIZE * 0.25f;
  71. constexpr F32 MANIP_SCALE_HALF_LIFE = 0.07f;
  72. constexpr F32 SNAP_ARROW_SCALE = 0.7f;
  73. static LLPointer<LLViewerTexture> sGridTex = NULL;
  74. const LLManip::EManipPart MANIPULATOR_IDS[9] =
  75. {
  76. LLManip::LL_X_ARROW,
  77. LLManip::LL_Y_ARROW,
  78. LLManip::LL_Z_ARROW,
  79. LLManip::LL_X_ARROW,
  80. LLManip::LL_Y_ARROW,
  81. LLManip::LL_Z_ARROW,
  82. LLManip::LL_YZ_PLANE,
  83. LLManip::LL_XZ_PLANE,
  84. LLManip::LL_XY_PLANE
  85. };
  86. static const U32 ARROW_TO_AXIS[4] =
  87. {
  88. VX,
  89. VX,
  90. VY,
  91. VZ
  92. };
  93. // Sort manipulator handles by their screen-space projection
  94. struct ClosestToCamera
  95. {
  96. bool operator()(const LLManipTranslate::ManipulatorHandle& a,
  97. const LLManipTranslate::ManipulatorHandle& b) const
  98. {
  99. return a.mEndPosition.mV[VZ] < b.mEndPosition.mV[VZ];
  100. }
  101. };
  102. LLManipTranslate::LLManipTranslate(LLToolComposite* composite)
  103. : LLManip("Move", composite),
  104. mLastHoverMouseX(-1),
  105. mLastHoverMouseY(-1),
  106. mMouseOutsideSlop(false),
  107. mCopyMadeThisDrag(false),
  108. mMouseDownX(-1),
  109. mMouseDownY(-1),
  110. mAxisArrowLength(50),
  111. mConeSize(0),
  112. mArrowLengthMeters(0.f),
  113. mPlaneManipOffsetMeters(0.f),
  114. mUpdateTimer(),
  115. mSnapOffsetMeters(0.f),
  116. mSubdivisions(10.f),
  117. mInSnapRegime(false),
  118. mArrowScales(1.f, 1.f, 1.f),
  119. mPlaneScales(1.f, 1.f, 1.f),
  120. mPlaneManipPositions(1.f, 1.f, 1.f, 1.f)
  121. {
  122. }
  123. // static
  124. bool LLManipTranslate::getSnapEnabled()
  125. {
  126. static LLCachedControl<bool> snap_enabled(gSavedSettings, "SnapEnabled");
  127. return snap_enabled;
  128. }
  129. // static
  130. bool LLManipTranslate::getSnapToMouseCursor()
  131. {
  132. static LLCachedControl<bool> snap_to_mouse_cursor(gSavedSettings,
  133. "SnapToMouseCursor");
  134. return snap_to_mouse_cursor;
  135. }
  136. // static
  137. F32 LLManipTranslate::getGridDrawSize()
  138. {
  139. static LLCachedControl<F32> grid_draw_size(gSavedSettings, "GridDrawSize");
  140. return grid_draw_size;
  141. }
  142. //static
  143. U32 LLManipTranslate::getGridTexName()
  144. {
  145. if (sGridTex.isNull())
  146. {
  147. restoreGL();
  148. }
  149. return sGridTex.isNull() ? 0 : sGridTex->getTexName();
  150. }
  151. //static
  152. void LLManipTranslate::destroyGL()
  153. {
  154. if (sGridTex)
  155. {
  156. sGridTex = NULL;
  157. }
  158. }
  159. //static
  160. void LLManipTranslate::restoreGL()
  161. {
  162. // Generate grid texture
  163. U32 rez = 512;
  164. U32 mip = 0;
  165. destroyGL();
  166. sGridTex = LLViewerTextureManager::getLocalTexture();
  167. if (!sGridTex->createGLTexture())
  168. {
  169. sGridTex = NULL;
  170. return;
  171. }
  172. GLuint* d = new GLuint[rez * rez];
  173. LLTexUnit* unit0 = gGL.getTexUnit(0);
  174. unit0->bindManual(LLTexUnit::TT_TEXTURE, sGridTex->getTexName(), true);
  175. unit0->setTextureFilteringOption(LLTexUnit::TFO_TRILINEAR);
  176. while (rez >= 1)
  177. {
  178. for (U32 i = 0; i < rez * rez; i++)
  179. {
  180. d[i] = 0x00FFFFFF;
  181. }
  182. U32 subcol = 0xFFFFFFFF;
  183. if (rez >= 4)
  184. {
  185. // Large grain grid
  186. for (U32 i = 0; i < rez; ++i)
  187. {
  188. if (rez <= 16)
  189. {
  190. if (rez == 16)
  191. {
  192. subcol = 0xA0FFFFFF;
  193. }
  194. else if (rez == 8)
  195. {
  196. subcol = 0x80FFFFFF;
  197. }
  198. else
  199. {
  200. subcol = 0x40FFFFFF;
  201. }
  202. }
  203. else
  204. {
  205. subcol = 0xFFFFFFFF;
  206. }
  207. d[i * rez] = subcol;
  208. d[i] = subcol;
  209. if (rez >= 32)
  210. {
  211. d[i * rez + rez - 1] = subcol;
  212. d[(rez - 1) * rez + i] = subcol;
  213. }
  214. if (rez >= 64)
  215. {
  216. subcol = 0xFFFFFFFF;
  217. if (i > 0 && i < rez - 1)
  218. {
  219. d[i * rez + 1] = subcol;
  220. d[i * rez + rez - 2] = subcol;
  221. d[rez + i] = subcol;
  222. d[(rez - 2) * rez + i] = subcol;
  223. }
  224. }
  225. }
  226. }
  227. subcol = 0x50A0A0A0;
  228. if (rez >= 128)
  229. {
  230. // Small grain grid
  231. for (U32 i = 8; i < rez; i += 8)
  232. {
  233. for (U32 j = 2; j < rez - 2; ++j)
  234. {
  235. d[i * rez + j] = subcol;
  236. d[j * rez + i] = subcol;
  237. }
  238. }
  239. }
  240. if (rez >= 64)
  241. {
  242. // Medium grain grid
  243. if (rez == 64)
  244. {
  245. subcol = 0x50A0A0A0;
  246. }
  247. else
  248. {
  249. subcol = 0xA0D0D0D0;
  250. }
  251. for (U32 i = 32; i < rez; i += 32)
  252. {
  253. U32 pi = i - 1;
  254. for (U32 j = 2; j < rez - 2; ++j)
  255. {
  256. d[i * rez + j] = subcol;
  257. d[j * rez + i] = subcol;
  258. if (rez > 128)
  259. {
  260. d[pi * rez + j] = subcol;
  261. d[j * rez + pi] = subcol;
  262. }
  263. }
  264. }
  265. }
  266. LLImageGL::setManualImage(GL_TEXTURE_2D, mip, GL_RGBA, rez, rez,
  267. GL_RGBA, GL_UNSIGNED_BYTE, d);
  268. rez = rez >> 1;
  269. ++mip;
  270. }
  271. delete[] d;
  272. }
  273. void LLManipTranslate::handleSelect()
  274. {
  275. gSelectMgr.saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
  276. if (gFloaterToolsp)
  277. {
  278. gFloaterToolsp->setStatusText("move");
  279. }
  280. LLManip::handleSelect();
  281. }
  282. bool LLManipTranslate::handleMouseDown(S32 x, S32 y, MASK mask)
  283. {
  284. bool handled = false;
  285. // Did not click in any UI object, so must have clicked in the world
  286. if (mHighlightedPart == LL_X_ARROW || mHighlightedPart == LL_Y_ARROW ||
  287. mHighlightedPart == LL_Z_ARROW || mHighlightedPart == LL_YZ_PLANE ||
  288. mHighlightedPart == LL_XZ_PLANE || mHighlightedPart == LL_XY_PLANE)
  289. {
  290. handled = handleMouseDownOnPart(x, y, mask);
  291. }
  292. return handled;
  293. }
  294. // Assumes that one of the arrows on an object was hit.
  295. bool LLManipTranslate::handleMouseDownOnPart(S32 x, S32 y, MASK mask)
  296. {
  297. if (!canAffectSelection())
  298. {
  299. return false;
  300. }
  301. highlightManipulators(x, y);
  302. S32 hit_part = mHighlightedPart;
  303. if (hit_part != LL_X_ARROW && hit_part != LL_Y_ARROW &&
  304. hit_part != LL_Z_ARROW && hit_part != LL_YZ_PLANE &&
  305. hit_part != LL_XZ_PLANE && hit_part != LL_XY_PLANE)
  306. {
  307. return true;
  308. }
  309. mHelpTextTimer.reset();
  310. sNumTimesHelpTextShown++;
  311. gSelectMgr.getGrid(mGridOrigin, mGridRotation, mGridScale);
  312. gSelectMgr.enableSilhouette(false);
  313. // We just started a drag, so save initial object positions
  314. gSelectMgr.saveSelectedObjectTransform(SELECT_ACTION_TYPE_MOVE);
  315. mManipPart = (EManipPart)hit_part;
  316. mMouseDownX = x;
  317. mMouseDownY = y;
  318. mMouseOutsideSlop = false;
  319. LLVector3 axis;
  320. LLSelectNode* nodep = mObjectSelection->getFirstMoveableNode(true);
  321. if (!nodep)
  322. {
  323. // Did not find the object in our selection... Oh well...
  324. llwarns << "Trying to translate an unselected object" << llendl;
  325. return true;
  326. }
  327. LLViewerObject* selected_object = nodep->getObject();
  328. if (!selected_object)
  329. {
  330. // Somehow we lost the object !
  331. llwarns << "Translate manip lost the object, no selected object"
  332. << llendl;
  333. gViewerWindowp->setCursor(UI_CURSOR_TOOLTRANSLATE);
  334. return true;
  335. }
  336. // Compute unit vectors for arrow hit and a plane through that vector
  337. bool axis_exists = getManipAxis(selected_object, mManipPart, axis);
  338. getManipNormal(selected_object, mManipPart, mManipNormal);
  339. LLVector3 select_center_agent = getPivotPoint();
  340. mSubdivisions = llclamp(getSubdivisionLevel(select_center_agent,
  341. axis_exists ? axis
  342. : LLVector3::z_axis,
  343. getMinGridScale()),
  344. sGridMinSubdivisionLevel,
  345. sGridMaxSubdivisionLevel);
  346. // If we clicked on a planar manipulator, recenter mouse cursor
  347. if (mManipPart >= LL_YZ_PLANE && mManipPart <= LL_XY_PLANE)
  348. {
  349. LLCoordGL mouse_pos;
  350. if (!gViewerCamera.projectPosAgentToScreen(select_center_agent, mouse_pos))
  351. {
  352. // mouse_pos may be nonsense
  353. llwarns << "Failed to project object center to screen" << llendl;
  354. }
  355. else if (getSnapToMouseCursor())
  356. {
  357. LLUI::setCursorPositionScreen(mouse_pos.mX, mouse_pos.mY);
  358. x = mouse_pos.mX;
  359. y = mouse_pos.mY;
  360. }
  361. }
  362. gSelectMgr.updateSelectionCenter();
  363. LLVector3d object_start_global =
  364. gAgent.getPosGlobalFromAgent(getPivotPoint());
  365. getMousePointOnPlaneGlobal(mDragCursorStartGlobal, x, y,
  366. object_start_global, mManipNormal);
  367. mDragSelectionStartGlobal = object_start_global;
  368. mCopyMadeThisDrag = false;
  369. // Route future Mouse messages here preemptively (release on mouse up).
  370. setMouseCapture(true);
  371. return true;
  372. }
  373. bool LLManipTranslate::handleHover(S32 x, S32 y, MASK mask)
  374. {
  375. // Translation tool only works if mouse button is down.
  376. // Bail out if mouse not down.
  377. if (!hasMouseCapture())
  378. {
  379. LL_DEBUGS("UserInput") << "hover handled by LLManipTranslate (inactive)"
  380. << LL_ENDL;
  381. // Always show cursor
  382. gViewerWindowp->setCursor(UI_CURSOR_TOOLTRANSLATE);
  383. highlightManipulators(x, y);
  384. return true;
  385. }
  386. // Handle auto-rotation if necessary.
  387. constexpr F32 ROTATE_ANGLE_PER_SECOND = 30.f * DEG_TO_RAD;
  388. const S32 rotate_h_margin = gViewerWindowp->getWindowWidth() / 20;
  389. const F32 rotate_angle = ROTATE_ANGLE_PER_SECOND / gFPSClamped;
  390. bool rotated = false;
  391. // ...build mode moves camera about focus point
  392. if (mObjectSelection->getSelectType() != SELECT_TYPE_HUD)
  393. {
  394. if (x < rotate_h_margin)
  395. {
  396. gAgent.cameraOrbitAround(rotate_angle);
  397. rotated = true;
  398. }
  399. else if (x > gViewerWindowp->getWindowWidth() - rotate_h_margin)
  400. {
  401. gAgent.cameraOrbitAround(-rotate_angle);
  402. rotated = true;
  403. }
  404. }
  405. // Suppress processing if mouse hasn't actually moved. This may cause
  406. // problems if the camera moves outside of the rotation above.
  407. if (x == mLastHoverMouseX && y == mLastHoverMouseY && !rotated)
  408. {
  409. LL_DEBUGS("UserInput") << "hover handled by LLManipTranslate (mouse unmoved)"
  410. << LL_ENDL;
  411. gViewerWindowp->setCursor(UI_CURSOR_TOOLTRANSLATE);
  412. return true;
  413. }
  414. mLastHoverMouseX = x;
  415. mLastHoverMouseY = y;
  416. // Suppress if mouse hasn't moved past the initial slop region. Reset once
  417. // we start moving
  418. if (!mMouseOutsideSlop)
  419. {
  420. if (abs(mMouseDownX - x) < MOUSE_DRAG_SLOP &&
  421. abs(mMouseDownY - y) < MOUSE_DRAG_SLOP)
  422. {
  423. LL_DEBUGS("UserInput") << "hover handled by LLManipTranslate (mouse inside slop)"
  424. << LL_ENDL;
  425. gViewerWindowp->setCursor(UI_CURSOR_TOOLTRANSLATE);
  426. return true;
  427. }
  428. else // ...Just went outside the slop region
  429. {
  430. mMouseOutsideSlop = true;
  431. // If holding down shift, leave behind a copy.
  432. if (mask == MASK_COPY)
  433. {
  434. // ...we are trying to make a copy
  435. //MK
  436. if (!gRLenabled || !gRLInterface.mContainsRez)
  437. {
  438. //mk
  439. gSelectMgr.selectDuplicate(LLVector3::zero, false);
  440. mCopyMadeThisDrag = true;
  441. // When we make the copy, we don't want to do any other
  442. // processing. If so, the object will also be moved, and
  443. // the copy will be offset.
  444. LL_DEBUGS("UserInput") << "hover handled by LLManipTranslate (made copy)"
  445. << LL_ENDL;
  446. gViewerWindowp->setCursor(UI_CURSOR_TOOLTRANSLATE);
  447. }
  448. }
  449. }
  450. }
  451. LLVector3 axis_f;
  452. LLVector3d axis_d;
  453. // Pick the first object to constrain to grid w/ common origin. This is so
  454. // we do not screw up groups
  455. LLSelectNode* nodep = mObjectSelection->getFirstMoveableNode(true);
  456. if (!nodep)
  457. {
  458. // Somehow we lost the object !
  459. llwarns << "Translate manip lost the object, no selection node"
  460. << llendl;
  461. gViewerWindowp->setCursor(UI_CURSOR_TOOLTRANSLATE);
  462. return true;
  463. }
  464. LLViewerObject* object = nodep->getObject();
  465. if (!object)
  466. {
  467. // Somehow we lost the object!
  468. llwarns << "Translate manip lost the object, no object in selection node"
  469. << llendl;
  470. gViewerWindowp->setCursor(UI_CURSOR_TOOLTRANSLATE);
  471. return true;
  472. }
  473. // Compute unit vectors for arrow hit and a plane through that vector
  474. bool axis_exists = getManipAxis(object, mManipPart, axis_f);
  475. axis_d.set(axis_f);
  476. gSelectMgr.updateSelectionCenter();
  477. LLVector3d current_pos_global = gAgent.getPosGlobalFromAgent(getPivotPoint());
  478. mSubdivisions = llclamp(getSubdivisionLevel(getPivotPoint(), axis_f,
  479. getMinGridScale()),
  480. sGridMinSubdivisionLevel,
  481. sGridMaxSubdivisionLevel);
  482. // Project the cursor onto that plane
  483. LLVector3d relative_move;
  484. getMousePointOnPlaneGlobal(relative_move, x, y, current_pos_global,
  485. mManipNormal);
  486. relative_move -= mDragCursorStartGlobal;
  487. // You can't move more than some distance from your original mousedown point.
  488. static LLCachedControl<bool> limit_drag_distance(gSavedSettings,
  489. "LimitDragDistance");
  490. static LLCachedControl<F32> max_drag_dist(gSavedSettings,
  491. "MaxDragDistance");
  492. if (limit_drag_distance &&
  493. relative_move.lengthSquared() > max_drag_dist * max_drag_dist)
  494. {
  495. LL_DEBUGS("UserInput") << "hover handled by LLManipTranslate (too far)"
  496. << LL_ENDL;
  497. gViewerWindowp->setCursor(UI_CURSOR_NOLOCKED);
  498. return true;
  499. }
  500. F64 axis_magnitude = relative_move * axis_d; // dot product
  501. LLVector3d cursor_point_snap_line;
  502. getMousePointOnPlaneGlobal(cursor_point_snap_line, x, y,
  503. current_pos_global, mSnapOffsetAxis % axis_f);
  504. F64 off_axis_magnitude =
  505. axis_exists ? fabs((cursor_point_snap_line - current_pos_global) *
  506. LLVector3d(mSnapOffsetAxis))
  507. : 0.f;
  508. if (getSnapEnabled())
  509. {
  510. if (off_axis_magnitude > mSnapOffsetMeters)
  511. {
  512. mInSnapRegime = true;
  513. LLVector3 mouse_down_offset(mDragCursorStartGlobal -
  514. mDragSelectionStartGlobal);
  515. LLVector3 cursor_snap_agent =
  516. gAgent.getPosAgentFromGlobal(cursor_point_snap_line);
  517. if (!getSnapToMouseCursor())
  518. {
  519. cursor_snap_agent -= mouse_down_offset;
  520. }
  521. F32 cursor_grid_dist = (cursor_snap_agent - mGridOrigin) * axis_f;
  522. F32 snap_dist = getMinGridScale() / (2.f * mSubdivisions);
  523. F32 relative_snap_dist =
  524. fmodf(fabsf(cursor_grid_dist) + snap_dist,
  525. getMinGridScale() / mSubdivisions);
  526. if (relative_snap_dist < snap_dist * 2.f)
  527. {
  528. if (cursor_grid_dist > 0.f)
  529. {
  530. cursor_grid_dist -= relative_snap_dist - snap_dist;
  531. }
  532. else
  533. {
  534. cursor_grid_dist += relative_snap_dist - snap_dist;
  535. }
  536. }
  537. F32 object_start_on_axis =
  538. (gAgent.getPosAgentFromGlobal(mDragSelectionStartGlobal) -
  539. mGridOrigin) * axis_f;
  540. axis_magnitude = cursor_grid_dist - object_start_on_axis;
  541. }
  542. else if (mManipPart >= LL_YZ_PLANE && mManipPart <= LL_XY_PLANE)
  543. {
  544. // Subtract offset from object center
  545. LLVector3d cursor_point_global;
  546. getMousePointOnPlaneGlobal(cursor_point_global, x, y,
  547. current_pos_global, mManipNormal);
  548. cursor_point_global -= mDragCursorStartGlobal -
  549. mDragSelectionStartGlobal;
  550. // Snap to planar grid
  551. LLVector3 cursor_point_agent =
  552. gAgent.getPosAgentFromGlobal(cursor_point_global);
  553. LLVector3 camera_plane_projection = gViewerCamera.getAtAxis();
  554. camera_plane_projection -= projected_vec(camera_plane_projection,
  555. mManipNormal);
  556. camera_plane_projection.normalize();
  557. LLVector3 camera_projected_dir = camera_plane_projection;
  558. camera_plane_projection.rotVec(~mGridRotation);
  559. camera_plane_projection.scaleVec(mGridScale);
  560. camera_plane_projection.abs();
  561. F32 max_grid_scale;
  562. if (camera_plane_projection.mV[VX] > camera_plane_projection.mV[VY] &&
  563. camera_plane_projection.mV[VX] > camera_plane_projection.mV[VZ])
  564. {
  565. max_grid_scale = mGridScale.mV[VX];
  566. }
  567. else if (camera_plane_projection.mV[VY] > camera_plane_projection.mV[VZ])
  568. {
  569. max_grid_scale = mGridScale.mV[VY];
  570. }
  571. else
  572. {
  573. max_grid_scale = mGridScale.mV[VZ];
  574. }
  575. F32 num_subdivisions = llclamp(getSubdivisionLevel(getPivotPoint(),
  576. camera_projected_dir,
  577. max_grid_scale),
  578. sGridMinSubdivisionLevel,
  579. sGridMaxSubdivisionLevel);
  580. F32 grid_scale_a;
  581. F32 grid_scale_b;
  582. LLVector3 cursor_point_grid = (cursor_point_agent - mGridOrigin) *
  583. ~mGridRotation;
  584. switch (mManipPart)
  585. {
  586. case LL_YZ_PLANE:
  587. grid_scale_a = mGridScale.mV[VY] / num_subdivisions;
  588. grid_scale_b = mGridScale.mV[VZ] / num_subdivisions;
  589. cursor_point_grid.mV[VY] -= fmod(cursor_point_grid.mV[VY] +
  590. grid_scale_a * 0.5f,
  591. grid_scale_a) -
  592. grid_scale_a * 0.5f;
  593. cursor_point_grid.mV[VZ] -= fmod(cursor_point_grid.mV[VZ] +
  594. grid_scale_b * 0.5f,
  595. grid_scale_b) -
  596. grid_scale_b * 0.5f;
  597. break;
  598. case LL_XZ_PLANE:
  599. grid_scale_a = mGridScale.mV[VX] / num_subdivisions;
  600. grid_scale_b = mGridScale.mV[VZ] / num_subdivisions;
  601. cursor_point_grid.mV[VX] -= fmod(cursor_point_grid.mV[VX] +
  602. grid_scale_a * 0.5f,
  603. grid_scale_a) -
  604. grid_scale_a * 0.5f;
  605. cursor_point_grid.mV[VZ] -= fmod(cursor_point_grid.mV[VZ] +
  606. grid_scale_b * 0.5f,
  607. grid_scale_b) -
  608. grid_scale_b * 0.5f;
  609. break;
  610. case LL_XY_PLANE:
  611. grid_scale_a = mGridScale.mV[VX] / num_subdivisions;
  612. grid_scale_b = mGridScale.mV[VY] / num_subdivisions;
  613. cursor_point_grid.mV[VX] -= fmod(cursor_point_grid.mV[VX] +
  614. grid_scale_a * 0.5f,
  615. grid_scale_a) -
  616. grid_scale_a * 0.5f;
  617. cursor_point_grid.mV[VY] -= fmod(cursor_point_grid.mV[VY] +
  618. grid_scale_b * 0.5f,
  619. grid_scale_b) -
  620. grid_scale_b * 0.5f;
  621. break;
  622. default:
  623. break;
  624. }
  625. cursor_point_agent = cursor_point_grid * mGridRotation +
  626. mGridOrigin;
  627. relative_move.set(cursor_point_agent -
  628. gAgent.getPosAgentFromGlobal(mDragSelectionStartGlobal));
  629. mInSnapRegime = true;
  630. }
  631. else
  632. {
  633. mInSnapRegime = false;
  634. }
  635. }
  636. else
  637. {
  638. mInSnapRegime = false;
  639. }
  640. // Clamp to arrow direction
  641. // *FIX: does this apply anymore?
  642. if (!axis_exists)
  643. {
  644. axis_magnitude = relative_move.normalize();
  645. axis_d.set(relative_move);
  646. axis_d.normalize();
  647. axis_f.set(axis_d);
  648. }
  649. // Scalar multiplications
  650. LLVector3d clamped_relative_move = axis_magnitude * axis_d;
  651. LLVector3 clamped_relative_move_f = (F32)axis_magnitude * axis_f;
  652. for (LLObjectSelection::iterator iter = mObjectSelection->begin(),
  653. end = mObjectSelection->end();
  654. iter != end; ++iter)
  655. {
  656. LLSelectNode* nodep = *iter;
  657. LLViewerObject* object = nodep->getObject();
  658. if (!object)
  659. {
  660. llwarns << "NULL selected object !" << llendl;
  661. continue;
  662. }
  663. if (nodep->mSelectedGLTFNode != -1)
  664. {
  665. // Manipulating a GLTF node
  666. clamped_relative_move_f -= nodep->mLastMoveLocal;
  667. object->moveGLTFNode(nodep->mSelectedGLTFNode,
  668. clamped_relative_move_f);
  669. nodep->mLastMoveLocal += clamped_relative_move_f;
  670. continue;
  671. }
  672. // Only apply motion to root objects and objects selected as
  673. // "individual".
  674. if (!object->isRootEdit() && !nodep->mIndividualSelection)
  675. {
  676. continue;
  677. }
  678. if (!object->isRootEdit())
  679. {
  680. // child objects should not update if parent is selected
  681. LLViewerObject* editable_root = (LLViewerObject*)object->getParent();
  682. if (editable_root->isSelected())
  683. {
  684. // we will be moved properly by our parent, so skip
  685. continue;
  686. }
  687. }
  688. LLViewerObject* root_object = object->getRootEdit();
  689. if (object->permMove() && !object->isPermanentEnforced() &&
  690. (!root_object || !root_object->isPermanentEnforced()))
  691. {
  692. // handle attachments in local space
  693. if (object->isAttachment() && object->mDrawable.notNull())
  694. {
  695. // calculate local version of relative move
  696. LLQuaternion obj_world_rot =
  697. object->mDrawable->mXform.getParent()->getWorldRotation();
  698. obj_world_rot.transpose();
  699. LLVector3 old_position_local = object->getPosition();
  700. LLVector3 new_position_local = nodep->mSavedPositionLocal +
  701. clamped_relative_move_f * obj_world_rot;
  702. // RN: I forget, but we need to do this because of snapping
  703. // which doesn't often result in position changes even when the
  704. // mouse moves
  705. object->setPositionLocal(new_position_local);
  706. rebuild(object);
  707. gAgentAvatarp->clampAttachmentPositions();
  708. new_position_local = object->getPosition();
  709. if (nodep->mIndividualSelection)
  710. {
  711. // Counter-translate child objects if we are moving the
  712. // root as an individual
  713. object->resetChildrenPosition(old_position_local -
  714. new_position_local, true);
  715. }
  716. }
  717. else
  718. {
  719. // Compute new position to send to simulators, but don't set
  720. // it yet. We need the old position to know which simulator to
  721. // send the move message to.
  722. LLVector3d new_pos_global = nodep->mSavedPositionGlobal +
  723. clamped_relative_move;
  724. // Do not let object centers go too far underground
  725. F64 min_height = gWorld.getMinAllowedZ(object);
  726. if (new_pos_global.mdV[VZ] < min_height)
  727. {
  728. new_pos_global.mdV[VZ] = min_height;
  729. }
  730. // For safety, cap heights where objects can be dragged
  731. if (new_pos_global.mdV[VZ] > MAX_OBJECT_Z)
  732. {
  733. new_pos_global.mdV[VZ] = MAX_OBJECT_Z;
  734. }
  735. // Grass is always drawn on the ground, so clamp its position
  736. // to the ground
  737. if (object->getPCode() == LL_PCODE_LEGACY_GRASS)
  738. {
  739. new_pos_global.mdV[VZ] =
  740. gWorld.resolveLandHeightGlobal(new_pos_global) + 1.f;
  741. }
  742. if (object->isRootEdit())
  743. {
  744. new_pos_global =
  745. gWorld.clipToVisibleRegions(object->getPositionGlobal(),
  746. new_pos_global);
  747. }
  748. // PR: Only update if changed
  749. LLVector3 old_position_agent = object->getPositionAgent();
  750. LLVector3 new_position_agent =
  751. gAgent.getPosAgentFromGlobal(new_pos_global);
  752. if (object->isRootEdit())
  753. {
  754. // Finally, move parent object after children have
  755. // calculated new offsets
  756. object->setPositionAgent(new_position_agent);
  757. rebuild(object);
  758. }
  759. else
  760. {
  761. LLViewerObject* root_object = object->getRootEdit();
  762. new_position_agent -= root_object->getPositionAgent();
  763. new_position_agent = new_position_agent *
  764. ~root_object->getRotation();
  765. object->setPositionParent(new_position_agent, false);
  766. rebuild(object);
  767. }
  768. if (nodep->mIndividualSelection)
  769. {
  770. // Counter-translate child objects if we are moving the
  771. // root as an individual
  772. object->resetChildrenPosition(old_position_agent -
  773. new_position_agent, true);
  774. }
  775. }
  776. nodep->mLastPositionLocal = object->getPosition();
  777. }
  778. }
  779. gSelectMgr.updateSelectionCenter();
  780. gAgent.clearFocusObject();
  781. dialog_refresh_all(); // is this necessary ?
  782. LL_DEBUGS("UserInput") << "Hover handled by LLManipTranslate (active)"
  783. << LL_ENDL;
  784. gViewerWindowp->setCursor(UI_CURSOR_TOOLTRANSLATE);
  785. return true;
  786. }
  787. void LLManipTranslate::highlightManipulators(S32 x, S32 y)
  788. {
  789. mHighlightedPart = LL_NO_PART;
  790. if (!mObjectSelection->getObjectCount())
  791. {
  792. return;
  793. }
  794. LLMatrix4 proj_mat = gViewerCamera.getProjection();
  795. LLMatrix4 model_view = gViewerCamera.getModelview();
  796. LLVector3 object_position = getPivotPoint();
  797. LLVector3 grid_origin;
  798. LLVector3 grid_scale;
  799. LLQuaternion grid_rotation;
  800. gSelectMgr.getGrid(grid_origin, grid_rotation, grid_scale);
  801. LLVector3 relative_camera_dir;
  802. LLMatrix4 transform;
  803. if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
  804. {
  805. relative_camera_dir = LLVector3::x_axis * ~grid_rotation;
  806. LLVector4 translation(object_position);
  807. transform.initRotTrans(grid_rotation, translation);
  808. LLMatrix4 cfr(OGL_TO_CFR_ROTATION);
  809. transform *= cfr;
  810. LLMatrix4 window_scale;
  811. F32 zoom_level = 2.f * gAgent.mHUDCurZoom;
  812. window_scale.initAll(LLVector3(zoom_level / gViewerCamera.getAspect(),
  813. zoom_level, 0.f),
  814. LLQuaternion::DEFAULT, LLVector3::zero);
  815. transform *= window_scale;
  816. }
  817. else
  818. {
  819. relative_camera_dir = (object_position - gViewerCamera.getOrigin()) *
  820. ~grid_rotation;
  821. relative_camera_dir.normalize();
  822. transform.initRotTrans(grid_rotation, LLVector4(object_position));
  823. transform *= model_view;
  824. transform *= proj_mat;
  825. }
  826. S32 num_manips = 0;
  827. // edges
  828. mManipulatorVertices[num_manips++] =
  829. LLVector4(mArrowLengthMeters * MANIP_HOTSPOT_START, 0.f, 0.f, 1.f);
  830. mManipulatorVertices[num_manips++] =
  831. LLVector4(mArrowLengthMeters * MANIP_HOTSPOT_END, 0.f, 0.f, 1.f);
  832. mManipulatorVertices[num_manips++] =
  833. LLVector4(0.f, mArrowLengthMeters * MANIP_HOTSPOT_START, 0.f, 1.f);
  834. mManipulatorVertices[num_manips++] =
  835. LLVector4(0.f, mArrowLengthMeters * MANIP_HOTSPOT_END, 0.f, 1.f);
  836. mManipulatorVertices[num_manips++] =
  837. LLVector4(0.f, 0.f, mArrowLengthMeters * MANIP_HOTSPOT_START, 1.f);
  838. mManipulatorVertices[num_manips++] =
  839. LLVector4(0.f, 0.f, mArrowLengthMeters * MANIP_HOTSPOT_END, 1.f);
  840. mManipulatorVertices[num_manips++] =
  841. LLVector4(mArrowLengthMeters * -MANIP_HOTSPOT_START, 0.f, 0.f, 1.f);
  842. mManipulatorVertices[num_manips++] =
  843. LLVector4(mArrowLengthMeters * -MANIP_HOTSPOT_END, 0.f, 0.f, 1.f);
  844. mManipulatorVertices[num_manips++] =
  845. LLVector4(0.f, mArrowLengthMeters * -MANIP_HOTSPOT_START, 0.f, 1.f);
  846. mManipulatorVertices[num_manips++] =
  847. LLVector4(0.f, mArrowLengthMeters * -MANIP_HOTSPOT_END, 0.f, 1.f);
  848. mManipulatorVertices[num_manips++] =
  849. LLVector4(0.f, 0.f, mArrowLengthMeters * -MANIP_HOTSPOT_START, 1.f);
  850. mManipulatorVertices[num_manips++] =
  851. LLVector4(0.f, 0.f, mArrowLengthMeters * -MANIP_HOTSPOT_END, 1.f);
  852. S32 num_arrow_manips = num_manips;
  853. // planar manipulators
  854. bool planar_manip_yz_visible = false;
  855. bool planar_manip_xz_visible = false;
  856. bool planar_manip_xy_visible = false;
  857. constexpr F32 PLANE_FACTOR1 = 1.f - PLANE_TICK_SIZE * 0.5f;
  858. constexpr F32 PLANE_FACTOR2 = 1.f + PLANE_TICK_SIZE * 0.5f;
  859. mManipulatorVertices[num_manips] =
  860. LLVector4(0.f, mPlaneManipOffsetMeters * PLANE_FACTOR1,
  861. mPlaneManipOffsetMeters * PLANE_FACTOR1, 1.f);
  862. mManipulatorVertices[num_manips++].scaleVec(mPlaneManipPositions);
  863. mManipulatorVertices[num_manips] =
  864. LLVector4(0.f, mPlaneManipOffsetMeters * PLANE_FACTOR2,
  865. mPlaneManipOffsetMeters * PLANE_FACTOR2, 1.f);
  866. mManipulatorVertices[num_manips++].scaleVec(mPlaneManipPositions);
  867. if (fabsf(relative_camera_dir.mV[VX]) > MIN_PLANE_MANIP_DOT_PRODUCT)
  868. {
  869. planar_manip_yz_visible = true;
  870. }
  871. mManipulatorVertices[num_manips] =
  872. LLVector4(mPlaneManipOffsetMeters * PLANE_FACTOR1, 0.f,
  873. mPlaneManipOffsetMeters * PLANE_FACTOR1, 1.f);
  874. mManipulatorVertices[num_manips++].scaleVec(mPlaneManipPositions);
  875. mManipulatorVertices[num_manips] =
  876. LLVector4(mPlaneManipOffsetMeters * PLANE_FACTOR2, 0.f,
  877. mPlaneManipOffsetMeters * PLANE_FACTOR2, 1.f);
  878. mManipulatorVertices[num_manips++].scaleVec(mPlaneManipPositions);
  879. if (fabsf(relative_camera_dir.mV[VY]) > MIN_PLANE_MANIP_DOT_PRODUCT)
  880. {
  881. planar_manip_xz_visible = true;
  882. }
  883. mManipulatorVertices[num_manips] =
  884. LLVector4(mPlaneManipOffsetMeters * PLANE_FACTOR1,
  885. mPlaneManipOffsetMeters * PLANE_FACTOR1, 0.f, 1.f);
  886. mManipulatorVertices[num_manips++].scaleVec(mPlaneManipPositions);
  887. mManipulatorVertices[num_manips] =
  888. LLVector4(mPlaneManipOffsetMeters * PLANE_FACTOR2,
  889. mPlaneManipOffsetMeters * PLANE_FACTOR2, 0.f, 1.f);
  890. mManipulatorVertices[num_manips++].scaleVec(mPlaneManipPositions);
  891. if (fabsf(relative_camera_dir.mV[VZ]) > MIN_PLANE_MANIP_DOT_PRODUCT)
  892. {
  893. planar_manip_xy_visible = true;
  894. }
  895. // Project up to 9 manipulators to screen space 2*X, 2*Y, 2*Z, 3*planes
  896. std::vector<ManipulatorHandle> projected_manipulators;
  897. projected_manipulators.reserve(9);
  898. for (S32 i = 0; i < num_arrow_manips; i += 2)
  899. {
  900. LLVector4 projected_start = mManipulatorVertices[i] * transform;
  901. projected_start = projected_start / projected_start.mV[VW];
  902. LLVector4 projected_end = mManipulatorVertices[i + 1] * transform;
  903. projected_end = projected_end / projected_end.mV[VW];
  904. ManipulatorHandle projected_manip(LLVector3(projected_start.mV[VX],
  905. projected_start.mV[VY],
  906. projected_start.mV[VZ]),
  907. LLVector3(projected_end.mV[VX],
  908. projected_end.mV[VY],
  909. projected_end.mV[VZ]),
  910. MANIPULATOR_IDS[i / 2],
  911. 10.f); // 10 pixel hotspot for arrows
  912. projected_manipulators.push_back(projected_manip);
  913. }
  914. if (planar_manip_yz_visible)
  915. {
  916. S32 i = num_arrow_manips;
  917. LLVector4 projected_start = mManipulatorVertices[i] * transform;
  918. projected_start = projected_start / projected_start.mV[VW];
  919. LLVector4 projected_end = mManipulatorVertices[i + 1] * transform;
  920. projected_end = projected_end / projected_end.mV[VW];
  921. ManipulatorHandle projected_manip(LLVector3(projected_start.mV[VX],
  922. projected_start.mV[VY],
  923. projected_start.mV[VZ]),
  924. LLVector3(projected_end.mV[VX],
  925. projected_end.mV[VY],
  926. projected_end.mV[VZ]),
  927. MANIPULATOR_IDS[i / 2],
  928. // 20 pixels for planar manipulators
  929. 20.f);
  930. projected_manipulators.push_back(projected_manip);
  931. }
  932. if (planar_manip_xz_visible)
  933. {
  934. S32 i = num_arrow_manips + 2;
  935. LLVector4 projected_start = mManipulatorVertices[i] * transform;
  936. projected_start = projected_start / projected_start.mV[VW];
  937. LLVector4 projected_end = mManipulatorVertices[i + 1] * transform;
  938. projected_end = projected_end / projected_end.mV[VW];
  939. ManipulatorHandle projected_manip(LLVector3(projected_start.mV[VX],
  940. projected_start.mV[VY],
  941. projected_start.mV[VZ]),
  942. LLVector3(projected_end.mV[VX],
  943. projected_end.mV[VY],
  944. projected_end.mV[VZ]),
  945. MANIPULATOR_IDS[i / 2],
  946. // 20 pixels for planar manipulators
  947. 20.f);
  948. projected_manipulators.push_back(projected_manip);
  949. }
  950. if (planar_manip_xy_visible)
  951. {
  952. S32 i = num_arrow_manips + 4;
  953. LLVector4 projected_start = mManipulatorVertices[i] * transform;
  954. projected_start = projected_start / projected_start.mV[VW];
  955. LLVector4 projected_end = mManipulatorVertices[i + 1] * transform;
  956. projected_end = projected_end / projected_end.mV[VW];
  957. ManipulatorHandle projected_manip(LLVector3(projected_start.mV[VX],
  958. projected_start.mV[VY],
  959. projected_start.mV[VZ]),
  960. LLVector3(projected_end.mV[VX],
  961. projected_end.mV[VY],
  962. projected_end.mV[VZ]),
  963. MANIPULATOR_IDS[i / 2],
  964. // 20 pixels for planar manipulators
  965. 20.f);
  966. projected_manipulators.push_back(projected_manip);
  967. }
  968. LLVector2 manip_start_2d;
  969. LLVector2 manip_end_2d;
  970. LLVector2 manip_dir;
  971. F32 half_width = gViewerWindowp->getWindowWidth() * 0.5f;
  972. F32 half_height = gViewerWindowp->getWindowHeight() * 0.5f;
  973. LLVector2 mousePos((F32)x - half_width, (F32)y - half_height);
  974. LLVector2 mouse_delta;
  975. // Keep order consistent with insertion via stable_sort
  976. std::stable_sort(projected_manipulators.begin(),
  977. projected_manipulators.end(), ClosestToCamera());
  978. std::vector<ManipulatorHandle>::iterator it = projected_manipulators.begin();
  979. for ( ; it != projected_manipulators.end(); ++it)
  980. {
  981. ManipulatorHandle& manipulator = *it;
  982. {
  983. manip_start_2d.set(manipulator.mStartPosition.mV[VX] * half_width,
  984. manipulator.mStartPosition.mV[VY] * half_height);
  985. manip_end_2d.set(manipulator.mEndPosition.mV[VX] * half_width,
  986. manipulator.mEndPosition.mV[VY] * half_height);
  987. manip_dir = manip_end_2d - manip_start_2d;
  988. mouse_delta = mousePos - manip_start_2d;
  989. F32 manip_length = manip_dir.normalize();
  990. F32 mouse_pos_manip = mouse_delta * manip_dir;
  991. F32 mouse_dist_manip_squared = mouse_delta.lengthSquared() -
  992. mouse_pos_manip * mouse_pos_manip;
  993. if (mouse_pos_manip > 0.f &&
  994. mouse_pos_manip < manip_length &&
  995. mouse_dist_manip_squared < manipulator.mHotSpotRadius *
  996. manipulator.mHotSpotRadius)
  997. {
  998. mHighlightedPart = manipulator.mManipID;
  999. break;
  1000. }
  1001. }
  1002. }
  1003. }
  1004. F32 LLManipTranslate::getMinGridScale()
  1005. {
  1006. F32 scale;
  1007. switch (mManipPart)
  1008. {
  1009. case LL_NO_PART:
  1010. default:
  1011. scale = 1.f;
  1012. break;
  1013. case LL_X_ARROW:
  1014. scale = mGridScale.mV[VX];
  1015. break;
  1016. case LL_Y_ARROW:
  1017. scale = mGridScale.mV[VY];
  1018. break;
  1019. case LL_Z_ARROW:
  1020. scale = mGridScale.mV[VZ];
  1021. break;
  1022. case LL_YZ_PLANE:
  1023. scale = llmin(mGridScale.mV[VY], mGridScale.mV[VZ]);
  1024. break;
  1025. case LL_XZ_PLANE:
  1026. scale = llmin(mGridScale.mV[VX], mGridScale.mV[VZ]);
  1027. break;
  1028. case LL_XY_PLANE:
  1029. scale = llmin(mGridScale.mV[VX], mGridScale.mV[VY]);
  1030. }
  1031. return scale;
  1032. }
  1033. bool LLManipTranslate::handleMouseUp(S32 x, S32 y, MASK mask)
  1034. {
  1035. // First, perform normal processing in case this was a quick-click
  1036. handleHover(x, y, mask);
  1037. if (hasMouseCapture())
  1038. {
  1039. // make sure arrow colors go back to normal
  1040. mManipPart = LL_NO_PART;
  1041. gSelectMgr.enableSilhouette(true);
  1042. // Might have missed last update due to UPDATE_DELAY timing.
  1043. gSelectMgr.sendMultipleUpdate(UPD_POSITION);
  1044. mInSnapRegime = false;
  1045. gSelectMgr.saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
  1046. #if 0
  1047. gAgent.setObjectTracking(gSavedSettings.getBool("TrackFocusObject"));
  1048. #endif
  1049. }
  1050. return LLManip::handleMouseUp(x, y, mask);
  1051. }
  1052. void LLManipTranslate::render()
  1053. {
  1054. gGL.matrixMode(LLRender::MM_MODELVIEW);
  1055. gGL.pushMatrix();
  1056. if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
  1057. {
  1058. F32 zoom = gAgent.mHUDCurZoom;
  1059. gGL.scalef(zoom, zoom, zoom);
  1060. }
  1061. {
  1062. LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
  1063. renderGuidelines();
  1064. }
  1065. {
  1066. renderTranslationHandles();
  1067. renderSnapGuides();
  1068. }
  1069. gGL.popMatrix();
  1070. renderText();
  1071. }
  1072. void LLManipTranslate::renderSnapGuides()
  1073. {
  1074. if (!getSnapEnabled())
  1075. {
  1076. return;
  1077. }
  1078. F32 max_subdivisions = sGridMaxSubdivisionLevel;
  1079. static LLCachedControl<F32> grid_opacity(gSavedSettings, "GridOpacity");
  1080. F32 line_alpha = grid_opacity;
  1081. LLTexUnit* unit0 = gGL.getTexUnit(0);
  1082. unit0->unbind(LLTexUnit::TT_TEXTURE);
  1083. LLGLDepthTest gls_depth(GL_TRUE);
  1084. LLGLDisable gls_cull(GL_CULL_FACE);
  1085. LLVector3 translate_axis;
  1086. if (mManipPart == LL_NO_PART)
  1087. {
  1088. return;
  1089. }
  1090. LLSelectNode *first_node = mObjectSelection->getFirstMoveableNode(true);
  1091. if (!first_node)
  1092. {
  1093. return;
  1094. }
  1095. updateGridSettings();
  1096. F32 smallest_grid_unit_scale = getMinGridScale() / max_subdivisions;
  1097. LLVector3 grid_origin;
  1098. LLVector3 grid_scale;
  1099. LLQuaternion grid_rotation;
  1100. gSelectMgr.getGrid(grid_origin, grid_rotation, grid_scale);
  1101. LLVector3 saved_selection_center = getSavedPivotPoint();
  1102. LLVector3 selection_center = getPivotPoint();
  1103. LLViewerObject* first_object = first_node->getObject();
  1104. // Pick appropriate projection plane for snap rulers according to relative
  1105. // camera position
  1106. if (mManipPart >= LL_X_ARROW && mManipPart <= LL_Z_ARROW)
  1107. {
  1108. LLVector3 normal;
  1109. LLColor4 inner_color;
  1110. LLManip::EManipPart temp_manip = mManipPart;
  1111. switch (mManipPart)
  1112. {
  1113. case LL_X_ARROW:
  1114. normal.set(1, 0, 0);
  1115. inner_color.set(0, 1, 1, line_alpha);
  1116. mManipPart = LL_YZ_PLANE;
  1117. break;
  1118. case LL_Y_ARROW:
  1119. normal.set(0, 1, 0);
  1120. inner_color.set(1, 0, 1, line_alpha);
  1121. mManipPart = LL_XZ_PLANE;
  1122. break;
  1123. case LL_Z_ARROW:
  1124. normal.set(0, 0, 1);
  1125. inner_color.set(1, 1, 0, line_alpha);
  1126. mManipPart = LL_XY_PLANE;
  1127. break;
  1128. default:
  1129. break;
  1130. }
  1131. highlightIntersection(normal, selection_center, grid_rotation,
  1132. inner_color);
  1133. mManipPart = temp_manip;
  1134. getManipAxis(first_object, mManipPart, translate_axis);
  1135. LLVector3 at_axis_abs;
  1136. if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
  1137. {
  1138. at_axis_abs = LLVector3::x_axis * ~grid_rotation;
  1139. }
  1140. else
  1141. {
  1142. at_axis_abs = saved_selection_center - gViewerCamera.getOrigin();
  1143. at_axis_abs.normalize();
  1144. at_axis_abs = at_axis_abs * ~grid_rotation;
  1145. }
  1146. at_axis_abs.abs();
  1147. if (at_axis_abs.mV[VX] > at_axis_abs.mV[VY] &&
  1148. at_axis_abs.mV[VX] > at_axis_abs.mV[VZ])
  1149. {
  1150. if (mManipPart == LL_Y_ARROW)
  1151. {
  1152. mSnapOffsetAxis = LLVector3::z_axis;
  1153. }
  1154. else if (mManipPart == LL_Z_ARROW)
  1155. {
  1156. mSnapOffsetAxis = LLVector3::y_axis;
  1157. }
  1158. else if (at_axis_abs.mV[VY] > at_axis_abs.mV[VZ])
  1159. {
  1160. mSnapOffsetAxis = LLVector3::z_axis;
  1161. }
  1162. else
  1163. {
  1164. mSnapOffsetAxis = LLVector3::y_axis;
  1165. }
  1166. }
  1167. else if (at_axis_abs.mV[VY] > at_axis_abs.mV[VZ])
  1168. {
  1169. if (mManipPart == LL_X_ARROW)
  1170. {
  1171. mSnapOffsetAxis = LLVector3::z_axis;
  1172. }
  1173. else if (mManipPart == LL_Z_ARROW)
  1174. {
  1175. mSnapOffsetAxis = LLVector3::x_axis;
  1176. }
  1177. else if (at_axis_abs.mV[VX] > at_axis_abs.mV[VZ])
  1178. {
  1179. mSnapOffsetAxis = LLVector3::z_axis;
  1180. }
  1181. else
  1182. {
  1183. mSnapOffsetAxis = LLVector3::x_axis;
  1184. }
  1185. }
  1186. else if (mManipPart == LL_X_ARROW)
  1187. {
  1188. mSnapOffsetAxis = LLVector3::y_axis;
  1189. }
  1190. else if (mManipPart == LL_Y_ARROW)
  1191. {
  1192. mSnapOffsetAxis = LLVector3::x_axis;
  1193. }
  1194. else if (at_axis_abs.mV[VX] > at_axis_abs.mV[VY])
  1195. {
  1196. mSnapOffsetAxis = LLVector3::y_axis;
  1197. }
  1198. else
  1199. {
  1200. mSnapOffsetAxis = LLVector3::x_axis;
  1201. }
  1202. mSnapOffsetAxis = mSnapOffsetAxis * grid_rotation;
  1203. F32 guide_size_meters;
  1204. if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
  1205. {
  1206. guide_size_meters = 1.f / gAgent.mHUDCurZoom;
  1207. mSnapOffsetMeters = mArrowLengthMeters * 1.5f;
  1208. }
  1209. else
  1210. {
  1211. LLVector3 cam_to_selection = getPivotPoint() -
  1212. gViewerCamera.getOrigin();
  1213. F32 current_range = cam_to_selection.normalize();
  1214. guide_size_meters = SNAP_GUIDE_SCREEN_SIZE *
  1215. gViewerWindowp->getWindowHeight() *
  1216. current_range /
  1217. gViewerCamera.getPixelMeterRatio();
  1218. F32 fraction_of_fov = mAxisArrowLength /
  1219. (F32)gViewerCamera.getViewHeightInPixels();
  1220. // in radians:
  1221. F32 apparent_angle = fraction_of_fov * gViewerCamera.getView();
  1222. F32 offset_at_camera = tanf(apparent_angle) * 1.5f;
  1223. F32 range =
  1224. dist_vec(gAgent.getPosAgentFromGlobal(first_node->mSavedPositionGlobal),
  1225. gViewerCamera.getOrigin());
  1226. mSnapOffsetMeters = range * offset_at_camera;
  1227. }
  1228. LLVector3 tick_start;
  1229. LLVector3 tick_end;
  1230. // how far away from grid origin is the selection along the axis of
  1231. // translation ?
  1232. F32 dist_grid_axis = (selection_center - mGridOrigin) * translate_axis;
  1233. // find distance to nearest smallest grid unit
  1234. F32 offset_nearest_grid_unit = fmodf(dist_grid_axis,
  1235. smallest_grid_unit_scale);
  1236. // how many smallest grid units are we away from largest grid scale?
  1237. S32 sub_div_offset =
  1238. ll_round(fmod(dist_grid_axis - offset_nearest_grid_unit,
  1239. getMinGridScale() / sGridMinSubdivisionLevel) /
  1240. smallest_grid_unit_scale);
  1241. S32 num_ticks_per_side = llmax(1,
  1242. llfloor(0.5f * guide_size_meters /
  1243. smallest_grid_unit_scale));
  1244. LLGLDepthTest gls_depth(GL_FALSE);
  1245. for (S32 pass = 0; pass < 3; ++pass)
  1246. {
  1247. LLColor4 line_color = setupSnapGuideRenderPass(pass);
  1248. gGL.begin(LLRender::LINES);
  1249. {
  1250. LLVector3 line_start = selection_center +
  1251. (mSnapOffsetMeters * mSnapOffsetAxis) +
  1252. (translate_axis *
  1253. (guide_size_meters * 0.5f +
  1254. offset_nearest_grid_unit));
  1255. LLVector3 line_end = selection_center +
  1256. mSnapOffsetMeters * mSnapOffsetAxis -
  1257. translate_axis *
  1258. (guide_size_meters * 0.5f +
  1259. offset_nearest_grid_unit);
  1260. LLVector3 line_mid = (line_start + line_end) * 0.5f;
  1261. gGL.color4f(line_color.mV[VX], line_color.mV[VY],
  1262. line_color.mV[VZ], line_color.mV[VW] * 0.2f);
  1263. gGL.vertex3fv(line_start.mV);
  1264. gGL.color4f(line_color.mV[VX], line_color.mV[VY],
  1265. line_color.mV[VZ], line_color.mV[VW]);
  1266. gGL.vertex3fv(line_mid.mV);
  1267. gGL.vertex3fv(line_mid.mV);
  1268. gGL.color4f(line_color.mV[VX], line_color.mV[VY],
  1269. line_color.mV[VZ], line_color.mV[VW] * 0.2f);
  1270. gGL.vertex3fv(line_end.mV);
  1271. line_start.set(selection_center +
  1272. mSnapOffsetAxis * -mSnapOffsetMeters +
  1273. translate_axis * guide_size_meters * 0.5f);
  1274. line_end.set(selection_center +
  1275. mSnapOffsetAxis * -mSnapOffsetMeters -
  1276. translate_axis * guide_size_meters * 0.5f);
  1277. line_mid = (line_start + line_end) * 0.5f;
  1278. gGL.color4f(line_color.mV[VX], line_color.mV[VY],
  1279. line_color.mV[VZ], line_color.mV[VW] * 0.2f);
  1280. gGL.vertex3fv(line_start.mV);
  1281. gGL.color4f(line_color.mV[VX], line_color.mV[VY],
  1282. line_color.mV[VZ], line_color.mV[VW]);
  1283. gGL.vertex3fv(line_mid.mV);
  1284. gGL.vertex3fv(line_mid.mV);
  1285. gGL.color4f(line_color.mV[VX], line_color.mV[VY],
  1286. line_color.mV[VZ], line_color.mV[VW] * 0.2f);
  1287. gGL.vertex3fv(line_end.mV);
  1288. for (S32 i = -num_ticks_per_side; i <= num_ticks_per_side; ++i)
  1289. {
  1290. tick_start = selection_center +
  1291. translate_axis *
  1292. (smallest_grid_unit_scale * (F32)i -
  1293. offset_nearest_grid_unit);
  1294. #if 0 // No need to check this condition to prevent tick position
  1295. // scaling (FIX MAINT-5207/5208)
  1296. F32 cur_subdivisions =
  1297. llclamp(getSubdivisionLevel(tick_start, translate_axis,
  1298. getMinGridScale()),
  1299. sGridMinSubdivisionLevel,
  1300. sGridMaxSubdivisionLevel);
  1301. if (fmodf((F32)(i + sub_div_offset),
  1302. max_subdivisions / cur_subdivisions) != 0.f)
  1303. {
  1304. continue;
  1305. }
  1306. #endif
  1307. // Add in off-axis offset
  1308. tick_start += (mSnapOffsetAxis * mSnapOffsetMeters);
  1309. F32 tick_scale = 1.f;
  1310. for (F32 division_level = max_subdivisions;
  1311. division_level >= sGridMinSubdivisionLevel;
  1312. division_level *= 0.5f)
  1313. {
  1314. if (fmodf((F32)(i + sub_div_offset),
  1315. division_level) == 0.f)
  1316. {
  1317. break;
  1318. }
  1319. tick_scale *= 0.7f;
  1320. }
  1321. tick_end = tick_start +
  1322. mSnapOffsetAxis * mSnapOffsetMeters *
  1323. tick_scale;
  1324. gGL.color4f(line_color.mV[VX], line_color.mV[VY],
  1325. line_color.mV[VZ], line_color.mV[VW]);
  1326. gGL.vertex3fv(tick_start.mV);
  1327. gGL.vertex3fv(tick_end.mV);
  1328. tick_start = selection_center +
  1329. mSnapOffsetAxis * -mSnapOffsetMeters +
  1330. translate_axis *
  1331. (getMinGridScale() / (F32)(max_subdivisions) *
  1332. (F32)i - offset_nearest_grid_unit);
  1333. tick_end = tick_start -
  1334. mSnapOffsetAxis * mSnapOffsetMeters *
  1335. tick_scale;
  1336. gGL.vertex3fv(tick_start.mV);
  1337. gGL.vertex3fv(tick_end.mV);
  1338. }
  1339. }
  1340. gGL.end();
  1341. if (mInSnapRegime)
  1342. {
  1343. LLVector3 line_start = selection_center -
  1344. mSnapOffsetAxis * mSnapOffsetMeters;
  1345. LLVector3 line_end = selection_center +
  1346. mSnapOffsetAxis * mSnapOffsetMeters;
  1347. gGL.begin(LLRender::LINES);
  1348. {
  1349. gGL.color4f(line_color.mV[VX], line_color.mV[VY],
  1350. line_color.mV[VZ], line_color.mV[VW]);
  1351. gGL.vertex3fv(line_start.mV);
  1352. gGL.vertex3fv(line_end.mV);
  1353. }
  1354. gGL.end();
  1355. // draw snap guide arrow
  1356. gGL.begin(LLRender::TRIANGLES);
  1357. {
  1358. gGL.color4f(line_color.mV[VX], line_color.mV[VY],
  1359. line_color.mV[VZ], line_color.mV[VW]);
  1360. LLVector3 arrow_dir;
  1361. LLVector3 arrow_span = translate_axis;
  1362. arrow_dir = -mSnapOffsetAxis;
  1363. gGL.vertex3fv((line_start + arrow_dir * mConeSize *
  1364. SNAP_ARROW_SCALE).mV);
  1365. gGL.vertex3fv((line_start + arrow_span * mConeSize *
  1366. SNAP_ARROW_SCALE).mV);
  1367. gGL.vertex3fv((line_start - arrow_span * mConeSize *
  1368. SNAP_ARROW_SCALE).mV);
  1369. arrow_dir = mSnapOffsetAxis;
  1370. gGL.vertex3fv((line_end + arrow_dir * mConeSize *
  1371. SNAP_ARROW_SCALE).mV);
  1372. gGL.vertex3fv((line_end + arrow_span * mConeSize *
  1373. SNAP_ARROW_SCALE).mV);
  1374. gGL.vertex3fv((line_end - arrow_span * mConeSize *
  1375. SNAP_ARROW_SCALE).mV);
  1376. }
  1377. gGL.end();
  1378. }
  1379. }
  1380. sub_div_offset = ll_round(fmod(dist_grid_axis - offset_nearest_grid_unit,
  1381. getMinGridScale() * 32.f) /
  1382. smallest_grid_unit_scale);
  1383. LLVector2 screen_translate_axis(fabsf(translate_axis *
  1384. gViewerCamera.getLeftAxis()),
  1385. fabsf(translate_axis *
  1386. gViewerCamera.getUpAxis()));
  1387. screen_translate_axis.normalize();
  1388. S32 tick_label_spacing = ll_round(screen_translate_axis *
  1389. sTickLabelSpacing);
  1390. // Render tickmark values
  1391. for (S32 i = -num_ticks_per_side; i <= num_ticks_per_side; ++i)
  1392. {
  1393. LLVector3 tick_pos = selection_center +
  1394. translate_axis *
  1395. (smallest_grid_unit_scale * (F32)i -
  1396. offset_nearest_grid_unit);
  1397. F32 alpha = line_alpha *
  1398. (1.f - (F32)abs(i) / (F32)num_ticks_per_side * 0.5f);
  1399. F32 tick_scale = 1.f;
  1400. for (F32 division_level = max_subdivisions;
  1401. division_level >= sGridMinSubdivisionLevel;
  1402. division_level /= 2.f)
  1403. {
  1404. if (fmodf((F32)(i + sub_div_offset), division_level) == 0.f)
  1405. {
  1406. break;
  1407. }
  1408. tick_scale *= 0.7f;
  1409. }
  1410. if (fmodf((F32)(i + sub_div_offset),
  1411. max_subdivisions / llmin(sGridMaxSubdivisionLevel,
  1412. getSubdivisionLevel(tick_pos,
  1413. translate_axis,
  1414. getMinGridScale(),
  1415. tick_label_spacing))) == 0.f)
  1416. {
  1417. F32 snap_offset_meters;
  1418. if (mSnapOffsetAxis * gViewerCamera.getUpAxis() > 0.f)
  1419. {
  1420. snap_offset_meters = mSnapOffsetMeters;
  1421. }
  1422. else
  1423. {
  1424. snap_offset_meters = -mSnapOffsetMeters;
  1425. }
  1426. LLVector3 text_origin = selection_center +
  1427. translate_axis *
  1428. (smallest_grid_unit_scale * (F32)i -
  1429. offset_nearest_grid_unit) +
  1430. mSnapOffsetAxis * snap_offset_meters *
  1431. (1.f + tick_scale);
  1432. LLVector3 tick_offset = (tick_pos - mGridOrigin) * ~mGridRotation;
  1433. F32 offset_val = 0.5f *
  1434. tick_offset.mV[ARROW_TO_AXIS[mManipPart]] /
  1435. getMinGridScale();
  1436. EGridMode grid_mode = gSelectMgr.getGridMode();
  1437. F32 text_highlight = 0.8f;
  1438. if (mInSnapRegime &&
  1439. i - ll_round(offset_nearest_grid_unit /
  1440. smallest_grid_unit_scale) == 0)
  1441. {
  1442. text_highlight = 1.f;
  1443. }
  1444. if (grid_mode == GRID_MODE_WORLD)
  1445. {
  1446. // Rescale units to meters from multiple of grid scale
  1447. offset_val *= 2.f * grid_scale[ARROW_TO_AXIS[mManipPart]];
  1448. renderTickValue(text_origin, offset_val, std::string("m"),
  1449. LLColor4(text_highlight, text_highlight,
  1450. text_highlight, alpha));
  1451. }
  1452. else
  1453. {
  1454. renderTickValue(text_origin, offset_val, std::string("x"),
  1455. LLColor4(text_highlight, text_highlight,
  1456. text_highlight, alpha));
  1457. }
  1458. }
  1459. }
  1460. if (mObjectSelection->getSelectType() != SELECT_TYPE_HUD)
  1461. {
  1462. // Render helpful text
  1463. static const LLFontGL* big_fontp = LLFontGL::getFontSansSerif();
  1464. static const std::string help_text1("Move mouse cursor over ruler to snap");
  1465. static const std::string help_text2("to snap to grid");
  1466. static const F32 text1_offset = -0.5f *
  1467. big_fontp->getWidthF32(help_text1);
  1468. static const F32 text2_offset = -0.5f *
  1469. big_fontp->getWidthF32(help_text2);
  1470. static const LLWString wtext1 = utf8str_to_wstring(help_text1);
  1471. static const LLWString wtext2 = utf8str_to_wstring(help_text2);
  1472. if (sNumTimesHelpTextShown < sMaxTimesShowHelpText &&
  1473. mHelpTextTimer.getElapsedTimeF32() <
  1474. sHelpTextVisibleTime + sHelpTextFadeTime)
  1475. {
  1476. F32 snap_offset_meters_up;
  1477. if (mSnapOffsetAxis * gViewerCamera.getUpAxis() > 0.f)
  1478. {
  1479. snap_offset_meters_up = mSnapOffsetMeters;
  1480. }
  1481. else
  1482. {
  1483. snap_offset_meters_up = -mSnapOffsetMeters;
  1484. }
  1485. bool is_hud =
  1486. mObjectSelection->getSelectType() == SELECT_TYPE_HUD;
  1487. LLVector3 selection_center_start = getSavedPivotPoint();
  1488. LLVector3 help_text_pos = selection_center_start +
  1489. snap_offset_meters_up * 3.f *
  1490. mSnapOffsetAxis;
  1491. LLColor4 help_text_color = LLColor4::white;
  1492. help_text_color.mV[VALPHA] =
  1493. clamp_rescale(mHelpTextTimer.getElapsedTimeF32(),
  1494. sHelpTextVisibleTime,
  1495. sHelpTextVisibleTime + sHelpTextFadeTime,
  1496. line_alpha, 0.f);
  1497. hud_render_text(wtext1, help_text_pos, *big_fontp,
  1498. LLFontGL::NORMAL, text1_offset, 3.f,
  1499. help_text_color, is_hud);
  1500. help_text_pos -= gViewerCamera.getUpAxis() *
  1501. mSnapOffsetMeters * 0.2f;
  1502. hud_render_text(wtext2, help_text_pos, *big_fontp,
  1503. LLFontGL::NORMAL, text2_offset, 3.f,
  1504. help_text_color, is_hud);
  1505. }
  1506. }
  1507. }
  1508. else // Render gridlines for planar snapping
  1509. {
  1510. F32 u = 0.f;
  1511. F32 v = 0.f;
  1512. LLColor4 inner_color;
  1513. LLVector3 normal;
  1514. LLVector3 grid_center = selection_center - grid_origin;
  1515. F32 usc = 1;
  1516. F32 vsc = 1;
  1517. grid_center *= ~grid_rotation;
  1518. switch (mManipPart)
  1519. {
  1520. case LL_YZ_PLANE:
  1521. u = grid_center.mV[VY];
  1522. v = grid_center.mV[VZ];
  1523. usc = grid_scale.mV[VY];
  1524. vsc = grid_scale.mV[VZ];
  1525. inner_color.set(0, 1, 1, line_alpha);
  1526. normal = LLVector3::x_axis;
  1527. break;
  1528. case LL_XZ_PLANE:
  1529. u = grid_center.mV[VX];
  1530. v = grid_center.mV[VZ];
  1531. usc = grid_scale.mV[VX];
  1532. vsc = grid_scale.mV[VZ];
  1533. inner_color.set(1, 0, 1, line_alpha);
  1534. normal = LLVector3::y_axis;
  1535. break;
  1536. case LL_XY_PLANE:
  1537. u = grid_center.mV[VX];
  1538. v = grid_center.mV[VY];
  1539. usc = grid_scale.mV[VX];
  1540. vsc = grid_scale.mV[VY];
  1541. inner_color.set(1, 1, 0, line_alpha);
  1542. normal = LLVector3::z_axis;
  1543. break;
  1544. default:
  1545. break;
  1546. }
  1547. unit0->unbind(LLTexUnit::TT_TEXTURE);
  1548. highlightIntersection(normal, selection_center, grid_rotation,
  1549. inner_color);
  1550. gGL.pushMatrix();
  1551. F32 x, y, z, angle_radians;
  1552. grid_rotation.getAngleAxis(&angle_radians, &x, &y, &z);
  1553. gGL.translatef(selection_center.mV[VX], selection_center.mV[VY],
  1554. selection_center.mV[VZ]);
  1555. gGL.rotatef(angle_radians * RAD_TO_DEG, x, y, z);
  1556. F32 sz = getGridDrawSize();
  1557. F32 tiles = sz;
  1558. gGL.matrixMode(LLRender::MM_TEXTURE);
  1559. gGL.pushMatrix();
  1560. usc = 1.f / usc;
  1561. vsc = 1.f / vsc;
  1562. while (usc > vsc * 4.f)
  1563. {
  1564. usc *= 0.5f;
  1565. }
  1566. while (vsc > usc * 4.f)
  1567. {
  1568. vsc *= 0.5f;
  1569. }
  1570. gGL.scalef(usc, vsc, 1.f);
  1571. gGL.translatef(u, v, 0);
  1572. float a = line_alpha;
  1573. {
  1574. // Draw grid behind objects
  1575. LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
  1576. {
  1577. LLGLDisable stencil(gUsePBRShaders ? 0 : GL_STENCIL_TEST);
  1578. {
  1579. LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_GREATER);
  1580. unit0->bindManual(LLTexUnit::TT_TEXTURE,
  1581. getGridTexName());
  1582. gGL.flush();
  1583. gGL.blendFunc(LLRender::BF_ZERO,
  1584. LLRender::BF_ONE_MINUS_SOURCE_ALPHA);
  1585. renderGrid(u, v, tiles,0.9f, 0.9f, 0.9f, a * 0.15f);
  1586. gGL.flush();
  1587. gGL.setSceneBlendType(LLRender::BT_ALPHA);
  1588. }
  1589. {
  1590. // Draw black overlay
  1591. unit0->unbind(LLTexUnit::TT_TEXTURE);
  1592. renderGrid(u, v, tiles, 0.f, 0.f, 0.f, a * 0.16f);
  1593. // Draw grid top
  1594. unit0->bindManual(LLTexUnit::TT_TEXTURE,
  1595. getGridTexName());
  1596. renderGrid(u, v, tiles, 1.f, 1.f, 1.f, a);
  1597. gGL.popMatrix();
  1598. gGL.matrixMode(LLRender::MM_MODELVIEW);
  1599. gGL.popMatrix();
  1600. }
  1601. {
  1602. LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
  1603. renderGuidelines();
  1604. }
  1605. {
  1606. LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_GREATER);
  1607. gGL.flush();
  1608. switch (mManipPart)
  1609. {
  1610. case LL_YZ_PLANE:
  1611. renderGuidelines(false, true, true);
  1612. break;
  1613. case LL_XZ_PLANE:
  1614. renderGuidelines(true, false, true);
  1615. break;
  1616. case LL_XY_PLANE:
  1617. renderGuidelines(true, true, false);
  1618. break;
  1619. default:
  1620. break;
  1621. }
  1622. gGL.flush();
  1623. }
  1624. }
  1625. }
  1626. }
  1627. }
  1628. void LLManipTranslate::renderGrid(F32 x, F32 y, F32 size, F32 r, F32 g, F32 b,
  1629. F32 a)
  1630. {
  1631. //MK
  1632. if (gRLenabled && gRLInterface.mVisionRestricted &&
  1633. gRLInterface.mCamDistDrawAlphaMax >= 0.25f)
  1634. {
  1635. return;
  1636. }
  1637. //mk
  1638. float dx, dy, da;
  1639. F32 d = size * 0.5f;
  1640. for (F32 xx = -size-d; xx < size + d; xx += d)
  1641. {
  1642. gGL.begin(LLRender::TRIANGLE_STRIP);
  1643. for (F32 yy = -size-d; yy < size + d; yy += d)
  1644. {
  1645. dx = xx;
  1646. dy = yy;
  1647. da = sqrtf(llmax(0.f, 1.f - sqrtf(dx * dx + dy * dy) / size)) * a;
  1648. gGL.texCoord2f(dx, dy);
  1649. renderGridVert(dx, dy, r, g, b, da);
  1650. dx = xx + d;
  1651. dy = yy;
  1652. da = sqrtf(llmax(0.f, 1.f - sqrtf(dx * dx + dy * dy) / size)) * a;
  1653. gGL.texCoord2f(dx, dy);
  1654. renderGridVert(dx, dy, r, g, b, da);
  1655. dx = xx;
  1656. dy = yy + d;
  1657. da = sqrtf(llmax(0.f, 1.f - sqrtf(dx * dx + dy * dy) / size)) * a;
  1658. gGL.texCoord2f(dx, dy);
  1659. renderGridVert(dx, dy, r, g, b, da);
  1660. dx = xx + d;
  1661. dy = yy + d;
  1662. da = sqrtf(llmax(0.f, 1.f - sqrtf(dx * dx + dy * dy) / size)) * a;
  1663. gGL.texCoord2f(dx, dy);
  1664. renderGridVert(dx, dy, r, g, b, da);
  1665. }
  1666. gGL.end();
  1667. }
  1668. }
  1669. void LLManipTranslate::highlightIntersection(LLVector3 normal,
  1670. LLVector3 selection_center,
  1671. LLQuaternion grid_rotation,
  1672. LLColor4 inner_color)
  1673. {
  1674. //MK
  1675. if (gRLenabled && gRLInterface.mVisionRestricted &&
  1676. gRLInterface.mCamDistDrawAlphaMax >= 0.25f)
  1677. {
  1678. return;
  1679. }
  1680. //mk
  1681. // Note: marked "deprecated" in LL's PBR viewer (likely because of heavy
  1682. // stencil usage, the latter having been completely disabled in the PBR
  1683. // code)... *TODO: see if we can de-deprecate, since this is a net loss in
  1684. // functionality, and we still have the stencil buffer available (for the
  1685. // EE renderer). HB
  1686. static LLCachedControl<bool> grid_cross_sections(gSavedSettings,
  1687. "GridCrossSections");
  1688. if (!grid_cross_sections || gUsePBRShaders)
  1689. {
  1690. return;
  1691. }
  1692. LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
  1693. static const U32 types[] =
  1694. {
  1695. LLRenderPass::PASS_SIMPLE,
  1696. LLRenderPass::PASS_ALPHA,
  1697. LLRenderPass::PASS_FULLBRIGHT,
  1698. LLRenderPass::PASS_SHINY
  1699. };
  1700. constexpr U32 num_types = LL_ARRAY_SIZE(types);
  1701. GLuint stencil_mask = 0xFFFFFFFF;
  1702. // Stencil in volumes
  1703. gGL.flush();
  1704. if (shader)
  1705. {
  1706. gClipProgram.bind();
  1707. }
  1708. LLTexUnit* unit0 = gGL.getTexUnit(0);
  1709. {
  1710. glStencilMask(stencil_mask);
  1711. glClearStencil(1);
  1712. glClear(GL_STENCIL_BUFFER_BIT);
  1713. glClearStencil(0);
  1714. LLGLEnable cull_face(GL_CULL_FACE);
  1715. LLGLEnable stencil(GL_STENCIL_TEST);
  1716. LLGLDepthTest depth (GL_TRUE, GL_FALSE, GL_ALWAYS);
  1717. glStencilFunc(GL_ALWAYS, 0, stencil_mask);
  1718. gGL.setColorMask(false, false);
  1719. unit0->unbind(LLTexUnit::TT_TEXTURE);
  1720. gGL.diffuseColor4f(1, 1, 1, 1);
  1721. // Setup clip plane
  1722. normal = normal * grid_rotation;
  1723. if (normal * (gViewerCamera.getOrigin() - selection_center) < 0)
  1724. {
  1725. normal = -normal;
  1726. }
  1727. F32 d = -(selection_center * normal);
  1728. LLVector4a plane(normal.mV[0], normal.mV[1], normal.mV[2], d);
  1729. LLMatrix4a inv_mat = gGL.getModelviewMatrix();
  1730. inv_mat.invert();
  1731. inv_mat.transpose();
  1732. inv_mat.rotate4(plane, plane);
  1733. static LLStaticHashedString sClipPlane("clip_plane");
  1734. gClipProgram.uniform4fv(sClipPlane, 1, plane.getF32ptr());
  1735. bool particles = gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_PARTICLES);
  1736. if (particles)
  1737. {
  1738. LLPipeline::toggleRenderType(LLPipeline::RENDER_TYPE_PARTICLES);
  1739. }
  1740. bool clouds = gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_CLOUDS);
  1741. if (clouds)
  1742. {
  1743. LLPipeline::toggleRenderType(LLPipeline::RENDER_TYPE_CLOUDS);
  1744. }
  1745. // stencil in volumes
  1746. glStencilOp(GL_INCR, GL_INCR, GL_INCR);
  1747. glCullFace(GL_FRONT);
  1748. for (U32 i = 0; i < num_types; ++i)
  1749. {
  1750. gPipeline.renderObjects(types[i], LLVertexBuffer::MAP_VERTEX, false);
  1751. }
  1752. glStencilOp(GL_DECR, GL_DECR, GL_DECR);
  1753. glCullFace(GL_BACK);
  1754. for (U32 i = 0; i < num_types; ++i)
  1755. {
  1756. gPipeline.renderObjects(types[i], LLVertexBuffer::MAP_VERTEX, false);
  1757. }
  1758. if (particles)
  1759. {
  1760. LLPipeline::toggleRenderType(LLPipeline::RENDER_TYPE_PARTICLES);
  1761. }
  1762. if (clouds)
  1763. {
  1764. LLPipeline::toggleRenderType(LLPipeline::RENDER_TYPE_CLOUDS);
  1765. }
  1766. gGL.setColorMask(true, false);
  1767. }
  1768. gGL.color4f(1, 1, 1, 1);
  1769. gGL.pushMatrix();
  1770. F32 x, y, z, angle_radians;
  1771. grid_rotation.getAngleAxis(&angle_radians, &x, &y, &z);
  1772. gGL.translatef(selection_center.mV[VX], selection_center.mV[VY],
  1773. selection_center.mV[VZ]);
  1774. gGL.rotatef(angle_radians * RAD_TO_DEG, x, y, z);
  1775. F32 sz = getGridDrawSize();
  1776. F32 tiles = sz;
  1777. if (shader)
  1778. {
  1779. shader->bind();
  1780. }
  1781. // Draw volume/plane intersections
  1782. {
  1783. unit0->unbind(LLTexUnit::TT_TEXTURE);
  1784. LLGLDepthTest depth(GL_FALSE);
  1785. LLGLEnable stencil(GL_STENCIL_TEST);
  1786. glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
  1787. glStencilFunc(GL_EQUAL, 0, stencil_mask);
  1788. renderGrid(0, 0, tiles,inner_color.mV[0], inner_color.mV[1],
  1789. inner_color.mV[2], 0.25f);
  1790. }
  1791. glStencilFunc(GL_ALWAYS, 255, 0xFFFFFFFF);
  1792. glStencilMask(0xFFFFFFFF);
  1793. glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
  1794. gGL.popMatrix();
  1795. }
  1796. void LLManipTranslate::renderText()
  1797. {
  1798. if (mObjectSelection->getRootObjectCount() &&
  1799. !mObjectSelection->isAttachment())
  1800. {
  1801. LLVector3 pos = getPivotPoint();
  1802. renderXYZ(pos);
  1803. }
  1804. else
  1805. {
  1806. constexpr bool children_ok = true;
  1807. LLViewerObject* objectp = mObjectSelection->getFirstRootObject(children_ok);
  1808. if (objectp)
  1809. {
  1810. renderXYZ(objectp->getPositionEdit());
  1811. }
  1812. }
  1813. }
  1814. void LLManipTranslate::renderTranslationHandles()
  1815. {
  1816. LLVector3 grid_origin;
  1817. LLVector3 grid_scale;
  1818. LLQuaternion grid_rotation;
  1819. LLGLDepthTest gls_depth(GL_FALSE);
  1820. gSelectMgr.getGrid(grid_origin, grid_rotation, grid_scale);
  1821. LLVector3 at_axis;
  1822. if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
  1823. {
  1824. at_axis = LLVector3::x_axis * ~grid_rotation;
  1825. }
  1826. else
  1827. {
  1828. at_axis = gViewerCamera.getAtAxis() * ~grid_rotation;
  1829. }
  1830. if (at_axis.mV[VX] > 0.f)
  1831. {
  1832. mPlaneManipPositions.mV[VX] = 1.f;
  1833. }
  1834. else
  1835. {
  1836. mPlaneManipPositions.mV[VX] = -1.f;
  1837. }
  1838. if (at_axis.mV[VY] > 0.f)
  1839. {
  1840. mPlaneManipPositions.mV[VY] = 1.f;
  1841. }
  1842. else
  1843. {
  1844. mPlaneManipPositions.mV[VY] = -1.f;
  1845. }
  1846. if (at_axis.mV[VZ] > 0.f)
  1847. {
  1848. mPlaneManipPositions.mV[VZ] = 1.f;
  1849. }
  1850. else
  1851. {
  1852. mPlaneManipPositions.mV[VZ] = -1.f;
  1853. }
  1854. LLViewerObject *first_object = mObjectSelection->getFirstMoveableObject(true);
  1855. if (!first_object) return;
  1856. LLVector3 selection_center = getPivotPoint();
  1857. // Drag handles
  1858. if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
  1859. {
  1860. mArrowLengthMeters = mAxisArrowLength / gViewerWindowp->getWindowHeight();
  1861. mArrowLengthMeters /= gAgent.mHUDCurZoom;
  1862. }
  1863. else
  1864. {
  1865. LLVector3 camera_pos_agent = gAgent.getCameraPositionAgent();
  1866. F32 range = dist_vec(camera_pos_agent, selection_center);
  1867. F32 range_from_agent = dist_vec(gAgent.getPositionAgent(), selection_center);
  1868. // Don't draw handles if you're too far away
  1869. static LLCachedControl<bool> limit_select_distance(gSavedSettings,
  1870. "LimitSelectDistance");
  1871. static LLCachedControl<F32> max_select_distance(gSavedSettings,
  1872. "MaxSelectDistance");
  1873. if (limit_select_distance)
  1874. {
  1875. if (range_from_agent > max_select_distance)
  1876. {
  1877. return;
  1878. }
  1879. }
  1880. if (range > 0.001f)
  1881. {
  1882. // range != zero
  1883. F32 fraction_of_fov = mAxisArrowLength /
  1884. (F32)gViewerCamera.getViewHeightInPixels();
  1885. // in radians:
  1886. F32 apparent_angle = fraction_of_fov * gViewerCamera.getView();
  1887. mArrowLengthMeters = range * tanf(apparent_angle);
  1888. }
  1889. else
  1890. {
  1891. // range == zero
  1892. mArrowLengthMeters = 1.f;
  1893. }
  1894. }
  1895. mPlaneManipOffsetMeters = mArrowLengthMeters * 1.8f;
  1896. mConeSize = mArrowLengthMeters * 0.25f;
  1897. gGL.matrixMode(LLRender::MM_MODELVIEW);
  1898. gGL.pushMatrix();
  1899. {
  1900. gGL.translatef(selection_center.mV[VX], selection_center.mV[VY],
  1901. selection_center.mV[VZ]);
  1902. F32 angle_radians, x, y, z;
  1903. grid_rotation.getAngleAxis(&angle_radians, &x, &y, &z);
  1904. gGL.rotatef(angle_radians * RAD_TO_DEG, x, y, z);
  1905. LLQuaternion invRotation = grid_rotation;
  1906. invRotation.transpose();
  1907. LLVector3 relative_camera_dir;
  1908. if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
  1909. {
  1910. relative_camera_dir = LLVector3::x_axis * invRotation;
  1911. }
  1912. else
  1913. {
  1914. relative_camera_dir = (selection_center -
  1915. gViewerCamera.getOrigin()) * invRotation;
  1916. }
  1917. relative_camera_dir.normalize();
  1918. LLTexUnit* unit0 = gGL.getTexUnit(0);
  1919. {
  1920. unit0->unbind(LLTexUnit::TT_TEXTURE);
  1921. LLGLDisable cull_face(GL_CULL_FACE);
  1922. LLColor4 color1;
  1923. LLColor4 color2;
  1924. // Update manipulator sizes
  1925. F32 critical_damp =
  1926. LLCriticalDamp::getInterpolant(MANIP_SCALE_HALF_LIFE);
  1927. for (S32 index = 0; index < 3; ++index)
  1928. {
  1929. if (index == mManipPart - LL_X_ARROW ||
  1930. index == mHighlightedPart - LL_X_ARROW)
  1931. {
  1932. mArrowScales.mV[index] = lerp(mArrowScales.mV[index],
  1933. SELECTED_ARROW_SCALE,
  1934. critical_damp);
  1935. mPlaneScales.mV[index] = lerp(mPlaneScales.mV[index], 1.f,
  1936. critical_damp);
  1937. }
  1938. else if (index == mManipPart - LL_YZ_PLANE ||
  1939. index == mHighlightedPart - LL_YZ_PLANE)
  1940. {
  1941. mArrowScales.mV[index] = lerp(mArrowScales.mV[index], 1.f,
  1942. critical_damp);
  1943. mPlaneScales.mV[index] = lerp(mPlaneScales.mV[index],
  1944. SELECTED_ARROW_SCALE,
  1945. critical_damp);
  1946. }
  1947. else
  1948. {
  1949. mArrowScales.mV[index] = lerp(mArrowScales.mV[index], 1.f,
  1950. critical_damp);
  1951. mPlaneScales.mV[index] = lerp(mPlaneScales.mV[index], 1.f,
  1952. critical_damp);
  1953. }
  1954. }
  1955. if ((mManipPart == LL_NO_PART || mManipPart == LL_YZ_PLANE) &&
  1956. fabsf(relative_camera_dir.mV[VX]) > MIN_PLANE_MANIP_DOT_PRODUCT)
  1957. {
  1958. // render YZ plane manipulator
  1959. gGL.pushMatrix();
  1960. gGL.scalef(mPlaneManipPositions.mV[VX],
  1961. mPlaneManipPositions.mV[VY],
  1962. mPlaneManipPositions.mV[VZ]);
  1963. gGL.translatef(0.f, mPlaneManipOffsetMeters,
  1964. mPlaneManipOffsetMeters);
  1965. gGL.scalef(mPlaneScales.mV[VX], mPlaneScales.mV[VX],
  1966. mPlaneScales.mV[VX]);
  1967. if (mHighlightedPart == LL_YZ_PLANE)
  1968. {
  1969. color1.set(0.f, 1.f, 0.f, 1.f);
  1970. color2.set(0.f, 0.f, 1.f, 1.f);
  1971. }
  1972. else
  1973. {
  1974. color1.set(0.f, 1.f, 0.f, 0.6f);
  1975. color2.set(0.f, 0.f, 1.f, 0.6f);
  1976. }
  1977. gGL.begin(LLRender::TRIANGLES);
  1978. {
  1979. gGL.color4fv(color1.mV);
  1980. gGL.vertex3f(0.f,
  1981. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE,
  1982. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE);
  1983. gGL.vertex3f(0.f,
  1984. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE,
  1985. mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.75f));
  1986. gGL.vertex3f(0.f,
  1987. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE,
  1988. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE);
  1989. gGL.color4fv(color2.mV);
  1990. gGL.vertex3f(0.f,
  1991. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE,
  1992. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE);
  1993. gGL.vertex3f(0.f,
  1994. mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.75f),
  1995. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE);
  1996. gGL.vertex3f(0.f,
  1997. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE,
  1998. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE);
  1999. }
  2000. gGL.end();
  2001. LLUI::setLineWidth(3.f);
  2002. gGL.begin(LLRender::LINES);
  2003. {
  2004. gGL.color4f(0.f, 0.f, 0.f, 0.3f);
  2005. gGL.vertex3f(0.f,
  2006. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE,
  2007. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE);
  2008. gGL.vertex3f(0.f,
  2009. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE,
  2010. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE);
  2011. gGL.vertex3f(0.f,
  2012. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE,
  2013. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE);
  2014. gGL.vertex3f(0.f,
  2015. mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.1f),
  2016. mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.1f));
  2017. gGL.vertex3f(0.f,
  2018. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE,
  2019. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE);
  2020. gGL.vertex3f(0.f,
  2021. mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.1f),
  2022. mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.4f));
  2023. gGL.vertex3f(0.f,
  2024. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE,
  2025. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE);
  2026. gGL.vertex3f(0.f,
  2027. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE,
  2028. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE);
  2029. gGL.vertex3f(0.f,
  2030. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE,
  2031. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE);
  2032. gGL.vertex3f(0.f,
  2033. mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.1f,
  2034. mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.1f));
  2035. gGL.vertex3f(0.f,
  2036. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE,
  2037. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE);
  2038. gGL.vertex3f(0.f,
  2039. mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.4f,
  2040. mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.1f));
  2041. }
  2042. gGL.end();
  2043. LLUI::setLineWidth(1.f);
  2044. gGL.popMatrix();
  2045. }
  2046. if ((mManipPart == LL_NO_PART || mManipPart == LL_XZ_PLANE) &&
  2047. fabsf(relative_camera_dir.mV[VY]) > MIN_PLANE_MANIP_DOT_PRODUCT)
  2048. {
  2049. // render XZ plane manipulator
  2050. gGL.pushMatrix();
  2051. gGL.scalef(mPlaneManipPositions.mV[VX],
  2052. mPlaneManipPositions.mV[VY],
  2053. mPlaneManipPositions.mV[VZ]);
  2054. gGL.translatef(mPlaneManipOffsetMeters, 0.f,
  2055. mPlaneManipOffsetMeters);
  2056. gGL.scalef(mPlaneScales.mV[VY], mPlaneScales.mV[VY],
  2057. mPlaneScales.mV[VY]);
  2058. if (mHighlightedPart == LL_XZ_PLANE)
  2059. {
  2060. color1.set(0.f, 0.f, 1.f, 1.f);
  2061. color2.set(1.f, 0.f, 0.f, 1.f);
  2062. }
  2063. else
  2064. {
  2065. color1.set(0.f, 0.f, 1.f, 0.6f);
  2066. color2.set(1.f, 0.f, 0.f, 0.6f);
  2067. }
  2068. gGL.begin(LLRender::TRIANGLES);
  2069. {
  2070. gGL.color4fv(color1.mV);
  2071. gGL.vertex3f(mPlaneManipOffsetMeters * QUARTER_TICK_SIZE,
  2072. 0.f,
  2073. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE);
  2074. gGL.vertex3f(mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.75f),
  2075. 0.f,
  2076. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE);
  2077. gGL.vertex3f(mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE,
  2078. 0.f,
  2079. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE);
  2080. gGL.color4fv(color2.mV);
  2081. gGL.vertex3f(mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE,
  2082. 0.f,
  2083. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE);
  2084. gGL.vertex3f(mPlaneManipOffsetMeters * QUARTER_TICK_SIZE,
  2085. 0.f,
  2086. mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.75f));
  2087. gGL.vertex3f(mPlaneManipOffsetMeters * QUARTER_TICK_SIZE,
  2088. 0.f,
  2089. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE);
  2090. }
  2091. gGL.end();
  2092. LLUI::setLineWidth(3.f);
  2093. gGL.begin(LLRender::LINES);
  2094. {
  2095. gGL.color4f(0.f, 0.f, 0.f, 0.3f);
  2096. gGL.vertex3f(mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE,
  2097. 0.f,
  2098. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE);
  2099. gGL.vertex3f(mPlaneManipOffsetMeters * QUARTER_TICK_SIZE,
  2100. 0.f,
  2101. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE);
  2102. gGL.vertex3f(mPlaneManipOffsetMeters * QUARTER_TICK_SIZE,
  2103. 0.f,
  2104. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE);
  2105. gGL.vertex3f(mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.1f),
  2106. 0.f,
  2107. mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.1f));
  2108. gGL.vertex3f(mPlaneManipOffsetMeters * QUARTER_TICK_SIZE,
  2109. 0.f,
  2110. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE);
  2111. gGL.vertex3f(mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.1f),
  2112. 0.f,
  2113. mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.4f));
  2114. gGL.vertex3f(mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE,
  2115. 0.f,
  2116. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE);
  2117. gGL.vertex3f(mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE,
  2118. 0.f,
  2119. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE);
  2120. gGL.vertex3f(mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE,
  2121. 0.f,
  2122. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE);
  2123. gGL.vertex3f(mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.1f),
  2124. 0.f,
  2125. mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.1f));
  2126. gGL.vertex3f(mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE,
  2127. 0.f,
  2128. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE);
  2129. gGL.vertex3f(mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.4f),
  2130. 0.f,
  2131. mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.1f));
  2132. }
  2133. gGL.end();
  2134. LLUI::setLineWidth(1.f);
  2135. gGL.popMatrix();
  2136. }
  2137. if ((mManipPart == LL_NO_PART || mManipPart == LL_XY_PLANE) &&
  2138. fabsf(relative_camera_dir.mV[VZ]) > MIN_PLANE_MANIP_DOT_PRODUCT)
  2139. {
  2140. // render XY plane manipulator
  2141. gGL.pushMatrix();
  2142. gGL.scalef(mPlaneManipPositions.mV[VX],
  2143. mPlaneManipPositions.mV[VY],
  2144. mPlaneManipPositions.mV[VZ]);
  2145. /* Y
  2146. ^
  2147. v1
  2148. | \
  2149. |<- v0
  2150. | /| \
  2151. v2__v__v3 > X
  2152. */
  2153. LLVector3 v0,v1,v2,v3;
  2154. #if 0
  2155. // This should theoretically work but looks off; could be
  2156. // tuned later -SJB
  2157. gGL.translatef(-mPlaneManipOffsetMeters,
  2158. -mPlaneManipOffsetMeters, 0.f);
  2159. v0 = LLVector3(mPlaneManipOffsetMeters * QUARTER_TICK_SIZE,
  2160. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE,
  2161. 0.f);
  2162. v1 = LLVector3(mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE,
  2163. mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.75f),
  2164. 0.f);
  2165. v2 = LLVector3(mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE,
  2166. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE,
  2167. 0.f);
  2168. v3 = LLVector3(mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.75f),
  2169. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE,
  2170. 0.f);
  2171. #else
  2172. gGL.translatef(mPlaneManipOffsetMeters,
  2173. mPlaneManipOffsetMeters, 0.f);
  2174. v0 = LLVector3(mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE,
  2175. mPlaneManipOffsetMeters * -QUARTER_TICK_SIZE,
  2176. 0.f);
  2177. v1 = LLVector3(mPlaneManipOffsetMeters * QUARTER_TICK_SIZE,
  2178. mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.75f),
  2179. 0.f);
  2180. v2 = LLVector3(mPlaneManipOffsetMeters * QUARTER_TICK_SIZE,
  2181. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE,
  2182. 0.f);
  2183. v3 = LLVector3(mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.75f),
  2184. mPlaneManipOffsetMeters * QUARTER_TICK_SIZE,
  2185. 0.f);
  2186. #endif
  2187. gGL.scalef(mPlaneScales.mV[VZ], mPlaneScales.mV[VZ],
  2188. mPlaneScales.mV[VZ]);
  2189. if (mHighlightedPart == LL_XY_PLANE)
  2190. {
  2191. color1.set(1.f, 0.f, 0.f, 1.f);
  2192. color2.set(0.f, 1.f, 0.f, 1.f);
  2193. }
  2194. else
  2195. {
  2196. color1.set(0.8f, 0.f, 0.f, 0.6f);
  2197. color2.set(0.f, 0.8f, 0.f, 0.6f);
  2198. }
  2199. gGL.begin(LLRender::TRIANGLES);
  2200. {
  2201. gGL.color4fv(color1.mV);
  2202. gGL.vertex3fv(v0.mV);
  2203. gGL.vertex3fv(v1.mV);
  2204. gGL.vertex3fv(v2.mV);
  2205. gGL.color4fv(color2.mV);
  2206. gGL.vertex3fv(v2.mV);
  2207. gGL.vertex3fv(v3.mV);
  2208. gGL.vertex3fv(v0.mV);
  2209. }
  2210. gGL.end();
  2211. LLUI::setLineWidth(3.f);
  2212. gGL.begin(LLRender::LINES);
  2213. {
  2214. gGL.color4f(0.f, 0.f, 0.f, 0.3f);
  2215. LLVector3 v12 = (v1 + v2) * .5f;
  2216. gGL.vertex3fv(v0.mV);
  2217. gGL.vertex3fv(v12.mV);
  2218. gGL.vertex3fv(v12.mV);
  2219. gGL.vertex3fv((v12 + (v0 - v12) * .3f +
  2220. (v2 - v12) * .3f).mV);
  2221. gGL.vertex3fv(v12.mV);
  2222. gGL.vertex3fv((v12 + (v0 - v12) * .3f +
  2223. (v1 - v12) * .3f).mV);
  2224. LLVector3 v23 = (v2 + v3) * .5f;
  2225. gGL.vertex3fv(v0.mV);
  2226. gGL.vertex3fv(v23.mV);
  2227. gGL.vertex3fv(v23.mV);
  2228. gGL.vertex3fv((v23 + (v0 - v23) * .3f +
  2229. (v3 - v23) * .3f).mV);
  2230. gGL.vertex3fv(v23.mV);
  2231. gGL.vertex3fv((v23 + (v0 - v23) * .3f +
  2232. (v2 - v23) * .3f).mV);
  2233. }
  2234. gGL.end();
  2235. LLUI::setLineWidth(1.f);
  2236. gGL.popMatrix();
  2237. }
  2238. }
  2239. {
  2240. unit0->unbind(LLTexUnit::TT_TEXTURE);
  2241. // Since we draw handles with depth testing off, we need to draw
  2242. // them in the proper depth order.
  2243. // Copied from LLDrawable::updateGeometry
  2244. LLVector3 pos_agent = first_object->getPositionAgent();
  2245. LLVector3 camera_agent = gAgent.getCameraPositionAgent();
  2246. LLVector3 headPos = pos_agent - camera_agent;
  2247. LLVector3 orientWRTHead = headPos * invRotation;
  2248. // Find nearest vertex
  2249. U32 nearest = (orientWRTHead.mV[0] < 0.f ? 1 : 0) +
  2250. (orientWRTHead.mV[1] < 0.f ? 2 : 0) +
  2251. (orientWRTHead.mV[2] < 0.f ? 4 : 0);
  2252. // opposite faces on Linden cubes:
  2253. // 0 & 5
  2254. // 1 & 3
  2255. // 2 & 4
  2256. // Table of order to draw faces, based on nearest vertex
  2257. static U32 face_list[8][NUM_AXES * 2] = {
  2258. { 2,0,1, 4,5,3 }, // v6 F201 F453
  2259. { 2,0,3, 4,5,1 }, // v7 F203 F451
  2260. { 4,0,1, 2,5,3 }, // v5 F401 F253
  2261. { 4,0,3, 2,5,1 }, // v4 F403 F251
  2262. { 2,5,1, 4,0,3 }, // v2 F251 F403
  2263. { 2,5,3, 4,0,1 }, // v3 F253 F401
  2264. { 4,5,1, 2,0,3 }, // v1 F451 F203
  2265. { 4,5,3, 2,0,1 }, // v0 F453 F201
  2266. };
  2267. static const EManipPart which_arrow[6] = {
  2268. LL_Z_ARROW,
  2269. LL_X_ARROW,
  2270. LL_Y_ARROW,
  2271. LL_X_ARROW,
  2272. LL_Y_ARROW,
  2273. LL_Z_ARROW
  2274. };
  2275. // Draw arrows for deeper faces first, closer faces last
  2276. LLVector3 camera_axis;
  2277. if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
  2278. {
  2279. camera_axis = LLVector3::x_axis;
  2280. }
  2281. else
  2282. {
  2283. camera_axis.set(gAgent.getCameraPositionAgent() -
  2284. first_object->getPositionAgent());
  2285. }
  2286. for (U32 i = 0; i < NUM_AXES * 2; ++i)
  2287. {
  2288. U32 face = face_list[nearest][i];
  2289. LLVector3 arrow_axis;
  2290. getManipAxis(first_object, which_arrow[face], arrow_axis);
  2291. renderArrow(which_arrow[face],
  2292. mManipPart,
  2293. face >= 3 ? -mConeSize : mConeSize,
  2294. face >= 3 ? -mArrowLengthMeters
  2295. : mArrowLengthMeters,
  2296. mConeSize, false);
  2297. }
  2298. }
  2299. }
  2300. gGL.popMatrix();
  2301. }
  2302. void LLManipTranslate::renderArrow(S32 which_arrow, S32 selected_arrow,
  2303. F32 box_size, F32 arrow_size,
  2304. F32 handle_size, bool reverse_direction)
  2305. {
  2306. gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
  2307. LLGLEnable gls_blend(GL_BLEND);
  2308. for (S32 pass = 1; pass <= 2; pass++)
  2309. {
  2310. LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE,
  2311. pass == 1 ? GL_LEQUAL : GL_GREATER);
  2312. gGL.pushMatrix();
  2313. S32 index = ARROW_TO_AXIS[which_arrow];
  2314. // Assign a color for this arrow
  2315. LLColor4 color; // black
  2316. if (which_arrow == selected_arrow || which_arrow == mHighlightedPart)
  2317. {
  2318. color.mV[index] = (pass == 1) ? 1.f : 0.5f;
  2319. }
  2320. else if (selected_arrow != LL_NO_PART)
  2321. {
  2322. color.mV[VALPHA] = 0.f;
  2323. }
  2324. else
  2325. {
  2326. color.mV[index] = pass == 1 ? .8f : .35f; // red, green, or blue
  2327. color.mV[VALPHA] = 0.6f;
  2328. }
  2329. gGL.color4fv(color.mV);
  2330. LLVector3 vec;
  2331. LLUI::setLineWidth(2.f);
  2332. gGL.begin(LLRender::LINES);
  2333. vec.mV[index] = box_size;
  2334. gGL.vertex3f(vec.mV[0], vec.mV[1], vec.mV[2]);
  2335. vec.mV[index] = arrow_size;
  2336. gGL.vertex3f(vec.mV[0], vec.mV[1], vec.mV[2]);
  2337. gGL.end();
  2338. LLUI::setLineWidth(1.f);
  2339. gGL.translatef(vec.mV[0], vec.mV[1], vec.mV[2]);
  2340. gGL.scalef(handle_size, handle_size, handle_size);
  2341. F32 rot = 0.f;
  2342. LLVector3 axis;
  2343. switch (which_arrow)
  2344. {
  2345. case LL_X_ARROW:
  2346. rot = reverse_direction ? -90.f : 90.f;
  2347. axis.mV[1] = 1.f;
  2348. break;
  2349. case LL_Y_ARROW:
  2350. rot = reverse_direction ? 90.f : -90.f;
  2351. axis.mV[0] = 1.f;
  2352. break;
  2353. case LL_Z_ARROW:
  2354. rot = reverse_direction ? 180.f : 0.f;
  2355. axis.mV[0] = 1.f;
  2356. break;
  2357. default:
  2358. llerrs << "Unknown arrow type " << which_arrow << llendl;
  2359. }
  2360. gGL.diffuseColor4fv(color.mV);
  2361. gGL.rotatef(rot, axis.mV[0], axis.mV[1], axis.mV[2]);
  2362. gGL.scalef(mArrowScales.mV[index], mArrowScales.mV[index],
  2363. mArrowScales.mV[index] * 1.5f);
  2364. gCone.render();
  2365. gGL.popMatrix();
  2366. }
  2367. }
  2368. void LLManipTranslate::renderGridVert(F32 x_trans, F32 y_trans,
  2369. F32 r, F32 g, F32 b, F32 alpha)
  2370. {
  2371. gGL.color4f(r, g, b, alpha);
  2372. switch (mManipPart)
  2373. {
  2374. case LL_YZ_PLANE:
  2375. gGL.vertex3f(0.f, x_trans, y_trans);
  2376. break;
  2377. case LL_XZ_PLANE:
  2378. gGL.vertex3f(x_trans, 0.f, y_trans);
  2379. break;
  2380. case LL_XY_PLANE:
  2381. gGL.vertex3f(x_trans, y_trans, 0.f);
  2382. break;
  2383. default:
  2384. gGL.vertex3f(0.f, 0.f, 0.f);
  2385. }
  2386. }
  2387. //virtual
  2388. bool LLManipTranslate::canAffectSelection()
  2389. {
  2390. bool can_move = mObjectSelection->getObjectCount() != 0;
  2391. if (can_move)
  2392. {
  2393. struct f final : public LLSelectedObjectFunctor
  2394. {
  2395. bool apply(LLViewerObject* objectp) override
  2396. {
  2397. static LLCachedControl<bool> edit_linked_parts(gSavedSettings,
  2398. "EditLinkedParts");
  2399. if (!objectp)
  2400. {
  2401. llwarns << "NULL object passed to functor !" << llendl;
  2402. return false;
  2403. }
  2404. LLViewerObject* root_object = objectp->getRootEdit();
  2405. return objectp->permMove() &&
  2406. !objectp->isPermanentEnforced() &&
  2407. (!root_object || !root_object->isPermanentEnforced()) &&
  2408. (objectp->permModify() || !edit_linked_parts);
  2409. }
  2410. } func;
  2411. can_move = mObjectSelection->applyToObjects(&func);
  2412. }
  2413. return can_move;
  2414. }