Public Group

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

This topic is 1744 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites

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.

##### Share on other sites

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.

##### Share on other sites

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.

##### Share on other sites

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:

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

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634107
• Total Posts
3015550
×