   2D Game Scrolling with 3D Coords
  Just a quick question about the practical implementation of a 2D scrolling game using 3D coords, as in Direct3D, where the centre of the screen is (0, 0).I understand the concept outlined here:http://lazyfoo.net/SDL_tutorials/lesson21/index.phpHowever, since I'm using Direct3D, (0, 0) is the centre of the screen and not any corner. So, that means that the EXACT way of doing scrolling in that tutorial doesn't work and the whole thing is kind of complicated by the coordinate system.For instance, assuming a 640x480 screen, a player is at (0, 0) in the centre of the screen and the camera is at the bottom of the screen. That puts the camera at screen coordinates of (0, -240). This also means that the player is at (320, 240) in the actual level if we assume level coordinates to start at the bottom left. Now, to display it correctly in relation to the camera we can't just put it at (y - camera.y) since that results in (0 + 240) and puts the player 240 pixels higher on the screen than it should be. What you need is the amount by which the camera is higher than the bottom of the level.So now I'm rather confused. Another thing adding to the confusion is a 64 pixel bar I have at the bottom of the screen to be used for various HUD elements. So the actual playable area of the screen is a rectangle from (-SCREEN_WIDTH/2, SCREEN_HEIGHT/2) to (SCREEN_WIDTH/2, -SCREEN_HEIGHT/2 + barHeight).Now we have several different "spaces". 1: The level's space, which is maybe 640x1024 for argument's sake. 2: The screen space which is 640x480. 3: The playable space which is the screen space minus the bottom 640x64 pixels.How should I go about implementing the scrolling without winding up with the code in a mess? I need to be consistent so it's easy to follow and won't confuse me later. It seems I'll have to put in some means of converting coords from one kind to another. The fact that the playable area of the screen begins many pixels below zero is essentially what seems to be causing this mess. Though another thing is that having to remember to add or subtract the height of the bottom bar is an annoyance that could be easily forgotten leading to buggy code that's difficult to debug.The simple solution is something that involves subtracting SCREEN_WIDTH/2 from every x and SCREEN_HEIGHT/2 from every y. But then should I implement that just by making sure when I pass parameters relating to (0, 0) in the bottom left to any function that I convert them to Direct3D coordinates first? Is there a better way? Should I make special provisions for the bottom bar and how the game's actual area begins 64 pixels above the bottom of the screen?   
  you can simplify this by using orthographic projection rather than perspective projection.  In OpenGL when you setup ortho you can put your 0,0 point into the corner of the screen and then everything will work as you expect.  I'm sure DirectX allows you to do the same.   ;  You should set the projection matrix to use orthographic projection. DirectX has a function to do this for you but I can't remember what it's called.Regarding the HUD and the game area; these two things shouldn't know about each other's positions on screen. Your playable area's rendering code doesn't need to know that there is a HUD rendering somewhere else on the screen. It should just deal with its own rendering. For example, a simple way would be for the game world to believe its rendering onto a 640*400 surface and the HUD to render to a 640*80 surface.   ;  Cool, I didn't know about that...Is it when you're calling something like:d3dDevice->SetTransform( D3DTS_PROJECTION, &Matrix] );And you just set up that matrix it uses in some way? I'll have to try a few things...Quote:Original post by rasher_b2It should just deal with its own rendering. For example, a simple way would be for the game world to believe its rendering onto a 640*400 surface and the HUD to render to a 640*80 surface.Right... makes sense. Should be easy enough to do.Thanks guys.   ;  I think I got it. You useD3DXMatrixOrthoOffCenterLH()to make the projection matrix and use the offsets from the center.   