Jump to content
  • Advertisement
Sign in to follow this  
mind in a box

Z-Axis calculation in 2D

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

Hello everyone!

I got a little problem with my Mario-like game. (What genre is it btw?)
The game needs a zoomable camera, so I implemented a Z-Axis in my camera code. But I got stuck at the point where I need to transform the Block's (My game is made out of blocks) Position and scale. I guess I have to shrink everything to the middle of the screen when moving away at the Z-Axis, but I don't know how I do that.

I have made a coordinate system which treads 0,0 as the middle of the screen instead of the upper left corner of the window, if that helps. And also the Scaling of the blocks is aligned to the left upper corner of the block. If that makes things more complicated I can change it.

Share this post


Link to post
Share on other sites
Advertisement
Zooming more often means changing the fov of the camera, rather than moving the camera. Depending on your API, you can setup a magnification variable (initialized to 1.0f) and set the projection matrix using that variable.

EDIT: (deleted perspective projection stuff)

Oops. 2D projection. Assuming ortho. Use the magnification to change the width and height of your projection matrix.

For ortho projection, something like:
float projHeight = normalHeight*mag;
float projWidth = aspect*projHeight;
SetProjection(..., projWidth, projHeight, ... );

Then increment/decrement the magnification instead of the camera position.

Decreasing mag = zoom in.
Increasing mag = zoom out.

Ensure mag never goes to 0 (or better, some small value).

EDIT2: re-read your post. Blocks aligned to a corner will get messed up unless you control the projHeight and mag so width and height values are compatible with (integer multiples of) your block sizes.

EDIT3: You may just want to ignore my response. [wink]

Share this post


Link to post
Share on other sites
You helped me in a way! [smile]
I was looking more closely at the Direct2D API and I found the matrix stuff somewhere. And I got it running. Thank you for pointing me into that direction!

Share this post


Link to post
Share on other sites
You said "Depending on your API", and this made me looking at the docs. And there I searched for "Matrix" and I found what I need [smile] I jsut didn't expected that D2D has that Matrix stuff.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!