#include <osg/Geode>
#include <osg/ShapeDrawable>
#include <osgViewer/Viewer>
// Get a new sphere geode
osg::ref_ptr<osg::Geode> CreateSphereGeode(
osg::Vec3 tCenter, // The location of the center of the sphere
osg::Vec4 tColor, // The color of the sphere
float fRadius // The sphere radius
)
{
// Create the geode to return
osg::ref_ptr<osg::Geode> pRetv = new osg::Geode;
// Create the sphere
osg::ref_ptr<osg::Sphere> pSphere = new osg::Sphere(tCenter, fRadius);
// Create the drawable
osg::ref_ptr<osg::ShapeDrawable> pSphereDrawable = new osg::ShapeDrawable(pSphere);
// Set the color
pSphereDrawable->setColor(tColor);
// Add the drawable
pRetv->addDrawable(pSphereDrawable);
// Return this geode
return pRetv;
}
// The main application entry point
int main(int argc, char *argv[])
{
// Create the viewer
osg::ref_ptr<osgViewer::Viewer> pViewer = new osgViewer::Viewer;
// Create the top group parent
osg::ref_ptr<osg::Group> pTopGroup = new osg::Group;
// Create some spheres
osg::ref_ptr<osg::Geode> pSphere1 = CreateSphereGeode(osg::Vec3(0.0f, 0.0f, 0.0f), osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f), 2.0f);
osg::ref_ptr<osg::Geode> pSphere2 = CreateSphereGeode(osg::Vec3(10.0f, 0.0f, 5.0f), osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f), 1.0f);
osg::ref_ptr<osg::Geode> pSphere3 = CreateSphereGeode(osg::Vec3(-15.0f, 6.0f, 0.0f), osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f), 4.0f);
// Add these spheres to the top group node
pTopGroup->addChild(pSphere1);
pTopGroup->addChild(pSphere2);
pTopGroup->addChild(pSphere3);
// Here I am attempting to change the initial perspective, but I can make these numbers anything and it doesn't seem to change anything
pViewer->getCamera()->setViewMatrixAsLookAt(
osg::Vec3(-0.9983f, 0.0252f, -0.0530f),
osg::Vec3(0.8639f, -2.5189f, -70.0939f),
osg::Vec3(0.8880f, -1.5194f, -70.0726f)
);
// Add a viewport to the viewer and attach the scene graph
pViewer->setSceneData(pTopGroup);
// Run the viewer
return pViewer->run();
}