Hello Stephane,

Stephane Routelous wrote:
> Hi,
> 
> I'm trying to implement a "window select" (meaning that the 3d objects
> are selected when the user drag a rectangle in the window).
> for that, I'm projecting my object to the screen with multFullMatrixPnt
> and check if the projected object (in screencoord) intersect the
> selection rectangle.

quick question:

> <pseudo-code>
> void WindowSelect(int x1,int y1,int x2.int y2) 
> {
>       //x1,y1 and x2,y2 are the 2d mouse position on the select
> rectangle in screen coordinates
>       ViewportPtr vp = getWindow()->getPort(0);
>       OSG::Matrix wtos;
>       getCamera()->getWorldToScreen(wtos,*vp);
>       int w = vp->getWidth();
>       int h = vp->getHeight();
>       foreach ( obj3d o in objList )
>       {
>               SphereVolume sph = o->GetSphereVolume();
                ^^^^^^^^^^^^^^^^^^^^^^
is this volume in world coordinates ? If not you are missing the local 
to world coordinate transformation. You can get the matrix for that from 
  a Node with getToWorld.

>               Pnt3f center = sph.GetCenter(); //the center of the
> sphere is on the center of the screen
>               Pnt3f projectedCenter ;
>               wtos.multFullMatrixPnt( center, projectedCenter ); 
>               //map the center to screen coordinates
>               //as the sphere center in in the middle of the screen, I
> expect projectedCenter[0] = 0 and projectedCenter[1] = 0
>               //but I got [0,1.66,0.93]
>               //as explained in
> http://www.mail-archive.com/[email protected]/msg02156.html
> 
> 
>               float curXC = w*(projectedCenter [0]+1)/2.0f; 
>               float curYC = h*(projectedCenter [1]+1)/2.0f;
>               if ( IsIn(curXC,curYC,x1,y1,x2,y2) )
>               {               
>                       obj3d->Select();
>               }
>       }
> }
> 
> </pseudocode>

        Hope it helps,
                Carsten

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users

Reply via email to