Rectangle surrounding the view

Started by
4 comments, last by Zakwayda 18 years, 7 months ago
I'm making a game where the camera will be locked in a specific angle but it will be moving in all the x, y and z planes. I thought it would be a good idea to perform the visibility checks by checking objects to a rectangle that will be aligned to the ground plane with the width and height of the frustum on that location. But how do I calculate those numbers? Only thing I have to start with is the cameras position and angle and the FOV. What's the next step? ;) I'm sorry for my horrible English and I hope I could explain my problem understandable :)
Advertisement
Quote:I'm making a game where the camera will be locked in a specific angle but it will be moving in all the x, y and z planes. I thought it would be a good idea to perform the visibility checks by checking objects to a rectangle that will be aligned to the ground plane with the width and height of the frustum on that location. But how do I calculate those numbers? Only thing I have to start with is the cameras position and angle and the FOV. What's the next step? ;)
This is an easy problem to solve, but I at least would need some more info before suggesting anything. So:

1. What do you mean by 'moving in the x, y and z planes'? Do you just mean that there are no limitations on its movement?

2. When you say locked in a specific angle, do you mean that its orientation cannot change? If so, what is its fixed orientation?

The projection of a perspective frustum onto a (properly aligned) plane is a trapezoid, not a rectangle, but perhaps that's what you meant. Anyway, give us a little more info if you can, and it should be easy to come up with an appropriate solution.
1,2: Well, it moves :P It zooms and moves around! The orientation will never change but i haven't really decided to what it will be. About 20 degrees towards the ground I'd guess.

3. Yes I know about that but I was thinking of using the widest side as the width of the rectangle! :)
Well, there are still some things I'm not quite clear on but I'll make some suggestions anyway.

There have been two or three threads recently on extracting the frustum planes from the view and projection matrices. This may be a more general solution than what you need right now. However, such a solution could be used in any project, not just your current one, so it might be worth the effort. Just a thought.

As for special-case solutions, there are at least a couple of ways to construct a rectangle or trapezoid that represents the projection of the frustum onto a plane. You can calculate the solution directly with some trig. Or, you can construct the corners in camera space using trig, then transform them into world space and project them onto the plane.

Anyway, when you say locked in a specific angle I think of a fixed orientation. But maybe you mean that the camera can rotate about a single axis (yaw), but otherwise will be fixed to a set pitch and no roll? If so, which axis is considered up?

Also, I gather your environment is sufficiently 2d-ish (such as a terrain) that visibility can reasonably be reduced to a 2d problem?
Yep it's almost like a 2D tile game. The camera is set to a 10 degree angle in the x-axis. No rotation whatsoever will ever occur. Finding out the width of the triangle is easy if I know the fov. But what abot the height of it? The screen isn't a circle so I suppose calculating with my fov won't worth to find out the rectangle height... :( I need to know the coords, because if a player steers his vehicle out of the screen I want to place it on the other side = making a infinite map alá asteroid game!

It would be really great if it was possible to pick out some values from OpenGL with information about the clipping planes and then just from those numbers project the "rectangle" on the ground plane!
I'm still having a little trouble visualizing your situation, but I think that's just 'cause I'm not tracking very well today. So I'll just refer you to a general solution which you should be able to adapt to any situation. This paper explains how to extract the frustum planes from OpenGL, although you will have to query the modelview and projection matrices and multiply them together yourself. Next, intersect the planes to find the corners. You can then do whatever you want with that information, such as project the corners onto a plane and construct a bounding rectangle or trapezoid.

I know that may not be what you're looking for; maybe someone else will understand what you're desribing a bit better and suggest a custom solution.

This topic is closed to new replies.

Advertisement