Advertisement Jump to content
Sign in to follow this  
Michael Anthony Wion

2D projection, but 3D effects?

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

So I'm trying to set up my project to act as a 2D game in 3D space. The goal in doing this is to allow for a short number of 3D effects.
Namely, when the character reaches the boundaries of the 2D screen (or plane), the screen should rotate (like a cube) into the new 2D screen.
I intend to set up the camera to "follow" the character around until the outer edges of the camera reach the bounds of the quad... so I'm assuming that I should check for when both the camera and the player reach the edge before firing off this effect.
But I could use some help determining the proper setup, and how this event should be handled... keeping in mind that this is mainly a 2D, left-handed orthogonal game (during gameplay the top-left screen coordinate should be {0,0}, bottom-right should be {screenWidth, screenHeight}).

A quick example... The camera and player reach the top of the screen.
At this moment, would it be best to create a new quad, render the new screen to it, calculate and place it's proper position, then rotate the camera upward to it?
Or would it be better to rotate the two quads downwards?
Or perhaps just have an actual cube being drawn at all times? -- (seems wasteful, but logically easier)
And most importantly, how would we stay true to the 2D coordinate system between 3D transitions?

I originally attempted to set up my world using D3DXMatrixPerspectiveFovLH and D3DXMatrixOrthoLH for the projection matrix, but I think I may have set up my matrices wrong cause when I tell the camera to rotate, the quad on the screen appears to infinitely skew into the far plane rather than actually rotate at it's own aspect (the way a cube would in most tutorials). And I'm not sure if that's the actual problem, or if I'm setting up my depth buffers incorrectly, or something else?
Please request any code you'd like to see, if it aids you in helping me getting this working properly.

Share this post

Link to post
Share on other sites
The way I'd first try to approach this would be to use an orthogonal projection during the level. When you reach the edge and want to rotate to the new level, render the current level to and the new level to off-screen buffers, and for the transition use a perspective projection and use the two off-screen buffers as the textures for the two sides of the cube. Once the rotation is complete you can go back to rendering just the new level with an orthogonal projection.

Share this post

Link to post
Share on other sites
Right, that's basically what I was thinking. But how would I calculate the box?
What I mean is, should it be an actual square/rectangular box, or just 2 planes matching the screen dimensions?
How would I calculate which face to render the buffer to?
And in the event of rotation, do you think I should rotate the camera in world space, or the box/planes in object space?

Also, when I tried changing my matrix setup to use perspective projection, the geometry would stretch and skew into the far plane whenever I rotated the camera, regardless of what I set my far plane to. It didn't seem very "boxy" to me at all, and instead turned my textured quads into taffy. What could cause this?

Share this post

Link to post
Share on other sites
If I get the effect, you want the first level to appear as if it's on one side of a cube, and for the next level to appear as if it's on the side of the cube around the corner (corresponding to the direction of travel), and that the cube will rotate to the next level on transition, correct?

If so, there are a couple easy ways to do this -- firstly, if you don't want the depth effect, you can do the rotation in orthographic mode and get a sort of "wipe" transition. you can further "fake" a certain amount of perspective by transforming the coordinates of the corner which is "into" the screen so that the effect stretches across the middle, looking similar to a rotating cube.

Another option would be for you to render the level(s) to a texture using orthographic projection, and then to render that texture onto a cube with perspective projection, and just align it to center the view when you're not in transition.

Share this post

Link to post
Share on other sites
Yes, that's the effect I'm going for... but I don't want to eliminate the 3D aspect of it, because I can do things like zoom out and back in during rotation if I wanted.
And eventually, it would be cool to turn this square into a sphere which represents the entire playable world, giving a more "infinite" effect when it zooms out.
But I'm trying not to get ahead of myself so soon.

I rewrote my entire setup and was able to avoid the skewing issues, to some degree.
But I'm still not sure how I would determine which side of the cube to render the new buffer to.
Perhaps I'll just have to keep it less dynamic, and start in an identity matrix every time the view goes 3D.
That way, I'll always know which way to rotate it, based on the traveled direction.

By the way... how would you tell the shader to render one texture for a given side, and a different texture for another side?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!