From d801620b6c971703998a185fd7b66dae6635bbed Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 4 Aug 2008 09:07:21 +0000 Subject: [PATCH] Merged LineSegment and Quicktime fixes from svn/trunk, using : merge -r 8709:8712 http://www.openscenegraph.org/svn/osg/OpenSceneGraph/trunk . --- src/osgGA/TerrainManipulator.cpp | 38 +++++--- src/osgPlugins/quicktime/QTImportExport.cpp | 19 ++-- src/osgUtil/LineSegmentIntersector.cpp | 97 +++++++++++---------- 3 files changed, 85 insertions(+), 69 deletions(-) diff --git a/src/osgGA/TerrainManipulator.cpp b/src/osgGA/TerrainManipulator.cpp index 504fbd133..5566305ec 100644 --- a/src/osgGA/TerrainManipulator.cpp +++ b/src/osgGA/TerrainManipulator.cpp @@ -475,22 +475,34 @@ bool TerrainManipulator::calcMovement() CoordinateFrame coordinateFrame = getCoordinateFrame(_center); // need to reintersect with the terrain - double distance = _node->getBound().radius()*0.1f; - osg::Vec3d start_segment = _center + getUpVector(coordinateFrame) * distance; - osg::Vec3d end_segment = start_segment - getUpVector(coordinateFrame) * (2.0f*distance); - - osg::notify(INFO)<<"start="<getBound().radius()*0.25f; + + osg::Vec3d ip1; + osg::Vec3d ip2; + bool hit_ip1 = intersect(_center, _center + getUpVector(coordinateFrame) * distance, ip1); + bool hit_ip2 = intersect(_center, _center - getUpVector(coordinateFrame) * distance, ip2); + if (hit_ip1) { - notify(INFO) << "Hit terrain ok"<< std::endl; - - _center = ip; - + if (hit_ip2) + { + _center = (_center-ip1).length2() < (_center-ip2).length2() ? + ip1 : + ip2; + + hitFound = true; + } + else + { + _center = ip1; + hitFound = true; + } + } + else if (hit_ip2) + { + _center = ip2; hitFound = true; } - + if (!hitFound) { // ?? diff --git a/src/osgPlugins/quicktime/QTImportExport.cpp b/src/osgPlugins/quicktime/QTImportExport.cpp index 13b5e68cf..a26ec4f0c 100644 --- a/src/osgPlugins/quicktime/QTImportExport.cpp +++ b/src/osgPlugins/quicktime/QTImportExport.cpp @@ -247,10 +247,11 @@ Handle getPtrDataRef(unsigned char *data, unsigned int size, const std::string & // Convert From CString in filename to a PascalString in pstr if (filename.length() > 255) { - CopyCStringToPascal(filename.c_str(), pstr); //hmm...not good, pascal string limit is 255! //do some error handling maybe?! + throw QTImportExportException(0, "filename length limit exceeded"); } + CopyCStringToPascal(filename.c_str(), pstr); // Add filename extension /*err = */PtrToHand(pstr, &fileNameHandle, filename.length() + 1); @@ -282,7 +283,7 @@ osg::Image* QuicktimeImportExport::doImport(unsigned char* data, unsigned int si ImageDescriptionHandle desc = 0; int depth = 32; unsigned int xsize, ysize; - unsigned char* imageData; + unsigned char* imageData = 0; // Data Handle for file data ( & load data from file ) Handle dataRef = getPtrDataRef(data, sizeData, fileTypeHint); @@ -359,7 +360,7 @@ osg::Image* QuicktimeImportExport::doImport(unsigned char* data, unsigned int si DisposeHandle(reinterpret_cast(desc)); DisposeHandle(dataRef); } - catch (QTImportExportException e) + catch (QTImportExportException& e) { setError(e.what()); @@ -383,9 +384,9 @@ osg::Image* QuicktimeImportExport::doImport(unsigned char* data, unsigned int si + unsigned int bytesPerPixel = depth / 8; unsigned int glpixelFormat; - - switch(depth >> 3) { + switch(bytesPerPixel) { case 3 : glpixelFormat = GL_RGB; break; @@ -393,20 +394,20 @@ osg::Image* QuicktimeImportExport::doImport(unsigned char* data, unsigned int si glpixelFormat = GL_RGBA; break; default : - delete imageData; + delete[] imageData; setError("unknown pixelformat"); return NULL; break; } - unsigned char* swizzled = pepareBufferForOSG(imageData, depth >> 3, xsize, ysize); + unsigned char* swizzled = pepareBufferForOSG(imageData, bytesPerPixel, xsize, ysize); delete[] imageData; osg::Image* image = new osg::Image(); image->setFileName(fileTypeHint.c_str()); image->setImage(xsize,ysize,1, - depth >> 3, + bytesPerPixel, glpixelFormat, GL_UNSIGNED_BYTE, swizzled, @@ -510,7 +511,7 @@ osg::Image* QuicktimeImportExport::doImport(unsigned char* data, unsigned int si } - catch (QTImportExportException e) + catch (QTImportExportException& e) { setError(e.what()); diff --git a/src/osgUtil/LineSegmentIntersector.cpp b/src/osgUtil/LineSegmentIntersector.cpp index fba241f5f..70124e7a8 100644 --- a/src/osgUtil/LineSegmentIntersector.cpp +++ b/src/osgUtil/LineSegmentIntersector.cpp @@ -287,16 +287,6 @@ void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, osg::Dr if (iv.getDoDummyTraversal()) return; - double epsilon = 1e-8; - if ((s-e).length()(drawable->getShape()) : 0; if (kdTree) { @@ -460,43 +450,56 @@ bool LineSegmentIntersector::intersects(const osg::BoundingSphere& bs) return true; } -bool LineSegmentIntersector::intersectAndClip(osg::Vec3d& s, osg::Vec3d& e,const osg::BoundingBox& bb) +bool LineSegmentIntersector::intersectAndClip(osg::Vec3d& s, osg::Vec3d& e,const osg::BoundingBox& bbInput) { + osg::Vec3d bb_min(bbInput._min); + osg::Vec3d bb_max(bbInput._max); + +#if 1 + double epsilon = 1e-4; + bb_min.x() -= epsilon; + bb_min.y() -= epsilon; + bb_min.z() -= epsilon; + bb_max.x() += epsilon; + bb_max.y() += epsilon; + bb_max.z() += epsilon; +#endif + // compate s and e against the xMin to xMax range of bb. if (s.x()<=e.x()) { // trivial reject of segment wholely outside. - if (e.x()bb.xMax()) return false; + if (e.x()bb_max.x()) return false; - if (s.x()bb.xMax()) + if (e.x()>bb_max.x()) { // clip e to xMax. - e = s+(e-s)*(bb.xMax()-s.x())/(e.x()-s.x()); + e = s+(e-s)*(bb_max.x()-s.x())/(e.x()-s.x()); } } else { - if (s.x()bb.xMax()) return false; + if (s.x()bb_max.x()) return false; - if (e.x()bb.xMax()) + if (s.x()>bb_max.x()) { // clip e to xMax. - s = s+(e-s)*(bb.xMax()-s.x())/(e.x()-s.x()); + s = s+(e-s)*(bb_max.x()-s.x())/(e.x()-s.x()); } } @@ -505,36 +508,36 @@ bool LineSegmentIntersector::intersectAndClip(osg::Vec3d& s, osg::Vec3d& e,const { // trivial reject of segment wholely outside. - if (e.y()bb.yMax()) return false; + if (e.y()bb_max.y()) return false; - if (s.y()bb.yMax()) + if (e.y()>bb_max.y()) { // clip e to yMax. - e = s+(e-s)*(bb.yMax()-s.y())/(e.y()-s.y()); + e = s+(e-s)*(bb_max.y()-s.y())/(e.y()-s.y()); } } else { - if (s.y()bb.yMax()) return false; + if (s.y()bb_max.y()) return false; - if (e.y()bb.yMax()) + if (s.y()>bb_max.y()) { // clip e to yMax. - s = s+(e-s)*(bb.yMax()-s.y())/(e.y()-s.y()); + s = s+(e-s)*(bb_max.y()-s.y())/(e.y()-s.y()); } } @@ -543,36 +546,36 @@ bool LineSegmentIntersector::intersectAndClip(osg::Vec3d& s, osg::Vec3d& e,const { // trivial reject of segment wholely outside. - if (e.z()bb.zMax()) return false; + if (e.z()bb_max.z()) return false; - if (s.z()bb.zMax()) + if (e.z()>bb_max.z()) { // clip e to zMax. - e = s+(e-s)*(bb.zMax()-s.z())/(e.z()-s.z()); + e = s+(e-s)*(bb_max.z()-s.z())/(e.z()-s.z()); } } else { - if (s.z()bb.zMax()) return false; + if (s.z()bb_max.z()) return false; - if (e.z()bb.zMax()) + if (s.z()>bb_max.z()) { // clip e to zMax. - s = s+(e-s)*(bb.zMax()-s.z())/(e.z()-s.z()); + s = s+(e-s)*(bb_max.z()-s.z())/(e.z()-s.z()); } }