Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

U Lookin at Me?

Rysidian Rubio
Ruby Red Head
Join date: 14 Jan 2004
Posts: 263
12-01-2004 18:05
I'm hopeless when it comes to rotations & vectors. What I'm after is a way of working out if an avatar is facing a prim. I'm sure there's a way to calculate this, using an avatar's position and rotation, but I have no idea how to do it.

I'll give L$500 to anyone who can give me the calculations (in LSL) to work this out. I don't need an entire script, just the calculations necessary to work this out. The prim that the script will be in will move around, so please keep this in mind. Use the below Sensor event if you want, or not.

CODE
sensor(integer num_detected)
{
integer i;
for (i = 0; i< num_detected; ++i)
{
vector pos = llDetectedPos(i);
rotation rot = llDetectedRot(i);

//calculate if avatar is facing me.

if (FACING)
llSetColor(<1,1,1>,ALL_SIDES);
else
llSetColor(<0,0,0>,ALL_SIDES);
}
}
If noone can help with this, but can provide a link to somewhere that explains how to do this that helps me I'll pay you L$250
Francis Chung
This sentence no verb.
Join date: 22 Sep 2003
Posts: 918
12-01-2004 18:56
I don't want your money. There are few ways to skin this cat. One approximation is to take the dot product of the avatar to the target, and the avatar's direction. If it's greater than some threshold, we'll say they're facing your prim.

The following is an uncompiled code that hopefully illustrates what I'm trying to do. (forgive me if I use an API that doesn't exist ;)

CODE


// Play around with this value
float threshold = .9;

sensor(integer num_detected)
{
integer i;
for (i = 0; i< num_detected; ++i)
{
vector pos = llDetectedPos(i);
rotation rot = llDetectedRot(i);

//calculate if avatar is facing me.
vector av_fwd = llVecNorm( llRot2Fwd( rot ) );
vector av2prim = llVecNorm( llGetPos() - pos );

if ( llVecMag(av_fwd*av2prim) > threshold )
FACING = TRUE;

if (FACING)
llSetColor(<1,1,1>,ALL_SIDES);
else
llSetColor(<0,0,0>,ALL_SIDES);
}
}


I believe Alondria has something more sophisticated that will actually calculate the intersection of your view and the prim face.
_____________________
--
~If you lived here, you would be home by now~
Rysidian Rubio
Ruby Red Head
Join date: 14 Jan 2004
Posts: 263
12-01-2004 19:34
Thanks Fran!!! *hugs*
I'll try this as soon as I get home tonight. I had no idea it would be so simple, well not simple but only 3 lines. I don't understand it, but as long as it works I'm happy :) hehe. I'd love to understand it, but I can't afford for my brain to explode at the moment.

I should have just asked you in the first place (but I know how busy you are).

Thanks again!!!
Rysidian Rubio
Ruby Red Head
Join date: 14 Jan 2004
Posts: 263
12-02-2004 00:05
There was one small error in the script posted by Fran, so I'll post the correction incase anyone else want to use this (Fran worked out the problem not me). :)

CODE
// Play around with this value
float threshold = .9;

sensor(integer num_detected)
{
integer i;
for (i = 0; i< num_detected; ++i)
{
vector pos = llDetectedPos(i);
rotation rot = llDetectedRot(i);

//calculate if avatar is facing me.
vector av_fwd = llVecNorm( llRot2Fwd( rot ) );
vector av2prim = llVecNorm( llGetPos() - pos );

if ( av_fwd*av2prim > threshold )
FACING = TRUE;

if (FACING)
llSetColor(<1,1,1>,ALL_SIDES);
else
llSetColor(<0,0,0>,ALL_SIDES);
}
}
The line: if ( llVecMag(av_fwd*av2prim) > threshold )
was changed to: if ( av_fwd*av2prim > threshold )

Thanks again Fran!
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
12-02-2004 09:17
Huh... looks like the wiki's description of vector * vector was a little incorrect, then. No wonder I was confused. :)
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
Rysidian Rubio
Ruby Red Head
Join date: 14 Jan 2004
Posts: 263
12-02-2004 20:07
From: Cross Lament
Huh... looks like the wiki's description of vector * vector was a little incorrect, then. No wonder I was confused. :)

Perhaps someone who understand vectors better than I should update the wiki for this..
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
12-03-2004 12:54
From: Rysidian Rubio
Perhaps someone who understand vectors better than I should update the wiki for this..


Done. :D
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
12-03-2004 13:34
sorry about that; when i was writing up the table i wasn't testing everything in SL as i was doing it... Was before I started playing SL in window mode.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
12-03-2004 19:25
We still love you, Strife. :D
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"