Jump to content
  • Advertisement
Sign in to follow this  
calidev234

Mesh Rotate?

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

I’m having difficulties understanding D3DXMatrixRotationAxis. I have a room mesh that I create and in that I place 3rd party mesh files. In order to place them (the 3rd party mesh files) in the correct place I have to transpose them and adjust the scale (so that they are the correct size). Also, I’m finding that many of them are not facing upwards (as my world is defined). So I’m trying to rotate them; but I’m not able to get them straight upwards. So for example I have a room and I want to drop a floor lamp on there; the lamp is completely PARALLEL with the floor and I need it to be PERPENDICULAR. Anyway in my main loop I do the following:
//Scales the object to the correct size
D3DXMATRIXA16 mScale;
D3DXMatrixScaling( &mScale, model->Scale, model->Scale, model->Scale);
D3DXMatrixMultiply( &mW, &mW, &mScale );
//d3ddev->SetTransform(D3DTS_WORLD, &mW);

//Transpose (puts the 3rd party mesh file in the correct spot in the room)
D3DXMATRIXA16 mTrans;
D3DXMatrixTranslation( &mTrans, model->OffX, model->OffY, model->OffZ );
D3DXMatrixMultiply( &mW, &mW, &mTrans );
d3ddev->SetTransform(D3DTS_WORLD, &mW);

//Rotation (around a point) (this part doesn't work well; the orientation of the object is never really good - I can never get it to be perpendicular to the floor;
D3DXMATRIXA16 mRot;
//D3DXMatrixRotationY(&mRot, 180); (I tried this; but this doesn't work)
D3DXVECTOR3 vRot(model->OffX, model->OffY, model->OffZ);
D3DXMatrixRotationAxis(&mRot, &vRot, model->Rotate);
D3DXMatrixMultiply( &mW, &mW, &mRot );
d3ddev->SetTransform(D3DTS_WORLD, &mW);

I’m trying to use the D3DXMatrixRotationAxis, but this does not seem to work. Does anybody have any ideas? I’ve tried the D3DXMatrixRotationX (Y AND X) but this doesn’t work; because I’ve already relocated the 3rd party mesh file into the correct place and then when I try the D3DXMatrixRotationX it rotates it around the X axis and puts the object in a way different spot. I would be greatly appreciated if anybody has any ideas. Thank you. (for a complete code sample look at my last post). Thank you very much, J

Share this post


Link to post
Share on other sites
Advertisement
The reason that the rotation of the mesh puts it in a completely wrong spot is because of the order of your matrix multiplication.

See my first post here about how to solve your problems.

Hope thats helped!

ace

Share this post


Link to post
Share on other sites
Also, just some additional ideas:

If you don't know what gimbal lock (some say gimble lock) is, you should read up on that. It might be the next stumbling block you have using the D3DX matrix rotation functions.

I would suggest hard coding the vertices when you load them or open them up in an editor and modify and save to the proper scale, position, and rotation. Anytime you can cut a SetTransform call out of the loop, you should.

One way you could accomplish this is to make an editor. In that editor, you save a data file for each mesh. In this data file, you list the mesh filename, the initial scaling, the rotations, and the position. When you load the mesh on startup, lock the vertices, then apply the transforms to all vertices. You could go even further and lock all the vertices, determine their bounding area (max/min x,y,z values) and scale it right there to be the "height" listed in the data file. i.e. a tree is 20 feet, but a bench is 3 feet. You state that each unit in your world space is 2 feet and so you would scale the tree (uniformly) to 20 feet and the bench to 2 feet.

Share this post


Link to post
Share on other sites
Thank you. So the problem was solved by ace's suggestion as well as me correcting a stupid error that I was making. So the code looks like this:


//Scale
D3DXMATRIXA16 mScale;
D3DXMatrixScaling( &mScale, model->Scale, model->Scale, model->Scale);
D3DXMatrixMultiply( &mW, &mW, &mScale );
//d3ddev->SetTransform(D3DTS_WORLD, &mW);

//Rotation (around a point)
D3DXMATRIXA16 mRot;
D3DXMatrixRotationYawPitchRoll(&mRot, 0, 1.57, 0);
D3DXMatrixMultiply( &mW, &mW, &mRot );
d3ddev->SetTransform(D3DTS_WORLD, &mW);


//Transpose
D3DXMATRIXA16 mTrans;
D3DXMatrixTranslation( &mTrans, model->OffX, model->OffY, 20 );
D3DXMatrixMultiply( &mW, &mW, &mTrans );
d3ddev->SetTransform(D3DTS_WORLD, &mW);



The major change was to use 1.57 (or pi/2) radians instead of 90 degrees. The function states that you have to use radians; but I overlooked that. So this works fine now. Thank you all very much.

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!