A question about the perspective in Irrlicht

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
benjani13
Posts: 25
Joined: Sat Aug 07, 2010 8:12 pm

A question about the perspective in Irrlicht

Post by benjani13 »

Hi! I have a question about the 3D perspective in Irrlicht. I find this scheme on a website who explain the 3D perspective:
Image

I'd like to find the angle formed by the lines leak, drawn in red on the image. Is a function in Irrlicht to get this angle or is an alternative method exist to find it?

Thank you.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Grab the camera you are using (ICameraSceneNode) and use getViewFrustum() to get the current view frustum (SViewFrustum). Then create 2 vectors (vector3df), v1 = (camera position - viewFrustum.getFarLeftUp()) and v2 (camera position - viewFrustum.getFarLeftDown()) and get the angle between these two vectors by doing v1.getHorizontalAngle() - v2.getHorizontalAngle(). Should serve your needs :)
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Mikhail9
Posts: 54
Joined: Mon Jun 29, 2009 8:41 am

Post by Mikhail9 »

BlindSide wrote:Grab the camera you are using (ICameraSceneNode) and use getViewFrustum() to get the current view frustum (SViewFrustum). Then create 2 vectors (vector3df), v1 = (camera position - viewFrustum.getFarLeftUp()) and v2 (camera position - viewFrustum.getFarLeftDown()) and get the angle between these two vectors by doing v1.getHorizontalAngle() - v2.getHorizontalAngle()
Or exploit the dot product by doing:

Code: Select all

acos(v1.normalize().dotProduct(v2.normalize()))
to get the angle between the vectors.

acos returns angles in radians, so divide by pi and multiply by 180 to get degrees.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Mikhail9 wrote:Or exploit the dot product by doing:

Code: Select all

acos(v1.normalize().dotProduct(v2.normalize()))
to get the angle between the vectors.

acos returns angles in radians, so divide by pi and multiply by 180 to get degrees.
Oh yes, do this instead, just remember it's important to normalize like in his example otherwise you will get unexpected results. You can also use the built in constant core::RADTODEG to switch to degrees.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Post Reply