Jump to content
  • Advertisement
Sign in to follow this  
madsravn

how do I calculate camera angle?

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

How do I calculate the angle between camera view and scene? I want to calculate the x and y values of the "borders" on my scene, so I don't draw outside of these. I have drawn what I mean. Is there a way to either set or determine the angle v in this image? http://www.upload-picture.com/images/UFx08090.jpg Thanks for your time.

Share this post


Link to post
Share on other sites
Advertisement
Hi,

It appears as you want to do frustum culling?
If you are, then there are other methods.

Anyhow, to answer your question:
If you have two vectors, A and B, and want the angle between them, then you can use the dot product. The dot product returns the cosine of the angle between the two vectors.
It looks like this:

float result = (A.x * B.x) + (A.y * B.y) + (A.z * B.z)

Now 'result' will have a value ranging from -1.0 to 1.0, where 1.0 means that the vectors are exactly the same, and 0.0 means that the vectors are perpendicular (perpendicular might be wrong wording..).
If its less than 0.0 then the directions are opposite, and -1.0 means exactly opposite.

Remember that vectors A and B have to be normalized before doing the dot product.

Share this post


Link to post
Share on other sites
Well, I know all about vectors. I want to do something similar to that frustrum culling, just a little more primitive. But if I want to calculate the angle between two vectors, I have to have 3 points, right? How do I find the "outer" points of my scene? Do I set it or can I find it somehow? But thanks for the thourough answer though..

Share this post


Link to post
Share on other sites
Nope, the dot product is basically the angle, its just not degrees. So to get the angle between two vectors you need two vectors ;)

Its actually a bit complex to do frustum culling, you should look around for some in-depth information.

http://local.wasp.uwa.edu.au/~pbourke/projection/frustum/

Share this post


Link to post
Share on other sites
Quote:
Original post by madsravn
How do I calculate the angle between camera view and scene?


You're kind of going at this backwards

That angle is called the FOV of the camera (Field of View). You set it arbitrarily at the beginning of a 3D application. There are some accepted FOVs that simulate what the human eye's actual FOV is, but really it's all just subjectively what looks right. In graphics programming we use 2 different angles because screens are square (you need one for the vertical and one for the horizontal).

After you pick an FOV you create a projection matrix that will transform things based on those values. You can then do clipping to the edges of the screen by using the frustum that is represented by that matrix.

Since you are programming a 3D app using openGL (assuming b/c of the forum you're in), you are already setting up this matrix and you can simply extract the frustum from the world matrices and do your draw culling based on that.

Just because it's math that you don't know doesn't mean it isn't the simplest way. =)

Now if you're talking 2D (ortho mode), then all you really have is a screen size. There is no camera in 2D.

Anyway, if my description is unrelated to what you're trying to do, could you explain in more detail the nature of your game/application?

-me

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!