PageRenderTime 40ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llagentui.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 175 lines | 127 code | 14 blank | 34 comment | 10 complexity | a5c2a8558acd29f8ef8f24b11c19c4c6 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llagentui.cpp
  3. * @brief Utility methods to process agent's data as slurl's etc. before displaying
  4. *
  5. * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llagentui.h"
  28. // Library includes
  29. #include "llparcel.h"
  30. // Viewer includes
  31. #include "llagent.h"
  32. #include "llviewercontrol.h"
  33. #include "llviewerregion.h"
  34. #include "llviewerparcelmgr.h"
  35. #include "llvoavatarself.h"
  36. #include "llslurl.h"
  37. //static
  38. void LLAgentUI::buildFullname(std::string& name)
  39. {
  40. if (isAgentAvatarValid())
  41. name = gAgentAvatarp->getFullname();
  42. }
  43. //static
  44. void LLAgentUI::buildSLURL(LLSLURL& slurl, const bool escaped /*= true*/)
  45. {
  46. LLSLURL return_slurl;
  47. LLViewerRegion *regionp = gAgent.getRegion();
  48. if (regionp)
  49. {
  50. return_slurl = LLSLURL(regionp->getName(), gAgent.getPositionGlobal());
  51. }
  52. slurl = return_slurl;
  53. }
  54. //static
  55. BOOL LLAgentUI::checkAgentDistance(const LLVector3& pole, F32 radius)
  56. {
  57. F32 delta_x = gAgent.getPositionAgent().mV[VX] - pole.mV[VX];
  58. F32 delta_y = gAgent.getPositionAgent().mV[VY] - pole.mV[VY];
  59. return sqrt( delta_x* delta_x + delta_y* delta_y ) < radius;
  60. }
  61. BOOL LLAgentUI::buildLocationString(std::string& str, ELocationFormat fmt,const LLVector3& agent_pos_region)
  62. {
  63. LLViewerRegion* region = gAgent.getRegion();
  64. LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
  65. if (!region || !parcel) return FALSE;
  66. S32 pos_x = S32(agent_pos_region.mV[VX]);
  67. S32 pos_y = S32(agent_pos_region.mV[VY]);
  68. S32 pos_z = S32(agent_pos_region.mV[VZ]);
  69. // Round the numbers based on the velocity
  70. F32 velocity_mag_sq = gAgent.getVelocity().magVecSquared();
  71. const F32 FLY_CUTOFF = 6.f; // meters/sec
  72. const F32 FLY_CUTOFF_SQ = FLY_CUTOFF * FLY_CUTOFF;
  73. const F32 WALK_CUTOFF = 1.5f; // meters/sec
  74. const F32 WALK_CUTOFF_SQ = WALK_CUTOFF * WALK_CUTOFF;
  75. if (velocity_mag_sq > FLY_CUTOFF_SQ)
  76. {
  77. pos_x -= pos_x % 4;
  78. pos_y -= pos_y % 4;
  79. }
  80. else if (velocity_mag_sq > WALK_CUTOFF_SQ)
  81. {
  82. pos_x -= pos_x % 2;
  83. pos_y -= pos_y % 2;
  84. }
  85. // create a default name and description for the landmark
  86. std::string parcel_name = LLViewerParcelMgr::getInstance()->getAgentParcelName();
  87. std::string region_name = region->getName();
  88. std::string sim_access_string = region->getSimAccessString();
  89. std::string buffer;
  90. if( parcel_name.empty() )
  91. {
  92. // the parcel doesn't have a name
  93. switch (fmt)
  94. {
  95. case LOCATION_FORMAT_LANDMARK:
  96. buffer = llformat("%.100s", region_name.c_str());
  97. break;
  98. case LOCATION_FORMAT_NORMAL:
  99. buffer = llformat("%s", region_name.c_str());
  100. break;
  101. case LOCATION_FORMAT_NO_COORDS:
  102. buffer = llformat("%s%s%s",
  103. region_name.c_str(),
  104. sim_access_string.empty() ? "" : " - ",
  105. sim_access_string.c_str());
  106. break;
  107. case LOCATION_FORMAT_NO_MATURITY:
  108. buffer = llformat("%s (%d, %d, %d)",
  109. region_name.c_str(),
  110. pos_x, pos_y, pos_z);
  111. break;
  112. case LOCATION_FORMAT_FULL:
  113. buffer = llformat("%s (%d, %d, %d)%s%s",
  114. region_name.c_str(),
  115. pos_x, pos_y, pos_z,
  116. sim_access_string.empty() ? "" : " - ",
  117. sim_access_string.c_str());
  118. break;
  119. }
  120. }
  121. else
  122. {
  123. // the parcel has a name, so include it in the landmark name
  124. switch (fmt)
  125. {
  126. case LOCATION_FORMAT_LANDMARK:
  127. buffer = llformat("%.100s", parcel_name.c_str());
  128. break;
  129. case LOCATION_FORMAT_NORMAL:
  130. buffer = llformat("%s, %s", parcel_name.c_str(), region_name.c_str());
  131. break;
  132. case LOCATION_FORMAT_NO_MATURITY:
  133. buffer = llformat("%s, %s (%d, %d, %d)",
  134. parcel_name.c_str(),
  135. region_name.c_str(),
  136. pos_x, pos_y, pos_z);
  137. break;
  138. case LOCATION_FORMAT_NO_COORDS:
  139. buffer = llformat("%s, %s%s%s",
  140. parcel_name.c_str(),
  141. region_name.c_str(),
  142. sim_access_string.empty() ? "" : " - ",
  143. sim_access_string.c_str());
  144. break;
  145. case LOCATION_FORMAT_FULL:
  146. buffer = llformat("%s, %s (%d, %d, %d)%s%s",
  147. parcel_name.c_str(),
  148. region_name.c_str(),
  149. pos_x, pos_y, pos_z,
  150. sim_access_string.empty() ? "" : " - ",
  151. sim_access_string.c_str());
  152. break;
  153. }
  154. }
  155. str = buffer;
  156. return TRUE;
  157. }
  158. BOOL LLAgentUI::buildLocationString(std::string& str, ELocationFormat fmt)
  159. {
  160. return buildLocationString(str,fmt, gAgent.getPositionAgent());
  161. }