C++ Learning Community Forum
August 01, 2010, 03:36:20 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Hello. Smiley
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: A useful little formula for 2.5D games/apps  (Read 907 times)
Melastoma
C++ Freak
***
Posts: 326


>:3


View Profile
« on: January 08, 2008, 02:10:05 PM »

I'm sure the following applies to DirectX and OpenGL but I figured it'd get more attention here since most of you guys use OpenGL

While browsing through the DirectX SDK a while back, I found this neat little diagram:


What particularly interested me was this formula
D * tan(FOV / 2)

In short, the above function'll give us half the height of the viewing frustum at any given distance from the camera
How can this be useful? Say you're working on a 2.5D game such as I am (very spontaneously I might add >: ), and the screen in the players plane of movement has to be say, 800 x 600. With a little bit of work, we could rework the formula to give us this:

D = H / 2 / tan(FOV / 2)

D being the distance the camera needs to be from the movement plane, H being the height of the screen at said distance, and FOV being the field of view, which is normally Pi / [2, 3, or 4].

If you're using Pi/4, here's a little define with it all precalculated you can use like a function Cheesy
Code:
#define GetZoom(DistanceH) (DistanceH / 2 / 0.4142135623730950488016887242097f)

Anywho, I'm off to work, 12 hour workdays are killer @_@
« Last Edit: January 08, 2008, 02:11:54 PM by Melastoma » Logged

Quote
The language itself isn't complicated, it's getting it to do what you want that's the puzzle.
Here, Here.That, my friend, should be on a T-shirt, or in somones signature.

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!