Difference between revisions of "Interpolation/Cosine"

From Second Life Wiki
Jump to navigation Jump to search
m
(Page not needed anymore.)
 
Line 1: Line 1:
{{LSL Header|[[Interpolation]]}}
{{RightToc|clear:right;}}


== Cosine Interpolation ==
{|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #ffffff; border-collapse: collapse" width="80%"
!style="color: #000000; background-color: #aaaaff;" height="20px"|
===Float Cosine===
|-
|
Cosine interpolation of f0 and f1 with fraction t.
<lsl>
float fCos(float f0,float f1,float t) {
    float F = (1 - llCos(t*PI))/2;
    return f0*(1-F)+f1*F;
}
</lsl>
{|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #ffffff; border-collapse: collapse" width="80%"
|
{|cellspacing="0" cellpadding="6" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #e0e0ff; border-collapse: collapse"
!style="background-color: #d0d0ee" | Input
!style="background-color: #d0d0ee" | Description
|-
| float f0
| Start (t = 0.0)
|-
| float f1
| End (t = 1.0)
|-
| float t
| Fraction of interpolation
|-
!style="background-color: #d0d0ee" | Output
!style="background-color: #d0d0ee" | Description
|-
| return float fCos
| Returns cosine interpolation of two floats
|}
| [[Image:Interp_Chart2.png|center]]
|}
<div style="float:right;font-size: 80%;">
Released to Public Domain. By Nexii Malthus</div>
|}
{|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #ffffff; border-collapse: collapse" width="80%"
!style="color: #000000; background-color: #aaaaff;" height="20px"|
===Vector Cosine===
|-
|
Cosine interpolation of v0 and v1 with fraction t.
<lsl>
vector vCos(vector v0,vector v1,float t){
    float F = (1 - llCos(t*PI))/2;
    return v0*(1-F)+v1*F;}
</lsl>
{|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #ffffff; border-collapse: collapse" width="80%"
|
{|cellspacing="0" cellpadding="6" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #e0e0ff; border-collapse: collapse"
!style="background-color: #d0d0ee" | Input
!style="background-color: #d0d0ee" | Description
|-
| vector v0
| Start (t = 0.0)
|-
| vector v1
| End (t = 1.0)
|-
| float t
| Fraction of interpolation
|-
!style="background-color: #d0d0ee" | Output
!style="background-color: #d0d0ee" | Description
|-
| return vector vCos
| Returns cosine interpolation of two vectors
|}
| Graph goes here, k.
|}
<div style="float:right;font-size: 80%;">
Released to Public Domain. By Nexii Malthus</div>
|}
{|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #ffffff; border-collapse: collapse" width="80%"
!style="color: #000000; background-color: #aaaaff;" height="20px"|
===Rotation Cosine===
|-
|
Spherical Cosine interpolation of r0 and r1 with fraction t.
I liken to call it as '''SCORP'''
<lsl>
rotation rCos(rotation r0,rotation r1,float t){
    // Spherical-Cosine Interpolation
    float f = (1 - llCos(t*PI))/2;
    float ang = llAngleBetween(r0, r1);
    if( ang > PI) ang -= TWO_PI;
    return r0 * llAxisAngle2Rot( llRot2Axis(r1/r0)*r0, ang*f);}
</lsl>
{|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #ffffff; border-collapse: collapse" width="80%"
|
{|cellspacing="0" cellpadding="6" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #e0e0ff; border-collapse: collapse"
!style="background-color: #d0d0ee" | Input
!style="background-color: #d0d0ee" | Description
|-
| rotation r0
| Start (t = 0.0)
|-
| rotation r1
| End (t = 1.0)
|-
| float t
| Fraction of interpolation
|-
!style="background-color: #d0d0ee" | Output
!style="background-color: #d0d0ee" | Description
|-
| return rotation rCos
| Returns spherical cosine interpolation of two rotations
|}
| Graph goes here, k.
|}
<div style="float:right;font-size: 80%;">
Released to Public Domain. By Nexii Malthus</div>
|}
{|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #ffffff; border-collapse: collapse" width="80%"
!style="color: #000000; background-color: #aaaaff;" height="20px"|
===Rotation Cosine Aim===
|-
|
Spherical Cosine interpolation of r0 and r1 with speed regulation.
Does the entire animation loop to rotate between r0 to r1 up to peak speed, using the cosine interpolation it makes it appear to accelerate and decelerate realistically.
<lsl>
rCosAim( rotation r0, rotation r1, float speed ){
    float ang = llAngleBetween(r0, r1) * RAD_TO_DEG;
    if( ang > PI) ang -= TWO_PI;
    float x; float y = (ang/speed)/0.2;
    for( x = 0.0; x < y; x += 1.0 )
        llSetRot( rCos( r0, r1, x/y ) );
}
</lsl>
{|cellspacing="0" cellpadding="3" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #ffffff; border-collapse: collapse" width="80%"
|
{|cellspacing="0" cellpadding="6" border="1" style="border: 1px solid #aaaaaa; margin: 1em 1em 1em 0pt; background-color: #e0e0ff; border-collapse: collapse"
!style="background-color: #d0d0ee" | Input
!style="background-color: #d0d0ee" | Description
|-
| rotation r0
| Start
|-
| rotation r1
| End
|-
| float speed
| Degrees peak speed of rotation in animation
|-
!style="background-color: #d0d0ee" | Output
!style="background-color: #d0d0ee" | Description
|-
| return rotation rCos
| Creates a spherical cosine animation of two rotations with a specific peak speed
|-
!style="background-color: #eed0d0" colspan="2"| Requirement
|-
|style="background-color: #eed0d0" colspan="2"| function rotation rCos(rotation r0,rotation r1,float t)
|}
| Graph goes here, k.
|}
<div style="float:right;font-size: 80%;">
Released to Public Domain. By Nexii Malthus</div>
|}

Latest revision as of 03:47, 14 September 2011