Jump to content

Radians do my head in


Ares Halostar
 Share

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

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

Recommended Posts

I am trying to make a script that uses llSetLinkPrimitiveParamsFast with PRIM_TEXTURE to rotate a texture.

Here is what I have so far.

integer WHEEL = 4;
float Rotate = PI;
default
{
    link_message(integer sender_num, integer num, string str, key id)
    {
        if (str == "Spin")
        {
            integer count = 0;
            while(count<llFrand(50.0))
            {
                Rotate = Rotate + count;
                llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_GLOW, ALL_SIDES, 0.1,PRIM_TEXTURE,ALL_SIDES,"roulette_image copy",<1,1,0>,<0,0,0>,Rotate]);
                llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_GLOW, ALL_SIDES, 0.0]);
                ++count;
            }
            
        }
    }
}

 I am basically trying to spin a wheel around a few times, and have it stop randomly in a different spot every time it is spun.  Any help would be appreciated.

Link to comment
Share on other sites

For spinning you may prefer http://wiki.secondlife.com/wiki/LlSetTextureAnim.  There is an example there that "rotates a texture counter-clockwise at 2 revolutions per second".  Change the 2 in the final parameter to make it rotate faster or slower (and make it negative to spin clockwise, eg; -5 * TWO_PI would be 5 clockwise rotations per second).

To set the final position turn off the animation and set the rotation using llSetPrimitiveParams() or equivalent with the rotation as "llFrand(360.0) * DEG_TO_RAD" (you aren't the only one not used to radians :-) ) (http://wiki.secondlife.com/wiki/Radians)

Link to comment
Share on other sites

Only problem with llSetTextureAnim is that it has that annoying tick after every rotation.  Plus when the texture stops, I need to query the position that the texture stops, to determine the finished angle of rotation so I can calculate what the winnings are (BTW this project does not pay or accept money, it is just a project I am working on).

Also noted that the "radian" is actually a float that is required by the function : 

llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_GLOW, ALL_SIDES, 0.1,PRIM_TEXTURE,ALL_SIDES,"roulette_image copy",<1,1,0>,<0,0,0>,Rotate]);
Link to comment
Share on other sites

Ok.  Nothing you can do about the tick every rotation.  In addition my suggestion would 'jump' to the final position but at least you would know what it was, since you're setting it the same way as before.  Stopping llTextureAnim always puts it back to the 'underlying' rotation (usually 0).

Setting rotation in increments is always going to be jerky.  If you do it in a loop like now there's a good chance that viewers won't update quickly enough to make it look smooth even if you use a fast repeat with small increments.  That is if SL even sends small-increment updates (with a lot of things it depends on the viewing distance, etc.).  Anyway, if the problem is radians then just work in degrees and multiply by DEG_TO_RAD to convert them.

How about actually moving the thing - http://wiki.secondlife.com/wiki/LlTargetOmega and http://wiki.secondlife.com/wiki/LlSetRot - instead of just the texture?

 

Link to comment
Share on other sites

With that while loop you won't be able to see the changes.
They will happen so rapidly that your viewer will not be updated until the loop stops.
To view changes you need a llSleep() in the loop or to rewrite the script with a timer event handler.

Five times around is 5*2*PI
May I suggest:

integer WHEEL = 4;float Rotate = PI;default{    link_message(integer sender_num, integer num, string str, key id)    {        if (str == "Spin")        {            integer count = 0;            integer countRandom=llFrand(5*TWO_PI);            while(count<countRandom)            {                llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_GLOW, ALL_SIDES, 0.1,PRIM_TEXTURE,ALL_SIDES,"roulette_image copy",<1,1,0>,<0,0,0>,Rotate]);                llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_GLOW, ALL_SIDES, 0.0]);                ++count;                llSleep(0.1);            }        }    }}

 If you are after a smooth change this will also not be what you want because
TWO_PI equals 6.28 and that is only 6 itterations in the loop you have suggested:smileyhappy:

Link to comment
Share on other sites

Thanks for all the suggestions.  I have learned a few things again.. mmm or relearned them.  Here is the code I worked out from your suggestions.  It works and gives me the final degree that the thing stops at so I can do other calculations.

Posting the code so that someone else may find it useful (please excuse my sloppy coding).

integer WHEEL = 4;float Rotate;default{    state_entry()    {        Rotate = llFrand(360.0) * DEG_TO_RAD;    }    link_message(integer sender_num, integer num, string str, key id)    {        if (str == "Spin")        {            llSetTimerEvent(0.1);        }        if (str == "BigwheelStop")        {            llSetTimerEvent(0.0);            float final = Rotate * RAD_TO_DEG;            llSay(0,(string)llFloor(final));        }    }    timer()    {        Rotate = llFrand(360.0) * DEG_TO_RAD;        //llSetTextureAnim(ANIM_ON|LOOP|SMOOTH|ROTATE, ALL_SIDES, 1, 1, 0, 0, 0.0);        llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_GLOW, ALL_SIDES, 0.1,PRIM_TEXTURE,ALL_SIDES,"roulette_image copy",<1,1,0>,<0,0,0>,Rotate]);    }}

 I will later use llMessageLinked to send the calculated stop position to the main program later on, after a bit of fliddling around.  Cheers.

Um and oops, yes I have a few things in that code to remove and clean up..LOL

Link to comment
Share on other sites

  • 1 year later...
You are about to reply to a thread that has been inactive for 4101 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...