• Advertisement

Archived

This topic is now archived and is closed to further replies.

Why is the model shaking like so?

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

Hello everyone. I am rotating a mesh using quaternions, but whenever I try to rotate up/down (pitch), the model starts shaking uncontrollably. I looked this up on the forums, and it said somewhere that is was a precision issue, but I cant seem to be able to fix it. Just ask and I will email you the project (not very big at all), to see if you (the potential problem solver) can see if anything is wrong. Also, it seems that there are lines running down the screen, and I dont know where thats coming from either. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Well, I still dont know how to fix the shaking thing, but I have found the potential problem for the lines running down across the model. For some reason, I have to turn off lighting to see the model, and since I am disabling it each frame, maybe its doing something. Again, I am ready to email the source ( no more than 500 lines, most of it initialization for DirectInput ) or the executable.

Share this post


Link to post
Share on other sites
g_pD3DDevice->SetRenderState( D3DRS_HIGHVOLTAGE, false );

I''m sorry, couldn''t resist

But seriously, why disable lighting each frame? Or did I misunderstand what you meant?

I often found when my models went nuts during rotation is the angles were either wrong (ie needed converting to radians from degrees (D3DXToRadian()/D3DXToDegree(), or something was going awry causing it to flicker or spin so fast it looked like it was flickering or shaking. If it only does it with pitch, it may be worth double checking the value and what may influence it each frame.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Try the usual suspects.

- Are you resetting the world/view matrices correctly between frames now that you''re rotating things.
- Is your quaternion normalized?
- Radians.. Mmmm....

And regarding the lighting comment, remember that all D3D render states are persistent. That is, the renderer does not know about the concept of a frame, so when you set something, you should be positive to reset it back (or if you don''t, at least don''t make any assumptions on the next frame about render states before you start drawing - i.e. set them all).


TLC

Share this post


Link to post
Share on other sites
Hmmm....lets see...well for one, how should I be resetting the matrices every frame? No, my quaternion is not normalized (is there even a function? I couldnt find one...) Pretty much, this is what the rotation code looks like:

  
D3DXQUATERNION qR;

D3DXMatrixTranslation (&m_matT, m_vT.x, m_vT.y, m_vT.z);
D3DXMatrixMultiply (&m_matLocal, &m_matT, &m_matLocal);
D3DXQuaternionRotationYawPitchRoll (&qR, m_vR.x, m_vR.y, m_vR.z);
D3DXMatrixRotationQuaternion (&m_matR, &qR);
D3DXMatrixMultiply (&m_matLocal, &m_matR, &m_matLocal);
D3DXMatrixInverse (&m_matLocal, NULL, &m_matLocal);

Share this post


Link to post
Share on other sites
Well, apparently I am doing everything wrong here. Could anybody show me the correct way to use quaternions, and how they should be initialized? thanks.

Share this post


Link to post
Share on other sites
I had the same problem, once it was pointing up then move to the side, it starts freaking out!!! it was kind of cool, I could controll it so it looked like a hologram

The problem was I was ADDING the quats when you are supost to MULTIPLY them. If you also use just the D3DX library it will be ok

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Umm... why the inverse?

TLC

P.S. It might help if you just post the entire frame function (minus the drawPrimitive calls). We need to see what you''re setting the DTS_WORLD, VIEW and PROJECTION to.. etc.


Share this post


Link to post
Share on other sites
Well, I got it to work -- sort of. The rotation seems to work fine with with this code:

  

D3DXMATRIX matR, matT, matTemp;
D3DXQUATERNION qR;
D3DXMatrixTranslation (&matT, vT.x, vT.y, vT.z);
D3DXMatrixMultiply (&matTemp, &matT, &matTemp);
D3DXQuaternionRotationYawPitchRoll (&qR, vR.x, vR.y, vR.z);
D3DXMatrixRotationQuaternion (&matR, &qR);
D3DXMatrixMultiply (&matTemp, &matR, &matT);
D3DXMatrixInverse (&matTemp, NULL, &matTemp);

pd3dDevice->SetTransform( D3DTS_WORLD, &matTemp );


However, lets say I move up 5 units. Then, for instance, when I try to roll, It trys to roll taking in the fact that I moved up 5 units, so when I roll, it rolls in a big cirlce with a radius of 5. I just want it to make a tight circle with a radius of zero. I know what I said probably doesnt make sense, but if it does, any help would be appreciated. Thanks

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Sheep,

First, a minor quibble: drop the first D3DXMatrixMultiply. It''s doing nothing and confounds the code.

Second, and the cause of it all: the inverse is still in there. That''s what''s causing the translation to be applied (in some coupled form) before rotation. Thus, the model to seemingly rotates off-axis.

Also, what I believe you want is to move your viewpoint. For that, you should change the VIEW matrix, not the world matrix. Not really necessary at this stage (when you get rid of that inverse) but useful to get into the habit of when you start putting in more objects.

I suggest that you look through the forums for book reviews for learning 3D graphics.

My recommendation is to start with the OpenGL red-book as that covers the basics of graphics in a easy to understand fashion, more so than any DirectX book I''ve seen so far. Don''t be afraid to get a book because you''re not going learn 3d graphics in any effective manner doing the plug-and-chug.

I wish you luck Sheep but please pick up a good graphics book. A lot of this can be avoided if you do.


TLC

Share this post


Link to post
Share on other sites

  • Advertisement