From 4abacc9d3d65b196bbb2cf945b1a8d07bb1dea01 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 28 May 2007 13:56:26 +0000 Subject: [PATCH] Added project down to base implementation. --- examples/osganimate/osganimate.cpp | 4 + src/osgSim/OverlayNode.cpp | 188 ++++++++++++++++++++++++----- 2 files changed, 159 insertions(+), 33 deletions(-) diff --git a/examples/osganimate/osganimate.cpp b/examples/osganimate/osganimate.cpp index eb93989c1..82cc0da26 100644 --- a/examples/osganimate/osganimate.cpp +++ b/examples/osganimate/osganimate.cpp @@ -181,6 +181,7 @@ osg::Node* createModel(bool overlay, osgSim::OverlayNode::OverlayTechnique techn osg::Group* root = new osg::Group; + float baseHeight = center.z()-radius*0.6; osg::Node* baseModel = createBase(center-osg::Vec3(0.0f,0.0f,radius*0.5),radius); osg::Node* movingModel = createMovingModel(center,radius*0.8f); @@ -189,6 +190,7 @@ osg::Node* createModel(bool overlay, osgSim::OverlayNode::OverlayTechnique techn osgSim::OverlayNode* overlayNode = new osgSim::OverlayNode(technique); overlayNode->setContinuousUpdate(true); overlayNode->setOverlaySubgraph(movingModel); + overlayNode->setOverlayBaseHeight(baseHeight); overlayNode->addChild(baseModel); root->addChild(overlayNode); } @@ -260,6 +262,8 @@ int main( int argc, char **argv ) // normal viewer usage. + viewer.setUpViewOnSingleScreen(1); + return viewer.run(); #endif diff --git a/src/osgSim/OverlayNode.cpp b/src/osgSim/OverlayNode.cpp index e1d6142c1..c8d786fe9 100644 --- a/src/osgSim/OverlayNode.cpp +++ b/src/osgSim/OverlayNode.cpp @@ -81,18 +81,18 @@ public: Face& face = createFace(); face.plane.set(0.0,1.0,0.0,1.0); face.vertices.push_back(v000); - face.vertices.push_back(v010); - face.vertices.push_back(v110); face.vertices.push_back(v100); + face.vertices.push_back(v101); + face.vertices.push_back(v001); } { // top plane. Face& face = createFace(); face.plane.set(0.0,-1.0,0.0,1.0); - face.vertices.push_back(v001); - face.vertices.push_back(v101); face.vertices.push_back(v111); face.vertices.push_back(v011); + face.vertices.push_back(v010); + face.vertices.push_back(v110); } if (withNear) @@ -100,24 +100,30 @@ public: Face& face = createFace(); face.plane.set(0.0,0.0,-1.0,1.0); face.vertices.push_back(v000); + face.vertices.push_back(v010); + face.vertices.push_back(v110); face.vertices.push_back(v100); - face.vertices.push_back(v101); - face.vertices.push_back(v001); } if (withFar) { // far plane Face& face = createFace(); face.plane.set(0.0,0.0,1.0,1.0); - face.vertices.push_back(v010); - face.vertices.push_back(v011); + face.vertices.push_back(v001); + face.vertices.push_back(v101); face.vertices.push_back(v111); - face.vertices.push_back(v110); + face.vertices.push_back(v011); } + } void setToBoundingBox(const osg::BoundingBox& bb) { +#if 0 + osg::notify(osg::NOTICE)<<"setToBoundingBox xrange "<=0.0) + { + removedFaces.push_back(face); + itr = _faces.erase(itr); + } + else + { + ++itr; + } + } + + if (removedFaces.empty()) return; + + typedef std::pair Edge; + typedef std::map Edges; + Edges edges; + + double numVerticesAdded=0.0; + osg::Vec3d center; + for(itr = removedFaces.begin(); + itr != removedFaces.end(); + ++itr) + { + Face& face = *itr; + Vertices& vertices = face.vertices; + for(unsigned int i=0; i VertexSet; + VertexSet uniqueVertices; + + for(Edges::iterator eitr = edges.begin(); + eitr != edges.end(); + ++eitr) + { + if (eitr->second==1) + { + // osg::notify(osg::NOTICE)<<" edge Ok"<first; + + double h_first = (edge.first-control) * normal; + osg::Vec3d projected_first = edge.first - normal * h_first; + + double h_second = (edge.second-control) * normal; + osg::Vec3d projected_second = edge.second - normal * h_second; + + Face face; + face.plane.set(projected_first, edge.first, edge.second); + face.vertices.push_back(projected_first); + face.vertices.push_back(projected_second); + face.vertices.push_back(edge.second); + face.vertices.push_back(edge.first); + + if (face.plane.distance(center)<0.0) face.plane.flip(); + _faces.push_back(face); + + uniqueVertices.insert(projected_first); + uniqueVertices.insert(projected_second); + } + } + + Face newFace; + newFace.plane.set(normal,control); + + osg::Vec3d side = ( fabs(normal.x()) < fabs(normal.y()) ) ? + osg::Vec3(1.0, 0.0, 0.0) : + osg::Vec3(0.0, 1.0, 0.0); + + osg::Vec3 v = normal ^ side; + v.normalize(); + + osg::Vec3 u = v ^ normal; + u.normalize(); + + typedef std::map AnglePositions; + AnglePositions anglePositions; + for(VertexSet::iterator vitr = uniqueVertices.begin(); + vitr != uniqueVertices.end(); + ++vitr) + { + osg::Vec3d delta = *vitr - center; + double angle = atan2(delta * u, delta * v); + if (angle<0.0) angle += 2.0*osg::PI; + anglePositions[angle] = *vitr; + } + + for(AnglePositions::iterator aitr = anglePositions.begin(); + aitr != anglePositions.end(); + ++aitr) + { + newFace.vertices.push_back(aitr->second); + } + + _faces.push_back(newFace); + + } @@ -521,7 +644,7 @@ public: ++itr) { Face& face = *itr; - geometry->addPrimitiveSet( new osg::DrawArrays(GL_LINE_STRIP, vertices->size(), face.vertices.size()) ); + geometry->addPrimitiveSet( new osg::DrawArrays(GL_LINE_LOOP, vertices->size(), face.vertices.size()) ); for(Vertices::iterator vitr = face.vertices.begin(); vitr != face.vertices.end(); ++vitr) @@ -1034,25 +1157,24 @@ void OverlayNode::traverse_VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY(osg::NodeVis else { double minHeight = -1000.0; - overlayPolytope.projectDowntoBase(osg::Vec3d(0.0,0.0,1.0), _overlayBaseHeight); + overlayPolytope.projectDowntoBase(osg::Vec3d(0.0,0.0,_overlayBaseHeight), osg::Vec3d(0.0,0.0,1.0)); } - if (overlayData._geode.valid() && overlayData._geode->getNumDrawables()>500) + if (overlayData._geode.valid() && overlayData._geode->getNumDrawables()>0) { overlayData._geode->removeDrawables(0, 3); } if (overlayData._geode.valid()) { - //overlayData._geode->addDrawable(overlayPolytope.createDrawable(osg::Vec4d(1.0f,1.0f,0.0f,1.0f))); - //overlayData._geode->addDrawable(frustum.createDrawable(osg::Vec4d(0.0f,0.0f,1.0f,1.0f))); + overlayData._geode->addDrawable(overlayPolytope.createDrawable(osg::Vec4d(1.0f,1.0f,0.0f,1.0f))); + overlayData._geode->addDrawable(frustum.createDrawable(osg::Vec4d(0.0f,0.0f,1.0f,1.0f))); } - CustomPolytope::Vertices corners; - overlayPolytope.cut(frustum); + //overlayPolytope.cut(frustum); overlayPolytope.getPoints(corners); if (overlayData._geode.valid())