lltoolfocus.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:11k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file lltoolfocus.cpp
  3.  * @brief A tool to set the build focus point.
  4.  *
  5.  * $LicenseInfo:firstyear=2001&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2001-2010, 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. // File includes
  34. #include "lltoolfocus.h" 
  35. // Library includes
  36. #include "v3math.h"
  37. #include "llfontgl.h"
  38. #include "llui.h"
  39. // Viewer includes
  40. #include "llagent.h"
  41. #include "llbutton.h"
  42. #include "llviewercontrol.h"
  43. #include "lldrawable.h"
  44. #include "lltooltip.h"
  45. #include "llhudmanager.h"
  46. #include "llfloatertools.h"
  47. #include "llselectmgr.h"
  48. #include "llstatusbar.h"
  49. #include "lltoolmgr.h"
  50. #include "llviewercamera.h"
  51. #include "llviewerobject.h"
  52. #include "llviewerwindow.h"
  53. #include "llvoavatarself.h"
  54. #include "llmorphview.h"
  55. #include "llfloaterreg.h"
  56. #include "llfloatercamera.h"
  57. // Globals
  58. BOOL gCameraBtnZoom = TRUE;
  59. BOOL gCameraBtnOrbit = FALSE;
  60. BOOL gCameraBtnPan = FALSE;
  61. const S32 SLOP_RANGE = 4;
  62. const F32 FOCUS_OFFSET_FACTOR = 1.f;
  63. //
  64. // Camera - shared functionality
  65. //
  66. LLToolCamera::LLToolCamera()
  67. : LLTool(std::string("Camera")),
  68. mAccumX(0),
  69. mAccumY(0),
  70. mMouseDownX(0),
  71. mMouseDownY(0),
  72. mOutsideSlopX(FALSE),
  73. mOutsideSlopY(FALSE),
  74. mValidClickPoint(FALSE),
  75. mMouseSteering(FALSE),
  76. mMouseUpX(0),
  77. mMouseUpY(0),
  78. mMouseUpMask(MASK_NONE)
  79. { }
  80. LLToolCamera::~LLToolCamera()
  81. { }
  82. // virtual
  83. void LLToolCamera::handleSelect()
  84. {
  85. if (gFloaterTools)
  86. {
  87. gFloaterTools->setStatusText("camera");
  88. }
  89. }
  90. // virtual
  91. void LLToolCamera::handleDeselect()
  92. {
  93. // gAgent.setLookingAtAvatar(FALSE);
  94. }
  95. BOOL LLToolCamera::handleMouseDown(S32 x, S32 y, MASK mask)
  96. {
  97. // Ensure a mouseup
  98. setMouseCapture(TRUE);
  99. // call the base class to propogate info to sim
  100. LLTool::handleMouseDown(x, y, mask);
  101. mAccumX = 0;
  102. mAccumY = 0;
  103. mOutsideSlopX = FALSE;
  104. mOutsideSlopY = FALSE;
  105. mValidClickPoint = FALSE;
  106. // If mouse capture gets ripped away, claim we moused up
  107. // at the point we moused down. JC
  108. mMouseUpX = x;
  109. mMouseUpY = y;
  110. mMouseUpMask = mask;
  111. gViewerWindow->hideCursor();
  112. gViewerWindow->pickAsync(x, y, mask, pickCallback);
  113. return TRUE;
  114. }
  115. void LLToolCamera::pickCallback(const LLPickInfo& pick_info)
  116. {
  117. if (!LLToolCamera::getInstance()->hasMouseCapture())
  118. {
  119. return;
  120. }
  121. LLToolCamera::getInstance()->mMouseDownX = pick_info.mMousePt.mX;
  122. LLToolCamera::getInstance()->mMouseDownY = pick_info.mMousePt.mY;
  123. gViewerWindow->moveCursorToCenter();
  124. // Potentially recenter if click outside rectangle
  125. LLViewerObject* hit_obj = pick_info.getObject();
  126. // Check for hit the sky, or some other invalid point
  127. if (!hit_obj && pick_info.mPosGlobal.isExactlyZero())
  128. {
  129. LLToolCamera::getInstance()->mValidClickPoint = FALSE;
  130. return;
  131. }
  132. // check for hud attachments
  133. if (hit_obj && hit_obj->isHUDAttachment())
  134. {
  135. LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
  136. if (!selection->getObjectCount() || selection->getSelectType() != SELECT_TYPE_HUD)
  137. {
  138. LLToolCamera::getInstance()->mValidClickPoint = FALSE;
  139. return;
  140. }
  141. }
  142. if( CAMERA_MODE_CUSTOMIZE_AVATAR == gAgent.getCameraMode() )
  143. {
  144. BOOL good_customize_avatar_hit = FALSE;
  145. if( hit_obj )
  146. {
  147. LLVOAvatar* avatar = gAgent.getAvatarObject();
  148. if( hit_obj == avatar) 
  149. {
  150. // It's you
  151. good_customize_avatar_hit = TRUE;
  152. }
  153. else
  154. if( hit_obj->isAttachment() && hit_obj->permYouOwner() )
  155. {
  156. // It's an attachment that you're wearing
  157. good_customize_avatar_hit = TRUE;
  158. }
  159. }
  160. if( !good_customize_avatar_hit )
  161. {
  162. LLToolCamera::getInstance()->mValidClickPoint = FALSE;
  163. return;
  164. }
  165. if( gMorphView )
  166. {
  167. gMorphView->setCameraDrivenByKeys( FALSE );
  168. }
  169. }
  170. //RN: check to see if this is mouse-driving as opposed to ALT-zoom or Focus tool
  171. else if (pick_info.mKeyMask & MASK_ALT || 
  172. (LLToolMgr::getInstance()->getCurrentTool()->getName() == "Camera")) 
  173. {
  174. LLViewerObject* hit_obj = pick_info.getObject();
  175. if (hit_obj)
  176. {
  177. // ...clicked on a world object, so focus at its position
  178. if (!hit_obj->isHUDAttachment())
  179. {
  180. gAgent.setFocusOnAvatar(FALSE, ANIMATE);
  181. gAgent.setFocusGlobal(pick_info);
  182. }
  183. }
  184. else if (!pick_info.mPosGlobal.isExactlyZero())
  185. {
  186. // Hit the ground
  187. gAgent.setFocusOnAvatar(FALSE, ANIMATE);
  188. gAgent.setFocusGlobal(pick_info);
  189. }
  190. if (!(pick_info.mKeyMask & MASK_ALT) &&
  191. gAgent.cameraThirdPerson() &&
  192. gViewerWindow->getLeftMouseDown() && 
  193. !gSavedSettings.getBOOL("FreezeTime") &&
  194. (hit_obj == gAgent.getAvatarObject() || 
  195. (hit_obj && hit_obj->isAttachment() && LLVOAvatar::findAvatarFromAttachment(hit_obj)->isSelf())))
  196. {
  197. LLToolCamera::getInstance()->mMouseSteering = TRUE;
  198. }
  199. }
  200. LLToolCamera::getInstance()->mValidClickPoint = TRUE;
  201. if( CAMERA_MODE_CUSTOMIZE_AVATAR == gAgent.getCameraMode() )
  202. {
  203. gAgent.setFocusOnAvatar(FALSE, FALSE);
  204. LLVector3d cam_pos = gAgent.getCameraPositionGlobal();
  205. cam_pos -= LLVector3d(LLViewerCamera::getInstance()->getLeftAxis() * gAgent.calcCustomizeAvatarUIOffset( cam_pos ));
  206. gAgent.setCameraPosAndFocusGlobal( cam_pos, pick_info.mPosGlobal, pick_info.mObjectID);
  207. }
  208. }
  209. // "Let go" of the mouse, for example on mouse up or when
  210. // we lose mouse capture.  This ensures that cursor becomes visible
  211. // if a modal dialog pops up during Alt-Zoom. JC
  212. void LLToolCamera::releaseMouse()
  213. {
  214. // Need to tell the sim that the mouse button is up, since this
  215. // tool is no longer working and cursor is visible (despite actual
  216. // mouse button status).
  217. LLTool::handleMouseUp(mMouseUpX, mMouseUpY, mMouseUpMask);
  218. gViewerWindow->showCursor();
  219. //for the situation when left click was performed on the Agent
  220. if (!LLFloaterCamera::inFreeCameraMode())
  221. {
  222. LLToolMgr::getInstance()->clearTransientTool();
  223. }
  224. mMouseSteering = FALSE;
  225. mValidClickPoint = FALSE;
  226. mOutsideSlopX = FALSE;
  227. mOutsideSlopY = FALSE;
  228. }
  229. BOOL LLToolCamera::handleMouseUp(S32 x, S32 y, MASK mask)
  230. {
  231. // Claim that we're mousing up somewhere
  232. mMouseUpX = x;
  233. mMouseUpY = y;
  234. mMouseUpMask = mask;
  235. if (hasMouseCapture())
  236. {
  237. if (mValidClickPoint)
  238. {
  239. if( CAMERA_MODE_CUSTOMIZE_AVATAR == gAgent.getCameraMode() )
  240. {
  241. LLCoordGL mouse_pos;
  242. LLVector3 focus_pos = gAgent.getPosAgentFromGlobal(gAgent.getFocusGlobal());
  243. BOOL success = LLViewerCamera::getInstance()->projectPosAgentToScreen(focus_pos, mouse_pos);
  244. if (success)
  245. {
  246. LLUI::setMousePositionScreen(mouse_pos.mX, mouse_pos.mY);
  247. }
  248. }
  249. else if (mMouseSteering)
  250. {
  251. LLUI::setMousePositionScreen(mMouseDownX, mMouseDownY);
  252. }
  253. else
  254. {
  255. gViewerWindow->moveCursorToCenter();
  256. }
  257. }
  258. else
  259. {
  260. // not a valid zoomable object
  261. LLUI::setMousePositionScreen(mMouseDownX, mMouseDownY);
  262. }
  263. // calls releaseMouse() internally
  264. setMouseCapture(FALSE);
  265. }
  266. else
  267. {
  268. releaseMouse();
  269. }
  270. return TRUE;
  271. }
  272. BOOL LLToolCamera::handleHover(S32 x, S32 y, MASK mask)
  273. {
  274. S32 dx = gViewerWindow->getCurrentMouseDX();
  275. S32 dy = gViewerWindow->getCurrentMouseDY();
  276. BOOL moved_outside_slop = FALSE;
  277. if (hasMouseCapture() && mValidClickPoint)
  278. {
  279. mAccumX += llabs(dx);
  280. mAccumY += llabs(dy);
  281. if (mAccumX >= SLOP_RANGE)
  282. {
  283. if (!mOutsideSlopX)
  284. {
  285. moved_outside_slop = TRUE;
  286. }
  287. mOutsideSlopX = TRUE;
  288. }
  289. if (mAccumY >= SLOP_RANGE)
  290. {
  291. if (!mOutsideSlopY)
  292. {
  293. moved_outside_slop = TRUE;
  294. }
  295. mOutsideSlopY = TRUE;
  296. }
  297. }
  298. if (mOutsideSlopX || mOutsideSlopY)
  299. {
  300. if (!mValidClickPoint)
  301. {
  302. lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolFocus [invalid point]" << llendl;
  303. gViewerWindow->setCursor(UI_CURSOR_NO);
  304. gViewerWindow->showCursor();
  305. return TRUE;
  306. }
  307. if (gCameraBtnOrbit ||
  308. mask == MASK_ORBIT || 
  309. mask == (MASK_ALT | MASK_ORBIT))
  310. {
  311. // Orbit tool
  312. if (hasMouseCapture())
  313. {
  314. const F32 RADIANS_PER_PIXEL = 360.f * DEG_TO_RAD / gViewerWindow->getWorldViewWidthScaled();
  315. if (dx != 0)
  316. {
  317. gAgent.cameraOrbitAround( -dx * RADIANS_PER_PIXEL );
  318. }
  319. if (dy != 0)
  320. {
  321. gAgent.cameraOrbitOver( -dy * RADIANS_PER_PIXEL );
  322. }
  323. gViewerWindow->moveCursorToCenter();
  324. }
  325. lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolFocus [active]" << llendl;
  326. }
  327. else if ( gCameraBtnPan ||
  328. mask == MASK_PAN ||
  329. mask == (MASK_PAN | MASK_ALT) )
  330. {
  331. // Pan tool
  332. if (hasMouseCapture())
  333. {
  334. LLVector3d camera_to_focus = gAgent.getCameraPositionGlobal();
  335. camera_to_focus -= gAgent.getFocusGlobal();
  336. F32 dist = (F32) camera_to_focus.normVec();
  337. // Fudge factor for pan
  338. F32 meters_per_pixel = 3.f * dist / gViewerWindow->getWorldViewWidthScaled();
  339. if (dx != 0)
  340. {
  341. gAgent.cameraPanLeft( dx * meters_per_pixel );
  342. }
  343. if (dy != 0)
  344. {
  345. gAgent.cameraPanUp( -dy * meters_per_pixel );
  346. }
  347. gViewerWindow->moveCursorToCenter();
  348. }
  349. lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolPan" << llendl;
  350. }
  351. else if (gCameraBtnZoom)
  352. {
  353. // Zoom tool
  354. if (hasMouseCapture())
  355. {
  356. const F32 RADIANS_PER_PIXEL = 360.f * DEG_TO_RAD / gViewerWindow->getWorldViewWidthScaled();
  357. if (dx != 0)
  358. {
  359. gAgent.cameraOrbitAround( -dx * RADIANS_PER_PIXEL );
  360. }
  361. const F32 IN_FACTOR = 0.99f;
  362. if (dy != 0 && mOutsideSlopY )
  363. {
  364. if (mMouseSteering)
  365. {
  366. gAgent.cameraOrbitOver( -dy * RADIANS_PER_PIXEL );
  367. }
  368. else
  369. {
  370. gAgent.cameraZoomIn( pow( IN_FACTOR, dy ) );
  371. }
  372. }
  373. gViewerWindow->moveCursorToCenter();
  374. }
  375. lldebugst(LLERR_USER_INPUT) << "hover handled by LLToolZoom" << llendl;
  376. }
  377. }
  378. if (gCameraBtnOrbit ||
  379. mask == MASK_ORBIT || 
  380. mask == (MASK_ALT | MASK_ORBIT))
  381. {
  382. gViewerWindow->setCursor(UI_CURSOR_TOOLCAMERA);
  383. }
  384. else if ( gCameraBtnPan ||
  385. mask == MASK_PAN ||
  386. mask == (MASK_PAN | MASK_ALT) )
  387. {
  388. gViewerWindow->setCursor(UI_CURSOR_TOOLPAN);
  389. }
  390. else
  391. {
  392. gViewerWindow->setCursor(UI_CURSOR_TOOLZOOMIN);
  393. }
  394. return TRUE;
  395. }
  396. void LLToolCamera::onMouseCaptureLost()
  397. {
  398. releaseMouse();
  399. }