PageRenderTime 345ms CodeModel.GetById 171ms app.highlight 16ms RepoModel.GetById 155ms 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
  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
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llagentui.h"
 30
 31// Library includes
 32#include "llparcel.h"
 33
 34// Viewer includes
 35#include "llagent.h"
 36#include "llviewercontrol.h"
 37#include "llviewerregion.h"
 38#include "llviewerparcelmgr.h"
 39#include "llvoavatarself.h"
 40#include "llslurl.h"
 41
 42//static
 43void LLAgentUI::buildFullname(std::string& name)
 44{
 45	if (isAgentAvatarValid())
 46		name = gAgentAvatarp->getFullname();
 47}
 48
 49//static
 50void LLAgentUI::buildSLURL(LLSLURL& slurl, const bool escaped /*= true*/)
 51{
 52      LLSLURL return_slurl;
 53      LLViewerRegion *regionp = gAgent.getRegion();
 54      if (regionp)
 55      {
 56		  return_slurl = LLSLURL(regionp->getName(), gAgent.getPositionGlobal());
 57      }
 58	slurl = return_slurl;
 59}
 60
 61//static
 62BOOL LLAgentUI::checkAgentDistance(const LLVector3& pole, F32 radius)
 63{
 64	F32 delta_x = gAgent.getPositionAgent().mV[VX] - pole.mV[VX];
 65	F32 delta_y = gAgent.getPositionAgent().mV[VY] - pole.mV[VY];
 66	
 67	return  sqrt( delta_x* delta_x + delta_y* delta_y ) < radius;
 68}
 69BOOL LLAgentUI::buildLocationString(std::string& str, ELocationFormat fmt,const LLVector3& agent_pos_region)
 70{
 71	LLViewerRegion* region = gAgent.getRegion();
 72	LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
 73
 74	if (!region || !parcel) return FALSE;
 75
 76	S32 pos_x = S32(agent_pos_region.mV[VX]);
 77	S32 pos_y = S32(agent_pos_region.mV[VY]);
 78	S32 pos_z = S32(agent_pos_region.mV[VZ]);
 79
 80	// Round the numbers based on the velocity
 81	F32 velocity_mag_sq = gAgent.getVelocity().magVecSquared();
 82
 83	const F32 FLY_CUTOFF = 6.f;		// meters/sec
 84	const F32 FLY_CUTOFF_SQ = FLY_CUTOFF * FLY_CUTOFF;
 85	const F32 WALK_CUTOFF = 1.5f;	// meters/sec
 86	const F32 WALK_CUTOFF_SQ = WALK_CUTOFF * WALK_CUTOFF;
 87
 88	if (velocity_mag_sq > FLY_CUTOFF_SQ)
 89	{
 90		pos_x -= pos_x % 4;
 91		pos_y -= pos_y % 4;
 92	}
 93	else if (velocity_mag_sq > WALK_CUTOFF_SQ)
 94	{
 95		pos_x -= pos_x % 2;
 96		pos_y -= pos_y % 2;
 97	}
 98
 99	// create a default name and description for the landmark
100	std::string parcel_name = LLViewerParcelMgr::getInstance()->getAgentParcelName();
101	std::string region_name = region->getName();
102	std::string sim_access_string = region->getSimAccessString();
103	std::string buffer;
104	if( parcel_name.empty() )
105	{
106		// the parcel doesn't have a name
107		switch (fmt)
108		{
109		case LOCATION_FORMAT_LANDMARK:
110			buffer = llformat("%.100s", region_name.c_str());
111			break;
112		case LOCATION_FORMAT_NORMAL:
113			buffer = llformat("%s", region_name.c_str());
114			break;
115		case LOCATION_FORMAT_NO_COORDS:
116			buffer = llformat("%s%s%s",
117				region_name.c_str(),
118				sim_access_string.empty() ? "" : " - ",
119				sim_access_string.c_str());
120			break;
121		case LOCATION_FORMAT_NO_MATURITY:
122			buffer = llformat("%s (%d, %d, %d)",
123				region_name.c_str(),
124				pos_x, pos_y, pos_z);
125			break;
126		case LOCATION_FORMAT_FULL:
127			buffer = llformat("%s (%d, %d, %d)%s%s",
128				region_name.c_str(),
129				pos_x, pos_y, pos_z,
130				sim_access_string.empty() ? "" : " - ",
131				sim_access_string.c_str());
132			break;
133		}
134	}
135	else
136	{
137		// the parcel has a name, so include it in the landmark name
138		switch (fmt)
139		{
140		case LOCATION_FORMAT_LANDMARK:
141			buffer = llformat("%.100s", parcel_name.c_str());
142			break;
143		case LOCATION_FORMAT_NORMAL:
144			buffer = llformat("%s, %s", parcel_name.c_str(), region_name.c_str());
145			break;
146		case LOCATION_FORMAT_NO_MATURITY:
147			buffer = llformat("%s, %s (%d, %d, %d)",
148				parcel_name.c_str(),
149				region_name.c_str(),
150				pos_x, pos_y, pos_z);
151			break;
152		case LOCATION_FORMAT_NO_COORDS:
153			buffer = llformat("%s, %s%s%s",
154							  parcel_name.c_str(),
155							  region_name.c_str(),
156							  sim_access_string.empty() ? "" : " - ",
157							  sim_access_string.c_str());
158				break;
159		case LOCATION_FORMAT_FULL:
160			buffer = llformat("%s, %s (%d, %d, %d)%s%s",
161				parcel_name.c_str(),
162				region_name.c_str(),
163				pos_x, pos_y, pos_z,
164				sim_access_string.empty() ? "" : " - ",
165				sim_access_string.c_str());
166			break;
167		}
168	}
169	str = buffer;
170	return TRUE;
171}
172BOOL LLAgentUI::buildLocationString(std::string& str, ELocationFormat fmt)
173{
174	return buildLocationString(str,fmt, gAgent.getPositionAgent());
175}