How to set camera to maximize the mesh view into the screen?

Started by
3 comments, last by jor1980 10 years ago

Hi.

I am making a program using jmonkey to preview the meshes contained into a filetype. Each file has a mesh of diferent sizes and positions, I want to make my program focus the mesh contained in the file trying to view it in a way that the mesh uses almost all the space in the viewport.

I would like to know if there is a mathematical way to make this, and achieve to preview the meshes using as much space in the screen as possible.

Advertisement

Couple of ways of doing this, both need to know the size of the mesh.

So you need to first generate a bounding box or a bounding sphere. (there are lots of online resources to help you with this)

Then you can either ...

1) Move the camera forward until the mesh fills the screen.

To work out the distance to place the camera you calculate distance = bounding_sphere.radius / tan(field_of_view)

2) You change the field of view in your projection matrix

To work out the field of view required you calculate fov = atan(bounding_sphere.radius/camera_distance)

Both might need a little adjustment , but it's a good starting point.

Couple of ways of doing this, both need to know the size of the mesh.

So you need to first generate a bounding box or a bounding sphere. (there are lots of online resources to help you with this)

Then you can either ...

1) Move the camera forward until the mesh fills the screen.

To work out the distance to place the camera you calculate distance = bounding_sphere.radius / tan(field_of_view)

2) You change the field of view in your projection matrix

To work out the field of view required you calculate fov = atan(bounding_sphere.radius/camera_distance)

Both might need a little adjustment , but it's a good starting point.

Personally, I like changing the distance of the camera approach. Messing with the FOV too much also messes with perspective. And sometimes that's just plain funny looking.

smile.png Yes it can do.

But at times it's great. For example on a recent racing game I used the FOV technique to give you the feeling of zooming in on a car.

Completely screwed up my shadows though.

As i am new in game programming, i was trying to obtain the field of view of my jme3 camera but i don´t know how to do it. Here is the camera class definition:

http://hub.jmonkeyengine.org/javadoc/

How can I get the field of fiew from the camera class defined in that javadoc?

This topic is closed to new replies.

Advertisement