View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# What on earth is wrong with this really basic rotation?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

4 replies to this topic

### #1davepl1968  Members

Posted 14 August 2013 - 06:09 PM

I have a nice little fireworks demo running, and I thought for the heck of it I'd spin the "ball of particles" that comprises the fireworks.  To do this, I assumed that the steps were:

- Translate back to origin from where it lives in space

- Apply rotation matrices for X, Y, Z

- Translate back to where object lived in space

- Set that as the World matrix before drawing the object (leaving projection and view completely alone)

It does not work as I would expect (or at all, really).  It just jumps around a bunch but largely stays put (no rotation).  I'm placing that new world matrix into the shader before drawing the instance.  I know all that works, as it draws them without rotation exactly as I'd hoped.  It's just my application of rotation that has broken everything...

Either I've got a really ugly bug or a very poor grasp of how to compose such a matrix.  A prod in either direction would be very much appreciated!

D3DXMATRIX matrixTranslateBefore;
D3DXMATRIX matrixRotationX;
D3DXMATRIX matrixRotationY;
D3DXMATRIX matrixRotationZ;
D3DXMATRIX matrixTranslateAfter;

float rads = fElapsedTime * 50.0f;

D3DXMatrixTranslation(&matrixTranslateBefore,  -pExplosion->_centerPosition.x,
-pExplosion->_centerPosition.y, -pExplosion->_centerPosition.z);
D3DXMatrixTranslation(&matrixTranslateAfter, pExplosion->_centerPosition.x,
pExplosion->_centerPosition.y, pExplosion->_centerPosition.z);

pCameraManager->_worldMatrix = matrixTranslateBefore * matrixRotationX * matrixRotationY * matrixRotationZ * matrixTranslateAfter; 

### #2Bacterius  Members

Posted 14 August 2013 - 07:07 PM

How exactly are you using the world matrix in your shader? It may be you're doing it wrong there and this more complex transformation has revealed a bug.

Also, are you sure your centerPosition field is correct, have you checked it?

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

### #3stu_pidd_cow  Members

Posted 14 August 2013 - 10:19 PM

What is in matrixTranslateBefore? Is it just translation or is there scaling, rotation, etc? Just to test, you might want to try:

D3DXVECTOR4 pos(0.0f, 0.0f, 0.0f, 1.0f);
D3DXVec4Transform(&pos, &pos, &(matrixTranslateBefore * matrixTranslateAfter));
// pos should be (0.0f, 0.0f, 0.0f, 1.0f) after this


If matrixTranslateBefore is just a translation, why don't you just use pExplosion->_centerPosition to translate once?

Also, you could simplify this:

D3DXMATRIX matrixRotationX;
D3DXMATRIX matrixRotationY;
D3DXMATRIX matrixRotationZ;

float rads = fElapsedTime * 50.0f;



into this:

D3DXMATRIX matrixRotation;

float rads = fElapsedTime * 50.0f;



### #4fpsulli3  Members

Posted 15 August 2013 - 01:18 AM

50 radians per second is really fast. Have you tried doing something like 1.0 radian per second?

Are you sure you want to rotate on all three axes like that? The results can be pretty unpredictable. Have you tried rotating on just one axis to start?

I am not sure I understand why you want to pre-translate (matrixTranslateBefore). If your verts are defined in model space, then you shouldn't need to do this. In fact, it would make things look glitchy, because you'd be translating away from the origin, rotating, and then translating again. Unless you have a really good reason to do this, consider removing that pre-translation.

### #5cozzie  Members

Posted 15 August 2013 - 11:56 AM

Just to be sure, are you passing radians where expected, or maybe should you convert from 50 deg to rad first?

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.