
Advertisement
This topic is 3081 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.
If you intended to correct an error in the post then please contact us.
Recommended Posts
Advertisement
Daniel E 224
Thanks, that already helped a lot. The pitch part works good as far as i can tell.
I'm not sure about the roll though and how to compute it. I literally compute the difference between the values. The results look correct for the most part but sometimes
the birds rotate very strangly, which could be caused by my velocity computations though. Mind taking a look at the new code?
I'm not sure about the roll though and how to compute it. I literally compute the difference between the values. The results look correct for the most part but sometimes
the birds rotate very strangly, which could be caused by my velocity computations though. Mind taking a look at the new code?
void MhBird::move(D3DXVECTOR3 v)
{
static float lastYaw = 0;
setPos(*position + v); // translate worldmatrix
yaw = atan2(v.x, v.z);
float roll = yaw  lastYaw;
float pitch = atan2(v.y, sqrtf(v.x * v.x + v.z * v.z));
lastYaw = yaw;
D3DXMatrixRotationYawPitchRoll(&rotationmatrix, yaw, pitch, roll);
D3DXMatrixMultiply(&worldmatrix, &rotationmatrix, &worldmatrix);
}
0
Daniel E 224
i'm actually pleased enough with the results for a flock of little birds. so if you dont see totally obvious mistakes, consider this topic solved.
0
Daniel E 224
the above code wasn working well btw
here's something that works if you ever want to move some birds in a decent looking way:
(
">new video)here's something that works if you ever want to move some birds in a decent looking way:
(
void MhBird::move(D3DXVECTOR3 v)
{
float yaw = atan2(v.x, v.z);
float yawDelta = abs(yaw  lastYaw);
if(yawDelta > D3DX_PI)
float roll = (2.0f * D3DX_PI  yawDelta) * 5.0f; // 5.0f = roll factor, to do: calculate
else
float roll = yawDelta * 5.0f;
float pitch = atan2(v.y, sqrtf(v.x * v.x + v.z * v.z));
lastYaw = yaw;
D3DXMatrixTranslation( &worldmatrix, v.x, v.y, v.z);
D3DXMatrixRotationYawPitchRoll(&rotationmatrix, yaw, pitch, roll);
D3DXMatrixMultiply(&worldmatrix, &rotationmatrix, &worldmatrix);
}
0
Locutusborg 124
when adding pitch using the tangens formula, you have to be carefull. this works fine as long as you dont turn 180 degrees (otherwise, your left and right will change sides)
using quaternions can solve this.
following is C++
D3DXQUATERNION tmp; //makes quaternion
D3DXQuaternionRotationYawPitchRoll(&tmp, yaw, pitch, roll); //rotates quaternion (object)
D3DXMatrixRotationQuaternion(&tmp, &rotationmatrix); //make a matrix from a quaternion
now you have turned using a quaternion and you have your rotationmatrix back.
using quaternions can solve this.
following is C++
D3DXQUATERNION tmp; //makes quaternion
D3DXQuaternionRotationYawPitchRoll(&tmp, yaw, pitch, roll); //rotates quaternion (object)
D3DXMatrixRotationQuaternion(&tmp, &rotationmatrix); //make a matrix from a quaternion
now you have turned using a quaternion and you have your rotationmatrix back.
0
Daniel E 224
thanks! that took my birds to another level
0
Sign in to follow this
Followers
0

Advertisement
Share this post
Link to post
Share on other sites