Fit object inside camera view
-
Lonesome Ducky
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
Fit object inside camera view
Assuming I have a 3d object and a camera, and I know the edges of the object's bb, how do I make the object fit perfectly inside of the camera's view? I want it to be as close as it can be while still inside the camera's view
-
olivehehe_03
- Posts: 157
- Joined: Tue Mar 20, 2007 8:30 am
Not sure exactly how to do what you're after, but there's a function that may help. In the ICameraSceneNode class, the function getViewFrustrum() returns a SViewFrustum struct which has a few things that may be useful to you
http://irrlicht.sourceforge.net/docu/cl ... 4f2c53477e
http://irrlicht.sourceforge.net/docu/st ... ustum.html
http://irrlicht.sourceforge.net/docu/cl ... 4f2c53477e
http://irrlicht.sourceforge.net/docu/st ... ustum.html
Tell me what you cherish most. Give me the pleasure of taking it away.
-
FuzzYspo0N
- Posts: 914
- Joined: Fri Aug 03, 2007 12:43 pm
- Location: South Africa
- Contact:
-
Lonesome Ducky
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
-
FuzzYspo0N
- Posts: 914
- Joined: Fri Aug 03, 2007 12:43 pm
- Location: South Africa
- Contact:
Is the render actually going into a texture file on disk? cos you wouldnt want to RTT just to focus on something, thats just a position/aspect change on the camera rather than a whole rerender to texture?
What "function" are you looking for? explain it from where you "see" or "know it" and ill explain how to acheive it
What "function" are you looking for? explain it from where you "see" or "know it" and ill explain how to acheive it
-
Lonesome Ducky
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm
Ok, well here's what I'm trying to do. I'm trying to fake a shadow, so I create a quad the exact size of the bounding box to display the shadow on. Now, to create the shadow, I need to render the model from the top in black, which I have achieved. But often times, the model is too big or smaller than the render texture, so I need to find out how close to put the camera so the object is just perfectly in view, no space wasted and not going over the size.
Here is the render texture after the model is rendered:

Now, I want that black model to fill up the screen. Right now I'm setting the camera's position as the center of the model's bounding box +10 y units, and setting the target as the model's bounding box center. The +10 to the y is what I need to change to make the model fit perfectly. Knowing the size of the model's bounding box, is there a way to figure out exactly how many y unites to offset the camera to make it fit just perfectly?
Here is the render texture after the model is rendered:

Now, I want that black model to fill up the screen. Right now I'm setting the camera's position as the center of the model's bounding box +10 y units, and setting the target as the model's bounding box center. The +10 to the y is what I need to change to make the model fit perfectly. Knowing the size of the model's bounding box, is there a way to figure out exactly how many y unites to offset the camera to make it fit just perfectly?
-
FuzzYspo0N
- Posts: 914
- Joined: Fri Aug 03, 2007 12:43 pm
- Location: South Africa
- Contact:
i have a solution, its probably a really simple way to do it but it requires some research on your part
i CAN do the maths FOR you but then theres no point in trying to learn.. Take a look below (this is how i would attempt it)

So, going back to high school trigonometry... Opposite, Adjacent and Hypotoneuse. You use triangle formulas, we have the Opposite side of out angle, and we have our angle... the angle is half of the fov/angle of the frustrum, and the opposite length is half of the width of the bounding box.
The maths is pretty simple to get the length of the Adjacent side (a) or the Hypot. (h) , using the angle ^1 and the side length of bb.length/2.
Hope this helps
it should be pretty simple from there.

So, going back to high school trigonometry... Opposite, Adjacent and Hypotoneuse. You use triangle formulas, we have the Opposite side of out angle, and we have our angle... the angle is half of the fov/angle of the frustrum, and the opposite length is half of the width of the bounding box.
The maths is pretty simple to get the length of the Adjacent side (a) or the Hypot. (h) , using the angle ^1 and the side length of bb.length/2.
Hope this helps
-
Lonesome Ducky
- Competition winner
- Posts: 1123
- Joined: Sun Jun 10, 2007 11:14 pm