| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | #include <osg/Geode> |
|---|
| 20 | #include <osg/ShapeDrawable> |
|---|
| 21 | #include <osg/Material> |
|---|
| 22 | #include <osg/Texture2D> |
|---|
| 23 | |
|---|
| 24 | #include <osgViewer/Viewer> |
|---|
| 25 | |
|---|
| 26 | #include <osgDB/ReadFile> |
|---|
| 27 | |
|---|
| 28 | #include <osg/Math> |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | #include "../osghangglide/terrain_coords.h" |
|---|
| 32 | |
|---|
| 33 | osg::Geode* createShapes() |
|---|
| 34 | { |
|---|
| 35 | osg::Geode* geode = new osg::Geode(); |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | osg::StateSet* stateset = new osg::StateSet(); |
|---|
| 41 | |
|---|
| 42 | osg::Image* image = osgDB::readImageFile( "Images/lz.rgb" ); |
|---|
| 43 | |
|---|
| 44 | if (image) |
|---|
| 45 | { |
|---|
| 46 | osg::Texture2D* texture = new osg::Texture2D; |
|---|
| 47 | texture->setImage(image); |
|---|
| 48 | stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | geode->setStateSet( stateset ); |
|---|
| 52 | |
|---|
| 53 | float radius = 0.8f; |
|---|
| 54 | float height = 1.0f; |
|---|
| 55 | |
|---|
| 56 | osg::TessellationHints* hints = new osg::TessellationHints; |
|---|
| 57 | hints->setDetailRatio(0.5f); |
|---|
| 58 | |
|---|
| 59 | geode->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f,0.0f,0.0f),radius),hints)); |
|---|
| 60 | geode->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(2.0f,0.0f,0.0f),2*radius),hints)); |
|---|
| 61 | geode->addDrawable(new osg::ShapeDrawable(new osg::Cone(osg::Vec3(4.0f,0.0f,0.0f),radius,height),hints)); |
|---|
| 62 | geode->addDrawable(new osg::ShapeDrawable(new osg::Cylinder(osg::Vec3(6.0f,0.0f,0.0f),radius,height),hints)); |
|---|
| 63 | geode->addDrawable(new osg::ShapeDrawable(new osg::Capsule(osg::Vec3(8.0f,0.0f,0.0f),radius,height),hints)); |
|---|
| 64 | |
|---|
| 65 | osg::HeightField* grid = new osg::HeightField; |
|---|
| 66 | grid->allocate(38,39); |
|---|
| 67 | grid->setXInterval(0.28f); |
|---|
| 68 | grid->setYInterval(0.28f); |
|---|
| 69 | |
|---|
| 70 | for(unsigned int r=0;r<39;++r) |
|---|
| 71 | { |
|---|
| 72 | for(unsigned int c=0;c<38;++c) |
|---|
| 73 | { |
|---|
| 74 | grid->setHeight(c,r,vertex[r+c*39][2]); |
|---|
| 75 | } |
|---|
| 76 | } |
|---|
| 77 | geode->addDrawable(new osg::ShapeDrawable(grid)); |
|---|
| 78 | |
|---|
| 79 | osg::ConvexHull* mesh = new osg::ConvexHull; |
|---|
| 80 | osg::Vec3Array* vertices = new osg::Vec3Array(4); |
|---|
| 81 | (*vertices)[0].set(9.0+0.0f,-1.0f+2.0f,-1.0f+0.0f); |
|---|
| 82 | (*vertices)[1].set(9.0+1.0f,-1.0f+0.0f,-1.0f+0.0f); |
|---|
| 83 | (*vertices)[2].set(9.0+2.0f,-1.0f+2.0f,-1.0f+0.0f); |
|---|
| 84 | (*vertices)[3].set(9.0+1.0f,-1.0f+1.0f,-1.0f+2.0f); |
|---|
| 85 | osg::UByteArray* indices = new osg::UByteArray(12); |
|---|
| 86 | (*indices)[0]=0; |
|---|
| 87 | (*indices)[1]=2; |
|---|
| 88 | (*indices)[2]=1; |
|---|
| 89 | (*indices)[3]=0; |
|---|
| 90 | (*indices)[4]=1; |
|---|
| 91 | (*indices)[5]=3; |
|---|
| 92 | (*indices)[6]=1; |
|---|
| 93 | (*indices)[7]=2; |
|---|
| 94 | (*indices)[8]=3; |
|---|
| 95 | (*indices)[9]=2; |
|---|
| 96 | (*indices)[10]=0; |
|---|
| 97 | (*indices)[11]=3; |
|---|
| 98 | mesh->setVertices(vertices); |
|---|
| 99 | mesh->setIndices(indices); |
|---|
| 100 | geode->addDrawable(new osg::ShapeDrawable(mesh)); |
|---|
| 101 | |
|---|
| 102 | return geode; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | int main(int, char **) |
|---|
| 106 | { |
|---|
| 107 | |
|---|
| 108 | osgViewer::Viewer viewer; |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | viewer.setSceneData( createShapes() ); |
|---|
| 112 | |
|---|
| 113 | return viewer.run(); |
|---|
| 114 | } |
|---|