Skip to content

Commit eb9c83c

Browse files
FelixWolfakleshchev
authored andcommitted
Initial limit look at distance code
1 parent 82477c4 commit eb9c83c

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

indra/newview/app_settings/settings.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16267,5 +16267,27 @@
1626716267
<key>Value</key>
1626816268
<integer>1</integer>
1626916269
</map>
16270+
<key>LimitLookAtHints</key>
16271+
<map>
16272+
<key>Comment</key>
16273+
<string>Whether or not to clamp the look at targets around the avatar head before sending</string>
16274+
<key>Persist</key>
16275+
<integer>1</integer>
16276+
<key>Type</key>
16277+
<string>Boolean</string>
16278+
<key>Value</key>
16279+
<integer>1</integer>
16280+
</map>
16281+
<key>LimitLookAtHintsDistance</key>
16282+
<map>
16283+
<key>Comment</key>
16284+
<string>Distance to limit look at target to</string>
16285+
<key>Persist</key>
16286+
<integer>1</integer>
16287+
<key>Type</key>
16288+
<string>F32</string>
16289+
<key>Value</key>
16290+
<integer>4</integer>
16291+
</map>
1627016292
</map>
1627116293
</llsd>

indra/newview/llhudeffectlookat.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "lldrawable.h"
3838
#include "llviewerobjectlist.h"
3939
#include "llviewercontrol.h"
40+
#include "llvoavatarself.h"
4041
#include "llrendersphere.h"
4142
#include "llselectmgr.h"
4243
#include "llglheaders.h"
@@ -390,7 +391,7 @@ void LLHUDEffectLookAt::setTargetPosGlobal(const LLVector3d &target_pos_global)
390391
// setLookAt()
391392
// called by agent logic to set look at behavior locally, and propagate to sim
392393
//-----------------------------------------------------------------------------
393-
bool LLHUDEffectLookAt::setLookAt(ELookAtType target_type, LLViewerObject *object, LLVector3 position)
394+
bool LLHUDEffectLookAt::setLookAt(ELookAtType target_type, LLViewerObject* object, LLVector3 position)
394395
{
395396
static LLCachedControl<bool> enable_lookat_hints(gSavedSettings, "EnableLookAtHints", true);
396397
if (!enable_lookat_hints)
@@ -415,6 +416,29 @@ bool LLHUDEffectLookAt::setLookAt(ELookAtType target_type, LLViewerObject *objec
415416
return false;
416417
}
417418

419+
static LLCachedControl<bool> limit_lookat_hints(gSavedSettings, "LimitLookAtHints", true);
420+
// Don't affect the look at if object is gAgentAvatarp (cursor head follow)
421+
if (limit_lookat_hints && object != gAgentAvatarp)
422+
{
423+
// If it is a object
424+
if (object)
425+
{
426+
position += object->getRenderPosition();
427+
object = NULL;
428+
}
429+
430+
LLVector3 agentHeadPosition = gAgentAvatarp->mHeadp->getWorldPosition();
431+
float dist = (float)dist_vec(agentHeadPosition, position);
432+
433+
static LLCachedControl<F32> limit_lookat_hints_distance(gSavedSettings, "LimitLookAtHintsDistance", 2.0f);
434+
if (dist > limit_lookat_hints_distance)
435+
{
436+
LLVector3 headOffset = position - agentHeadPosition;
437+
headOffset *= limit_lookat_hints_distance / dist;
438+
position.setVec(agentHeadPosition + headOffset);
439+
}
440+
}
441+
418442
F32 current_time = mTimer.getElapsedTimeF32();
419443

420444
// type of lookat behavior or target object has changed

0 commit comments

Comments
 (0)