47 const ShapeBase *shape =
object->
getShape();
48 const Coord& position =
object->getPosition();
49 const Quaternion& orientation =
object->getOrientation();
50 const RotationMatrix rotation(orientation.toEulerAngles());
53 const Cuboid *cuboid =
dynamic_cast<const Cuboid *
>(shape);
54 if (cuboid !=
nullptr) {
55 auto size = cuboid->getSize();
56 auto drawable =
new osg::ShapeDrawable(
new osg::Box(osg::Vec3d(0, 0, 0), size.x, size.y, size.z));
58 drawable->setStateSet(stateSet);
59 auto geode =
new osg::Geode();
60 geode->addDrawable(drawable);
66 const Sphere *sphere =
dynamic_cast<const Sphere *
>(shape);
67 if (sphere !=
nullptr) {
68 double radius = sphere->getRadius();
69 auto drawable =
new osg::ShapeDrawable(
new osg::Sphere(osg::Vec3(position.x, position.y, position.z), radius));
71 auto geode =
new osg::Geode();
72 geode->addDrawable(drawable);
73 scene->addChild(geode);
76 const Prism *prism =
dynamic_cast<const Prism *
>(shape);
77 if (prism !=
nullptr) {
78 auto geode =
new osg::Geode();
81 bottomFace->setStateSet(stateSet);
83 topFace->setStateSet(stateSet);
84 geode->addDrawable(bottomFace);
85 geode->addDrawable(topFace);
86 for (
auto face : prism->getFaces()) {
88 sideFace->setStateSet(stateSet);
89 geode->addDrawable(sideFace);
96 const Polyhedron *polyhedron =
dynamic_cast<const Polyhedron *
>(shape);
97 if (polyhedron !=
nullptr) {
98 auto geode =
new osg::Geode();
100 for (
auto face : polyhedron->getFaces()) {
101 auto geometry =
new osg::Geometry();
102 auto vertices =
new osg::Vec3Array();
103 for (
auto edge : face->getEdges())
104 vertices->push_back(osg::Vec3d(edge->getP1()->x, edge->getP1()->y, edge->getP1()->z));
105 geometry->setVertexArray(vertices);
106 geometry->addPrimitiveSet(
new osg::DrawArrays(osg::PrimitiveSet::POLYGON, 0, face->getEdges().size()));
107 geometry->setStateSet(stateSet);
108 geode->addDrawable(geometry);
111 pat->addChild(geode);
112 scene->addChild(pat);