Sign in to follow this  

How to do this transformation

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

Ok, I hope this is real easy for someone because it has'nt been for me. I want to rotate my whole vertexbuffer about the center of the screen. (I can do that) I want to then move the whole vertex buffer about the x, and y axis in corrdinate space, whitout rotating the x and y axis of coordinate space. (I can do that) I can't do them both at once.
device.Transform.World = Matrix.Multiply(Matrix.Translation(x, y, z), Matrix.RotationZ(angle))
' Rotates about 0,0,0, but X,Y doesn't stay static               
device.Transform.World = Matrix.Multiply(Matrix.RotationZ(angle), Matrix.Translation(x, y, z))
' X,Y stays static, but rotates about the center of the vertices.


What combination shall I use? Should I set up a temporary matrix equal to one of the above transformations and then put it on the left or the right of the another rotation or another translation matrix? I've tried that and it produces some weird results. I've looked in my math book, and unless I sludge through the whole matrix chapters a couple times, I doubt I'll figure it out.

Share this post


Link to post
Share on other sites
This should be fairly simple.

Assuming you dont know about matrices at all then here ya go.

1. Create a rotation matrix about the y axis like so

D3DXMATRIXA16 matRot;

// fill the matrix like so

D3DXMatrixRotationY( &matRot, /* rot amount in radians */ 1);

// apply toi the world matrix

l_pD3DDevice->SetTransform(D3DTS_WORLD, &matRot);




Share this post


Link to post
Share on other sites
Ok, maybe this is not clear.
I want to rotate about the z axis firstly. I want to rotate about 0,0,0. I want to move the whole vertex buffer up and down, left and right, about the x and y axis, while I am rotating. I do not want to transform the x and y axis, I want them to stay fixed.

If I do what you say, then it simply rotates it about the Y axis.
right right.. how it looks in VB Transposing Y for Z.

rotatematrix = Matrix.RotationZ(angle)
OuterSpace.device.SetTransform(TransformType.World, rotatematrix)

Thanks for trying!

Share this post


Link to post
Share on other sites
You're description isn't very clear.

You want to move up & down, left & right, whilst rotating around the Z axis... that's probably really easy but really difficult to picture with your description.

Is the effect you're looking for something like an orbit camera that seems to rotate around an arbitrary point in space?

Quote:
GreggBz: I want to rotate my whole vertexbuffer about the center of the screen. (I can do that) I want to then move the whole vertex buffer about the x, and y axis in corrdinate space, whitout rotating the x and y axis of coordinate space. (I can do that) I can't do them both at once.


So you wanna rotate to alter the angle you view the vertices at, then move it to another point in space.
Whats that about rotating your coordinate space? It seems like you simply need rotation and translation matrices and multiply them together in the correct order into a world matrix like you're code seems to be laid out to do.

Describe what visual effect you're looking for and i'll try to figure it out.

Andy

[edit]: fixed some typos[/edit]

Share this post


Link to post
Share on other sites
If you want to rotate by Z and then translate only by XY the 2nd line in your code should be:
device.Transform.World = Matrix.Multiply(Matrix.RotationZ(angle), Matrix.Translation(x, y, 0))
This should roll the vertices by Z and translate them by XY.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The Short Explanation:
Basically, the vehicle is located at the center of the screen while the world rotates around it.

The Long Explanation:
Imagine you have a map, pasted right in the middle
of the screen laying flat. When I hit the up arrow, the map goes straight down, at 180 deg, towards the bottom of the monitor.
When I hit the right arrow, the map goes left at 270 deg, towards the left of the monitor. etc..Now when I rotate it, put a pin in the center of the screen. Not the middle
of the map, but the middle of the screen. And rotate.
After I rotate it, I still want to be able to do the top part again. Still having it go straight down, left right ect.

I can do this with my 2d Move function, so that X, Y are calcuated outside of the matrix transformations, manually, i.e. x and y updating based on the angle of the vehicle relative to the world. Which, is really what I should do so nevermind... =)

BUT, there has to be a transformation that will do it instead. Based on an angle and then the amount
of displacement in whatever dirrection altered first.

I'm not lazy, this is just frustrating me as I thought I understood transformations, and I can't get it to work.

enigma1, that's what this does basically, see comment though.
device.Transform.World = Matrix.Multiply(Matrix.RotationZ(angle), Matrix.Translation(x, y, z))
' X,Y stays static, but rotates about the center of the map, (vb)

Thanks for any help folks,

Share this post


Link to post
Share on other sites
The key concept you might be missing is the order of multiplication. RotationMatrix*TranslationMatrix is not equal to TranslationMatrix*RotationMatrix.

From what you said, it sounds like you think "rotate around the WORLD origin, then move to some XY location" is different from "Move to some XY location, then rotate around the MODEL origin". Those are one in the same. The first one is easy to do: Final = Rotation*Translation. The second one is more complicated, and well to save space why even bother. :)

Check this site out:
Angelcode.com Tutorial

EDIT: I forgot to tell you what Tranlation*Rotation will give you. It will translate first, then rotate about the world origin, kinda like you pointed out in the example of rotating about the 0,0,0 point on the map. Obviously, this will make the object fly around a large circle at the radius of its offset with respect to that origin.

Good luck,
Chris

Share this post


Link to post
Share on other sites

This topic is 4837 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this