Ahroun Maelstrom
Registered User
Join date: 30 Sep 2004
Posts: 22
|
04-03-2005 04:04
I need some help with what should be a fairly simple function. I'm trying to code a plain cube (standard box prim) so that when it lands on a surface, it will announce which face is closest to the up direction. here's how a very simple script might work using it: // --------------------------------
jpFaceUp() { // THIS IS WHAT I NEED!
return FaceNumber; }
default {
state_entry() {
}
touch_start(integer number) { llSay(0, "The face closest to up is: " + (string) jpFaceUp() ); }
}
// ------------------------------------
|
Zuzi Martinez
goth dachshund
Join date: 4 Sep 2004
Posts: 1,860
|
04-03-2005 06:28
you might be able to use llRot2Fwd, llRot2Left and llRot2Up. links at the bottom of this page.
_____________________
Zuzi Martinez: if Jeska was Canadian would she be from Jeskatchewan? that question keeps me up at nite. Jeska Linden: That is by far the weirdest question I've ever seen.
|
Ahroun Maelstrom
Registered User
Join date: 30 Sep 2004
Posts: 22
|
04-03-2005 18:35
WOW... okay... I went into MEGA-HACK-MODE and grokked the HELL out of rotations and vectors, and used the knowledge I have of neural network data pre-processing... AND FIGURED IT OUT! Here ya' go: integer jpWhichFaceUp() { vector up_vec; vector fwd_vec; vector left_vec; float up_dir; float fwd_dir; float left_dir; float up_abs; float fwd_abs; float left_abs; up_vec = llRot2Up(llGetRot()); fwd_vec = llRot2Fwd(llGetRot()); left_vec = llRot2Left(llGetRot()); up_dir = up_vec.z; fwd_dir = fwd_vec.z; left_dir = left_vec.z; up_abs = llFabs(up_vec.z); fwd_abs = llFabs(fwd_vec.z); left_abs = llFabs(left_vec.z);
// If UP is dominant, and neither FWD nor LEFT is just as dominant, if( (up_abs> fwd_abs) && (up_abs> left_abs) && (llFabs(up_abs-fwd_abs) > 0.001) && (llFabs(up_abs-fwd_abs) > 0.001) ) { // Then if UP is > 0, return face 0, else return face 5. if( up_dir > 0 ) return 0; else return 5; } // If FWD is dominant, and neither UP nor LEFT is just as dominant, else if( (fwd_abs > up_abs) && (fwd_abs > left_abs) && (llFabs(fwd_abs-up_abs) > 0.001) && (llFabs(fwd_abs-left_abs) > 0.001) ) { // Then if FWD is > 0, return face 2, else return face 4. if( fwd_dir > 0 ) return 2; else return 4; } // If LEFT is dominant, and neither UP nor FWD is just as dominant, else if( (left_abs > up_abs) && (left_abs > fwd_abs) && (llFabs(left_abs-up_abs) > 0.001) && (llFabs(left_abs-fwd_abs) > 0.001) ) { // Then if LEFT is > 0, return face 0, else return face 5. if( left_dir > 0 ) return 3; else return 1; } else { return -1; } } This would work on any prim, buuuuut... would be somewhat silly to use on anything other than a cube or POSSIBLY a sphere. Anything else would just be fairly strange.
|