Jump to content
  • Advertisement
Sign in to follow this  
DefCom

Object Rotation - Yaw, Pitch and Roll - Help

This topic is 2927 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

First, many apologies for asking a question that seems to have been asked many times, but after days of searching and expermenting i do not seem to be getting anywhere.

I am like many trying to create aeroplane style rotation. The ability to bank(roll) and then change the pitch of the craft, using the new Y axis which of course is no longer straight up

My original code is as follows

D3DXMatrixScaling(&matScale, bike.vScl.x, bike.vScl.y, bike.vScl.z);
D3DXMatrixTranslation(&matWorld, bike.vLoc.x, bike.vLoc.y, bike.vLoc.z);
D3DXMatrixRotationX( &matRotateX, bike.vR.x );
D3DXMatrixRotationY( &matRotateY, bike.vR.y );
D3DXMatrixRotationZ( &matRotateZ, bike.vR.z );
D3DXMatrixMultiply( &matWorld, &matWorld, &matScale);
D3DXMatrixMultiply( &matTemp, &matRotateX, &matRotateY );
D3DXMatrixMultiply( &matTemp, &matRotateZ, &matTemp );
D3DXMatrixMultiply( &matWorld, &matTemp, &matWorld );
bike.setMatLocal(matWorld);



I have tried quite a few things, but many resources seem to focus on the 'camera'
i assume(hoping) i could just tranform the Y axis and it would all work quite happily.

If anybody could point me in the right direction (no pun intended) it would be appreciated.
Thanks.

Share this post


Link to post
Share on other sites
Advertisement
You can try changing around the order of rotations to see if you can get something closer to what you're wanting, but for true relative motion, you may want to switch to a fully 6DOF control system using relative incremental rotations. (This has been discussed frequently - recently, even - so a search for '6dof' will likely turn up some useful references.)

Share this post


Link to post
Share on other sites
Hi,
Thanks for the response.

I have researched the 6 DOF. Everything i come across discuses this in the context of the camera and the view matrix. I have applied many methods pinched off the net and I have tried simple switching the order of matrix multiplication.

I want to be able to turn the user input pitch and roll and have it control the object, as you would in a RC model plane simulator. For the sake of keeping it simple, the camera will remain static.

If I am right in saying I want the roll to change the 'up' vector (?)
And the pitch would change 'right' (?)
I don't actually know how to transform them ...

Am I going about this all wrong?
Any further help would be greatly appreciated , thank you

Share this post


Link to post
Share on other sites
Quote:
I have researched the 6 DOF. Everything i come across discuses this in the context of the camera and the view matrix.
Control schemes and camera/view transforms are orthogonal issues. 6DOF motion doesn't have anything in particular to do with cameras, and isn't specifically tied to cameras or view transforms in any way. I'm guessing whatever you were reading just happened to be discussing both of these topics at the same time, but they're not interrelated in any way.
Quote:
I want to be able to turn the user input pitch and roll and have it control the object, as you would in a RC model plane simulator. For the sake of keeping it simple, the camera will remain static.
Do you want pitch and roll only? Or do you want yaw also?
Quote:
If I am right in saying I want the roll to change the 'up' vector (?)
And the pitch would change 'right' (?)
I don't actually know how to transform them ...
Do you want the rotations always to occur about the object's local axes, regardless of how it's oriented? If so, there's a variety of ways to accomplish this, one of which is to rotate the direction vectors manually similar to what you describe and then reorthonormalize. (Not really the most direct way to do it, but it does work.) Not sure if you have all the details exactly right, but in general, yes, when you apply a rotation about one of the axes, the other two direction vectors will need to be rotated accordingly.

Share this post


Link to post
Share on other sites
Hi, Thanks again for the reply.

I am not too bothered about yaw at this time, the game is to be controlled by a single stick.

I have spent the past couple of days reading and experimenting, still no further.

I have a cerated a simple 3d enviroment using only Win32 GDI in the hope i can fully grasp what is going on without code being hidden in DirectX functions and data structures.

ermm.. what's reorthonormalize?

And i don't know how to rotate the other vectors accordingly.

I can rotate objects all dimension, just do not know how to take into account that the local Y axis is now different to the World Y axis.

Thans again.

Share this post


Link to post
Share on other sites
To orthogonalize a matrix or orthonormalize a set of basis vectors is to make the basis vectors unit-length and mutually perpendicular.

As for the problems you're running into implementing 6DOF motion, I'm not sure what I could say that hasn't been covered in the many other threads on the topic, but if you have some specific code that's causing you problems, maybe you could post it.

Share this post


Link to post
Share on other sites
Thanks for the help so far.
After much reading and tinkering i have the rotation working as desired, but now... i do not know how to move in the correct direction :(

so story so far...


Quaternion tQ1, tQ2, tQ3;
Quaternion rotChange;

tQ1.CreateFromAxisAngle(1,0,0, pitch); //pitch (i think....)
tQ2.CreateFromAxisAngle(0,1,0, yaw); //roll
tQ3.CreateFromAxisAngle(0,0,1, -roll); //yaw
rotChange= tQ1 * tQ2 * tQ3;
planeRot = rotChange * planeRot;

//covert my matrix to d3dxmatrix
createD3DXMATRIX(matWorld, planeRot);
aeroplane.setMatLocal(matWorld);



Up until now all my 3d projects have usually moved in 2d only.

Again any help pointing me in the right direction of how to get my object moving would be much appeciated.

I have tried this based on a few articles and forums.


Quaternion addVector, invVector;
addVector.x=-1;
addVector.y=0;
addVector.z=0;
addVector.w=0;

invVector.x=-planeRot.x;
invVector.y=-planeRot.y;
invVector.z=-planeRot.z;
invVector.w=0;

addVector=planeRot * addVector * invVector;

aeroplane.vLoc.x+=addVector.x;
aeroplane.vLoc.y+=addVector.y;
aeroplane.vLoc.z+=addVector.z;



Which does move the object, but not as desired.

Share this post


Link to post
Share on other sites
I didn't look at your code, but here's the short answer. Presumably, you have the orientation in matrix form, or can convert the orientation to matrix form. Assuming the object is axis-aligned in local space (as is typical), the direction vectors for the object will be the first three rows or columns of the transform matrix (depending on convention). You can use these direction vectors to move the object forward and backward, left and right, etc.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!