Fit object inside camera view

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
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Fit object inside camera view

Post by Lonesome Ducky »

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
Jookia
Posts: 170
Joined: Wed Nov 19, 2008 1:11 am

Post by Jookia »

You mean like zooming into a TV screen?
olivehehe_03
Posts: 157
Joined: Tue Mar 20, 2007 8:30 am

Post by olivehehe_03 »

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
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:

Post by FuzzYspo0N »

he is meaning like in a 3d app , "zoom extents" zooms into the object you have selected i am assuming.
Jookia
Posts: 170
Joined: Wed Nov 19, 2008 1:11 am

Post by Jookia »

I'd say the best approach would be defining a direction that the object is facing then move the camera to it offset in the direction, and the rotation flipped so you look at it's front.
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

FuzzYspo0N wrote:he is meaning like in a 3d app , "zoom extents" zooms into the object you have selected i am assuming.
Yep, that's exactly what I mean. What I'm try to do is render an object from the top and have it fit perfectly in the render texture.
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

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
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

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:
Image


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:

Post by FuzzYspo0N »

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)

Image

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 :P it should be pretty simple from there.
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

Ah, many thanks FuzzySpoon!
Post Reply