madsravn 100 Report post Posted May 8, 2007 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. 0 Share this post Link to post Share on other sites
polymorphed 272 Report post Posted May 8, 2007 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. 0 Share this post Link to post Share on other sites
madsravn 100 Report post Posted May 8, 2007 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.. 0 Share this post Link to post Share on other sites
polymorphed 272 Report post Posted May 8, 2007 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/ 0 Share this post Link to post Share on other sites
Palidine 1315 Report post Posted May 8, 2007 Quote:Original post by madsravnHow do I calculate the angle between camera view and scene?You're kind of going at this backwardsThat 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 0 Share this post Link to post Share on other sites