# Camera position for top down view?

Is there a simple way to work out the necessary camera position so that it has a particular field of view?

I’m trying to make a basic 2D game, so all the elements exist in the X-Z plane with Y = 0. I place the camera above the scene at (0, -height, 0), looking down (hpr = 0,0,0). My question is, what is the relationship between the camera height and the amount of the XZ plane I can see? Do I have to work it out with trig, or is there a way (perhaps using Lens classes) to get it automatically?

Is there a way to say "I want to show the rectangle (left, 0, top)-(right, 0, bottom)? And a related question: is there a way to adjust the size of the display window from within the program?

Malcolm

In fact, there is such a method. It’s called lens.setFrustumFromCorners. You’ll need to convert the four corners of your field-of-view into camera space and then pass them to setFrustumFromCorners, something like this:

``````p1 = base.cam.getRelativePoint(render, Point3(-x, 0, z))
p2 = base.cam.getRelativePoint(render, Point3(x, 0, z))
p3 = base.cam.getRelativePoint(render, Point3(-x, 0, -z))
p4 = base.cam.getRelativePoint(render, Point3(x, 0, -z))
base.camLens.setFrustumFromCorners(p1, p2, p3, p4, Lens.FCRoll | Lens.FCAspectRatio)``````

But all this is really unnecessary. If you’re making a 2-d game, you probably really want to use an OrthographicLens, which doesn’t involve any of this trigonometry nonsense.

``````lens = OrthographicLens()
lens.setFilmSize(x * 2, z * 2)
base.camNode.setLens(lens)``````

In fact, you might consider forgoing render, and just parenting the contents of your game to render2d, which is already set up with such an OrthographicLens (you can use a scale node–similar to aspect2d–or change the film size of base.cam2d.node().getLens(), to make it the right scale).

To resize a window at runtime, you request the new size via WindowProperties:

``````wp = WindowProperties()
wp.setSize(512, 512)
base.win.requestProperties(wp)``````

David