Jump to content
Sign in to follow this  
Villain Baroque

Which Side of a cube is up?

Recommended Posts

I am looking for an easy way to determine which face of a cube points up on the z-plane. 

I want to script a dice. After some arbitrary rotations on all planes one side (face) is pointing up but which one?

Thanks for your help.

 

A dice 

 

Share this post


Link to post
Share on other sites
vector vPosTest;vPosTest = llRot2Up( llGetRot() );if (llFabs( vPosTest.z ) > 0.5){    if (vPosTest.z > 0){        //-- top is up    }else{        //-- bottom is up    }}else{    vPosTest = llRot2Left( llGetRot() );   if (llFabs( vPosTest.z ) > 0.5){        if (vPosTest.z > 0){            //-- left side is up        }else{            //-- right side is up        }    }else{        vPosTest = llRot2Fwd( llGetRot() );       if (vPosTest.z > 0){            //-- front is up        }else{            //-- back is up        }    }}

 

Share this post


Link to post
Share on other sites

EDIT: Void beat me while I was doing my tests in-world. Nevermind... It's almost the same thing but in a function.

I retrieved this old thing in my inventory:

 

integer uuRot2Face(rotation rot){    vector vee = llRot2Up(rot);    integer k = llRound(vee.z);    if (k == 1){ return 0; }    else if (k == -1){ return 5; }    vee = llRot2Fwd(rot);    k = llRound(vee.z);    if (k == 1){ return 3; }    else if (k == -1){ return 2; }    vee = llRot2Left(rot);    k = llRound(vee.z);    if (k == 1){ return 1; }    else if (k == -1){ return 4; }    return -1; // So that the compiler doesn't complain.}

 

It works quite well even if the dice isn't exactly straight.

 

Share this post


Link to post
Share on other sites

there's a way to do it quicker, but I can't remember it... I think it used additions of <1,1,0> and <1,0, 1> multiplied by the rotation

Share this post


Link to post
Share on other sites

Better late than never, here is a routine I made for a dice back in April 2008
Note that the list gives the connection between pips and sides so it instantly returns the pip number:smileywink:

integer pips_up(){    vector u = llRot2Fwd( llGetRot() );    vector v = llRot2Left( llGetRot() );    vector w = llRot2Up( llGetRot() );    // Vectors associated with dice pip numbers    list pips_list = [ u.z, 1, -u.z, 6, v.z, 2, -v.z, 5, w.z, 3, -w.z, 4 ];    // sort for the one with the biggest Z (vertical up) component,    // the associated pip number is upward    return llList2Integer( llListSort( pips_list, 2, FALSE ), 1 );}

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...