Change font size
It is currently Thu May 23, 2013 11:18 am

Forum rules


Image



Post a new topicPost a reply Page 1 of 1   [ 2 posts ]
Author Message
 Post subject: Calling all Quaternion/Euler/Rotation Experts......Help!!!!
PostPosted: Wed May 02, 2012 6:50 am 

Joined: Wed Apr 25, 2012 5:45 pm
Posts: 1
Hi Guys and Gals,

I am trying (unsuccessfully so far) to simulate a realistic, gentle rocking motion for a static boat. It seemed simple enough:

Get current positions on entry(hopefully 0, 0, 0)>>> Produce a Rand 300/100>>> Check if current Pos is +/-/= 0>>> Add/Subtract the Rand (depending on whether neg/pos of 0>>> do this for each axis randomly in a loop. Start again.

This should hopefully produce a variable, max difference of 0 to3 degrees in any direction when placed in an attached prim centralised at water level in the hull of the boat.

Sounded simple enough....lol Now I know why I have never seen it implemented in my travels. I have searched both OSG and SL for a comparable script, with no luck.

So now I turn to the experts ... Fancy giving it a go? (or maybe point me in the right direction)
All constructive suggestions will be gratefully received ... Thank you


Top
 Profile  
 
 Post subject: Re: Calling all Quaternion/Euler/Rotation Experts......Help!!!!
PostPosted: Thu May 24, 2012 12:43 pm 

Joined: Fri Apr 13, 2012 1:19 am
Posts: 23
I'm at work and can't test this, but here is how I would approach it:
Start with a vector that points in the direction of the forward X axis of the boat:
vector fwd = <1,0,0>*llGetRot();
(What? You didn't build your ship to have the X axis pointing forward? That will make things difficult. Most people solve this problem by adding a new prim that does have X pointing forward and making that prim the root prim. Rotation will be around the center of that prim as well, a nice feature since careful placement of that prim will set the center of rotation where you want it).
Construct an “up” vector that is randomly tilted fore-aft back and forth:
vector up = llVecNorm(<llFrand(0.1),llFrand(0.1),1>);
(note that his tilts at maximum angle of atan(.1) or 5.7 degrees, change that number to set the tilt)
(note: if you want different rocking fore/aft from port/starboard and you use different value for the two random numbers, you will want to multiply the resulting vector by llGetRot() to align it with the axis of the boat).
Now you use my FAVORITE LSL function call, llAxes2Rot to turn that back into a rotation:
llSetRot(llAxes2Rot(fwd,up%fwd,up));
Do this in the timer() event, set it up to run once a second, and your ship will totally ROCK!

OK, I snuck in-world from work and tested it. Turns out I DID misspell llAxes2Rot the first time. I fixed that and the following script rocks the boat nicely:
Code:
default
{
    state_entry()
    {
        llSetTimerEvent(1);
    }

    timer()
    {
        vector fwd = <1,0,0>*llGetRot();
        vector up = llVecNorm(<llFrand(0.1),llFrand(0.1),1>);
        llSetRot(llAxes2Rot(fwd,up%fwd,up));
    }
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 2 posts ]


Who is online

Users browsing this forum: legacy_google [bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net