Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Detecting the direction of approach

Lemieux Primeau
Registered User
Join date: 25 Oct 2006
Posts: 49
01-06-2007 12:51
I am working on a project with a door and a mat under it. The mat is currently 2 prims (one on each side of the door) because I am using the collision event in each one to determine the direction of approaching agents. For the sake of reducing prims and code, I would like to use one prim for the mat instead of two (with the door then sitting on the center of the xy plane of the 1 prim, at any rotation around z) and determine the direction of the approaching agent using llDetectedPos.

Can anyone offer the calculation necessary (or point me to something that will lead me in the right direction) to take the vector returned by llDetectedPos and, knowing the rotation of the door around z (and also knowing that it will always be parallel to z), determine if the detected position is on side 1 or 2?

EDIT: One other note. The door and the mat are linked and their rotations relative to each other will not change. That is, side A of the mat will always be on side A of the door. The entire linkset can be rotated, but the door alone will never be rotated without the mat rotating with it. If any of what I just said makes sense, I would expect that it would make the calculation easier - but maybe not.

thanks
Lemieux Primeau
Registered User
Join date: 25 Oct 2006
Posts: 49
01-06-2007 13:01
Ok, duh. I just figured it out. The door's local rotation is parallel to x, so all I have to do is see if the vector's y is less than or greater that the door's y.

If an admin or somebody wants to delete this thread, please do.
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
01-06-2007 13:02
It depends exactly how the mat is built, really. But assuming that in this case the "up" direction is pointing out of the door, you can use the dot product, based on the idea that the centre of the mat will be returned by llSetPos().

CODE

...
vector up = llRot2Up(llGetRot());
vector dirFromMatCentre = llDetectedPos(0) - llGetPos();
if (up * dirFromMatCentre > 0) llSay(0, "In front of mat");
else llSay(0, "Behind mat");
...
_____________________
http://ordinalmalaprop.com/forum/ - visit Ordinal's Scripting Colloquium for scripting discussion with actual working BBCode!

http://ordinalmalaprop.com/engine/ - An Engine Fit For My Proceeding, my Aethernet Journal

http://www.flickr.com/groups/slgriefbuild/ - Second Life Griefbuild Digest, pictures of horrible ad griefing and land spam, and the naming of names
Lemieux Primeau
Registered User
Join date: 25 Oct 2006
Posts: 49
01-06-2007 13:36
Thanks, ordinal. Actually, though, as I mentioned in my own reply above, I know that a) the door's x and y rotations will always be 0 and b) that the door crosses the center of y parallel to x (in local rotation). So, basically, any positive local y position is on one side and any negative local y position is on the other.

The problem I'm having now is that the vector returned from llDetectedPos is region coordinates and what i need is that position's local coordinate. How can I translate from region to local position?
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
01-06-2007 14:25
If you want it relative to the doormat, just subtract llGetPos() from the detected position.
_____________________
http://ordinalmalaprop.com/forum/ - visit Ordinal's Scripting Colloquium for scripting discussion with actual working BBCode!

http://ordinalmalaprop.com/engine/ - An Engine Fit For My Proceeding, my Aethernet Journal

http://www.flickr.com/groups/slgriefbuild/ - Second Life Griefbuild Digest, pictures of horrible ad griefing and land spam, and the naming of names
Lemieux Primeau
Registered User
Join date: 25 Oct 2006
Posts: 49
01-06-2007 18:11
Ah, yes. Thanks, Ordinal!