i have a map application, that contains a background map as a texture, and it is possible to place objects on the map.
right now i'm working on the following functions:
1)zoom.
2)navigating.
the current implemention for these features is by changing the background texture coordinates (U,V), and changing the objects (that you can place on the map) coordinates on the screen (X,Y).
At the moment, not all of the features work properly and i think that with a bit of tuning i can make them work almost as i want them to.
Now- to my question. I've read a bit about Transformation and as i understood i can use it to help me navigate and zoom but i couldn't figure out how.
can Transformation help me
can you give an example or guidelines for using it
It's importnat to mention that when zooming in and out i only want the map to zoom, while the objects stay at the same size.
thanks.

2D application using D3D - zoom and navigate
jiggs
The idea is to calculate your vertices' positions in a way that after applying all of your transforms and viewport offsetting/scaling, they'd result in values that cover the size of your viewport... Personally, for a pure 2D app, I'd stick with a transformation setup that allows me to write verts positions in screen space directly (e.g. [0,1024]). Such a setup would use an identity world and view matrix, plus a parallel projection matrix that scales your verts all over the viewport. This setup allows for better batching than doing it with the conventional world transformation thing... And it shouldn't be that much of a problem for your CPU to calculate and expand a couple hundreds of sprites every frame... This way you can batch your sprites by texture and improve performance...
Prior to calling DrawPrimitive() or DrawPrimitiveIndexed() for every object, you call SetTransform() with the matrix you want to use for that object.
barisrael
When you say 'its only 2d' do you mean you are using transformed coordinates (screen coordinates) in your vertex buffer
If so then you can't use transforms (i.e move the camera) becuase the coordinates are already transformed.
So you can either change the coordiates as you are doing - or change your vertex buffer to be non transformed.
The interesting problem is changing the zoom without zooming the objects. To do this you would have to calculate the amount of scale moving the camera is giving you and then add the inverse of theat scale into the world matrix for each of the objects.
BillGo
Thanks everyone,
I did use tranformed verts... I'm changing it to positioned.
but now i'm a bit confused - let's say i want to spread a triangle strip (2 trinagles that create a square) over the all window. how can i do it
and another question
I thought i can set world transformation only for the all scene. how do u set world transformation for one object
Thanks again, you've been great help.
MA2005
1) Move the objects closer to the eye.
2) Move the camera closer to the objects
3) Scaling the objects (Make them bigger)
The implementations for the 3 ways
1) Matrix.Transform.World = Matrix.Translation(0.0f, 0.0f, -10.0f); move a object 10 units back, usually closer to the eye. This means that the next object that will be rendered with be rendered 10 units back from the center of the world (0.0f, 0.0f, 0.0f);
2) Matrix.Transform.View = Matrix.LookAtLH(new Vector3(0.0f, 0.0f, 10.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f)); Move the camera 10 units into the screen. Closer to the center of the object.
3) Matrix.Transform.World = Matrix.Scaling(5.0f, 5.0f, 5.0f). This will scale the original size of the object to 5 times in each direction. x, y, z.
I hope this helps a bit,
Take care.
Furqan Farooqui
Assuming he's not using a camera that transforms all of his verts, and he's scaling and offestting vertices manually, he can just apply the scaling to the sprites' center positions (XY) instead of their vertices...
John.Doe
That's exactly what i did, except for positioning my camera and directing it at the center of the window, so my coordinates will be more understandable (as i saw in a few tutorials).
Almost everything works good. :)
When I zoom in without applying the new world transformation (using the scale) the objects which i placed on the map grow with the background (as i could of guessed). When i apply the new world transformation - the objects stay at their original size, but the problem is that they are moving inside the window. I thought maybe i need to multipy the scale matrix with some other matrix, to get the result i wanted, but i couldn't figure out which one. Am i in the right direction
I'm almost there guys.
breceivemail
Kumar Venkat
Babax
Thanks Pieter, but none of them seemes to be working.
Maybe I'll give your more details about my application:
The backgorund map is a texture spread over a vertexbuffer. it's only 2D.
The objects are also textures sperad over a vertexbuffer. also 2D.
Maybe now you have more information to give me other solution.
Thanks.
ozakiweb
I don't really understand what you mean. As per your previous descriptions, you want to have two scaling behaviors:
1) Zoom-in in a natural way into your 2D map (i.e. everything gets larger).
2) Some objects drawn on this map must not become larger, but still be placed at the right position after scaling the map underneath...
For (1) you scale your sprite's verts only, and for (2) you scale your sprite's center position only and keep the verts in their original scale.
How you do these operations depends on your transformation setup...