Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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.

  • You cannot reply to this topic
4 replies to this topic

#1 davepl1968   Members   -  Reputation: 166

Like
2Likes
Like

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);
D3DXMatrixRotationX(&matrixRotationX, rads);
D3DXMatrixRotationY(&matrixRotationY, rads);
D3DXMatrixRotationZ(&matrixRotationZ, rads);
D3DXMatrixTranslation(&matrixTranslateAfter, pExplosion->_centerPosition.x,
pExplosion->_centerPosition.y, pExplosion->_centerPosition.z);

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

 



Sponsor:

#2 Bacterius   Crossbones+   -  Reputation: 9262

Like
1Likes
Like

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? 


The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#3 stu_pidd_cow   Crossbones+   -  Reputation: 2027

Like
0Likes
Like

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;

D3DXMatrixRotationX(&matrixRotationX, rads);
D3DXMatrixRotationY(&matrixRotationY, rads);
D3DXMatrixRotationZ(&matrixRotationZ, rads);

into this:

D3DXMATRIX matrixRotation;

float rads = fElapsedTime * 50.0f;

D3DXMatrixRotationYawPitchRoll(&matrixRotation, rads, rads, rads);


#4 CDProp   Members   -  Reputation: 1045

Like
0Likes
Like

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.



#5 cozzie   Members   -  Reputation: 1758

Like
0Likes
Like

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?




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.



PARTNERS