Jump to content

Move root and rotate link


petitelouison
 Share

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

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

Recommended Posts

Hello,

I have a root for which I make a translation and a linked prim for which I make a rotation. I created this script for my tests:

// Parameters to change
float       TIME            = 3;  // Time in seconds
float       HEIGHT          = 2;  // Height in meters
float       ANGLE           = .5;  // Angle in radian

// Don't touch it!
float       TIME_BASE       = .04;
float       f_step;
vector      v_pos;
vector      v_rot;
float       step;
integer     stop = TRUE;
integer     up;

float fCos(float x, float y, float t)
{
	float F = (1.0 - llCos(t * PI)) / 2.0;
	return x * (1.0 - F) + y * F;
}

move()
{
	v_pos = llGetPos();
	v_rot = llRot2Euler(llList2Rot(llGetLinkPrimitiveParams(2, [PRIM_ROT_LOCAL]), 0));
	step = .0;
	up = TRUE;
	llSetTimerEvent(TIME_BASE);
}

default
{
	state_entry()
	{
		f_step = 1.0 / (TIME / TIME_BASE);
	}

	on_rez(integer start_param)
	{
		stop = TRUE;
		llSetTimerEvent(.0);
	}

	touch_end(integer total_number)
	{
		if(stop = !stop)
		{
			llSetTimerEvent(.0);
			llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_POSITION, v_pos,
			 PRIM_LINK_TARGET, 2, PRIM_ROT_LOCAL, llEuler2Rot(v_rot)]);
		}
		else move();
	}

	timer()
	{
		if(up)
		{
			if((step += f_step) >= 1.0) up = FALSE;
		}
		else
		{
			if((step -= f_step) <= .0) up = TRUE;
		}
		llSetLinkPrimitiveParamsFast(LINK_THIS, [PRIM_POSITION, v_pos + <0, 0, fCos(0, HEIGHT, step)>,
			PRIM_LINK_TARGET, 2, PRIM_ROT_LOCAL, llEuler2Rot(v_rot + <0, 0, fCos(0, ANGLE, step)>)]);
	}
}

So just 2 linked prims.

It starts and stop with a click.

The move is ok, the rotation is ok but... the relative position of the linked related to the root changes with shaking with a very unsightly effect.

As I do both movements in the same function, I thought I wouldn't have this kind of problem.

If someone has an idea to help me to get a good visual effect !

Thanks.

Link to comment
Share on other sites

26 minutes ago, petitelouison said:

the relative position of the linked related to the root changes with shaking with a very unsightly effect

I'm not seeing that when I just put the script in 2 linked cubes. Perhaps you could share a video of how it looks to you?

Link to comment
Share on other sites

Just for my own fun, I wrote a slightly different script that does the same thing. The only difference that should actually matter is that I synced to llGetTime() rather than an incremented global step variable:

float time = 6.0;
float height = 2.0;
float angle = .5;

integer isRunning = FALSE;

vector gPosA;
vector gPosB;

rotation gRotA;
rotation gRotB;

vector cosInterp(float time, float rate, vector posA, vector posB)
{   float ct = 0.5*(1+llCos(time*TWO_PI/rate));
    return ct*posA + (1-ct)*posB;
}
rotation cosRotInterp(float time, float rate, rotation rA, rotation rB)
{   float ct = 0.5*(1+llCos(time*TWO_PI/rate));
    return 
        <ct*rA.x + (1-ct)*rB.x,
         ct*rA.y + (1-ct)*rB.y,
         ct*rA.z + (1-ct)*rB.z,
         ct*rA.s + (1-ct)*rB.s>;
}
default
{
    state_entry()
    {
        gPosA = llGetPos();
        gPosB = gPosA + <0,0,height>;
        gRotA = ZERO_ROTATION;
        gRotB = llAxisAngle2Rot(<0,0,1>, angle);
        //llSetTimerEvent(0.044);
    }
    touch_end(integer n)
    {   llResetTime();
        llSetLinkPrimitiveParamsFast(LINK_THIS,
        [   PRIM_POSITION,gPosA,
            PRIM_LINK_TARGET, 2,
            PRIM_ROT_LOCAL, gRotA
        ]);
        llSetTimerEvent(0.044*(isRunning=!isRunning));
    }
    timer()
    {   float t = llGetTime();
        vector pos = cosInterp(t,time,gPosA, gPosB);
        rotation rot = cosRotInterp(t,time,gRotA, gRotB);
        llSetLinkPrimitiveParamsFast(LINK_THIS,
        [   PRIM_POSITION,pos,
            PRIM_LINK_TARGET, 2,
            PRIM_ROT_LOCAL, rot
        ]);
    }
}

 

Link to comment
Share on other sites

Hello,

Thanks for the fast answer !

I don't know why, but now it works smooth for me in world. Maybe this was laggy when I made my test before.

Sync on llGetTime() is interesting, I never thought to use it this way. I can't notice a visual difference but it's nice to see how someone else would make the same thing.

Edit : today I get the same shaking issue. I made a video but I really don't know how to put it here.

Edited by petitelouison
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
You are about to reply to a thread that has been inactive for 434 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...