View previous topic :: View next topic |
Author |
Message |
Angel
Joined: 02 Jan 2005 Posts: 113 Location: Latvija
|
Posted: Wed May 18, 2005 3:36 pm Post subject: SLERP |
|
Varbuut izklausaas mazliet stulbi, bet ko dara shis zveers (paskaidrojiet latviski un cilveekiem saprotamaa valodaa ):
Code: | void Slerp(const CQuaternion &q1, const CQuaternion &q2, float t)
{
float cosTheta = 0.0f;
float sinTheta = 0.0f;
float beta = 0.0f;
float q2Array[4];
// Temporary array to hold second quaternion.
q2Array[0] = q2.x; q2Array[1] = q2.y; q2Array[2] = q2.z; q2Array[3] = q2.w;
cosTheta = q1.x * q2.x + q1.y * q2.y + q1.z * q2.z + q1.w * q2.w;
if(cosTheta < 0.0f)
{
// Flip sigh if so.
q2Array[0] = -q2Array[0]; q2Array[1] = -q2Array[1];
q2Array[2] = -q2Array[2]; q2Array[3] = -q2Array[3];
cosTheta = -cosTheta;
}
beta = 1.0f - t;
if(1.0f - cosTheta > 0.001f)
{
// We are using spherical interpolation.
cosTheta = (float)acos(cosTheta);
sinTheta = 1.0f / (float)sin(cosTheta);
beta = (float)sin(cosTheta * beta) * sinTheta;
t = (float)sin(cosTheta * t) * sinTheta;
}
// Interpolation.
x = beta * q1.x + t * q2Array[0];
y = beta * q1.y + t * q2Array[1];
z = beta * q1.z + t * q2Array[2];
w = beta * q1.w + t * q2Array[3];
} |
P.S Pie klases CQuaterion pieder float x,y,z,w; |
|
Back to top |
|
|
Vecais_Dumais_Laacis Guru
Joined: 29 Jan 2004 Posts: 800
|
|
Back to top |
|
|
bubu Indago Uzvarētājs
Joined: 23 Mar 2004 Posts: 3223 Location: Riga
|
Posted: Wed May 18, 2005 3:47 pm Post subject: |
|
Šitais veic sfērisko interpolāciju, starp q1 un q2. (kautkas pēc idejas līdzīgs lineārai interpolācijai starp diviem punktiem pa taisni, tikai pa sfēras virsmu)
Lineārai interpolācijai (tb īsākais ceļš pa taisni) formula būtu šitāda: q = (1-t)*q1 + t*q2 (tātad, pie t=0 - q=q1, bet pie t=1 - q=q2)
Bet sfēriskai interpolācijai (īsākais ceļš pa sfēras virsmu) formula ir šāda: q = (q1*sin(phi*(1-t)) + q2*sin(phi*t))/sin(phi), kur phi = arccos(q1.q2) (leņķis starp q1, q2). |
|
Back to top |
|
|
Angel
Joined: 02 Jan 2005 Posts: 113 Location: Latvija
|
Posted: Wed May 18, 2005 7:59 pm Post subject: |
|
Ja shis ir aplis..............Tad shis buus tas slerp?:
.......______............................x1_
...../..............\...............................\
../....................\...............................\
|........................|...............................|
|........................|...............................|
..\..................../.............................../
.....\............../...............................x2
.......--------
.................................Paarvitojums no x1 uz x2? |
|
Back to top |
|
|
bubu Indago Uzvarētājs
Joined: 23 Mar 2004 Posts: 3223 Location: Riga
|
Posted: Wed May 18, 2005 9:52 pm Post subject: |
|
Tieši tā. Ja būtu tikai LERP, tad iznāktu gandrīz vertikāla taisne, nevis loks. |
|
Back to top |
|
|
|