Sign in to follow this  
BenDrummin58

Zooming out in a 2d C++ game

Recommended Posts

I'm currently working on a 2-D top-down game that has a very very big map, because the whole game is set in a city. Well, to make a long story short, I developed my own map maker which allowed me to visually develop my map and not have to sit hours at the computer plotting numbers in a 2dimensional array. Everything works good, except I want to make it just a little bit easier to get around. Right now, I have it where the camera is fixed height wise, and in order for me to go from the very left part of the map to the very right part of the map, I have to wait forever before I can get there. Also, when I'm making roads and such, I have to scroll all around the map and figure out where one part of the road meets with the other part. It's getting annoying, so I wanted to see if I could put a zoom out function in there. Only problem is, I have no clue how. I've searched this forum and can only find zoom in functions, most using openGL, which I would prefer to not use. So my question..is there any way to create a zoom out function in C++ using DirectX8.0? And if so, can somebody point me towards a tutorial or something :) Thanks!

Share this post


Link to post
Share on other sites
If it's a 2D game, can I assume you're using orthographic projection? Or are you using perspective projection?

Share this post


Link to post
Share on other sites
It's slightly perspective projection. It's mostly top-down...but I wanted to be able to see the front sides of buildings as well, not just the roof..lol.

Share this post


Link to post
Share on other sites
the perspective of the game shouldn't matter at all. All I want is to basically make the images shrink so I can zoom out. Or any other way of zooming out. I don't really care if it looks horrible, since this is just my map editor.

Share this post


Link to post
Share on other sites
Quote:
Original post by BenDrummin58
the perspective of the game shouldn't matter at all.
It does matter, because how you implement the zoom effect will depend on how your projection is being set up. Perhaps you could post the code where your projection matrix is being constructed? From there it should be easy to make a suggestion as to how to implement zoom.

Share this post


Link to post
Share on other sites
ok...I'm sorry..I think I mis answered your first question... mathematically..my game has orthographic projection. I have square tiles that are placed in a grid type format. The way my game seems like perspective projection, is because some of my tiles (the building tiles) are drawn in a way that make it look 3D...when really it is still orthographic. I dunno if that makes sense...lol.

basically...the game is orthographic projection. sorry for the confusion..I'm just a little tired right now..

Share this post


Link to post
Share on other sites
If you're using an ortho projection you simply have to change the scale of the values passed in, ie. instead of a width of 0 to 800 you'd go from 0 to 1600 (where your scale factor is 1/zoom). Obviously you apply the same on the y as well.

This should sort the graphics out without a problem (although you may need to tweek your culling to take this zoom into account). The tricky bit is handling mouse clicks - you've now also got to take into account the zoom factor instead of just translating the clicks by the appropriate amount.

The easiest way to do this I find is to first convert to a 'normalised' mouse click (ie in a rectangular region from [0..1]) and then convert from this to your actual world click location.

Share this post


Link to post
Share on other sites
Hw owuld someone do somehting like this in SDL? I realize that I need to shrink my coordinate system, but how do I scale images?

Share this post


Link to post
Share on other sites
Quote:
Original post by NIm
Hw owuld someone do somehting like this in SDL? I realize that I need to shrink my coordinate system, but how do I scale images?


*You* don't; SDL (specifically, the projection) takes care of it for you. Re-set-up the orthographic projection with different parameters, such that a different fraction of the "game world" fits within the camera's view.

Share this post


Link to post
Share on other sites
Actually, in SDL (assuming you are not using OpenGL) it's not that easy: you have to scale the image yourself (by using a scaled blit, I'm not sure the exact calls but you should be able to find it in the docs).

In DirectX and OpenGL, you can just change the projection matrix as described above.

Share this post


Link to post
Share on other sites
Thanks for the responses :) I got some good code written from those ideas. Although it isn't actually working yet..lol..it's on its way to being completed.

Share this post


Link to post
Share on other sites
Well maybe I'll switch to openGL to make things easier. Most of the things I'm doing would eb better with textured polys than sprites anyway.

Share this post


Link to post
Share on other sites

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