Jump to content
  • Advertisement
Sign in to follow this  
Gelroth

Object Translation Problem

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

Hi everyone. I have an 2 object in 0,0,0 and 25,0,0 coordinates but as you see in the picture http://img366.imageshack.us/img366/162/translationmj6.jpg first one is at right coordinates but second one is not at right coordinates it says 17 (by the way this is x coordinate of ball). D3DXMatrixTranslation(&matTranslate_Origin,0,0,0); D3DXMatrixTranslation(&matTranslate_Test,25,0,0); d3ddev->SetTransform(D3DTS_WORLD,&(matTranslate_Origin * matScale_Can)); d3ddev->SetTexture(0,Wood); meshCoke->DrawSubset(0); meshCoke->DrawSubset(1); d3ddev->SetTransform(D3DTS_WORLD,&(matTranslate_Test *matScale_Can)); d3ddev->SetTexture(0,Metal); meshCoke->DrawSubset(0); meshCoke->DrawSubset(1); How can i solve this problem?

Share this post


Link to post
Share on other sites
Advertisement
First, which two objects are you talking about? I see 4 objects in that picture.

Second, what do you mean by "it says 17"? what says that?

Share this post


Link to post
Share on other sites
i am talking about coke cans not the box or ball.
look at the left top side of the screen you will see a number it is x position of ball.

Share this post


Link to post
Share on other sites
Do Scale * Translation, not the other way around. Otherwise you won't end up translating to the position you want (same with rotation).

Share this post


Link to post
Share on other sites
Assume e.g. that the object's mesh has to vertices, one on the left and one on the right:
v1 = [ -1 0 0 ]
v2 = [ +1 0 0 ]
Scaling the mesh by a factor s yields in
v1' := [ -s 0 0 ]
v2' := [ +s 0 0 ]
Now translating the result (!) by [ t 0 0 ] yields in
v1" := [ -s+t 0 0 ]
v2" := [ +s+t 0 0 ]

Using the other order, the translation yields in
v1' := [ -1+t 0 0 ]
v2' := [ +1+t 0 0 ]
and the sub-sequent scaling yields in
v1" := [ -s+t*s 0 0 ]
v2" := [ +s+t*s 0 0 ]
what is obviously not the same as the result above.

The mathematical reason is that matrix multiplication isn't commutative:
M1 * M2 != M2 * M1

To have the lowest impact of a transformation onto the other, often the sequence scaling - rotation - translation is used. In D3D, where row vectors are used, the sequence would be computed by
matrix = scalingMatrix * rotationMatrix * translationMatrix

Rotation doesn't play a role in the OP's case, hence it can be replaced by the identity matrix. The simplified result is then
matrix = scalingMatrix * translationMatrix

Share this post


Link to post
Share on other sites
Transformations happen in the order you apply the multiplications of the matrices. This means when you do Scale * Translation, the vertices of the mesh are all scaled first and then translated. Usually this is the desired behavior, as it makes the mesh sized the way you want it but only moves it by the amount specified. For example say the mesh is centered about <0,0,0> in object space: you'd expect that if you translate by <10,0,0> the center of the mesh would end up at <10,0,0>. This happens if you scale first: scaling <0,0,0> by a factor of <2,2,2> gives you <0,0,0>, which means adding <10,0,0> results in a position of <10,0,0>. However if you translate first you get <10,0,0>, which when multiplied by the scale gets you <20,0,0> (which isn't what you wanted).

This is fairly basic material for 3D graphics, and is something you'll want to be familiar with before getting deep into using D3D. You may want to check out the SDK documentation on the subject or perhaps consult a book or some other learning reference.

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!