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