PageRenderTime 125ms CodeModel.GetById 72ms app.highlight 47ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/lltracker.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 830 lines | 611 code | 116 blank | 103 comment | 65 complexity | a70abf204d6bcecd754aca73acc00520 MD5 | raw file
  1/** 
  2 * @file lltracker.cpp
  3 * @brief Container for objects user is tracking.
  4 *
  5 * $LicenseInfo:firstyear=2003&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// library includes
 30#include "llcoord.h"
 31#include "lldarray.h"
 32#include "llfontgl.h"
 33#include "llgl.h"
 34#include "llrender.h"
 35#include "llinventory.h"
 36#include "llinventorydefines.h"
 37#include "llpointer.h"
 38#include "llstring.h"
 39#include "lluuid.h"
 40#include "v3math.h"
 41#include "v3dmath.h"
 42#include "v4color.h"
 43
 44// viewer includes
 45#include "llappviewer.h"
 46#include "lltracker.h"
 47#include "llagent.h"
 48#include "llagentcamera.h"
 49#include "llcallingcard.h"
 50#include "llfloaterworldmap.h"
 51#include "llhudtext.h"
 52#include "llhudview.h"
 53#include "llinventorymodel.h"
 54#include "llinventoryobserver.h"
 55#include "lllandmarklist.h"
 56#include "llprogressview.h"
 57#include "llsky.h"
 58#include "llui.h"
 59#include "llviewercamera.h"
 60#include "llviewerinventory.h"
 61#include "llviewerwindow.h"
 62#include "llworld.h"
 63#include "llworldmapview.h"
 64#include "llviewercontrol.h"
 65
 66const F32 DESTINATION_REACHED_RADIUS    = 3.0f;
 67const F32 DESTINATION_VISITED_RADIUS    = 6.0f;
 68
 69// this last one is useful for when the landmark is
 70// very close to agent when tracking is turned on
 71const F32 DESTINATION_UNVISITED_RADIUS = 12.0f;
 72
 73const S32 ARROW_OFF_RADIUS_SQRD = 100;
 74
 75const S32 HUD_ARROW_SIZE = 32;
 76
 77// static
 78LLTracker *LLTracker::sTrackerp = NULL;
 79BOOL LLTracker::sCheesyBeacon = FALSE;
 80
 81LLTracker::LLTracker()
 82:	mTrackingStatus(TRACKING_NOTHING),
 83	mTrackingLocationType(LOCATION_NOTHING),
 84	mHUDArrowCenterX(0),
 85	mHUDArrowCenterY(0),
 86	mToolTip( "" ),
 87	mTrackedLandmarkName(""),
 88	mHasReachedLandmark(FALSE),
 89	mHasLandmarkPosition(FALSE),
 90	mLandmarkHasBeenVisited(FALSE),
 91	mTrackedLocationName( "" ),
 92	mIsTrackingLocation(FALSE),
 93	mHasReachedLocation(FALSE)
 94{ }
 95
 96
 97LLTracker::~LLTracker()
 98{ 
 99	purgeBeaconText();
100}
101
102
103// static
104void LLTracker::stopTracking(void* userdata)
105{
106	BOOL clear_ui = ((BOOL)(intptr_t)userdata);
107	instance()->stopTrackingAll(clear_ui);
108}
109
110
111// static virtual
112void LLTracker::drawHUDArrow()
113{
114	if (!gSavedSettings.getBOOL("RenderTrackerBeacon")) return;
115
116	if (gViewerWindow->getProgressView()->getVisible()) return;
117
118	static LLUIColor map_track_color = LLUIColorTable::instance().getColor("MapTrackColor", LLColor4::white);
119	
120	/* tracking autopilot destination has been disabled 
121	   -- 2004.01.09, Leviathan
122	// Draw dot for autopilot target
123	if (gAgent.getAutoPilot())
124	{
125		instance()->drawMarker( gAgent.getAutoPilotTargetGlobal(), map_track_color );
126		return;
127	}
128	*/
129	switch (getTrackingStatus())
130	{ 
131	case TRACKING_AVATAR:
132		// Tracked avatar
133		if(LLAvatarTracker::instance().haveTrackingInfo())
134		{
135			instance()->drawMarker( LLAvatarTracker::instance().getGlobalPos(), map_track_color );
136		} 
137		break;
138
139	case TRACKING_LANDMARK:
140		instance()->drawMarker( getTrackedPositionGlobal(), map_track_color );
141		break;
142
143	case TRACKING_LOCATION:
144		// HACK -- try to keep the location just above the terrain
145#if 0
146		// UNHACKED by CRO - keep location where the location is
147		instance()->mTrackedPositionGlobal.mdV[VZ] = 
148				0.9f * instance()->mTrackedPositionGlobal.mdV[VZ]
149				+ 0.1f * (LLWorld::getInstance()->resolveLandHeightGlobal(getTrackedPositionGlobal()) + 1.5f);
150#endif
151		instance()->mTrackedPositionGlobal.mdV[VZ] = llclamp((F32)instance()->mTrackedPositionGlobal.mdV[VZ], LLWorld::getInstance()->resolveLandHeightGlobal(getTrackedPositionGlobal()) + 1.5f, (F32)instance()->getTrackedPositionGlobal().mdV[VZ]);
152		instance()->drawMarker( getTrackedPositionGlobal(), map_track_color );
153		break;
154
155	default:
156		break;
157	}
158}
159
160
161// static 
162void LLTracker::render3D()
163{
164	if (!gFloaterWorldMap || !gSavedSettings.getBOOL("RenderTrackerBeacon"))
165	{
166		return;
167	}
168	
169	static LLUIColor map_track_color = LLUIColorTable::instance().getColor("MapTrackColor", LLColor4::white);
170	
171	// Arbitary location beacon
172	if( instance()->mIsTrackingLocation )
173 	{
174		if (!instance()->mBeaconText)
175		{
176			instance()->mBeaconText = (LLHUDText *)LLHUDObject::addHUDObject(LLHUDObject::LL_HUD_TEXT);
177			instance()->mBeaconText->setDoFade(FALSE);
178		}
179
180		LLVector3d pos_global = instance()->mTrackedPositionGlobal;
181		// (z-attenuation < 1) means compute "shorter" distance in z-axis,
182		// so cancel tracking even if avatar is a little above or below.
183		F32 dist = gFloaterWorldMap->getDistanceToDestination(pos_global, 0.5f);
184		if (dist < DESTINATION_REACHED_RADIUS)
185		{
186			instance()->stopTrackingLocation();
187		}
188		else
189		{
190			renderBeacon( instance()->mTrackedPositionGlobal, map_track_color, 
191					  	instance()->mBeaconText, instance()->mTrackedLocationName );
192		}
193	}
194
195	// Landmark beacon
196	else if( !instance()->mTrackedLandmarkAssetID.isNull() )
197	{
198		if (!instance()->mBeaconText)
199		{
200			instance()->mBeaconText = (LLHUDText *)LLHUDObject::addHUDObject(LLHUDObject::LL_HUD_TEXT);
201			instance()->mBeaconText->setDoFade(FALSE);
202		}
203
204		if (instance()->mHasLandmarkPosition)
205		{
206			F32 dist = gFloaterWorldMap->getDistanceToDestination(instance()->mTrackedPositionGlobal, 1.0f);
207
208			if (   !instance()->mLandmarkHasBeenVisited
209				&& dist < DESTINATION_VISITED_RADIUS )
210			{
211				// its close enough ==> flag as visited
212				instance()->setLandmarkVisited();
213			}
214
215			if (   !instance()->mHasReachedLandmark 
216				&& dist < DESTINATION_REACHED_RADIUS )
217			{
218				// its VERY CLOSE ==> automatically stop tracking
219				instance()->stopTrackingLandmark();
220			}
221			else
222			{
223				if (    instance()->mHasReachedLandmark 
224					 && dist > DESTINATION_UNVISITED_RADIUS )
225				{
226					// this is so that landmark beacons don't immediately 
227					// disappear when they're created only a few meters 
228					// away, yet disappear when the agent wanders away 
229					// and back again
230					instance()->mHasReachedLandmark = FALSE;
231				}
232				renderBeacon( instance()->mTrackedPositionGlobal, map_track_color, 
233							  instance()->mBeaconText, instance()->mTrackedLandmarkName );
234			}
235		}
236		else
237		{
238			// probably just finished downloading the asset
239			instance()->cacheLandmarkPosition();
240		}
241	}
242	else
243	{
244		// Avatar beacon
245		LLAvatarTracker& av_tracker = LLAvatarTracker::instance();
246		if(av_tracker.haveTrackingInfo())
247		{
248			if (!instance()->mBeaconText)
249			{
250				instance()->mBeaconText = (LLHUDText *)LLHUDObject::addHUDObject(LLHUDObject::LL_HUD_TEXT);
251				instance()->mBeaconText->setDoFade(FALSE);
252			}
253			
254			F32 dist = gFloaterWorldMap->getDistanceToDestination(instance()->mTrackedPositionGlobal, 0.0f);
255			if (dist < DESTINATION_REACHED_RADIUS)
256			{
257				instance()->stopTrackingAvatar();
258			}
259			else
260			{
261				renderBeacon( av_tracker.getGlobalPos(), map_track_color, 
262						  	instance()->mBeaconText, av_tracker.getName() );
263			}
264		}
265		else
266		{
267			BOOL stop_tracking = FALSE;
268			const LLUUID& avatar_id = av_tracker.getAvatarID();
269			if(avatar_id.isNull())
270			{
271				stop_tracking = TRUE;
272			}
273			else 
274			{
275				const LLRelationship* buddy = av_tracker.getBuddyInfo(avatar_id);
276				if(buddy && !buddy->isOnline() && !gAgent.isGodlike())
277				{
278					stop_tracking = TRUE;
279				}
280				if(!buddy && !gAgent.isGodlike())
281				{
282					stop_tracking = TRUE;
283				}
284			}
285			if(stop_tracking)
286			{
287				instance()->stopTrackingAvatar();
288			}
289		}
290	}
291}
292
293
294// static 
295void LLTracker::trackAvatar( const LLUUID& avatar_id, const std::string& name )
296{
297	instance()->stopTrackingLandmark();
298	instance()->stopTrackingLocation();
299	
300	LLAvatarTracker::instance().track( avatar_id, name );
301	instance()->mTrackingStatus = TRACKING_AVATAR;
302	instance()->mLabel = name;
303	instance()->mToolTip = "";
304}
305
306
307// static 
308void LLTracker::trackLandmark( const LLUUID& asset_id, const LLUUID& item_id, const std::string& name)
309{
310	instance()->stopTrackingAvatar();
311	instance()->stopTrackingLocation();
312	
313 	instance()->mTrackedLandmarkAssetID = asset_id;
314 	instance()->mTrackedLandmarkItemID = item_id;
315 	instance()->mTrackedLandmarkName = name;
316	instance()->cacheLandmarkPosition();
317	instance()->mTrackingStatus = TRACKING_LANDMARK;
318	instance()->mLabel = name;
319	instance()->mToolTip = "";
320}
321
322
323// static 
324void LLTracker::trackLocation(const LLVector3d& pos_global, const std::string& full_name, const std::string& tooltip, ETrackingLocationType location_type)
325{
326	instance()->stopTrackingAvatar();
327	instance()->stopTrackingLandmark();
328
329	instance()->mTrackedPositionGlobal = pos_global;
330	instance()->mTrackedLocationName = full_name;
331	instance()->mIsTrackingLocation = TRUE;
332	instance()->mTrackingStatus = TRACKING_LOCATION;
333	instance()->mTrackingLocationType = location_type;
334	instance()->mLabel = full_name;
335	instance()->mToolTip = tooltip;
336}
337
338
339// static 
340BOOL LLTracker::handleMouseDown(S32 x, S32 y)
341{
342	BOOL eat_mouse_click = FALSE;
343	// fortunately, we can always compute the tracking arrow center
344	S32 dist_sqrd = (x - instance()->mHUDArrowCenterX) * (x - instance()->mHUDArrowCenterX) + 
345					(y - instance()->mHUDArrowCenterY) * (y - instance()->mHUDArrowCenterY);
346	if (dist_sqrd < ARROW_OFF_RADIUS_SQRD)
347	{
348		/* tracking autopilot destination has been disabled
349		   -- 2004.01.09, Leviathan
350		// turn off tracking
351		if (gAgent.getAutoPilot())
352		{
353			gAgent.stopAutoPilot(TRUE);	// TRUE because cancelled by user
354			eat_mouse_click = TRUE;
355		}
356		*/
357		if (getTrackingStatus())
358		{
359			instance()->stopTrackingAll();
360			eat_mouse_click = TRUE;
361		}
362	}
363	return eat_mouse_click;
364}
365
366
367// static 
368LLVector3d LLTracker::getTrackedPositionGlobal()
369{
370	LLVector3d pos_global;
371	switch (getTrackingStatus())
372	{
373	case TRACKING_AVATAR:
374	{
375		LLAvatarTracker& av_tracker = LLAvatarTracker::instance();
376		if (av_tracker.haveTrackingInfo())
377		{
378			pos_global = av_tracker.getGlobalPos(); }
379		break;
380	}
381	case TRACKING_LANDMARK:
382		if( instance()->mHasLandmarkPosition )
383		{
384			pos_global = instance()->mTrackedPositionGlobal;
385		}
386		break;
387	case TRACKING_LOCATION:
388		pos_global = instance()->mTrackedPositionGlobal;
389		break;
390	default:
391		break;
392	}
393	return pos_global;
394}
395
396
397// static
398BOOL LLTracker::hasLandmarkPosition()
399{
400	if (!instance()->mHasLandmarkPosition)
401	{
402		// maybe we just received the landmark position info
403		instance()->cacheLandmarkPosition();
404	}
405	return instance()->mHasLandmarkPosition;
406}
407
408
409// static
410const std::string& LLTracker::getTrackedLocationName()
411{
412	return instance()->mTrackedLocationName;
413}
414
415F32 pulse_func(F32 t, F32 z)
416{
417	if (!LLTracker::sCheesyBeacon)
418	{
419		return 0.f;
420	}
421	
422	t *= F_PI;
423	z -= t*64.f - 256.f;
424	
425	F32 a = cosf(z*F_PI/512.f)*10.0f;
426	a = llmax(a, 9.9f);
427	a -= 9.9f;
428	a *= 10.f;
429	return a;
430}
431
432void draw_shockwave(F32 center_z, F32 t, S32 steps, LLColor4 color)
433{
434	if (!LLTracker::sCheesyBeacon)
435	{
436		return;
437	}
438	
439	t *= 0.6284f/F_PI;
440	
441	t -= (F32) (S32) t;	
442
443	t = llmax(t, 0.5f);
444	t -= 0.5f;
445	t *= 2.0f;
446	
447	F32 radius = t*16536.f;
448	
449	// Inexact, but reasonably fast.
450	F32 delta = F_TWO_PI / steps;
451	F32 sin_delta = sin( delta );
452	F32 cos_delta = cos( delta );
453	F32 x = radius;
454	F32 y = 0.f;
455
456	LLColor4 ccol = LLColor4(1,1,1,(1.f-t)*0.25f);
457	gGL.begin(LLRender::TRIANGLE_FAN);
458	gGL.color4fv(ccol.mV);
459	gGL.vertex3f(0.f, 0.f, center_z);
460	// make sure circle is complete
461	steps += 1;
462	
463	color.mV[3] = (1.f-t*t);
464	
465	gGL.color4fv(color.mV);
466	while( steps-- )
467	{
468		// Successive rotations
469		gGL.vertex3f( x, y, center_z );
470		F32 x_new = x * cos_delta - y * sin_delta;
471		y = x * sin_delta +  y * cos_delta;
472		x = x_new;
473	}
474	gGL.end();
475}
476
477
478// static 
479void LLTracker::renderBeacon(LLVector3d pos_global, 
480							 const LLColor4& color, 
481							 LLHUDText* hud_textp, 
482							 const std::string& label )
483{
484	sCheesyBeacon = gSavedSettings.getBOOL("CheesyBeacon");
485	LLVector3d to_vec = pos_global - gAgentCamera.getCameraPositionGlobal();
486
487	F32 dist = (F32)to_vec.magVec();
488	F32 color_frac = 1.f;
489	if (dist > 0.99f * LLViewerCamera::getInstance()->getFar())
490	{
491		color_frac = 0.4f;
492	//	pos_global = gAgentCamera.getCameraPositionGlobal() + 0.99f*(LLViewerCamera::getInstance()->getFar()/dist)*to_vec;
493	}
494	else
495	{
496		color_frac = 1.f - 0.6f*(dist/LLViewerCamera::getInstance()->getFar());
497	}
498
499	LLColor4 fogged_color = color_frac * color + (1 - color_frac)*gSky.getFogColor();
500
501	F32 FADE_DIST = 3.f;
502	fogged_color.mV[3] = llmax(0.2f, llmin(0.5f,(dist-FADE_DIST)/FADE_DIST));
503
504	LLVector3 pos_agent = gAgent.getPosAgentFromGlobal(pos_global);
505
506	LLGLSTracker gls_tracker; // default+ CULL_FACE + LIGHTING + GL_BLEND + GL_ALPHA_TEST
507	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
508	LLGLDisable cull_face(GL_CULL_FACE);
509	LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
510	
511	
512	gGL.matrixMode(LLRender::MM_MODELVIEW);
513	gGL.pushMatrix();
514	{
515		gGL.translatef(pos_agent.mV[0], pos_agent.mV[1], pos_agent.mV[2]);
516		
517		draw_shockwave(1024.f, gRenderStartTime.getElapsedTimeF32(), 32, fogged_color);
518
519		gGL.color4fv(fogged_color.mV);
520		const U32 BEACON_VERTS = 256;
521		const F32 step = 1024.0f/BEACON_VERTS;
522		
523		LLVector3 x_axis = LLViewerCamera::getInstance()->getLeftAxis();
524		F32 t = gRenderStartTime.getElapsedTimeF32();
525		F32 dr = dist/LLViewerCamera::getInstance()->getFar();
526		
527		for (U32 i = 0; i < BEACON_VERTS; i++)
528		{
529			F32 x = x_axis.mV[0];
530			F32 y = x_axis.mV[1];
531			
532			F32 z = i * step;
533			F32 z_next = (i+1)*step;
534		
535			F32 a = pulse_func(t, z);
536			F32 an = pulse_func(t, z_next);
537			
538			LLColor4 c_col = fogged_color + LLColor4(a,a,a,a);
539			LLColor4 col_next = fogged_color + LLColor4(an,an,an,an);
540			LLColor4 col_edge = fogged_color * LLColor4(a,a,a,0.0f);
541			LLColor4 col_edge_next = fogged_color * LLColor4(an,an,an,0.0f);
542			
543			a *= 2.f;
544			a += 1.0f+dr;
545			
546			an *= 2.f;
547			an += 1.0f+dr;
548		
549			gGL.begin(LLRender::TRIANGLE_STRIP);
550			gGL.color4fv(col_edge.mV);
551			gGL.vertex3f(-x*a, -y*a, z);
552			gGL.color4fv(col_edge_next.mV);
553			gGL.vertex3f(-x*an, -y*an, z_next);
554			
555			gGL.color4fv(c_col.mV);
556			gGL.vertex3f(0, 0, z);
557			gGL.color4fv(col_next.mV);
558			gGL.vertex3f(0, 0, z_next);
559			
560			gGL.color4fv(col_edge.mV);
561			gGL.vertex3f(x*a,y*a,z);
562			gGL.color4fv(col_edge_next.mV);
563			gGL.vertex3f(x*an,y*an,z_next);
564			
565			gGL.end();
566		}
567	}
568	gGL.popMatrix();
569
570	std::string text;
571	text = llformat( "%.0f m", to_vec.magVec());
572
573	std::string str;
574	str += label;
575	str += '\n';
576	str += text;
577
578	hud_textp->setFont(LLFontGL::getFontSansSerif());
579	hud_textp->setZCompare(FALSE);
580	hud_textp->setColor(LLColor4(1.f, 1.f, 1.f, llmax(0.2f, llmin(1.f,(dist-FADE_DIST)/FADE_DIST))));
581
582	hud_textp->setString(str);
583	hud_textp->setVertAlignment(LLHUDText::ALIGN_VERT_CENTER);
584	hud_textp->setPositionAgent(pos_agent);
585}
586
587
588void LLTracker::stopTrackingAll(BOOL clear_ui)
589{
590	switch (mTrackingStatus)
591	{
592	case TRACKING_AVATAR :
593		stopTrackingAvatar(clear_ui);
594		break;
595	case TRACKING_LANDMARK :
596		stopTrackingLandmark(clear_ui);
597		break;
598	case TRACKING_LOCATION :
599		stopTrackingLocation(clear_ui);
600		break;
601	default:
602		mTrackingStatus = TRACKING_NOTHING;
603		break;
604	}
605}
606
607
608void LLTracker::stopTrackingAvatar(BOOL clear_ui)
609{
610	LLAvatarTracker& av_tracker = LLAvatarTracker::instance();
611	if( !av_tracker.getAvatarID().isNull() )
612	{
613		av_tracker.untrack( av_tracker.getAvatarID() );
614	}
615
616	purgeBeaconText();
617	gFloaterWorldMap->clearAvatarSelection(clear_ui);
618	mTrackingStatus = TRACKING_NOTHING;
619}
620
621
622void LLTracker::stopTrackingLandmark(BOOL clear_ui)
623{
624	purgeBeaconText();
625	mTrackedLandmarkAssetID.setNull();
626	mTrackedLandmarkItemID.setNull();
627	mTrackedLandmarkName.assign("");
628	mTrackedPositionGlobal.zeroVec();
629	mHasLandmarkPosition = FALSE;
630	mHasReachedLandmark = FALSE;
631	mLandmarkHasBeenVisited = TRUE;
632	gFloaterWorldMap->clearLandmarkSelection(clear_ui);
633	mTrackingStatus = TRACKING_NOTHING;
634}
635
636
637void LLTracker::stopTrackingLocation(BOOL clear_ui)
638{
639	purgeBeaconText();
640	mTrackedLocationName.assign("");
641	mIsTrackingLocation = FALSE;
642	mTrackedPositionGlobal.zeroVec();
643	gFloaterWorldMap->clearLocationSelection(clear_ui);
644	mTrackingStatus = TRACKING_NOTHING;
645	mTrackingLocationType = LOCATION_NOTHING;
646}
647
648void LLTracker::clearFocus()
649{
650	instance()->mTrackingStatus = TRACKING_NOTHING;
651}
652
653void LLTracker::drawMarker(const LLVector3d& pos_global, const LLColor4& color)
654{
655	// get position
656	LLVector3 pos_local = gAgent.getPosAgentFromGlobal(pos_global);
657
658	// check in frustum
659	LLCoordGL screen;
660	S32 x = 0;
661	S32 y = 0;
662	const BOOL CLAMP = TRUE;
663
664	if (LLViewerCamera::getInstance()->projectPosAgentToScreen(pos_local, screen, CLAMP)
665		|| LLViewerCamera::getInstance()->projectPosAgentToScreenEdge(pos_local, screen) )
666	{
667		gHUDView->screenPointToLocal(screen.mX, screen.mY, &x, &y);
668
669		// the center of the rendered position of the arrow obeys 
670		// the following rules:
671		// (1) it lies on an ellipse centered on the target position 
672		// (2) it lies on the line between the target and the window center
673		// (3) right now the radii of the ellipse are fixed, but eventually
674		//     they will be a function of the target text
675		// 
676		// from those rules we can compute the position of the 
677		// lower left corner of the image
678		LLRect rect = gHUDView->getRect();
679		S32 x_center = lltrunc(0.5f * (F32)rect.getWidth());
680		S32 y_center = lltrunc(0.5f * (F32)rect.getHeight());
681		x = x - x_center;	// x and y relative to center
682		y = y - y_center;
683		F32 dist = sqrt((F32)(x*x + y*y));
684		S32 half_arrow_size = lltrunc(0.5f * HUD_ARROW_SIZE);
685		if (dist > 0.f)
686		{
687			const F32 ARROW_ELLIPSE_RADIUS_X = 2 * HUD_ARROW_SIZE;
688			const F32 ARROW_ELLIPSE_RADIUS_Y = HUD_ARROW_SIZE;
689
690			// compute where the arrow should be
691			F32 x_target = (F32)(x + x_center) - (ARROW_ELLIPSE_RADIUS_X * ((F32)x / dist) );	
692			F32 y_target = (F32)(y + y_center) - (ARROW_ELLIPSE_RADIUS_Y * ((F32)y / dist) );
693
694			// keep the arrow within the window
695			F32 x_clamped = llclamp( x_target, (F32)half_arrow_size, (F32)(rect.getWidth() - half_arrow_size));
696			F32 y_clamped = llclamp( y_target, (F32)half_arrow_size, (F32)(rect.getHeight() - half_arrow_size));
697
698			F32 slope = (F32)(y) / (F32)(x);
699			F32 window_ratio = (F32)(rect.getHeight() - HUD_ARROW_SIZE) / (F32)(rect.getWidth() - HUD_ARROW_SIZE);
700
701			// if the arrow has been clamped on one axis
702			// then we need to compute the other axis
703			if (llabs(slope) > window_ratio)
704			{  
705				if (y_clamped != (F32)y_target)
706				{
707					// clamp by y 
708					x_clamped = (y_clamped - (F32)y_center) / slope + (F32)x_center;
709				}
710			}
711			else if (x_clamped != (F32)x_target)
712			{
713				// clamp by x
714				y_clamped = (x_clamped - (F32)x_center) * slope + (F32)y_center;
715			}
716			mHUDArrowCenterX = lltrunc(x_clamped);
717			mHUDArrowCenterY = lltrunc(y_clamped);
718		}
719		else
720		{
721			// recycle the old values
722			x = mHUDArrowCenterX - x_center;
723			y = mHUDArrowCenterY - y_center;
724		}
725
726		F32 angle = atan2( (F32)y, (F32)x );
727
728		gl_draw_scaled_rotated_image(mHUDArrowCenterX - half_arrow_size, 
729									 mHUDArrowCenterY - half_arrow_size, 
730									 HUD_ARROW_SIZE, HUD_ARROW_SIZE, 
731									 RAD_TO_DEG * angle, 
732									 LLWorldMapView::sTrackArrowImage->getImage(), 
733									 color);
734	}
735}
736
737
738void LLTracker::setLandmarkVisited()
739{
740	// poke the inventory item
741	if (!mTrackedLandmarkItemID.isNull())
742	{
743		LLInventoryItem* i = gInventory.getItem( mTrackedLandmarkItemID );
744		LLViewerInventoryItem* item = (LLViewerInventoryItem*)i;
745		if (   item 
746			&& !(item->getFlags()&LLInventoryItemFlags::II_FLAGS_LANDMARK_VISITED))
747		{
748			U32 flags = item->getFlags();
749			flags |= LLInventoryItemFlags::II_FLAGS_LANDMARK_VISITED;
750			item->setFlags(flags);
751			LLMessageSystem* msg = gMessageSystem;
752			msg->newMessage("ChangeInventoryItemFlags");
753			msg->nextBlock("AgentData");
754			msg->addUUID("AgentID", gAgent.getID());
755			msg->addUUID("SessionID", gAgent.getSessionID());
756			msg->nextBlock("InventoryData");
757			msg->addUUID("ItemID", mTrackedLandmarkItemID);
758			msg->addU32("Flags", flags);
759			gAgent.sendReliableMessage();
760
761			LLInventoryModel::LLCategoryUpdate up(item->getParentUUID(), 0);
762			gInventory.accountForUpdate(up);
763
764			// need to communicate that the icon needs to change...
765			gInventory.addChangedMask(LLInventoryObserver::INTERNAL, item->getUUID());
766			gInventory.notifyObservers();
767		}
768	}
769}
770
771
772void LLTracker::cacheLandmarkPosition()
773{
774	// the landmark asset download may have finished, in which case
775	// we'll now be able to figure out where we're trying to go
776	BOOL found_landmark = FALSE;
777	if( mTrackedLandmarkAssetID == LLFloaterWorldMap::getHomeID())
778	{
779		LLVector3d pos_global;
780		if ( gAgent.getHomePosGlobal( &mTrackedPositionGlobal ))
781		{
782			found_landmark = TRUE;
783		}
784		else
785		{
786			llwarns << "LLTracker couldn't find home pos" << llendl;
787			mTrackedLandmarkAssetID.setNull();
788			mTrackedLandmarkItemID.setNull();
789		}
790	}
791	else
792	{
793		LLLandmark* landmark = gLandmarkList.getAsset(mTrackedLandmarkAssetID);
794		if(landmark && landmark->getGlobalPos(mTrackedPositionGlobal))
795		{
796			found_landmark = TRUE;
797
798			// cache the object's visitation status
799			mLandmarkHasBeenVisited = FALSE;
800			LLInventoryItem* item = gInventory.getItem(mTrackedLandmarkItemID);
801			if (   item 
802				&& item->getFlags()&LLInventoryItemFlags::II_FLAGS_LANDMARK_VISITED)
803			{
804				mLandmarkHasBeenVisited = TRUE;
805			}
806		}
807	}
808	if ( found_landmark && gFloaterWorldMap )
809	{
810		mHasReachedLandmark = FALSE;
811		F32 dist = gFloaterWorldMap->getDistanceToDestination(mTrackedPositionGlobal, 1.0f);
812		if ( dist < DESTINATION_UNVISITED_RADIUS )
813		{
814			mHasReachedLandmark = TRUE;
815		}
816		mHasLandmarkPosition = TRUE;
817	}
818	mHasLandmarkPosition = found_landmark;
819}
820
821
822void LLTracker::purgeBeaconText()
823{
824	if(!mBeaconText.isNull())
825	{
826		mBeaconText->markDead();
827		mBeaconText = NULL;
828	}
829}
830