From 0c44e9ac198183a8ee4fa015f5b144ed978a2e9a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 29 Mar 2007 14:45:35 +0000 Subject: [PATCH] Added creation of basic geoemtry to test Locator and extents --- examples/osgterrain/osgterrain.cpp | 47 ++++++++++++++++++++- src/osgTerrain/GeometryTechnique.cpp | 61 ++++++++++++++++++++++++++-- 2 files changed, 103 insertions(+), 5 deletions(-) diff --git a/examples/osgterrain/osgterrain.cpp b/examples/osgterrain/osgterrain.cpp index 2b043d103..ceb420842 100644 --- a/examples/osgterrain/osgterrain.cpp +++ b/examples/osgterrain/osgterrain.cpp @@ -1,5 +1,3 @@ -#include - #include #include #include @@ -15,6 +13,18 @@ #include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + + #include #include #include @@ -31,6 +41,39 @@ int main(int argc, char** argv) // construct the viewer. osgViewer::Viewer viewer; + // set up the camera manipulators. + { + osg::ref_ptr keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; + + keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); + keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); + keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); + keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); + + std::string pathfile; + char keyForAnimationPath = '5'; + while (arguments.read("-p",pathfile)) + { + osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); + if (apm || !apm->valid()) + { + unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); + keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); + keyswitchManipulator->selectMatrixManipulator(num); + ++keyForAnimationPath; + } + } + + viewer.setCameraManipulator( keyswitchManipulator.get() ); + } + + + // add the state manipulator + viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) ); + + // add the stats handler + viewer.addEventHandler(new osgViewer::StatsHandler); + double x = 0.0; double y = 0.0; double w = 1.0; diff --git a/src/osgTerrain/GeometryTechnique.cpp b/src/osgTerrain/GeometryTechnique.cpp index c2b11b999..07a2f103e 100644 --- a/src/osgTerrain/GeometryTechnique.cpp +++ b/src/osgTerrain/GeometryTechnique.cpp @@ -97,11 +97,66 @@ void GeometryTechnique::init() _geode = new osg::Geode; _geometry = new osg::Geometry; _geode->addDrawable(_geometry.get()); + + unsigned int numRows = 100; + unsigned int numColumns = 100; + unsigned int numVertices = numRows * numColumns; - osg::Vec3Array* vertices = new osg::Vec3Array; - osg::Vec3Array* normals = new osg::Vec3Array; - osg::Vec2Array* texcoords = new osg::Vec2Array; + // allocate and assign vertices + osg::Vec3Array* vertices = new osg::Vec3Array(numVertices); + _geometry->setVertexArray(vertices); + // allocate and assign normals + osg::Vec3Array* normals = new osg::Vec3Array(numVertices); + _geometry->setNormalArray(normals); + _geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); + + // allocate and assign tex coords + osg::Vec2Array* texcoords = new osg::Vec2Array(numVertices); + _geometry->setTexCoordArray(0, texcoords); + + // allocate and assign color + osg::Vec4Array* colors = new osg::Vec4Array(1); + _geometry->setColorArray(colors); + _geometry->setColorBinding(osg::Geometry::BIND_OVERALL); + (*colors)[0].set(1.0f,1.0f,1.0f,1.0f); + + // populate vertex and tex coord arrays + unsigned int j; + for(j=0; jconvertLocalToModel(ndc, model); + + (*vertices)[iv] = model; + (*texcoords)[iv].set(ndc.x(), ndc.y()); + + // compute the local normal + osg::Vec3d ndc_one( (double)i/(double)(numColumns-1), (double)j/(double)(numColumns-1), 1.0); + osg::Vec3d model_one; + masterLocator->convertLocalToModel(ndc_one, model_one); + model_one -= model; + model_one.normalize(); + (*normals)[iv] = model_one; + } + } + + // populate primitive sets + for(j=0; jaddPrimitiveSet(elements); + } _dirty = false; }