Advertisement Jump to content
Sign in to follow this  
jor1980

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
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 this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!