Added creation of basic geoemtry to test Locator and extents
This commit is contained in:
parent
e8ede168c9
commit
0c44e9ac19
@ -1,5 +1,3 @@
|
|||||||
#include <osgViewer/Viewer>
|
|
||||||
|
|
||||||
#include <osg/Group>
|
#include <osg/Group>
|
||||||
#include <osg/Geode>
|
#include <osg/Geode>
|
||||||
#include <osg/ShapeDrawable>
|
#include <osg/ShapeDrawable>
|
||||||
@ -15,6 +13,18 @@
|
|||||||
|
|
||||||
#include <osgText/FadeText>
|
#include <osgText/FadeText>
|
||||||
|
|
||||||
|
#include <osgViewer/Viewer>
|
||||||
|
#include <osgViewer/StatsHandler>
|
||||||
|
|
||||||
|
#include <osgGA/TrackballManipulator>
|
||||||
|
#include <osgGA/FlightManipulator>
|
||||||
|
#include <osgGA/DriveManipulator>
|
||||||
|
#include <osgGA/KeySwitchMatrixManipulator>
|
||||||
|
#include <osgGA/StateSetManipulator>
|
||||||
|
#include <osgGA/AnimationPathManipulator>
|
||||||
|
#include <osgGA/TerrainManipulator>
|
||||||
|
|
||||||
|
|
||||||
#include <osgTerrain/TerrainNode>
|
#include <osgTerrain/TerrainNode>
|
||||||
#include <osgTerrain/GeometryTechnique>
|
#include <osgTerrain/GeometryTechnique>
|
||||||
#include <osgTerrain/Layer>
|
#include <osgTerrain/Layer>
|
||||||
@ -31,6 +41,39 @@ int main(int argc, char** argv)
|
|||||||
// construct the viewer.
|
// construct the viewer.
|
||||||
osgViewer::Viewer viewer;
|
osgViewer::Viewer viewer;
|
||||||
|
|
||||||
|
// set up the camera manipulators.
|
||||||
|
{
|
||||||
|
osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> 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 x = 0.0;
|
||||||
double y = 0.0;
|
double y = 0.0;
|
||||||
double w = 1.0;
|
double w = 1.0;
|
||||||
|
@ -97,11 +97,66 @@ void GeometryTechnique::init()
|
|||||||
_geode = new osg::Geode;
|
_geode = new osg::Geode;
|
||||||
_geometry = new osg::Geometry;
|
_geometry = new osg::Geometry;
|
||||||
_geode->addDrawable(_geometry.get());
|
_geode->addDrawable(_geometry.get());
|
||||||
|
|
||||||
|
unsigned int numRows = 100;
|
||||||
|
unsigned int numColumns = 100;
|
||||||
|
unsigned int numVertices = numRows * numColumns;
|
||||||
|
|
||||||
osg::Vec3Array* vertices = new osg::Vec3Array;
|
// allocate and assign vertices
|
||||||
osg::Vec3Array* normals = new osg::Vec3Array;
|
osg::Vec3Array* vertices = new osg::Vec3Array(numVertices);
|
||||||
osg::Vec2Array* texcoords = new osg::Vec2Array;
|
_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; j<numRows; ++j)
|
||||||
|
{
|
||||||
|
for(unsigned int i=0; i<numColumns; ++i)
|
||||||
|
{
|
||||||
|
unsigned int iv = j*numColumns + i;
|
||||||
|
osg::Vec3d ndc( (double)i/(double)(numColumns-1), (double)j/(double)(numColumns-1), 0.0);
|
||||||
|
osg::Vec3d model;
|
||||||
|
masterLocator->convertLocalToModel(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; j<numRows-1; ++j)
|
||||||
|
{
|
||||||
|
osg::DrawElementsUInt* elements = new osg::DrawElementsUInt(GL_TRIANGLE_STRIP, numColumns*2);
|
||||||
|
for(unsigned int i=0; i<numColumns; ++i)
|
||||||
|
{
|
||||||
|
unsigned int iv = j*numColumns + i;
|
||||||
|
(*elements)[i*2] = iv + numColumns;
|
||||||
|
(*elements)[i*2+1] = iv;
|
||||||
|
}
|
||||||
|
_geometry->addPrimitiveSet(elements);
|
||||||
|
}
|
||||||
|
|
||||||
_dirty = false;
|
_dirty = false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user