Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

finding what way a vector is pointing

ac14 Hutson
Tredpro
Join date: 17 Jun 2006
Posts: 30
09-12-2008 20:49
hi, i need some help finding what way a vector is pointing, and example would be if you were making a boat and wanted to know if it was capsized or not.
_____________________
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
09-13-2008 03:44
From: ac14 Hutson
hi, i need some help finding what way a vector is pointing, and example would be if you were making a boat and wanted to know if it was capsized or not.

A little vague, no?
In terms of what do you want know the direction?
The vector coordinates accurately describes where it is pointing:(
_____________________
From Studio Dora
Pedro McMillan
SLOODLE Developer
Join date: 28 Jul 2007
Posts: 231
09-13-2008 03:47
If you are wanting to know if the vector is simply pointing up or down, then examine the Z component of it, like this:

CODE

if (vec.z > 0.0) {
// Pointing up
} else {
// Pointing down
}


Alternatively, if you need to check a vector against an arbitrary direction, then you can use the 'dot product'. For example, if you have a direction called "dir" and you want to check if vector "vec" is pointing in roughly that direction, you can do this:

CODE

if ((dir * vec) > 0) {
// Vec is pointing roughly the same way as dir
} else {
// Vec is pointing away from dir
}


Remember, "dir" is a direction, not a point! If you need to find out if a vector is pointing towards a point, then it's very similar. Let's say you have the position of your boat "pos", direction vector of your boat "vec", and you have some point "pnt"... you want to see if the boat is pointing roughly towards "pnt"... you'd start by doing this:

CODE

vector dir = pnt - pos;


Everything else would be the same as for the "dir" example above.
ac14 Hutson
Tredpro
Join date: 17 Jun 2006
Posts: 30
09-13-2008 08:24
im not sure if that helps me or not, lets say you had a boat, and you got the local rotatation around the x (forward) so it would be the "roll" of the boat, now if the roll of the is below/above a certian angle, or an amount from 90, then do something. im not sure how i would do that.
_____________________
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
09-13-2008 09:39
From: ac14 Hutson
im not sure if that helps me or not, lets say you had a boat, and you got the local rotatation around the x (forward) so it would be the "roll" of the boat, now if the roll of the is below/above a certian angle, or an amount from 90, then do something. im not sure how i would do that.

You don't want the local rotation to see if the boat is rolled.
vector vecLeft = llRot2Left( llGetRot() );
The vecLeft will tell you how the boat is rolled.
if (vecLeft.z == 0.0) the boat is level (not rolled)
if (vecLeft.z == 1.0) it is rolled +90 degree
if (vecLeft.z == -1.0) it is rolled -90 degree
In general the roll angle is:
float angle = llAsin( vecLeft.z ); // radians
or
float angle = RAD_TO_DEG*llAsin( vecLeft.z ); // degree

note: this method wont tell you if the boat is upside down, use llRotUp( llGetRot()) for that.
_____________________
From Studio Dora