Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to set viewing volume to show whole object?

4 views
Skip to first unread message

pjac...@elka.pw.edu.pl

unread,
Sep 18, 2002, 3:56:39 PM9/18/02
to

I have 3D object and its vertices (its x,y,z coords).
It can be situated anywhere in 3d space.
How do I calculate the eye(camera) position and viewing volume
that will show the whole object?

I.e. how to calculate the middle of the object, at which the camera will
point? Some kind of center of weight calculation?

My 1st idea to calc. view volume was to sort all x coords, choose biggest
and smallest, which
will be the left and right clipping planes, do the sorting for y-coords
(to have top and bottom clipping planes) and for z coords (to have
near/far clipping planes).
But there are probably better ways to do it?

What OpenGL functions to use (gluLookAt? gluPerspective? glFrustrumm?
glOrtho? ) to set eye pos. and viewing volume?

Przemek

--------------------------
pjac...@elka.pw.edu.pl
--------------------------

Mikko 'memon' Mononen

unread,
Sep 18, 2002, 5:42:15 PM9/18/02
to
On Wed, 18 Sep 2002 21:56:39 +0200, pjac...@elka.pw.edu.pl
<pjac...@elka.pw.edu.pl> wrote:
>
>I have 3D object and its vertices (its x,y,z coords).
>It can be situated anywhere in 3d space.
>How do I calculate the eye(camera) position and viewing volume
>that will show the whole object?
>
>I.e. how to calculate the middle of the object, at which the camera will
>point? Some kind of center of weight calculation?
>
>My 1st idea to calc. view volume was to sort all x coords, choose biggest
>and smallest, which
>will be the left and right clipping planes, do the sorting for y-coords
>(to have top and bottom clipping planes) and for z coords (to have
>near/far clipping planes).
>But there are probably better ways to do it?
>
>What OpenGL functions to use (gluLookAt? gluPerspective? glFrustrumm?
>glOrtho? ) to set eye pos. and viewing volume?

I believe the easiest way is to use the objects bounding sphere. As you
have the bounding sphere, you also have the target point the camera should
look at. Next you should calc the distance how far the camera should that
the whole object (bouding sphere) would be visible. Fir this you will need
the FOV of your camera and the radius of the bounding sphere. The distance
is calculated as follows:

dist = radius / tan( FOV / 2 )

Then you need to know the direction of the camera. You can start just by
translating it backwards of the object by some amount.

You could use glPerspective to set the projection, and glLookat to set
look at transformation.


--memon

cos(pi),sin(pi) lddoW 6Jo'3p15u1@uow3w
uow3W uow3w~/6Jo'3p15u1'mmm

pjac...@elka.pw.edu.pl

unread,
Sep 18, 2002, 6:19:23 PM9/18/02
to
> I believe the easiest way is to use the objects bounding sphere. As you
> have the bounding sphere, you also have the target point the camera should
> look at. Next you should calc the distance how far the camera should that
> the whole object (bouding sphere) would be visible. Fir this you will need
> the FOV of your camera and the radius of the bounding sphere. The distance
> is calculated as follows:
>
> dist = radius / tan( FOV / 2 )
>
> Then you need to know the direction of the camera. You can start just by
> translating it backwards of the object by some amount.
>
> You could use glPerspective to set the projection, and glLookat to set
> look at transformation.
>
> --memon
>
Thank you for the reply!

But how I can get bounding sphere having my object?

Przemek


Mikko 'memon' Mononen

unread,
Sep 18, 2002, 6:46:12 PM9/18/02
to

See:
http://www.magic-software.com/

There browse: Source Code > 3D Source Code: Containment. There you should
see sources on how to calculate minimum volume bounding sphere.

0 new messages