Skip to main content
Tweeted twitter.com/#!/StackGameDev/status/150537316652429313
edited title
Link
Tetrad
  • 30.1k
  • 12
  • 96
  • 143

XNA - Avoid screen from displaying How can I calculate where my camera can be to avoid showing something outside a region?

Source Link
Joel
  • 1.5k
  • 1
  • 12
  • 29

XNA - Avoid screen from displaying outside region

I have a landscape model, which goes from the coordinate -45, -45 to 90, 90.

The edge of the model just cuts off and i would like to somehow stop the screen from ever passing these points. Basically sticking a boundary so that you can't see off the side. The game is always in top view, with the camera directly facing down.

However the problem is that the player can zoom in and out, obviously you have a wider range of view when zoomed out. (There is a limit to how far you can zoom out, you couldn't zoom out say, so that opposite sides of the map are seen at once).

I am assuming using something like Viewport.Project or Unproject, which changes screen coordinates to 3d space and the other way round, could somehow help me in the situation.

My initial idea may lag too much, which would be a while loop saying "While projection of screen point.X is less that -45, add 1 to the camera.X" etc.

Does anyone have any ideas for this? To sum it up, i need to find a way of stopping anything outside the area of -45, -45 to 90, 90 from being shown on the screen.

Thanks for any help!