| | 151 | |
|---|
| | 152 | osg::Node* createDemoScene(osgManipulator::CommandManager* cmdMgr) { |
|---|
| | 153 | |
|---|
| | 154 | osg::Group* root = new osg::Group; |
|---|
| | 155 | |
|---|
| | 156 | osg::ref_ptr<osg::Geode> geode_1 = new osg::Geode; |
|---|
| | 157 | osg::ref_ptr<osg::MatrixTransform> transform_1 = new osg::MatrixTransform; |
|---|
| | 158 | |
|---|
| | 159 | osg::ref_ptr<osg::Geode> geode_2 = new osg::Geode; |
|---|
| | 160 | osg::ref_ptr<osg::MatrixTransform> transform_2 = new osg::MatrixTransform; |
|---|
| | 161 | |
|---|
| | 162 | osg::ref_ptr<osg::Geode> geode_3 = new osg::Geode; |
|---|
| | 163 | osg::ref_ptr<osg::MatrixTransform> transform_3 = new osg::MatrixTransform; |
|---|
| | 164 | |
|---|
| | 165 | osg::ref_ptr<osg::Geode> geode_4 = new osg::Geode; |
|---|
| | 166 | osg::ref_ptr<osg::MatrixTransform> transform_4 = new osg::MatrixTransform; |
|---|
| | 167 | |
|---|
| | 168 | osg::ref_ptr<osg::Geode> geode_5 = new osg::Geode; |
|---|
| | 169 | osg::ref_ptr<osg::MatrixTransform> transform_5 = new osg::MatrixTransform; |
|---|
| | 170 | |
|---|
| | 171 | osg::ref_ptr<osg::Geode> geode_6 = new osg::Geode; |
|---|
| | 172 | osg::ref_ptr<osg::MatrixTransform> transform_6 = new osg::MatrixTransform; |
|---|
| | 173 | |
|---|
| | 174 | osg::ref_ptr<osg::Geode> geode_7 = new osg::Geode; |
|---|
| | 175 | osg::ref_ptr<osg::MatrixTransform> transform_7 = new osg::MatrixTransform; |
|---|
| | 176 | |
|---|
| | 177 | |
|---|
| | 178 | |
|---|
| | 179 | |
|---|
| | 180 | |
|---|
| | 181 | const float radius = 0.8f; |
|---|
| | 182 | const float height = 1.0f; |
|---|
| | 183 | osg::ref_ptr<osg::TessellationHints> hints = new osg::TessellationHints; |
|---|
| | 184 | hints->setDetailRatio(2.0f); |
|---|
| | 185 | osg::ref_ptr<osg::ShapeDrawable> shape; |
|---|
| | 186 | |
|---|
| | 187 | shape = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0f, 0.0f, -2.0f), 10, 10.0f, 0.1f), hints.get()); |
|---|
| | 188 | shape->setColor(osg::Vec4(0.5f, 0.5f, 0.7f, 1.0f)); |
|---|
| | 189 | geode_1->addDrawable(shape.get()); |
|---|
| | 190 | |
|---|
| | 191 | shape = new osg::ShapeDrawable(new osg::Cylinder(osg::Vec3(0.0f, 0.0f, 0.0f), radius * 2,radius), hints.get()); |
|---|
| | 192 | shape->setColor(osg::Vec4(0.8f, 0.8f, 0.8f, 1.0f)); |
|---|
| | 193 | geode_2->addDrawable(shape.get()); |
|---|
| | 194 | |
|---|
| | 195 | shape = new osg::ShapeDrawable(new osg::Cylinder(osg::Vec3(-3.0f, 0.0f, 0.0f), radius,radius), hints.get()); |
|---|
| | 196 | shape->setColor(osg::Vec4(0.6f, 0.8f, 0.8f, 1.0f)); |
|---|
| | 197 | geode_3->addDrawable(shape.get()); |
|---|
| | 198 | |
|---|
| | 199 | shape = new osg::ShapeDrawable(new osg::Cone(osg::Vec3(3.0f, 0.0f, 0.0f), 2 * radius,radius), hints.get()); |
|---|
| | 200 | shape->setColor(osg::Vec4(0.4f, 0.9f, 0.3f, 1.0f)); |
|---|
| | 201 | geode_4->addDrawable(shape.get()); |
|---|
| | 202 | |
|---|
| | 203 | shape = new osg::ShapeDrawable(new osg::Cone(osg::Vec3(0.0f, -3.0f, 0.0f), radius, height), hints.get()); |
|---|
| | 204 | shape->setColor(osg::Vec4(0.2f, 0.5f, 0.7f, 1.0f)); |
|---|
| | 205 | geode_5->addDrawable(shape.get()); |
|---|
| | 206 | |
|---|
| | 207 | shape = new osg::ShapeDrawable(new osg::Cylinder(osg::Vec3(0.0f, 3.0f, 0.0f), radius, height), hints.get()); |
|---|
| | 208 | shape->setColor(osg::Vec4(1.0f, 0.3f, 0.3f, 1.0f)); |
|---|
| | 209 | geode_6->addDrawable(shape.get()); |
|---|
| | 210 | |
|---|
| | 211 | shape = new osg::ShapeDrawable(new osg::Cone(osg::Vec3(0.0f, 0.0f, 3.0f), 2.0f, 2.0f), hints.get()); |
|---|
| | 212 | shape->setColor(osg::Vec4(0.8f, 0.8f, 0.4f, 1.0f)); |
|---|
| | 213 | geode_7->addDrawable(shape.get()); |
|---|
| | 214 | |
|---|
| | 215 | |
|---|
| | 216 | |
|---|
| | 217 | |
|---|
| | 218 | |
|---|
| | 219 | |
|---|
| | 220 | // material |
|---|
| | 221 | osg::ref_ptr<osg::Material> matirial = new osg::Material; |
|---|
| | 222 | matirial->setColorMode(osg::Material::DIFFUSE); |
|---|
| | 223 | matirial->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1)); |
|---|
| | 224 | matirial->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(1, 1, 1, 1)); |
|---|
| | 225 | matirial->setShininess(osg::Material::FRONT_AND_BACK, 64.0f); |
|---|
| | 226 | root->getOrCreateStateSet()->setAttributeAndModes(matirial.get(), osg::StateAttribute::ON); |
|---|
| | 227 | |
|---|
| | 228 | transform_1.get()->addChild(addDraggerToScene(geode_1.get(),cmdMgr,"TabBoxDragger")); |
|---|
| | 229 | transform_2.get()->addChild(addDraggerToScene(geode_2.get(),cmdMgr,"TabPlaneDragger")); |
|---|
| | 230 | transform_3.get()->addChild(addDraggerToScene(geode_3.get(),cmdMgr,"TabPlaneTrackballDragger")); |
|---|
| | 231 | transform_4.get()->addChild(addDraggerToScene(geode_4.get(),cmdMgr,"TrackballDragger")); |
|---|
| | 232 | transform_5.get()->addChild(addDraggerToScene(geode_5.get(),cmdMgr,"Translate1DDragger")); |
|---|
| | 233 | transform_6.get()->addChild(addDraggerToScene(geode_6.get(),cmdMgr,"Translate2DDragger")); |
|---|
| | 234 | transform_7.get()->addChild(addDraggerToScene(geode_7.get(),cmdMgr,"TranslateAxisDragger")); |
|---|
| | 235 | |
|---|
| | 236 | root->addChild(transform_1.get()); |
|---|
| | 237 | root->addChild(transform_2.get()); |
|---|
| | 238 | root->addChild(transform_3.get()); |
|---|
| | 239 | root->addChild(transform_4.get()); |
|---|
| | 240 | root->addChild(transform_5.get()); |
|---|
| | 241 | root->addChild(transform_6.get()); |
|---|
| | 242 | root->addChild(transform_7.get()); |
|---|
| | 243 | |
|---|
| | 244 | |
|---|
| | 245 | |
|---|
| | 246 | return root; |
|---|
| | 247 | } |
|---|
| | 248 | |
|---|