RE: [osg-users] Bounding Rect in Screen Space

2007-07-06 Thread Pecoraro, Alexander N
Since I didn't get any responses to my last email, perhaps if I provide
code I'll have more luck. Can someone tell me why this code doesn't work
for calculating the bounding rectangle of an object in screen space.
What I would expect to see is that the rectangle would get drawn right
over the top of the object, but its always wrong. Please note that the
object in question is part of a model that I am rendering to a texture
and then applying the texture to a polygon that covers the entire
screen. So I need a way to tell if the mouse is over the top of a
particular piece of the model. So I am trying to calculate the bounding
rect of that part of the model, but I've tried about 5 different ways of
calculating it (the code below being my most recent attempt) and I get
pretty much the same result with all 5 different ways of doing it (see
attached image):

//This is my custom cull callback function
virtual void operator()(osg::Node *pNode, osg::NodeVisitor *pNV)
{

if(m_spGeode-getNumDrawables()  0)
m_spGeode-removeDrawables(0, m_spGeode-getNumDrawables());

osgUtil::CullVisitor* pCullVisitor =
dynamic_castosgUtil::CullVisitor*(pNV);

osg::BoundingBox bb;
bb.expandBy(pNode-getBound());

m_rect.minPt.set(SHRT_MAX, SHRT_MAX);
m_rect.maxPt.set(SHRT_MIN, SHRT_MIN);
CalculateScreenSpaceBoundingRect(bb, pCullVisitor, m_rect);


 
m_spGeode-addDrawable(CreateScreenPolygon(osg::BoundingBox(m_rect.minPt
.x(), 
m_rect.minPt.y(),
0.0f,
m_rect.maxPt.x(), 
m_rect.maxPt.y(),
0.0f), 0.5f));
pCullVisitor-traverse(*pNode);
}

void CalculateScreenSpaceBoundingRect(const osg::BoundingBox bb,
osgUtil::CullVisitor* pCullVisitor, M2CompassModel::BoundingRect brect)
{
const osg::RefMatrix MVPW = pCullVisitor-getMVPW();

//point #1
osg::Vec4 vtx(bb.xMin(), bb.yMin(), bb.zMin(), 1.0f);
osg::Vec4 screenVtx =  MVPW.preMult(vtx);

brect.expand(screenVtx);

//... This is repeated for each point in the bounding box
}

osg::Geometry* CreateScreenPolygon(const osg::BoundingBox bb, float
red)
{
osg::Geometry* polyGeom = new osg::Geometry();

osg::Vec3Array* vertices = new osg::Vec3Array;
float depth = bb.zMin()-0.1;
vertices-push_back(osg::Vec3(bb.xMin(),bb.yMax(),depth));
vertices-push_back(osg::Vec3(bb.xMin(),bb.yMin(),depth));
vertices-push_back(osg::Vec3(bb.xMax(),bb.yMin(),depth));
vertices-push_back(osg::Vec3(bb.xMax(),bb.yMax(),depth));
polyGeom-setVertexArray(vertices);

osg::Vec3Array* normals = new osg::Vec3Array;
normals-push_back(osg::Vec3(0.0f,0.0f,1.0f));
polyGeom-setNormalArray(normals);
polyGeom-setNormalBinding(osg::Geometry::BIND_OVERALL);

osg::Vec4Array* colors = new osg::Vec4Array;
colors-push_back(osg::Vec4(red,1.0f,1.0f,1.0f));
polyGeom-setColorArray(colors);
polyGeom-setColorBinding(osg::Geometry::BIND_OVERALL);

polyGeom-addPrimitiveSet(new
osg::DrawArrays(osg::PrimitiveSet::QUADS,0,vertices-size()));

return polyGeom;
}

Any suggestions? Thanks.

Alex

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Pecoraro,
Alexander N
Sent: Tuesday, July 03, 2007 9:48 AM
To: osg users
Subject: [osg-users] Bounding Rect in Screen Space

Is there an easy way to calculate the bounding rectangle of an object in
screen space? I'm hoping for some easy function that I could pass my
osg::Node to and have it return the bounding rectangle of the pixels
that it covers.

Thanks.

Alex
___
osg-users mailing list
osg-users@openscenegraph.net
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
attachment: WTF.JPG___
osg-users mailing list
osg-users@openscenegraph.net
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

[osg-users] Bounding Rect in Screen Space

2007-07-03 Thread Pecoraro, Alexander N
Is there an easy way to calculate the bounding rectangle of an object in
screen space? I'm hoping for some easy function that I could pass my
osg::Node to and have it return the bounding rectangle of the pixels
that it covers.

Thanks.

Alex
___
osg-users mailing list
osg-users@openscenegraph.net
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/


RE: [osg-users] OpenFlight plugin threadsafe?

2007-07-02 Thread Pecoraro, Alexander N
I am using 1.2. I will try upgrading to 2.0.

Alex 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Robert
Osfield
Sent: Saturday, June 30, 2007 1:18 AM
To: osg users
Subject: Re: [osg-users] OpenFlight plugin threadsafe?

Hi Alex,

The OpenFlight plugin does not support multi-threaded usage, but does
have a reentrant mutex to marshal access through it - effectively
serializing access to it.  There was a point when the OpenFlight plugin
didn't yet have this serializing feature.  Which version of the OSG are
you using?

When using the DatabasePager it runs its own background thread for doing
the file reading and data prep, there is only currently one thread that
it runs, so typically reading from plugins is still still
single-threaded.

 Oh yea - I am using the plugin in src/osgPlugins/OpenFlight, not the 
 one in src/osgPlugins/flt. Out of curiosity, why is there two 
 different plugins for the same file type?

OSG-2.0 only has the new OpenFlight plugin, the old flt plugin has been
removed.  In 1.2 we kept the flt plugin around for cases where the new
plugin wasn't quite mature enough.

Robert.

On 6/30/07, Pecoraro, Alexander N [EMAIL PROTECTED] wrote:
 Hi, I was wondering if anyone was using the OpenFlight ReaderWriter 
 plugin in combination with the osgDB::DatabasePager? I modified the 
 plugin so that it creates PagedLOD nodes for external reference 
 records, instead of ProxyNodes, so that I could have paging 
 functionality in my OpenFlight terrain. I made sure to set thread safe

 reference counting to true, but I still seem to get segfaults when I
fly around the terrain.
 It appears to happen in the std::vector class when the OpenFlight 
 plugin tries to add some new object, such as a vertex, to a vector.

 I'm just trying to confirm whether it could be something that I caused

 or if the OpenFlight plugin doesn't work well with the database pager.
 So if anyone has used openflight files with the database pager please 
 let me know.


 Thanks.

 Alex
 ___
 osg-users mailing list
 osg-users@openscenegraph.net
 http://openscenegraph.net/mailman/listinfo/osg-users
 http://www.openscenegraph.org/

___
osg-users mailing list
osg-users@openscenegraph.net
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
___
osg-users mailing list
osg-users@openscenegraph.net
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/


[osg-users] OpenFlight plugin threadsafe?

2007-06-29 Thread Pecoraro, Alexander N
Hi, I was wondering if anyone was using the OpenFlight ReaderWriter
plugin in combination with the osgDB::DatabasePager? I modified the
plugin so that it creates PagedLOD nodes for external reference records,
instead of ProxyNodes, so that I could have paging functionality in my
OpenFlight terrain. I made sure to set thread safe reference counting to
true, but I still seem to get segfaults when I fly around the terrain.
It appears to happen in the std::vector class when the OpenFlight plugin
tries to add some new object, such as a vertex, to a vector.

I'm just trying to confirm whether it could be something that I caused
or if the OpenFlight plugin doesn't work well with the database pager.
So if anyone has used openflight files with the database pager please
let me know.

Oh yea - I am using the plugin in src/osgPlugins/OpenFlight, not the one
in src/osgPlugins/flt. Out of curiosity, why is there two different
plugins for the same file type?

Thanks.

Alex
___
osg-users mailing list
osg-users@openscenegraph.net
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/