| 30 | | FRONT_FACE = 1, |
| 31 | | BACK_FACE = 2, |
| 32 | | LEFT_FACE = 4, |
| 33 | | RIGHT_FACE = 8, |
| 34 | | TOP_FACE = 16, |
| 35 | | BOTTOM_FACE = 32 |
| 36 | | }; |
| 37 | | |
| 38 | | osg::Node* createCube(unsigned int mask) |
| | 38 | |
| | 39 | enum Faces |
| | 40 | { |
| | 41 | FRONT_FACE = 1, |
| | 42 | BACK_FACE = 2, |
| | 43 | LEFT_FACE = 4, |
| | 44 | RIGHT_FACE = 8, |
| | 45 | TOP_FACE = 16, |
| | 46 | BOTTOM_FACE = 32 |
| | 47 | }; |
| | 48 | |
| | 49 | osg::Node* createCube(unsigned int mask) |
| | 50 | { |
| | 51 | osg::Geode* geode = new osg::Geode; |
| | 52 | |
| | 53 | osg::Geometry* geometry = new osg::Geometry; |
| | 54 | geode->addDrawable(geometry); |
| | 55 | |
| | 56 | osg::Vec3Array* vertices = new osg::Vec3Array; |
| | 57 | geometry->setVertexArray(vertices); |
| | 58 | |
| | 59 | osg::Vec3Array* normals = new osg::Vec3Array; |
| | 60 | geometry->setNormalArray(normals); |
| | 61 | geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); |
| | 62 | |
| | 63 | osg::Vec4Array* colours = new osg::Vec4Array; |
| | 64 | geometry->setColorArray(colours); |
| | 65 | geometry->setColorBinding(osg::Geometry::BIND_OVERALL); |
| | 66 | colours->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); |
| | 67 | |
| | 68 | |
| | 69 | osg::Vec3 origin(0.0f,0.0f,0.0f); |
| | 70 | osg::Vec3 dx(2.0f,0.0f,0.0f); |
| | 71 | osg::Vec3 dy(0.0f,1.0f,0.0f); |
| | 72 | osg::Vec3 dz(0.0f,0.0f,1.0f); |
| | 73 | |
| | 74 | osg::Vec3 px(1.0f,0.0,0.0f); |
| | 75 | osg::Vec3 nx(-1.0f,0.0,0.0f); |
| | 76 | osg::Vec3 py(0.0f,1.0f,0.0f); |
| | 77 | osg::Vec3 ny(0.0f,-1.0f,0.0f); |
| | 78 | osg::Vec3 pz(0.0f,0.0f,1.0f); |
| | 79 | osg::Vec3 nz(0.0f,0.0f,-1.0f); |
| | 80 | |
| | 81 | if (mask & FRONT_FACE) |
| | 82 | { |
| | 83 | // front face |
| | 84 | vertices->push_back(origin); |
| | 85 | vertices->push_back(origin+dx); |
| | 86 | vertices->push_back(origin+dx+dz); |
| | 87 | vertices->push_back(origin+dz); |
| | 88 | normals->push_back(ny); |
| | 89 | normals->push_back(ny); |
| | 90 | normals->push_back(ny); |
| | 91 | normals->push_back(ny); |
| | 92 | } |
| | 93 | |
| | 94 | if (mask & BACK_FACE) |
| | 95 | { |
| | 96 | // back face |
| | 97 | vertices->push_back(origin+dy); |
| | 98 | vertices->push_back(origin+dy+dz); |
| | 99 | vertices->push_back(origin+dy+dx+dz); |
| | 100 | vertices->push_back(origin+dy+dx); |
| | 101 | normals->push_back(py); |
| | 102 | normals->push_back(py); |
| | 103 | normals->push_back(py); |
| | 104 | normals->push_back(py); |
| | 105 | } |
| | 106 | |
| | 107 | if (mask & LEFT_FACE) |
| | 108 | { |
| | 109 | // left face |
| | 110 | vertices->push_back(origin+dy); |
| | 111 | vertices->push_back(origin); |
| | 112 | vertices->push_back(origin+dz); |
| | 113 | vertices->push_back(origin+dy+dz); |
| | 114 | normals->push_back(nx); |
| | 115 | normals->push_back(nx); |
| | 116 | normals->push_back(nx); |
| | 117 | normals->push_back(nx); |
| | 118 | } |
| | 119 | |
| | 120 | if (mask & RIGHT_FACE) |
| | 121 | { |
| | 122 | // right face |
| | 123 | vertices->push_back(origin+dx+dy); |
| | 124 | vertices->push_back(origin+dx+dy+dz); |
| | 125 | vertices->push_back(origin+dx+dz); |
| | 126 | vertices->push_back(origin+dx); |
| | 127 | normals->push_back(px); |
| | 128 | normals->push_back(px); |
| | 129 | normals->push_back(px); |
| | 130 | normals->push_back(px); |
| | 131 | } |
| | 132 | |
| | 133 | if (mask & TOP_FACE) |
| | 134 | { |
| | 135 | // top face |
| | 136 | vertices->push_back(origin+dz); |
| | 137 | vertices->push_back(origin+dz+dx); |
| | 138 | vertices->push_back(origin+dz+dx+dy); |
| | 139 | vertices->push_back(origin+dz+dy); |
| | 140 | normals->push_back(pz); |
| | 141 | normals->push_back(pz); |
| | 142 | normals->push_back(pz); |
| | 143 | normals->push_back(pz); |
| | 144 | } |
| | 145 | |
| | 146 | if (mask & BOTTOM_FACE) |
| | 147 | { |
| | 148 | // bottom face |
| | 149 | vertices->push_back(origin); |
| | 150 | vertices->push_back(origin+dy); |
| | 151 | vertices->push_back(origin+dx+dy); |
| | 152 | vertices->push_back(origin+dx); |
| | 153 | normals->push_back(nz); |
| | 154 | normals->push_back(nz); |
| | 155 | normals->push_back(nz); |
| | 156 | normals->push_back(nz); |
| | 157 | } |
| | 158 | |
| | 159 | geometry->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, vertices->size())); |
| | 160 | |
| | 161 | return geode; |
| | 162 | } |
| | 163 | |
| | 164 | class SwitchHandler : public osgGA::GUIEventHandler |
| | 165 | { |
| | 166 | public: |
| | 167 | |
| | 168 | SwitchHandler(): |
| | 169 | _childNum(0) {} |
| | 170 | |
| | 171 | virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& /*aa*/, osg::Object* object, osg::NodeVisitor* /*nv*/) |
| | 172 | { |
| | 173 | osg::Switch* sw = dynamic_cast<osg::Switch*>(object); |
| | 174 | if (!sw) return false; |
| | 175 | |
| | 176 | if (ea.getHandled()) return false; |
| | 177 | |
| | 178 | switch(ea.getEventType()) |
| | 179 | { |
| | 180 | case(osgGA::GUIEventAdapter::KEYDOWN): |
| | 181 | { |
| | 182 | if (ea.getKey()=='n') |
| | 183 | { |
| | 184 | ++_childNum; |
| | 185 | if (_childNum >= sw->getNumChildren()) _childNum = 0; |
| | 186 | |
| | 187 | sw->setSingleChildOn(_childNum); |
| | 188 | return true; |
| | 189 | } |
| | 190 | break; |
| | 191 | } |
| | 192 | default: |
| | 193 | break; |
| | 194 | } |
| | 195 | return false; |
| | 196 | } |
| | 197 | |
| | 198 | protected: |
| | 199 | |
| | 200 | virtual ~SwitchHandler() {} |
| | 201 | unsigned int _childNum; |
| | 202 | |
| | 203 | }; |
| | 204 | |
| | 205 | |
| | 206 | osg::Node* createModel(osg::ArgumentParser& /*arguments*/) |
| | 207 | { |
| | 208 | osg::Switch* sw = new osg::Switch; |
| | 209 | sw->setEventCallback(new ModelOne::SwitchHandler); |
| | 210 | |
| | 211 | sw->addChild(ModelOne::createCube(ModelOne::FRONT_FACE), true); |
| | 212 | sw->addChild(ModelOne::createCube(ModelOne::FRONT_FACE | ModelOne::BACK_FACE), false); |
| | 213 | sw->addChild(ModelOne::createCube(ModelOne::FRONT_FACE | ModelOne::BACK_FACE | ModelOne::LEFT_FACE), false); |
| | 214 | sw->addChild(ModelOne::createCube(ModelOne::FRONT_FACE | ModelOne::BACK_FACE | ModelOne::LEFT_FACE | ModelOne::RIGHT_FACE), false); |
| | 215 | sw->addChild(ModelOne::createCube(ModelOne::FRONT_FACE | ModelOne::BACK_FACE | ModelOne::LEFT_FACE | ModelOne::RIGHT_FACE | ModelOne::TOP_FACE), false); |
| | 216 | sw->addChild(ModelOne::createCube(ModelOne::FRONT_FACE | ModelOne::BACK_FACE | ModelOne::LEFT_FACE | ModelOne::RIGHT_FACE | ModelOne::TOP_FACE | ModelOne::BOTTOM_FACE), false); |
| | 217 | |
| | 218 | return sw; |
| | 219 | } |
| | 220 | } |
| | 221 | |
| | 222 | namespace ModelTwo |
| 40 | | osg::Geode* geode = new osg::Geode; |
| 41 | | |
| 42 | | osg::Geometry* geometry = new osg::Geometry; |
| 43 | | geode->addDrawable(geometry); |
| 44 | | |
| 45 | | osg::Vec3Array* vertices = new osg::Vec3Array; |
| 46 | | geometry->setVertexArray(vertices); |
| 47 | | |
| 48 | | osg::Vec3Array* normals = new osg::Vec3Array; |
| 49 | | geometry->setNormalArray(normals); |
| 50 | | geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); |
| 51 | | |
| 52 | | osg::Vec4Array* colours = new osg::Vec4Array; |
| 53 | | geometry->setColorArray(colours); |
| 54 | | geometry->setColorBinding(osg::Geometry::BIND_OVERALL); |
| 55 | | colours->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f)); |
| 56 | | |
| 57 | | |
| 58 | | osg::Vec3 origin(0.0f,0.0f,0.0f); |
| 59 | | osg::Vec3 dx(2.0f,0.0f,0.0f); |
| 60 | | osg::Vec3 dy(0.0f,1.0f,0.0f); |
| 61 | | osg::Vec3 dz(0.0f,0.0f,1.0f); |
| 62 | | |
| 63 | | osg::Vec3 px(1.0f,0.0,0.0f); |
| 64 | | osg::Vec3 nx(-1.0f,0.0,0.0f); |
| 65 | | osg::Vec3 py(0.0f,1.0f,0.0f); |
| 66 | | osg::Vec3 ny(0.0f,-1.0f,0.0f); |
| 67 | | osg::Vec3 pz(0.0f,0.0f,1.0f); |
| 68 | | osg::Vec3 nz(0.0f,0.0f,-1.0f); |
| 69 | | |
| 70 | | if (mask & FRONT_FACE) |
| 71 | | { |
| 72 | | // front face |
| 73 | | vertices->push_back(origin); |
| 74 | | vertices->push_back(origin+dx); |
| 75 | | vertices->push_back(origin+dx+dz); |
| 76 | | vertices->push_back(origin+dz); |
| 77 | | normals->push_back(ny); |
| 78 | | normals->push_back(ny); |
| 79 | | normals->push_back(ny); |
| 80 | | normals->push_back(ny); |
| 81 | | } |
| 82 | | |
| 83 | | if (mask & BACK_FACE) |
| 84 | | { |
| 85 | | // back face |
| 86 | | vertices->push_back(origin+dy); |
| 87 | | vertices->push_back(origin+dy+dz); |
| 88 | | vertices->push_back(origin+dy+dx+dz); |
| 89 | | vertices->push_back(origin+dy+dx); |
| 90 | | normals->push_back(py); |
| 91 | | normals->push_back(py); |
| 92 | | normals->push_back(py); |
| 93 | | normals->push_back(py); |
| 94 | | } |
| 95 | | |
| 96 | | if (mask & LEFT_FACE) |
| 97 | | { |
| 98 | | // left face |
| 99 | | vertices->push_back(origin+dy); |
| 100 | | vertices->push_back(origin); |
| 101 | | vertices->push_back(origin+dz); |
| 102 | | vertices->push_back(origin+dy+dz); |
| 103 | | normals->push_back(nx); |
| 104 | | normals->push_back(nx); |
| 105 | | normals->push_back(nx); |
| 106 | | normals->push_back(nx); |
| 107 | | } |
| 108 | | |
| 109 | | if (mask & RIGHT_FACE) |
| 110 | | { |
| 111 | | // right face |
| 112 | | vertices->push_back(origin+dx+dy); |
| 113 | | vertices->push_back(origin+dx+dy+dz); |
| 114 | | vertices->push_back(origin+dx+dz); |
| 115 | | vertices->push_back(origin+dx); |
| 116 | | normals->push_back(px); |
| 117 | | normals->push_back(px); |
| 118 | | normals->push_back(px); |
| 119 | | normals->push_back(px); |
| 120 | | } |
| 121 | | |
| 122 | | if (mask & TOP_FACE) |
| 123 | | { |
| 124 | | // top face |
| 125 | | vertices->push_back(origin+dz); |
| 126 | | vertices->push_back(origin+dz+dx); |
| 127 | | vertices->push_back(origin+dz+dx+dy); |
| 128 | | vertices->push_back(origin+dz+dy); |
| 129 | | normals->push_back(pz); |
| 130 | | normals->push_back(pz); |
| 131 | | normals->push_back(pz); |
| 132 | | normals->push_back(pz); |
| 133 | | } |
| 134 | | |
| 135 | | if (mask & BOTTOM_FACE) |
| 136 | | { |
| 137 | | // bottom face |
| 138 | | vertices->push_back(origin); |
| 139 | | vertices->push_back(origin+dy); |
| 140 | | vertices->push_back(origin+dx+dy); |
| 141 | | vertices->push_back(origin+dx); |
| 142 | | normals->push_back(nz); |
| 143 | | normals->push_back(nz); |
| 144 | | normals->push_back(nz); |
| 145 | | normals->push_back(nz); |
| 146 | | } |
| 147 | | |
| 148 | | geometry->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, vertices->size())); |
| 149 | | |
| 150 | | return geode; |
| | 224 | osg::AnimationPath* createAnimationPath(const osg::Vec3& center,float radius,double looptime) |
| | 225 | { |
| | 226 | // set up the animation path |
| | 227 | osg::AnimationPath* animationPath = new osg::AnimationPath; |
| | 228 | animationPath->setLoopMode(osg::AnimationPath::LOOP); |
| | 229 | |
| | 230 | int numSamples = 40; |
| | 231 | float yaw = 0.0f; |
| | 232 | float yaw_delta = 2.0f*osg::PI/((float)numSamples-1.0f); |
| | 233 | float roll = osg::inDegrees(30.0f); |
| | 234 | |
| | 235 | double time=0.0f; |
| | 236 | double time_delta = looptime/(double)numSamples; |
| | 237 | for(int i=0;i<numSamples;++i) |
| | 238 | { |
| | 239 | osg::Vec3 position(center+osg::Vec3(sinf(yaw)*radius,cosf(yaw)*radius,0.0f)); |
| | 240 | osg::Quat rotation(osg::Quat(roll,osg::Vec3(0.0,1.0,0.0))*osg::Quat(-(yaw+osg::inDegrees(90.0f)),osg::Vec3(0.0,0.0,1.0))); |
| | 241 | |
| | 242 | animationPath->insert(time,osg::AnimationPath::ControlPoint(position,rotation)); |
| | 243 | |
| | 244 | yaw += yaw_delta; |
| | 245 | time += time_delta; |
| | 246 | |
| | 247 | } |
| | 248 | return animationPath; |
| | 249 | } |
| | 250 | |
| | 251 | osg::Node* createBase(const osg::Vec3& center,float radius) |
| | 252 | { |
| | 253 | |
| | 254 | osg::Geode* geode = new osg::Geode; |
| | 255 | |
| | 256 | // set up the texture of the base. |
| | 257 | osg::StateSet* stateset = new osg::StateSet(); |
| | 258 | osg::Image* image = osgDB::readImageFile("Images/lz.rgb"); |
| | 259 | if (image) |
| | 260 | { |
| | 261 | osg::Texture2D* texture = new osg::Texture2D; |
| | 262 | texture->setImage(image); |
| | 263 | stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); |
| | 264 | } |
| | 265 | |
| | 266 | geode->setStateSet( stateset ); |
| | 267 | |
| | 268 | |
| | 269 | osg::HeightField* grid = new osg::HeightField; |
| | 270 | grid->allocate(38,39); |
| | 271 | grid->setOrigin(center+osg::Vec3(-radius,-radius,0.0f)); |
| | 272 | grid->setXInterval(radius*2.0f/(float)(38-1)); |
| | 273 | grid->setYInterval(radius*2.0f/(float)(39-1)); |
| | 274 | |
| | 275 | float minHeight = FLT_MAX; |
| | 276 | float maxHeight = -FLT_MAX; |
| | 277 | |
| | 278 | |
| | 279 | unsigned int r; |
| | 280 | for(r=0;r<39;++r) |
| | 281 | { |
| | 282 | for(unsigned int c=0;c<38;++c) |
| | 283 | { |
| | 284 | float h = vertex[r+c*39][2]; |
| | 285 | if (h>maxHeight) maxHeight=h; |
| | 286 | if (h<minHeight) minHeight=h; |
| | 287 | } |
| | 288 | } |
| | 289 | |
| | 290 | float hieghtScale = radius*0.5f/(maxHeight-minHeight); |
| | 291 | float hieghtOffset = -(minHeight+maxHeight)*0.5f; |
| | 292 | |
| | 293 | for(r=0;r<39;++r) |
| | 294 | { |
| | 295 | for(unsigned int c=0;c<38;++c) |
| | 296 | { |
| | 297 | float h = vertex[r+c*39][2]; |
| | 298 | grid->setHeight(c,r,(h+hieghtOffset)*hieghtScale); |
| | 299 | } |
| | 300 | } |
| | 301 | |
| | 302 | geode->addDrawable(new osg::ShapeDrawable(grid)); |
| | 303 | |
| | 304 | osg::Group* group = new osg::Group; |
| | 305 | group->addChild(geode); |
| | 306 | |
| | 307 | return group; |
| | 308 | |
| | 309 | } |
| | 310 | |
| | 311 | osg::Node* createMovingModel(const osg::Vec3& center, float radius) |
| | 312 | { |
| | 313 | float animationLength = 10.0f; |
| | 314 | |
| | 315 | osg::AnimationPath* animationPath = createAnimationPath(center,radius,animationLength); |
| | 316 | |
| | 317 | osg::Group* model = new osg::Group; |
| | 318 | |
| | 319 | osg::Node* cessna = osgDB::readNodeFile("cessna.osg"); |
| | 320 | if (cessna) |
| | 321 | { |
| | 322 | const osg::BoundingSphere& bs = cessna->getBound(); |
| | 323 | |
| | 324 | float size = radius/bs.radius()*0.3f; |
| | 325 | osg::MatrixTransform* positioned = new osg::MatrixTransform; |
| | 326 | positioned->setDataVariance(osg::Object::STATIC); |
| | 327 | positioned->setMatrix(osg::Matrix::translate(-bs.center())* |
| | 328 | osg::Matrix::scale(size,size,size)* |
| | 329 | osg::Matrix::rotate(osg::inDegrees(180.0f),0.0f,0.0f,2.0f)); |
| | 330 | |
| | 331 | positioned->addChild(cessna); |
| | 332 | |
| | 333 | osg::MatrixTransform* xform = new osg::MatrixTransform; |
| | 334 | xform->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0.0f,2.0)); |
| | 335 | xform->addChild(positioned); |
| | 336 | |
| | 337 | model->addChild(xform); |
| | 338 | } |
| | 339 | |
| | 340 | return model; |
| | 341 | } |
| | 342 | |
| | 343 | osg::Node* createModel(osg::ArgumentParser& /*arguments*/) |
| | 344 | { |
| | 345 | osg::Vec3 center(0.0f,0.0f,0.0f); |
| | 346 | float radius = 100.0f; |
| | 347 | osg::Vec3 lightPosition(center+osg::Vec3(0.0f,0.0f,radius)); |
| | 348 | |
| | 349 | // the shadower model |
| | 350 | osg::Node* shadower = createMovingModel(center,radius*0.5f); |
| | 351 | shadower->setNodeMask(CastsShadowTraversalMask); |
| | 352 | |
| | 353 | // the shadowed model |
| | 354 | osg::Node* shadowed = createBase(center-osg::Vec3(0.0f,0.0f,radius*0.25),radius); |
| | 355 | shadowed->setNodeMask(RecievesShadowTraversalMask); |
| | 356 | |
| | 357 | osg::Group* group = new osg::Group; |
| | 358 | |
| | 359 | group->addChild(shadowed); |
| | 360 | group->addChild(shadower); |
| | 361 | |
| | 362 | return group; |
| | 363 | } |
| 155 | | public: |
| 156 | | |
| 157 | | SwitchHandler(): |
| 158 | | _childNum(0) {} |
| 159 | | |
| 160 | | virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& /*aa*/, osg::Object* object, osg::NodeVisitor* /*nv*/) |
| 161 | | { |
| 162 | | osg::Switch* sw = dynamic_cast<osg::Switch*>(object); |
| 163 | | if (!sw) return false; |
| 164 | | |
| 165 | | if (ea.getHandled()) return false; |
| 166 | | |
| 167 | | switch(ea.getEventType()) |
| 168 | | { |
| 169 | | case(osgGA::GUIEventAdapter::KEYDOWN): |
| 170 | | { |
| 171 | | if (ea.getKey()=='n') |
| 172 | | { |
| 173 | | ++_childNum; |
| 174 | | if (_childNum >= sw->getNumChildren()) _childNum = 0; |
| 175 | | |
| 176 | | sw->setSingleChildOn(_childNum); |
| 177 | | return true; |
| 178 | | } |
| 179 | | break; |
| 180 | | } |
| 181 | | default: |
| 182 | | break; |
| 183 | | } |
| 184 | | return false; |
| 185 | | } |
| 186 | | |
| 187 | | protected: |
| 188 | | |
| 189 | | virtual ~SwitchHandler() {} |
| 190 | | unsigned int _childNum; |
| 191 | | |
| 192 | | }; |
| | 368 | osg::Group* createModel(osg::ArgumentParser& arguments) |
| | 369 | { |
| | 370 | osg::Group* scene = new osg::Group; |
| | 371 | |
| | 372 | osg::ref_ptr<osg::Geode> geode_1 = new osg::Geode; |
| | 373 | scene->addChild(geode_1.get()); |
| | 374 | |
| | 375 | osg::ref_ptr<osg::Geode> geode_2 = new osg::Geode; |
| | 376 | osg::ref_ptr<osg::MatrixTransform> transform_2 = new osg::MatrixTransform; |
| | 377 | transform_2->addChild(geode_2.get()); |
| | 378 | transform_2->setUpdateCallback(new osg::AnimationPathCallback(osg::Vec3(0, 0, 0), osg::Z_AXIS, osg::inDegrees(45.0f))); |
| | 379 | scene->addChild(transform_2.get()); |
| | 380 | |
| | 381 | osg::ref_ptr<osg::Geode> geode_3 = new osg::Geode; |
| | 382 | osg::ref_ptr<osg::MatrixTransform> transform_3 = new osg::MatrixTransform; |
| | 383 | transform_3->addChild(geode_3.get()); |
| | 384 | transform_3->setUpdateCallback(new osg::AnimationPathCallback(osg::Vec3(0, 0, 0), osg::Z_AXIS, osg::inDegrees(-22.5f))); |
| | 385 | scene->addChild(transform_3.get()); |
| | 386 | |
| | 387 | const float radius = 0.8f; |
| | 388 | const float height = 1.0f; |
| | 389 | osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints; |
| | 390 | hints->setDetailRatio(2.0f); |
| | 391 | osg::ref_ptr<osg::ShapeDrawable> shape; |
| | 392 | |
| | 393 | shape = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0f, 0.0f, -2.0f), 10, 10.0f, 0.1f), hints.get()); |
| | 394 | shape->setColor(osg::Vec4(0.5f, 0.5f, 0.7f, 1.0f)); |
| | 395 | geode_1->addDrawable(shape.get()); |
| | 396 | |
| | 397 | shape = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0.0f, 0.0f, 0.0f), radius * 2), hints.get()); |
| | 398 | shape->setColor(osg::Vec4(0.8f, 0.8f, 0.8f, 1.0f)); |
| | 399 | geode_1->addDrawable(shape.get()); |
| | 400 | |
| | 401 | shape = new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(-3.0f, 0.0f, 0.0f), radius), hints.get()); |
| | 402 | shape->setColor(osg::Vec4(0.6f, 0.8f, 0.8f, 1.0f)); |
| | 403 | geode_2->addDrawable(shape.get()); |
| | 404 | |
| | 405 | shape = new osg::ShapeDrawable(new osg::Box(osg::Vec3(3.0f, 0.0f, 0.0f), 2 * radius), hints.get()); |
| | 406 | shape->setColor(osg::Vec4(0.4f, 0.9f, 0.3f, 1.0f)); |
| | 407 | geode_2->addDrawable(shape.get()); |
| | 408 | |
| | 409 | shape = new osg::ShapeDrawable(new osg::Cone(osg::Vec3(0.0f, -3.0f, 0.0f), radius, height), hints.get()); |
| | 410 | shape->setColor(osg::Vec4(0.2f, 0.5f, 0.7f, 1.0f)); |
| | 411 | geode_2->addDrawable(shape.get()); |
| | 412 | |
| | 413 | shape = new osg::ShapeDrawable(new osg::Cylinder(osg::Vec3(0.0f, 3.0f, 0.0f), radius, height), hints.get()); |
| | 414 | shape->setColor(osg::Vec4(1.0f, 0.3f, 0.3f, 1.0f)); |
| | 415 | geode_2->addDrawable(shape.get()); |
| | 416 | |
| | 417 | shape = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0f, 0.0f, 3.0f), 2.0f, 2.0f, 0.1f), hints.get()); |
| | 418 | shape->setColor(osg::Vec4(0.8f, 0.8f, 0.4f, 1.0f)); |
| | 419 | geode_3->addDrawable(shape.get()); |
| | 420 | |
| | 421 | // material |
| | 422 | osg::ref_ptr<osg::Material> matirial = new osg::Material; |
| | 423 | matirial->setColorMode(osg::Material::DIFFUSE); |
| | 424 | matirial->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1)); |
| | 425 | matirial->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(1, 1, 1, 1)); |
| | 426 | matirial->setShininess(osg::Material::FRONT_AND_BACK, 64.0f); |
| | 427 | scene->getOrCreateStateSet()->setAttributeAndModes(matirial.get(), osg::StateAttribute::ON); |
| | 428 | |
| | 429 | bool withBaseTexture = true; |
| | 430 | while(arguments.read("--with-base-texture")) { withBaseTexture = true; } |
| | 431 | while(arguments.read("--no-base-texture")) { withBaseTexture = false; } |
| | 432 | |
| | 433 | if (withBaseTexture) |
| | 434 | { |
| | 435 | scene->getOrCreateStateSet()->setTextureAttributeAndModes( 0, new osg::Texture2D(osgDB::readImageFile("Images/lz.rgb")), osg::StateAttribute::ON); |
| | 436 | } |
| | 437 | |
| | 438 | return scene; |
| | 439 | } |
| | 440 | |
| | 441 | } |
| | 442 | |