Re: Too lazy to find an algorithm myself :-)

Christian Van Brussel <[email protected]>
Newsgroups gmane.comp.graphics.crystalspace.devel
Organization UCL - TELE
Message-ID <1336752717.2028.401.camel@scylla>
The algorithm wouldn't be that complex, eg:
- iterate on all corner of the bbox
- for each corner, compute the minimal distance where the point will be
visible
- take the maximum of those distances

But of course, that's the step of computing the minimal distance that is
complex.

You can find the equations that compute the projection of a point into
screen space in the methods DrawLineProjected() in the file
'libs/csplugincommon/opengl/glcommon2d.h'. In those methods, the values
px1 and py1 are the screen coordinates of the projected point, and you
need that those values are inside the width and height of the screen.

Inversing those equations is straightforward in the case of the first
method DrawLineProjected() with a perspective projection. In that case,
if my computations are correct, it should be:

float distanceX = fov * point.x / g2d->GetWidth ();
float distanceY = fov * point.y / g2d->GetHeight ();
float distance = csMin (distanceX, distanceY);

For a generic projection matrix, the computations are much more
complex...


On Fri, 2012-05-11 at 16:21 +0200, Jorrit Tyberghein wrote:
> So I just ask you guys.
> 
> 
> Given an axis aligned bounding box in world space and given a camera
> that is located
> at a certain spot in the world I would like to calculate at which the
> camera has to be
> so that the entire bounding box is exactly visible in the given view
> rectangle. So assume
> there is a line between the center of the box going through the
> current camera position.
> I want a new position on that line where the camera can see the
> bounding box (assuming
> it is oriented so that it looks at the center of the bounding box) and
> the box is just visible
> in the view rectangle.
> 
> 
> Any takers? :-)
> 
> 
> Thanks in advance,
> 
> 
> -- 
> Project Manager of Crystal Space (http://www.crystalspace3d.org)
> and CEL (http://cel.crystalspace3d.org)
> Support Crystal Space. Donate at
> https://sourceforge.net/donate/index.php?group_id=649
> Personal page: http://users.telenet.be/jorritTyberghein/
> 
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and 
> threat landscape has changed and how IT managers can respond. Discussions 
> will include endpoint security, mobile security and the latest in malware 
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Crystal-develop mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/crystal-develop



------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.