Jump to content

Rotation of points


Lochlyn Dragonash
 Share

You are about to reply to a thread that has been inactive for 1030 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

To recreate the sample for this question,

  1. Make you a sphere as small as possible, make it glow or something. 
  2. Name it Ball. 
  3. Make a script inside Ball with code below so it will kill itself.
  4. Make a Cube and put Ball inside the Cube.
  5. Make a script inside Cube.
  6. Touch Cube to rez the Balls.
  7. Touch Cube again to kill them.

EXERSIZE:

Identify a circle of points on the face of Cube, visually represented by a Ball rezzed on its surface.

WHAT WORKS:

When Cube is oriented with default rotation, the ring of points (and thus the position of rezzed Balls) is fine.

WHAT FAILS:

Any rotation of the cube in 3D space is not translated into the position of the points.  The Balls want to stay in their own plane.

THE QUESTION:

It goes without saying my math is wrong and I am not properly taking into account the rotation of Cube when calculating the positions necessary for the Balls.  My question is what am I missing, and is there some simple way for my Neanderthal brain to make sense of it?  I have read countless things on Rotations and Rotation Math and ... still can't grasp it.

 

Code for Ball:

default
{
    state_entry()
    {
        llListen(15,"",NULL_KEY,"");
    }

    touch_start(integer total_number)
    {
        llDie();
    }
    
    listen(integer channel, string name, key id, string message)
    {
        llDie();
    }
}

 

Code for Cube:

float a = PI;
float b = PI;

float angle;
float radius;
vector size;
integer balls = 20;
integer kill = FALSE;

makeBall(){
    if (a >= TWO_PI) a = 0; 
    if (b >= TWO_PI) b = 0;
    vector position = ((llGetPos() + <0,-(size.z / 2),0>)) + <radius * llCos(a += angle), 0, radius * llSin(b += angle)>;
    llRezObject("Ball",position, <0,0,0>,ZERO_ROTATION, 0);
}

default
{
    state_entry()
    {
        angle = (360.0 / balls) / 180.0 * PI;
        size = llGetScale();
        radius = size.x * 0.67 / 2;
    }

    touch_start(integer num) {
        if (kill) {
            llSay(15,"x");        
        } else {
            integer ct = 0;
            do {
                makeBall();            
                ct++;
            } while (ct < balls);
        }
        kill = !kill;
    }
}

 

  • Like 1
Link to comment
Share on other sites

20 minutes ago, Lochlyn Dragonash said:

Identify a circle of points on the face of Cube, visually represented by a Ball rezzed on its surface.

I can't parse that sentence. actually I can, but it took a couple tries.

If I'm understanding correctly what you want is to translate local coordinates to global ones. The code to do that is:

vector local2Global(vector pos)
{   return llGetRootPosition()+pos*llGetRootRotation();
}

and if I'm understanding correctly (too lazy to check) you want something like this in your make_ball function:

vector position = local2Global( <0,-(size.z / 2),0> + <radius * llCos(a += angle), 0, radius * llSin(b += angle)> );

 

Edited by Quistess Alpha
fixed parentheces.
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Thank you for the quick response.  Sorry if I wasn't clear enough in my description.  Makes more sense when you see it in world.

That's a step in the right direction - the plane of the rezzed ring does appear to obey the rotation of the cube, but now the ring is perpendicular to the face rather than flush with it.  I might can figure this out though.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1030 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...