I tried using a quaternion SLERP to update the vertices of a polygon and the problem I ran into is that as the polygon tries to rotate a full 360 it stretches along an axis, I think its the y-axis actually.
This is the polygon initially.
[attachment=19541:image2.png]
and this is what happens at about 45 degrees into the rotation (notice the polygon stretches towards the edge and actually escapes to the
corner).
[attachment=19540:image1.png]
I can post the code on pastebin if needed.
Here's an excerpt from the program, its the main call that updates the vertices which calls the SLERP function to interpolate 2 quaternions.
CVec3 RotatePoint( float t, CVec3 P1,
float angle_i, float angle_f,
int x1, int y1, int z1
, int x2, int y2, int z2)
{
CQuat QRot;
CQuat Q1( angle_i, CVec3( x1, y1, z1)); // Set by axis-angle
CQuat Q2( angle_f, CVec3( x2, y2, z2));
//QRot.Slerp( Q1, Q2, t, false);
QRot.QuaternionSlerp( Q1, Q2, t);
CMatrix M;
QRot.ToMatrix( M.mf);
return M*P1;
}
void calc_quaternion_verts( verts *c_verts, verts *s_verts,
int vertices_count, float t,
float angle_i, float angle_f,
int x1, int y1, int z1,
int x2, int y2, int z2)
{
CVec3 P1;
float new_x = 0.0f;
float new_y = 0.0f;
float new_z = 0.0f;
float x_center = (float)SCREEN_X / 2.0f;
float y_center = (float)SCREEN_Y / 2.0f;
for( int i = 0; i < vertices_count; i++)
{
P1.x = c_verts[i].vx;
P1.y = c_verts[i].vy;
P1.z = c_verts[i].vz;
//P1 = RotatePoint( t, P1, angle_i, angle_f, x1, 0.0f, 0.0f, x2, 0.0f, 0.0f);
//P1 = RotatePoint( t, P1, angle_i, angle_f, 0.0f, y1, 0.0f, 0.0f, y2, 0.0f);
//P1 = RotatePoint( t, P1, angle_i, angle_f, 0.0f, 0.0f, z1, 0.0f, 0.0f, z2);
P1 = RotatePoint( t, P1, angle_i, angle_f, x1, y1, z1, x2, y2, z2);
new_x = P1.x;
new_y = P1.y;
new_z = P1.z;
s_verts[i].vx = new_x + x_center;
s_verts[i].vy = new_y + y_center;
s_verts[i].vz = new_z;
}
}