Skip to main content
GameDev.net gamedev.net
🔒 Locked

Slerp

Started by tamlin Apr 21, 2003 at 9:26 PM 1 replies 1.2k views
Original Post
tamlin
tamlin
hi i''m using slerps to do homing missiles and turning gun turrets etc, and it''s working smashingly well except for two details. i''m using D3DX functions for matrices and quaternions, and the method consists of these steps: 1. create a lefthanded lookat-matrix involving the missile and the target - and get it''s transpose. 2. convert this matrix into a quaternion. 3. convert the orientation/rotation matrix for the missile to a quaternion. 4. perform a slerp making the direction of the missile to turn towards the target. the two problems i have ar the following: 1. in some positions the result of the slerp makes the missile kind of twitch and act strangely, and i suspect this has to do with the up-vector i use whencreating the lookat matrix. what vector should i use? 2. the slerp function in directx works with three parameters: two quaternions and a scalar telling the slerp how much of the interpolation to perform on a scale of 0.0f to 1.0f. my problem is that i want the speed of the interpolation to be absolute, not relative, i.e. i want it to turn a specific ammount of degrees per second. how do i do that? thanks for your time / tamlin
minorlogic
minorlogic
"1. in some positions the result of the slerp makes the missile kind of twitch and act strangely, and i suspect this has to do with the up-vector i use whencreating the lookat matrix. what vector should i use?"

Just Cross Product of dir and up must produce vector with not NULL length.

"2. the slerp function in directx works with three parameters: two quaternions and a scalar telling the slerp how much of the interpolation to perform on a scale of 0.0f to 1.0f. my problem is that i want the speed of the interpolation to be absolute, not relative, i.e. i want it to turn a specific ammount of degrees per second. how do i do that?"

You can calculate "angle between quaternoion" with their dot product and arccos.

Angle = acos( 2.0f * dot( q1, q2 ) );



minorlogic
minorlogic
And for turels you can use LERP instead of SLERP.

You will not see the diffrence


inline void QLerp( const quaternion& Q0, const quaternion& Q1,
float T, quaternion& r) {

quaternion q0(Q0);
quaternion q1(Q1);
float CosTheta = innerproduct(q0, q1);
//q0.x*q1.x + q0.y*q1.y + q0.z*q1.z + q0.w*q1.w;
if( CosTheta < 0){
T = -T;
q0.x += T*( q1.x + q0.x );
q0.y += T*( q1.y + q0.y );
q0.z += T*( q1.z + q0.z );
q0.w += T*( q1.w + q0.w );
}else{
q0.x += T*( q1.x - q0.x );
q0.y += T*( q1.y - q0.y );
q0.z += T*( q1.z - q0.z );
q0.w += T*( q1.w - q0.w );
}

float n = q0.x*q0.x + q0.y*q0.y + q0.z*q0.z + q0.w*q0.w;
// ASSERT( n > 0.01f );
float s = 1.0f/(float)sqrt( n );
r.x = q0.x*s; r.y = q0.y*s; r.z = q0.z*s; r.w = q0.w*s;

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.