All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OsgUnitSphere.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_GRAPHICS_OSGUNITSPHERE_H
17 #define SURGSIM_GRAPHICS_OSGUNITSPHERE_H
18 
19 #include <osg/Geode>
20 #include <osg/PositionAttitudeTransform>
21 #include <osg/Quat>
22 #include <osg/Shape>
23 #include <osg/ShapeDrawable>
24 
25 namespace SurgSim
26 {
27 
28 namespace Graphics
29 {
30 
35 {
36 public:
39  m_transform(new osg::PositionAttitudeTransform())
40  {
41  osg::ref_ptr<osg::Sphere> unitSphere = new osg::Sphere(osg::Vec3(0.0, 0.0, 0.0), 1.0);
42  osg::ref_ptr<osg::ShapeDrawable> drawable = new osg::ShapeDrawable(unitSphere);
43  osg::ref_ptr<osg::Geode> geode = new osg::Geode();
44  geode->addDrawable(drawable);
45  geode->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
46  m_transform->addChild(geode);
47  osg::Quat rotation;
48  rotation.makeRotate(osg::Vec3d(0.0, 0.0, 1.0), osg::Vec3d(0.0, 1.0, 0.0));
49  m_transform->setAttitude(rotation);
50  }
51 
53  osg::ref_ptr<osg::Node> getNode() const
54  {
55  return m_transform;
56  }
57 
58 private:
60  osg::ref_ptr<osg::PositionAttitudeTransform> m_transform;
61 };
62 
63 }; // namespace Graphics
64 
65 }; // namespace SurgSim
66 
67 #endif // SURGSIM_GRAPHICS_OSGUNITSPHERE_H
OsgUnitSphere()
Constructor.
Definition: OsgUnitSphere.h:38
osg::ref_ptr< osg::PositionAttitudeTransform > m_transform
Root OSG node of the sphere.
Definition: OsgUnitSphere.h:60
osg::ref_ptr< osg::Node > getNode() const
Returns the root OSG node for the plane to be inserted into the scene-graph.
Definition: OsgUnitSphere.h:53
OSG unit sphere geode to be used as a primitive shape The sphere is located at (0, 0, 0) and has a radius of 1.
Definition: OsgUnitSphere.h:34