Made the LineSegment destructor protected to force users to create segments
on the stack thus ensure that they arn't created locally and have their memory deleted incorrectly. Also updated the IntersectVisitor so that it no used osg::ref_ptr<> internally for storing all data. Have also move the IntersectState helper class to inside the IntersectVisitor which simplifies the external interface to the class.
This commit is contained in:
@@ -1,126 +0,0 @@
|
||||
osgcopy.o: osgcopy.cpp /home/robert/OpenSceneGraph/include/osg/Transform \
|
||||
/home/robert/OpenSceneGraph/include/osg/Group \
|
||||
/home/robert/OpenSceneGraph/include/osg/Node \
|
||||
/home/robert/OpenSceneGraph/include/osg/Object \
|
||||
/home/robert/OpenSceneGraph/include/osg/Referenced \
|
||||
/home/robert/OpenSceneGraph/include/osg/Export /usr/include/g++-3/set \
|
||||
/usr/include/g++-3/stl_tree.h /usr/include/g++-3/stl_algobase.h \
|
||||
/usr/include/g++-3/stl_config.h /usr/include/_G_config.h \
|
||||
/usr/include/bits/types.h /usr/include/features.h \
|
||||
/usr/include/sys/cdefs.h /usr/include/gnu/stubs.h \
|
||||
/usr/lib/gcc-lib/i586-mandrake-linux/2.96/include/stddef.h \
|
||||
/usr/include/bits/pthreadtypes.h /usr/include/bits/sched.h \
|
||||
/usr/include/wchar.h /usr/include/bits/wchar.h /usr/include/gconv.h \
|
||||
/usr/include/g++-3/stl_relops.h /usr/include/g++-3/stl_pair.h \
|
||||
/usr/include/g++-3/type_traits.h /usr/include/string.h \
|
||||
/usr/lib/gcc-lib/i586-mandrake-linux/2.96/include/limits.h \
|
||||
/usr/lib/gcc-lib/i586-mandrake-linux/2.96/include/syslimits.h \
|
||||
/usr/include/limits.h /usr/include/bits/posix1_lim.h \
|
||||
/usr/include/bits/local_lim.h /usr/include/linux/limits.h \
|
||||
/usr/include/bits/posix2_lim.h /usr/include/stdlib.h \
|
||||
/usr/include/sys/types.h /usr/include/time.h /usr/include/endian.h \
|
||||
/usr/include/bits/endian.h /usr/include/sys/select.h \
|
||||
/usr/include/bits/select.h /usr/include/bits/sigset.h \
|
||||
/usr/include/bits/time.h /usr/include/sys/sysmacros.h \
|
||||
/usr/include/alloca.h \
|
||||
/usr/lib/gcc-lib/i586-mandrake-linux/2.96/include/new.h \
|
||||
/usr/lib/gcc-lib/i586-mandrake-linux/2.96/include/new \
|
||||
/usr/lib/gcc-lib/i586-mandrake-linux/2.96/include/exception \
|
||||
/usr/include/g++-3/iostream.h /usr/include/g++-3/streambuf.h \
|
||||
/usr/include/libio.h \
|
||||
/usr/lib/gcc-lib/i586-mandrake-linux/2.96/include/stdarg.h \
|
||||
/usr/include/g++-3/stl_iterator.h /usr/include/g++-3/stl_alloc.h \
|
||||
/usr/include/assert.h /usr/include/pthread.h /usr/include/sched.h \
|
||||
/usr/include/signal.h /usr/include/bits/initspin.h \
|
||||
/usr/include/bits/sigthread.h /usr/include/g++-3/stl_construct.h \
|
||||
/usr/include/g++-3/stl_function.h /usr/include/g++-3/stl_set.h \
|
||||
/usr/include/g++-3/stl_multiset.h \
|
||||
/home/robert/OpenSceneGraph/include/osg/CopyOp \
|
||||
/home/robert/OpenSceneGraph/include/osg/StateSet \
|
||||
/home/robert/OpenSceneGraph/include/osg/StateAttribute \
|
||||
/home/robert/OpenSceneGraph/include/osg/GL /usr/X11R6/include/GL/gl.h \
|
||||
/usr/X11R6/include/GL/glext.h \
|
||||
/usr/lib/gcc-lib/i586-mandrake-linux/2.96/include/typeinfo \
|
||||
/home/robert/OpenSceneGraph/include/osg/ref_ptr /usr/include/g++-3/map \
|
||||
/usr/include/g++-3/stl_map.h /usr/include/g++-3/stl_multimap.h \
|
||||
/usr/include/g++-3/vector /usr/include/g++-3/stl_uninitialized.h \
|
||||
/usr/include/g++-3/stl_vector.h /usr/include/g++-3/stl_bvector.h \
|
||||
/usr/include/g++-3/string /usr/include/g++-3/std/bastring.h \
|
||||
/usr/include/g++-3/cstddef /usr/include/g++-3/std/straits.h \
|
||||
/usr/include/g++-3/cctype /usr/include/ctype.h \
|
||||
/usr/include/g++-3/cstring /usr/include/g++-3/alloc.h \
|
||||
/usr/include/g++-3/iterator /usr/include/g++-3/cassert \
|
||||
/usr/include/g++-3/std/bastring.cc \
|
||||
/home/robert/OpenSceneGraph/include/osg/BoundingSphere \
|
||||
/home/robert/OpenSceneGraph/include/osg/Vec3 \
|
||||
/home/robert/OpenSceneGraph/include/osg/Math /usr/include/math.h \
|
||||
/usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \
|
||||
/usr/include/bits/mathcalls.h /usr/include/bits/mathinline.h \
|
||||
/usr/include/g++-3/iostream \
|
||||
/home/robert/OpenSceneGraph/include/osg/NodeCallback \
|
||||
/home/robert/OpenSceneGraph/include/osg/NodeVisitor \
|
||||
/home/robert/OpenSceneGraph/include/osg/FrameStamp \
|
||||
/usr/include/g++-3/ctime /home/robert/OpenSceneGraph/include/osg/Matrix \
|
||||
/home/robert/OpenSceneGraph/include/osg/Vec4 \
|
||||
/home/robert/OpenSceneGraph/include/osg/Billboard \
|
||||
/home/robert/OpenSceneGraph/include/osg/Geode \
|
||||
/home/robert/OpenSceneGraph/include/osg/Drawable \
|
||||
/home/robert/OpenSceneGraph/include/osg/BoundingBox \
|
||||
/usr/lib/gcc-lib/i586-mandrake-linux/2.96/include/float.h \
|
||||
/home/robert/OpenSceneGraph/include/osg/State \
|
||||
/home/robert/OpenSceneGraph/include/osg/Camera \
|
||||
/home/robert/OpenSceneGraph/include/osg/Quat \
|
||||
/home/robert/OpenSceneGraph/include/osg/ClippingVolume \
|
||||
/home/robert/OpenSceneGraph/include/osg/Plane \
|
||||
/home/robert/OpenSceneGraph/include/osg/Viewport \
|
||||
/home/robert/OpenSceneGraph/include/osg/Types \
|
||||
/home/robert/OpenSceneGraph/include/osg/DisplaySettings \
|
||||
/home/robert/OpenSceneGraph/include/osg/Vec2 \
|
||||
/home/robert/OpenSceneGraph/include/osg/Notify \
|
||||
/usr/include/g++-3/fstream /usr/include/g++-3/fstream.h \
|
||||
/home/robert/OpenSceneGraph/include/osg/Texture \
|
||||
/home/robert/OpenSceneGraph/include/osg/Image \
|
||||
/home/robert/OpenSceneGraph/include/osgDB/Registry \
|
||||
/home/robert/OpenSceneGraph/include/osgDB/DynamicLibrary \
|
||||
/home/robert/OpenSceneGraph/include/osgDB/Export \
|
||||
/home/robert/OpenSceneGraph/include/osgDB/ReaderWriter \
|
||||
/home/robert/OpenSceneGraph/include/osgDB/DotOsgWrapper \
|
||||
/home/robert/OpenSceneGraph/include/osgDB/Input \
|
||||
/home/robert/OpenSceneGraph/include/osgDB/FieldReaderIterator \
|
||||
/home/robert/OpenSceneGraph/include/osgDB/Field \
|
||||
/home/robert/OpenSceneGraph/include/osgDB/FieldReader \
|
||||
/home/robert/OpenSceneGraph/include/osgDB/Output \
|
||||
/home/robert/OpenSceneGraph/include/osgDB/ReadFile \
|
||||
/home/robert/OpenSceneGraph/include/osgDB/WriteFile \
|
||||
/home/robert/OpenSceneGraph/include/osgUtil/TrackballManipulator \
|
||||
/home/robert/OpenSceneGraph/include/osgUtil/CameraManipulator \
|
||||
/home/robert/OpenSceneGraph/include/osgUtil/Export \
|
||||
/home/robert/OpenSceneGraph/include/osgUtil/GUIEventHandler \
|
||||
/home/robert/OpenSceneGraph/include/osgUtil/GUIEventAdapter \
|
||||
/home/robert/OpenSceneGraph/include/osgUtil/GUIActionAdapter \
|
||||
/home/robert/OpenSceneGraph/include/osgUtil/FlightManipulator \
|
||||
/home/robert/OpenSceneGraph/include/osgUtil/DriveManipulator \
|
||||
/home/robert/OpenSceneGraph/include/osgGLUT/glut \
|
||||
/usr/X11R6/include/GL/glut.h /usr/X11R6/include/GL/glu.h \
|
||||
/home/robert/OpenSceneGraph/include/osgGLUT/Viewer \
|
||||
/home/robert/OpenSceneGraph/include/osg/Light \
|
||||
/home/robert/OpenSceneGraph/include/osg/Timer /usr/include/sys/time.h \
|
||||
/home/robert/OpenSceneGraph/include/osgUtil/SceneView \
|
||||
/home/robert/OpenSceneGraph/include/osgUtil/CullVisitor \
|
||||
/home/robert/OpenSceneGraph/include/osg/Impostor \
|
||||
/home/robert/OpenSceneGraph/include/osg/LOD \
|
||||
/home/robert/OpenSceneGraph/include/osg/ImpostorSprite \
|
||||
/home/robert/OpenSceneGraph/include/osg/AlphaFunc \
|
||||
/home/robert/OpenSceneGraph/include/osg/TexEnv \
|
||||
/home/robert/OpenSceneGraph/include/osg/EarthSky \
|
||||
/home/robert/OpenSceneGraph/include/osgUtil/RenderGraph \
|
||||
/home/robert/OpenSceneGraph/include/osgUtil/RenderLeaf \
|
||||
/home/robert/OpenSceneGraph/include/osgUtil/RenderStage \
|
||||
/home/robert/OpenSceneGraph/include/osg/ColorMask \
|
||||
/home/robert/OpenSceneGraph/include/osgUtil/RenderBin \
|
||||
/home/robert/OpenSceneGraph/include/osg/Statistics \
|
||||
/home/robert/OpenSceneGraph/include/osgUtil/RenderStageLighting \
|
||||
/home/robert/OpenSceneGraph/include/osgUtil/CullViewState \
|
||||
/home/robert/OpenSceneGraph/include/osgGLUT/Window \
|
||||
/home/robert/OpenSceneGraph/include/osgGLUT/Export \
|
||||
/home/robert/OpenSceneGraph/include/osgUtil/Optimizer
|
||||
|
||||
@@ -1055,9 +1055,9 @@ void Viewer::keyboard(unsigned char key, int x, int y)
|
||||
{
|
||||
osg::Vec3 ip = hitr->_intersectPoint;
|
||||
osg::Vec3 in = hitr->_intersectNormal;
|
||||
osg::Geode* geode = hitr->_geode;
|
||||
osg::Geode* geode = hitr->_geode.get();
|
||||
osg::notify(osg::NOTICE) << " Itersection Point ("<<ip<<") Normal ("<<in<<")"<< std::endl;
|
||||
if (hitr->_matrix)
|
||||
if (hitr->_matrix.valid())
|
||||
{
|
||||
osg::Vec3 ipEye = ip*(*(hitr->_matrix));
|
||||
osg::Vec3 inEye = (in+ip)*(*(hitr->_matrix))-ipEye;
|
||||
@@ -1069,7 +1069,7 @@ void Viewer::keyboard(unsigned char key, int x, int y)
|
||||
if (key=='r' && geode)
|
||||
{
|
||||
// remove geoset..
|
||||
osg::GeoSet* gset = hitr->_geoset;
|
||||
osg::GeoSet* gset = hitr->_geoset.get();
|
||||
osg::notify(osg::NOTICE) << " geoset ("<<gset<<") "<<geode->removeDrawable(gset)<<")"<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -294,84 +294,84 @@ void TriangleViewFrustumIntersect::intersect_triangle(const osg::Vec3& vert1, co
|
||||
|
||||
//construct line segment of two triangle vertices and check if they intersect any clipping plane
|
||||
//but within correct clipping plane triangle
|
||||
osg::LineSegment s12(v1, v2);
|
||||
osg::ref_ptr<osg::LineSegment> s12 = new LineSegment(v1, v2);
|
||||
|
||||
|
||||
//left triangle
|
||||
if(intersect_linesegment_and_triangle(returned, s12, _eye, UpLeft, DownLeft) == 0)
|
||||
if(intersect_linesegment_and_triangle(returned, *s12, _eye, UpLeft, DownLeft) == 0)
|
||||
_listVectors[returned] = true;
|
||||
|
||||
//up triangle
|
||||
if(intersect_linesegment_and_triangle(returned, s12, _eye, UpLeft, UpRight) == 0)
|
||||
if(intersect_linesegment_and_triangle(returned, *s12, _eye, UpLeft, UpRight) == 0)
|
||||
_listVectors[returned] = true;
|
||||
|
||||
//right triangle
|
||||
if(intersect_linesegment_and_triangle(returned, s12, _eye, UpRight, DownRight) == 0)
|
||||
if(intersect_linesegment_and_triangle(returned, *s12, _eye, UpRight, DownRight) == 0)
|
||||
_listVectors[returned] = true;
|
||||
|
||||
//bottom triangled
|
||||
if(intersect_linesegment_and_triangle(returned, s12, _eye, DownLeft, DownRight) == 0)
|
||||
if(intersect_linesegment_and_triangle(returned, *s12, _eye, DownLeft, DownRight) == 0)
|
||||
_listVectors[returned] = true;
|
||||
|
||||
//now for second edge of triangle
|
||||
s12.set(v2, v3);
|
||||
s12->set(v2, v3);
|
||||
|
||||
//left triangle
|
||||
if(intersect_linesegment_and_triangle(returned, s12, _eye, UpLeft, DownLeft) == 0)
|
||||
if(intersect_linesegment_and_triangle(returned, *s12, _eye, UpLeft, DownLeft) == 0)
|
||||
_listVectors[returned] = true;
|
||||
|
||||
//up triangle
|
||||
if(intersect_linesegment_and_triangle(returned, s12, _eye, UpLeft, UpRight) == 0)
|
||||
if(intersect_linesegment_and_triangle(returned, *s12, _eye, UpLeft, UpRight) == 0)
|
||||
_listVectors[returned] = true;
|
||||
|
||||
//right triangle
|
||||
if(intersect_linesegment_and_triangle(returned, s12, _eye, UpRight, DownRight) == 0)
|
||||
if(intersect_linesegment_and_triangle(returned, *s12, _eye, UpRight, DownRight) == 0)
|
||||
_listVectors[returned] = true;
|
||||
|
||||
//bottom triangled
|
||||
if(intersect_linesegment_and_triangle(returned, s12, _eye, DownLeft, DownRight) == 0)
|
||||
if(intersect_linesegment_and_triangle(returned, *s12, _eye, DownLeft, DownRight) == 0)
|
||||
_listVectors[returned] = true;
|
||||
|
||||
s12.set(v3, v1);
|
||||
s12->set(v3, v1);
|
||||
|
||||
//left triangle
|
||||
if(intersect_linesegment_and_triangle(returned, s12, _eye, UpLeft, DownLeft) == 0)
|
||||
if(intersect_linesegment_and_triangle(returned, *s12, _eye, UpLeft, DownLeft) == 0)
|
||||
_listVectors[returned] = true;
|
||||
|
||||
//up triangle
|
||||
if(intersect_linesegment_and_triangle(returned, s12, _eye, UpLeft, UpRight) == 0)
|
||||
if(intersect_linesegment_and_triangle(returned, *s12, _eye, UpLeft, UpRight) == 0)
|
||||
_listVectors[returned] = true;
|
||||
|
||||
//right triangle
|
||||
if(intersect_linesegment_and_triangle(returned, s12, _eye, UpRight, DownRight) == 0)
|
||||
if(intersect_linesegment_and_triangle(returned, *s12, _eye, UpRight, DownRight) == 0)
|
||||
_listVectors[returned] = true;
|
||||
|
||||
//bottom triangled
|
||||
if(intersect_linesegment_and_triangle(returned, s12, _eye, DownLeft, DownRight) == 0)
|
||||
if(intersect_linesegment_and_triangle(returned, *s12, _eye, DownLeft, DownRight) == 0)
|
||||
_listVectors[returned] = true;
|
||||
|
||||
|
||||
//we still have possibility of camera being above huge triangle, so it is possible that clipping volume
|
||||
//intersects this triangle thus giving coordinates relevant for determination of near plane
|
||||
|
||||
s12.set(_eye, UpLeft);
|
||||
s12->set(_eye, UpLeft);
|
||||
|
||||
if(intersect_linesegment_and_triangle(returned, s12, v1, v2, v3) == 0)
|
||||
if(intersect_linesegment_and_triangle(returned, *s12, v1, v2, v3) == 0)
|
||||
_listVectors[returned] = true;
|
||||
|
||||
s12.set(_eye, DownLeft);
|
||||
s12->set(_eye, DownLeft);
|
||||
|
||||
if(intersect_linesegment_and_triangle(returned, s12, v1, v2, v3) == 0)
|
||||
if(intersect_linesegment_and_triangle(returned, *s12, v1, v2, v3) == 0)
|
||||
_listVectors[returned] = true;
|
||||
|
||||
s12.set(_eye, UpRight);
|
||||
s12->set(_eye, UpRight);
|
||||
|
||||
if(intersect_linesegment_and_triangle(returned, s12, v1, v2, v3) == 0)
|
||||
if(intersect_linesegment_and_triangle(returned, *s12, v1, v2, v3) == 0)
|
||||
_listVectors[returned] = true;
|
||||
|
||||
s12.set(_eye, DownRight);
|
||||
s12->set(_eye, DownRight);
|
||||
|
||||
if(intersect_linesegment_and_triangle(returned, s12, v1, v2, v3) == 0)
|
||||
if(intersect_linesegment_and_triangle(returned, *s12, v1, v2, v3) == 0)
|
||||
_listVectors[returned] = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,32 +12,87 @@
|
||||
using namespace osg;
|
||||
using namespace osgUtil;
|
||||
|
||||
IntersectState::IntersectState()
|
||||
|
||||
|
||||
Hit::Hit()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Hit::Hit(const Hit& hit)
|
||||
{
|
||||
// copy data across.
|
||||
_ratio = hit._ratio;
|
||||
_originalLineSegment = hit._originalLineSegment;
|
||||
_localLineSegment = hit._localLineSegment;
|
||||
_nodePath = hit._nodePath;
|
||||
_geode = hit._geode;
|
||||
_geoset = hit._geoset;
|
||||
_matrix = hit._matrix;
|
||||
_inverse = hit._inverse;
|
||||
|
||||
_vecIndexList = hit._vecIndexList;
|
||||
_primitiveIndex = hit._primitiveIndex;
|
||||
_intersectPoint = hit._intersectPoint;
|
||||
_intersectNormal = hit._intersectNormal;
|
||||
}
|
||||
|
||||
|
||||
Hit::~Hit()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Hit& Hit::operator = (const Hit& hit)
|
||||
{
|
||||
if (&hit==this) return *this;
|
||||
|
||||
_matrix = hit._matrix;
|
||||
_inverse = hit._inverse;
|
||||
_originalLineSegment = hit._originalLineSegment;
|
||||
_localLineSegment = hit._localLineSegment;
|
||||
|
||||
// copy data across.
|
||||
_ratio = hit._ratio;
|
||||
_originalLineSegment = hit._originalLineSegment;
|
||||
_localLineSegment = hit._localLineSegment;
|
||||
_nodePath = hit._nodePath;
|
||||
_geode = hit._geode;
|
||||
_geoset = hit._geoset;
|
||||
|
||||
_vecIndexList = hit._vecIndexList;
|
||||
_primitiveIndex = hit._primitiveIndex;
|
||||
_intersectPoint = hit._intersectPoint;
|
||||
_intersectNormal = hit._intersectNormal;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
const osg::Vec3 Hit::getWorldIntersectNormal() const
|
||||
{
|
||||
if (_inverse.valid())
|
||||
{
|
||||
osg::Vec3 norm = osg::Matrix::transform3x3(*_inverse,_intersectNormal);
|
||||
norm.normalize();
|
||||
return norm;
|
||||
}
|
||||
else return _intersectNormal;
|
||||
}
|
||||
|
||||
|
||||
|
||||
IntersectVisitor::IntersectState::IntersectState()
|
||||
{
|
||||
_matrix = NULL;
|
||||
_inverse = NULL;
|
||||
_segmentMaskStack.push_back(0xffffffff);
|
||||
}
|
||||
|
||||
|
||||
IntersectState::~IntersectState()
|
||||
IntersectVisitor::IntersectState::~IntersectState()
|
||||
{
|
||||
if (_matrix) _matrix->unref();
|
||||
if (_inverse) _inverse->unref();
|
||||
for(LineSegmentList::iterator itr=_segList.begin();
|
||||
itr!=_segList.end();
|
||||
++itr)
|
||||
{
|
||||
itr->first->unref();
|
||||
itr->second->unref();
|
||||
}
|
||||
|
||||
_matrix = (osg::Matrix *)0xffffffff;
|
||||
_inverse = (osg::Matrix *)0xffffffff;
|
||||
}
|
||||
|
||||
|
||||
bool IntersectState::isCulled(const BoundingSphere& bs,LineSegmentmentMask& segMaskOut)
|
||||
bool IntersectVisitor::IntersectState::isCulled(const BoundingSphere& bs,LineSegmentmentMask& segMaskOut)
|
||||
{
|
||||
bool hit = false;
|
||||
LineSegmentmentMask mask = 0x00000001;
|
||||
@@ -61,7 +116,7 @@ bool IntersectState::isCulled(const BoundingSphere& bs,LineSegmentmentMask& segM
|
||||
}
|
||||
|
||||
|
||||
bool IntersectState::isCulled(const BoundingBox& bb,LineSegmentmentMask& segMaskOut)
|
||||
bool IntersectVisitor::IntersectState::isCulled(const BoundingBox& bb,LineSegmentmentMask& segMaskOut)
|
||||
{
|
||||
bool hit = false;
|
||||
LineSegmentmentMask mask = 0x00000001;
|
||||
@@ -81,92 +136,6 @@ bool IntersectState::isCulled(const BoundingBox& bb,LineSegmentmentMask& segMask
|
||||
return !hit;
|
||||
}
|
||||
|
||||
|
||||
Hit::Hit()
|
||||
{
|
||||
_originalLineSegment=NULL;
|
||||
_localLineSegment=NULL;
|
||||
_geode=NULL;
|
||||
_geoset=NULL;
|
||||
_matrix=NULL;
|
||||
}
|
||||
|
||||
|
||||
Hit::Hit(const Hit& hit):Referenced()
|
||||
{
|
||||
// copy data across.
|
||||
_ratio = hit._ratio;
|
||||
_originalLineSegment = hit._originalLineSegment;
|
||||
_localLineSegment = hit._localLineSegment;
|
||||
_nodePath = hit._nodePath;
|
||||
_geode = hit._geode;
|
||||
_geoset = hit._geoset;
|
||||
_matrix = hit._matrix;
|
||||
|
||||
_vecIndexList = hit._vecIndexList;
|
||||
_primitiveIndex = hit._primitiveIndex;
|
||||
_intersectPoint = hit._intersectPoint;
|
||||
_intersectNormal = hit._intersectNormal;
|
||||
|
||||
if (_matrix) _matrix->ref();
|
||||
if (_originalLineSegment) _originalLineSegment->ref();
|
||||
if (_localLineSegment) _localLineSegment->ref();
|
||||
}
|
||||
|
||||
|
||||
Hit::~Hit()
|
||||
{
|
||||
if (_matrix) _matrix->unref();
|
||||
if (_originalLineSegment) _originalLineSegment->unref();
|
||||
if (_localLineSegment) _localLineSegment->unref();
|
||||
_matrix = (osg::Matrix*)0xffffffff;
|
||||
_localLineSegment = (osg::LineSegment*)0xffffffff;
|
||||
_localLineSegment = (osg::LineSegment*)0xffffffff;
|
||||
_geode = (osg::Geode*)0xffffffff;
|
||||
}
|
||||
|
||||
|
||||
Hit& Hit::operator = (const Hit& hit)
|
||||
{
|
||||
if (&hit==this) return *this;
|
||||
|
||||
// free old memory.
|
||||
if (_matrix!=hit._matrix)
|
||||
{
|
||||
if (_matrix) _matrix->unref();
|
||||
_matrix = hit._matrix;
|
||||
if (_matrix) _matrix->ref();
|
||||
}
|
||||
if (_originalLineSegment!=hit._originalLineSegment)
|
||||
{
|
||||
if (_originalLineSegment) _originalLineSegment->unref();
|
||||
_originalLineSegment = hit._originalLineSegment;
|
||||
if (_originalLineSegment) _originalLineSegment->ref();
|
||||
}
|
||||
if (_localLineSegment!=hit._localLineSegment)
|
||||
{
|
||||
if (_localLineSegment) _localLineSegment->unref();
|
||||
_localLineSegment = hit._localLineSegment;
|
||||
if (_localLineSegment) _localLineSegment->ref();
|
||||
}
|
||||
|
||||
// copy data across.
|
||||
_ratio = hit._ratio;
|
||||
_originalLineSegment = hit._originalLineSegment;
|
||||
_localLineSegment = hit._localLineSegment;
|
||||
_nodePath = hit._nodePath;
|
||||
_geode = hit._geode;
|
||||
_geoset = hit._geoset;
|
||||
|
||||
_vecIndexList = hit._vecIndexList;
|
||||
_primitiveIndex = hit._primitiveIndex;
|
||||
_intersectPoint = hit._intersectPoint;
|
||||
_intersectNormal = hit._intersectNormal;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
IntersectVisitor::IntersectVisitor()
|
||||
{
|
||||
// overide the default node visitor mode.
|
||||
@@ -182,16 +151,10 @@ IntersectVisitor::~IntersectVisitor()
|
||||
|
||||
void IntersectVisitor::reset()
|
||||
{
|
||||
|
||||
//
|
||||
// first unref all referenced objects and then empty the containers.
|
||||
//
|
||||
_intersectStateStack.clear();
|
||||
|
||||
// create a empty IntersectState on the the intersectStateStack.
|
||||
IntersectState* nis = new IntersectState;
|
||||
nis->_matrix = NULL;
|
||||
nis->_inverse = NULL;
|
||||
|
||||
_intersectStateStack.push_back(nis);
|
||||
|
||||
@@ -231,11 +194,11 @@ void IntersectVisitor::addLineSegment(LineSegment* seg)
|
||||
// create a new segment transformed to local coordintes.
|
||||
IntersectState* cis = _intersectStateStack.back().get();
|
||||
LineSegment* ns = new LineSegment;
|
||||
if (cis->_inverse) ns->mult(*seg,*(cis->_inverse));
|
||||
|
||||
if (cis->_inverse.valid()) ns->mult(*seg,*(cis->_inverse));
|
||||
else *ns = *seg;
|
||||
cis->_segList.push_back(std::pair<LineSegment*,LineSegment*>(seg,ns));
|
||||
seg->ref();
|
||||
ns->ref();
|
||||
|
||||
cis->addLineSegmentPair(seg,ns);
|
||||
|
||||
}
|
||||
|
||||
@@ -246,7 +209,7 @@ void IntersectVisitor::pushMatrix(const Matrix& matrix)
|
||||
|
||||
IntersectState* cis = _intersectStateStack.back().get();
|
||||
|
||||
if (cis->_matrix)
|
||||
if (cis->_matrix.valid())
|
||||
{
|
||||
nis->_matrix = new Matrix;
|
||||
nis->_matrix->mult(matrix,*(cis->_matrix));
|
||||
@@ -255,10 +218,8 @@ void IntersectVisitor::pushMatrix(const Matrix& matrix)
|
||||
{
|
||||
nis->_matrix = new Matrix(matrix);
|
||||
}
|
||||
nis->_matrix->ref();
|
||||
|
||||
Matrix* inverse_world = new Matrix;
|
||||
inverse_world->ref();
|
||||
inverse_world->invert(*(nis->_matrix));
|
||||
nis->_inverse = inverse_world;
|
||||
|
||||
@@ -272,16 +233,12 @@ void IntersectVisitor::pushMatrix(const Matrix& matrix)
|
||||
{
|
||||
LineSegment* seg = new LineSegment;
|
||||
seg->mult(*(sitr->first),*inverse_world);
|
||||
nis->_segList.push_back(std::pair<LineSegment*,LineSegment*>(sitr->first,seg));
|
||||
seg->ref();
|
||||
sitr->first->ref();
|
||||
nis->addLineSegmentPair(sitr->first.get(),seg);
|
||||
}
|
||||
mask = mask << 1;
|
||||
}
|
||||
|
||||
_intersectStateStack.push_back(nis);
|
||||
|
||||
// notify(INFO) << << "IntersectVisitor::pushMatrix()"<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -289,11 +246,8 @@ void IntersectVisitor::popMatrix()
|
||||
{
|
||||
if (!_intersectStateStack.empty())
|
||||
{
|
||||
// IntersectState* pvs = _intersectStateStack.back().get();
|
||||
// pvs->unref();
|
||||
_intersectStateStack.pop_back();
|
||||
}
|
||||
// notify(INFO) << << "IntersectVisitor::popMatrix()"<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -335,7 +289,7 @@ void IntersectVisitor::apply(Node& node)
|
||||
|
||||
struct TriangleIntersect
|
||||
{
|
||||
LineSegment _seg;
|
||||
osg::ref_ptr<LineSegment> _seg;
|
||||
|
||||
Vec3 _s;
|
||||
Vec3 _d;
|
||||
@@ -350,13 +304,13 @@ struct TriangleIntersect
|
||||
|
||||
TriangleIntersect(const LineSegment& seg,float ratio=FLT_MAX)
|
||||
{
|
||||
_seg=seg;
|
||||
_seg=new LineSegment(seg);
|
||||
_hit=false;
|
||||
_index = 0;
|
||||
_ratio = ratio;
|
||||
|
||||
_s = _seg.start();
|
||||
_d = _seg.end()-_seg.start();
|
||||
_s = _seg->start();
|
||||
_d = _seg->end()-_seg->start();
|
||||
_length = _d.length();
|
||||
_d /= _length;
|
||||
|
||||
@@ -485,7 +439,7 @@ bool IntersectVisitor::intersect(GeoSet& gset)
|
||||
Hit hit;
|
||||
hit._nodePath = _nodePath;
|
||||
hit._matrix = cis->_matrix;
|
||||
if (hit._matrix) hit._matrix->ref();
|
||||
hit._inverse = cis->_inverse;
|
||||
hit._geoset = &gset;
|
||||
if (_nodePath.empty()) hit._geode = NULL;
|
||||
else hit._geode = dynamic_cast<Geode*>(_nodePath.back());
|
||||
@@ -493,25 +447,21 @@ bool IntersectVisitor::intersect(GeoSet& gset)
|
||||
hit._ratio = thitr->first;
|
||||
hit._primitiveIndex = thitr->second.first;
|
||||
hit._originalLineSegment = sitr->first;
|
||||
if (hit._originalLineSegment) hit._originalLineSegment->ref();
|
||||
hit._localLineSegment = sitr->second;
|
||||
if (hit._localLineSegment) hit._localLineSegment->ref();
|
||||
|
||||
hit._intersectPoint = sitr->second->start()*(1.0f-hit._ratio)+
|
||||
sitr->second->end()*hit._ratio;
|
||||
|
||||
hit._intersectNormal = thitr->second.second;
|
||||
|
||||
// _segHitList[sitr->first].insert(hit);
|
||||
_segHitList[sitr->first].push_back(hit);
|
||||
std::sort(_segHitList[sitr->first].begin(),_segHitList[sitr->first].end());
|
||||
_segHitList[sitr->first.get()].push_back(hit);
|
||||
std::sort(_segHitList[sitr->first.get()].begin(),_segHitList[sitr->first.get()].end());
|
||||
|
||||
hitFlag = true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// else notify(INFO) << << "no BB hit"<< std::endl;
|
||||
}
|
||||
|
||||
return hitFlag;
|
||||
|
||||
Reference in New Issue
Block a user