I have a few questions about this
device.Transform.view = Matrix would set the camera for the rendering screen
and
device.Transform.World = Matrix would place the mesh object into the world space right
if all the above is correct what would be the best matrix seting for turning a mesh and placing it into a set location on the screen

understanding view/world matrix
Ömer KAYA
thanks a ton for clearing this up for me
Steve Wright
i suppose the "D3DXMATRIX" isn't identical to the Microsoft.Directx.Matrix structure
James.Zhang - MSFT
There's one thing on my mind though.
I'm trying to do a top-down type of view, just a test project... it has some polygons that move around towards the mouse.
I've tried using matrixes to move the polys around, by doing Translate*Rotates I've been able to get the objects move quite nicely towards the mouse... but there is just a small problem: The polys ALWAYS seem to use 0,0,0 as the center of their rotation!
Is it possible to rotate something with matrixes so that it rotates around some other point than 0 0 0 There are not enough examples around of matrix stuff
phoy
Bhaskar Reddy
Yes, this is possible.
Matrix math takes a little getting used to but its not so bad once you understand the basic ideas. It has to do with coordinate systems. Say you have a square like this (please forgive my terrible attempt at ASCII art):
0,0--------------------->
| (100,100)
| -----
| | |
| |____|
| (200,200)
|
V
The square is defined relative to the origin of the screen. The coordinates of the square are saying "move 100 units along the x axis and move 100 units along the y axis, then start drawing the square". So the "coordinate system" that the square lives in is the screen. All matrix operations happen relative to the coordinate system that the object is defined in. In this case, the square is defined in the coordinate system of the screen. So if you rotate this square, you will rotate it relative to its screen-space coordinate system.
If you would like to rotate the square relative to the middle of itself, you have to peroform "a change in coordinate system." So say you wanted to rotate the square about its center (150,150). What you would do is translate the center of the square to the origin, rotate however much you want, and then translate back to your starting position:
[source]
D3DXMATRIX matTranslate, matRotate, matFinal;
D3DXMatrixTranslation( &matTranslate, -150.0f, -150.0f, 0.0f );
D3DXMatrixRotation....
D3DXMatrixTranslation( &matFinal, 150.0f, 150.0f, 0.0f );
matFinal = matTranslate * matRotate * matFinal;
[/source]
A slightly less expensive way of doing this is to define all of your squares assuming their centers are at 0,0. That would mean that the square in the above example would have min/max extents of (-50,-50) and (50, 50), respectively. You could then rotate and place this square where you need it to go like this:
[source]
D3DXMATRIX matRotate, matFinal;
D3DXMatrixRotation....
D3DXMatrixTranslation( &matFinal, 150.0f, 150.0f, 0.0f );
matFinal = matRotate * matFinal;
[/source]
In this case, you avoid having to translate back to the origin because your square is already defined assuming the center of it is the origin. This gives the added benefit that if you wanted another square somewhere else on the screen, you don't have to create a new one; you could just use the same one you have and translate it to another part of the screen by changing the D3DXMatrixTranslation call.
Hope this helps,
Francisco
Wisc
You probably need to think of the world matrix as being a way for you place and construct all the pieces of your world - irrespective of what you can actually see.
The view matrix then determines how you look into this world - which parts are in front, to the left, to the right or behind you.
The projection matrix then determines how much you can actually see (and any perspective operations).
Factors such as "Field Of View" (FOV) and the "Near Z" and "Far Z" values (in the projection matrix) combine with the position/orientation of the camera (defined by the view matrix) to describe, mathematically, a box ("Frustum") such that any objects inside the box become visible and any objects outside the box are invisible.
So, to go back to your original question...
You need to use the world matrix to position/rotate/scale your mesh, but it is the view matrix that will make the biggest difference as to where it actually appears on the screen... If your camera is looking directly at your mesh then it'll appear in the center of the final image for example.
If you're wanting to line your mesh up with a particular part of the screen (say always in the top-left of your image) that can be a lot more challenging ;-)
hth
Jack
binglehopper
That's not quite how it works... the view matrix defines the center of the screen. That is, whatever you put in as the "at" vector when constructing your view matrix will be at the middle of the screen, so if your mesh was placed at the same position as the "at" vector, it would be in the middle of the screen.
By "set locations" do you mean in 'screen space' That is, you want to set your mesh so that it is drawn at (100,100) - the top left of your display
If so, you will need to do a bit of maths in order to get it correct. You need to know the boundary (e.g. is it to appear 50 pixels wide and 50 pixels tall) as well as the center (e.g. at 100,100). Using the D3DX functions you can project a ray from the screen into world space. You then need to manipulate your mesh (via the World matrix) to be at a point on that line. If you use an orthogonal projection matrix *where* on that line doesn't matter, if you're using a regular perspective matrix then the mesh will be smaller the further along that line you place it.
It is, mathematically, the equivalent of doing everything backwards
Normally you'd go World -> View -> Projection -> Screen. But (assuming I'm not misinterpretting your post) you would be saying "I know the screen-space coordinates, and I need to know the world space coordinates" which is actually Screen -> Projection -> View -> World...
If I have interpretted what you're doing wrong, and you *dont* need to line it up pixel-perfect on your screen, then if you set the view matrix as a constant (that is, once you've configured it you never change/move the camera) and leave the projection alone, modifying the world matrix accordingly will allow you to position it somewhere constant on the screen...
hth
Jack
colodrmn
here is what I did with the world, view, and projection matrix all the other code is the same
device.Transform.World = Matrix.Transformation(
new Vector3(2,2,2), Quaternion.Identity, new Vector3(1, 1, 1), new Vector3(1,1,1), Quaternion.RotationYawPitchRoll(-0.2F,-0.1F,0), new Vector3(0.0F, 0.0F, -20.0F));device.Transform.View = Matrix.LookAtLH(
new Vector3( 0.0f, 3.0f,-50.0f ), new Vector3( 0.0f, 0.0f, 0.0f ), new Vector3( 0.0f, 1.0f, 0.0f ) );device.Transform.Projection = Matrix.PerspectiveFovLH((
float)(Math.PI / 4),this.Width/this.Height, 1.0f, 500.0f );