Sign in to follow this  

Camera implementation when doing 2D in Direct3D.

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

A few weeks ago I made a post regarding moving a 3D camera in my 2D world. (This is for a 2D game being made in Direct3D.) Read the original post here. The last post in that thread I was told that I shouldn't be using a 3D camera in my 2D world. So how should I do it? Why should I not use a 3D camera? How would I implement a fake camera if I'm not going to use a 3D camera. I'd love a solution to my problem. Any code snippets or examples would be great. Edit: It seems to me that I should use a 3D camera if it's already available to me.

Share this post


Link to post
Share on other sites
Personally, I don't use a camera as such for 2D games. I have a pair of floats representing the position of the top left corner of the screen in world co-ordinates, then I subtract that value from the position of everything I render (in simple terms. Obviously for drawing tilemaps and so on, I only render the objects that are visible).

I guess you could use a D3D transform rather than subtracting the values yourself, but then you have to render everything regardless of whether it is on the screen or not.

Share this post


Link to post
Share on other sites
Quote:
Original post by EasilyConfused
Personally, I don't use a camera as such for 2D games. I have a pair of floats representing the position of the top left corner of the screen in world co-ordinates, then I subtract that value from the position of everything I render (in simple terms. Obviously for drawing tilemaps and so on, I only render the objects that are visible).

I guess you could use a D3D transform rather than subtracting the values yourself, but then you have to render everything regardless of whether it is on the screen or not.


Interesting. Can't you do some sort of frustrum culling to not render what's on screen? Thanks for the tip!

Share this post


Link to post
Share on other sites
Quote:
Original post by Gary the Llama
Quote:
Original post by EasilyConfused
Personally, I don't use a camera as such for 2D games. I have a pair of floats representing the position of the top left corner of the screen in world co-ordinates, then I subtract that value from the position of everything I render (in simple terms. Obviously for drawing tilemaps and so on, I only render the objects that are visible).

I guess you could use a D3D transform rather than subtracting the values yourself, but then you have to render everything regardless of whether it is on the screen or not.


Interesting. Can't you do some sort of frustrum culling to not render what's on screen? Thanks for the tip!


Well, assuming in 2D you are calling the rectangle currently onscreen the frustrum, I'd say any calculation that skips drawing an object outside of the rectangle qualifies as frustrum culling, but I'm no 3D expert so I am happy to be corrected.

Bascially, how I look at it is that with a 2D tilemap, I know more about the structure of the map than Direct3D possibly can, so rather than throw every tile at the screen and let Direct3D clip it, I just loop through the tiles I know are fully or partially visible and draw them. Otherwise, as levels get bigger, you are throwing more and more tiles at DrawPrimitive() or whatever every frame, when you know than the majority are going to be clipped.

If, on the other hand, all I would be doing was examing a single object and testing it against the screen rect, that's probably just a less efficient version of what Direct3D does internally, so I'd just chuck the quad at Direct3D and let it clip it for me.

[Edited by - EasilyConfused on October 3, 2007 12:52:24 PM]

Share this post


Link to post
Share on other sites

This topic is 3728 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.

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