Jump to content
  • Advertisement
Sign in to follow this  
Selendis

World and other transformations

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

Hey, guys, I'm starting to learn DirectX for fun, i've got some decent C++ afaik :-)

Basically, i'm drawing the triangle and rotating it through changing Worldview just like below.
indexv and indexh get their values in WindowProc, 0.05 for right or up arrow, -0.05 for left or down arrow, not really important.

The thing that is important is below - i got this matrix multiplication problem. Like if I'm doing the Commented way - everything works fine, but if I use this thing that is working right now - nothing really works. And i don't get it - it is essentially the same - the uncommented and the separated part below.


D3DXMatrixRotationX(&matRotateRes, 0.0);
D3DXMatrixRotationY(&matRotateResY, 0.0);
D3DXMatrixRotationX(&matRotateResX, 0.0);
D3DXMatrixRotationX(&matRotateIn, 0.0);

d3ddev->GetTransform(D3DTS_WORLD, &matRotateIn);

D3DXMatrixRotationX(&matRotateX, indexv);
indexv = 0.0;
D3DXMatrixRotationY(&matRotateY, indexh);
indexh = 0.0;
////////////////////////////////////////////////////////////////////////
D3DXMatrixMultiply(&matRotateResY, &matRotateIn, &matRotateY);
D3DXMatrixMultiply(&matRotateResX, &matRotateIn, &matRotateX);
D3DXMatrixMultiply(&matRotateRes, &matRotateResX, &matRotateResY);
d3ddev->SetTransform(D3DTS_WORLD, &matRotateRes);
////////////////////////////////////////////////////////////////////////
/*
D3DXMatrixMultiply(&matRotateRes, &matRotateY, &matRotateX);
D3DXMatrixMultiply(&matRotateResX, &matRotateIn, &matRotateRes); d3ddev->SetTransform(D3DTS_WORLD, &matRotateResX);



And my second question is about World and View transforms. Here I'm using World transform to "rotate my viewpoint" so-to-say. But i think that's the wrong way to do it because i probably should be rotating the Camera instead of displacing all the objects on the screen. Or is this the right way?
Generally, what should be used to achieve my purpose and alike?
And how does Projection view come into the game?

Thanks for responding.

Share this post


Link to post
Share on other sites
Advertisement
See the documentation for D3DXMatrixMultiply here.



D3DXMatrixMultiply(&matRotateResY, &matRotateIn, &matRotateY);
D3DXMatrixMultiply(&matRotateResX, &matRotateIn, &matRotateX);
D3DXMatrixMultiply(&matRotateRes, &matRotateResX, &matRotateResY);
d3ddev->SetTransform(D3DTS_WORLD, &matRotateRes);




This will set D3DTS_WORLD = matRotateIn * matRotateX * matRotateIn * matRotateY. This sounds somewhat wrong, since you're multiplying the matRotateIn matrix twice there.







D3DXMatrixMultiply(&matRotateRes, &matRotateY, &matRotateX);
D3DXMatrixMultiply(&matRotateResX, &matRotateIn, &matRotateRes);

d3ddev->SetTransform(D3DTS_WORLD, &matRotateResX);






This will set D3DTS_WORLD = matRotateIn * matRotateY * matRotateX.



And my second question is about World and View transforms. Here I'm using World transform to "rotate my viewpoint" so-to-say. But i think that's the wrong way to do it because i probably should be rotating the Camera instead of displacing all the objects on the screen. Or is this the right way?
Generally, what should be used to achieve my purpose and alike?
And how does Projection view come into the game?



This is indeed about whatever you are trying to achieve. Setting the World transform changes the orientation of the rendered object in the scene. Setting the View transform specifies the (inverse of the) coordinate frame of the camera in the scene. Setting the Projection matrix specifies the properties of the camera, e.g. field-of-view and aspect ratio, see D3DXMatrixPerspectiveFovLH for example.

Share this post


Link to post
Share on other sites
Just a suggestion, there's overloaded multiplication operator, it might make more sense what's going on when using it rather than functions. For example:
D3DXMatrixMultiply(&matRotateRes, &matRotateResX, &matRotateResY); // is equivalent to the line below
matRotateRes = (matRotateIn * matRotateX) * (matRotateIn * matRotateY);

Are you sure you need to multiply by matRotateIn twice?
If I understood correctly, you get previous world matrix, and want to rotate it? If yes, then it looks quite simply:
matRotate = matRotateIn * matRotateX * matRotateY;

When you multiply transformations, left most transformation will be applied first, and right most will be applied last, for example:
world = RotationX * RotationY * Translation; // first it'll rotate around X axis, then around Y axis, and finally move vertices to other place
You can quickly notice that different order will result in very different effect:
world = Translation * RotationX * RotationY; // first move vertices and only then rotate

Usually World Matrix is used to define object's or mesh's scaling, rotation and translation (for example house is upside down in the sky, not at the center of the world)
View Matrix is used to define camera; it's position and where it's looking at (see: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205342(v=VS.85).aspx )
Projection matrix just defines ratio of your backbuffer's width & height and Z planes (see: http://msdn.microsoft.com/en-us/library/windows/desktop/bb205350(v=VS.85).aspx )
Therefore, usually in shader vertex position is calculated these 3 matrices:
screen_position = vertex_position * (world * view * projection);

Hopefully this helps (and hopefully I'm correct)

Share this post


Link to post
Share on other sites
Oh, this is genius guys, i should've not multiplied two times. smile.gif

I just got lazy and never looked into the matrices - i'd see that.

Thanks for the overloaded multiplication - i seriously thought about implementing matrix multiplication just to be sure smile.gif

About those views - yes, i know what they do, it's just that i wanna know how it should be done in this case - like if you got 20 separate visible objects, don't you have to call DrawPrimitive like 20 times after displacing each object according to like 5-degree camera turn? And with D3DTS_VIEW you would just move the camera!

Or am I misinterpreting the role of D3DTS_WORLD ?

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!