Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Why might I need to use a slerp?

Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
01-17-2010 06:14
I've been reading round this a bit -- the wiki article, /54/3b/50692/1.html#post536622, Wikipedia and the first few hits in Google search, and I think I understand roughly what they are, but I can't really get a handle on when I might want to use them in SL or how.

In the wiki example, from where might I take rotations a and b, and what would I do with rotation slerp when I'd calculated it?
CODE
rotation slerp( rotation a, rotation b, float t ) {
return llAxisAngle2Rot( llRot2Axis(b /= a), t * llRot2Angle(b)) * a;
}
Astra Melody
Registered User
Join date: 5 Jan 2010
Posts: 10
01-17-2010 11:17
Hi Innula, from what I understood, it's used to get the rotation between the 2 rotations you gave.

So this is useful to make an animation...

For example you can use llGetRot to get the starting position, and move the object manually then llGetRot with end position then you can make your animation...useful for a spinning door and what not.
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
01-17-2010 12:24
Thanks, Astra. But when I make doors normally, I get the open and closed rotations, and then use llSetLocalRot() to move between them (or llSetPrimitiveParams if I have to). If I use the wiki's example and put in the open and closed rotations, that gives me one rotation, "slerp". What do I do with it to make it open and close doors?
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
01-17-2010 13:10
From: Innula Zenovka
Thanks, Astra. But when I make doors normally, I get the open and closed rotations, and then use llSetLocalRot() to move between them (or llSetPrimitiveParams if I have to). If I use the wiki's example and put in the open and closed rotations, that gives me one rotation, "slerp". What do I do with it to make it open and close doors?
The t parameter is a number between 0.0 and 1.0, it indicates how close the rotation is to either of the two fixed rotations. When t=0 you get the one fixed rotation, when t=1 you get the other. If you were to use it for a door you would have to compute a number of intermediate rotations(different values of t) and make some kind of loop to rotate the door through those rotations.
I doubt there is any really good purpose for 'slerp' in LSL programs.
I guess it is used in your viewer though. When you llSetRot() you set a new rotation for an object. The viewer is only given two rotations: start and stop, but it shows a smooth rotation from one to the other. If it isn't it would be an obvious place to utilize 'slerp'. When the camera moves and rotates from one position/rotation to a second, that would be another.
_____________________
From Studio Dora
Anti Antonelli
Deranged Toymaker
Join date: 25 Apr 2006
Posts: 1,091
01-17-2010 13:22
Innula, slerp is useful when you need accurate intermediate rotations given the rotations at start and finish, particularly when you need the intermediate rotations to give an impression of something turning at a constant angular velocity. Doors don't make a good example because they generally rotate on only a single axis and are meant to operate quickly and without pauses, so nobody sees or cares exactly what is happening at the points partway through (and the viewer interpolates such movements well enough anyway).

But what if you were making (to pull a plausible-sounding example out of my hat) a non-physical model cat that falls like cats fall and always lands on its feet? It wouldn't do to have it fall straight down and suddenly twist at the end to turn rightside-up with one big llSetRot. Ideally you'd have it gradually turn in such a way that by the time it hits the ground it's in the correct orientation. A slerp function would allow you to determine what the proper orientation is for any point along the fall path, so you could apply a series of adjustments that might lend a smoother and more realistic motion.

Specific to that LSL function: For 10 in-between steps, set t equal to 0.1, 0.2, 0.3 etc., and use the resulting rotations along the path of motion. But don't use it on your door, unless you're simulating a door that falls off its hinges in an earthquake and needs to tumble to the ground to land at a precise 37 degree Z-rotation relative to the front patio ;)


edit: beaten by my own wordiness once again :o Nice explanation Dora.
_____________________
Designer of sensual, tasteful couple's animations - for residents who take their leisure time seriously. ;)

http://slurl.com/secondlife/Brownlee/203/110/109/

Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
01-17-2010 15:33
Thanks, Dora and Anti .. now I think I understand; between them the two examples make a lot of sense. The door, then, is -- as it were -- slerping without me having to do anything; the viewer knows to do it when it opens and shuts?
Astra Melody
Registered User
Join date: 5 Jan 2010
Posts: 10
01-17-2010 19:23
Anti is right the door is a bad example, not because the viewer can do it, but because there is a much simpler way to do it than using this, with llTargetOmega.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-17-2010 21:06
collision avoidance is another fun usage, though due to SL limitations it's rather short ranged and slow moving, you can do edge following, thread the needle, bounce reflection, smooth path cornering, tracking and a host of other operations.

and now I have an urge to model a zombie sim....
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -