dev.gamez.lv Forum Index dev.gamez.lv
Latvian Game Developers Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 

SLERP

 
dev.gamez.lv Forum Index -> Matemātika un fizika
View previous topic :: View next topic  
Author Message
Angel



Joined: 02 Jan 2005
Posts: 113
Location: Latvija

PostPosted: 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 Confused ):
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
View user's profile Send e-mail
Vecais_Dumais_Laacis
Guru
Guru


Joined: 29 Jan 2004
Posts: 800

PostPosted: Wed May 18, 2005 3:46 pm    Post subject:

http://number-none.com/product/Understanding%20Slerp,%20Then%20Not%20Using%20It/

ja pareizi saprotu tad slerp atgriezh poziiciju uz iisaakaa celja starp abiem Quaternioniem. poziiciju nosaka float t no 0 liidz 1.
_________________
...un ja bites buutu laachi...
Back to top
View user's profile
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: 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
View user's profile Send e-mail
Angel



Joined: 02 Jan 2005
Posts: 113
Location: Latvija

PostPosted: 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
View user's profile Send e-mail
bubu
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 23 Mar 2004
Posts: 3223
Location: Riga

PostPosted: 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
View user's profile Send e-mail
Display posts from previous:   
dev.gamez.lv Forum Index -> Matemātika un fizika All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group