| | 65 | pat->addChild(sun_geode); |
| | 66 | |
| | 67 | osg::Geometry * unitCircle = new osg::Geometry(); |
| | 68 | { |
| | 69 | osg::Vec4Array * colours = new osg::Vec4Array(1); |
| | 70 | (*colours)[0] = osg::Vec4d(1.0,1.0,1.0,1.0); |
| | 71 | unitCircle->setColorArray(colours); |
| | 72 | unitCircle->setColorBinding(osg::Geometry::BIND_OVERALL); |
| | 73 | const unsigned int n_points = 1024; |
| | 74 | osg::Vec3Array * coords = new osg::Vec3Array(n_points); |
| | 75 | const double dx = 2.0*M_PI/n_points; |
| | 76 | double s,c; |
| | 77 | for (unsigned int j=0; j<n_points; ++j) { |
| | 78 | s = sin(dx*j); |
| | 79 | c = cos(dx*j); |
| | 80 | (*coords)[j].set(osg::Vec3d(c,s,0.0)); |
| | 81 | } |
| | 82 | unitCircle->setVertexArray(coords); |
| | 83 | unitCircle->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF); |
| | 84 | unitCircle->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP,0,n_points)); |
| | 85 | } |
| | 87 | osg::Geometry *axes = new osg::Geometry; |
| | 88 | { |
| | 89 | osg::Vec4Array *colours = new osg::Vec4Array(1); |
| | 90 | (*colours)[0] = osg::Vec4d(1.0,0.0,0.0,1.0); |
| | 91 | axes->setColorArray(colours); |
| | 92 | axes->setColorBinding(osg::Geometry::BIND_OVERALL); |
| | 93 | osg::Vec3Array *coords = new osg::Vec3Array(6); |
| | 94 | (*coords)[0].set(osg::Vec3d(0.0, 0.0, 0.0)); |
| | 95 | (*coords)[1].set(osg::Vec3d(0.5, 0.0, 0.0)); |
| | 96 | (*coords)[2].set(osg::Vec3d(0.0, 0.0, 0.0)); |
| | 97 | (*coords)[3].set(osg::Vec3d(0.0, 0.5, 0.0)); |
| | 98 | (*coords)[4].set(osg::Vec3d(0.0, 0.0, 0.0)); |
| | 99 | (*coords)[5].set(osg::Vec3d(0.0, 0.0, 0.5)); |
| | 100 | axes->setVertexArray(coords); |
| | 101 | axes->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF); |
| | 102 | axes->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,6)); |
| | 103 | } |
| | 104 | |
| | 105 | // Earth orbit |
| | 106 | osg::Geode * earthOrbitGeode = new osg::Geode; |
| | 107 | earthOrbitGeode->addDrawable(unitCircle); |
| | 108 | earthOrbitGeode->addDrawable(axes); |
| | 109 | earthOrbitGeode->setName("EarthOrbitGeode"); |
| | 110 | |
| | 111 | osg::PositionAttitudeTransform * earthOrbitPAT = new osg::PositionAttitudeTransform; |
| | 112 | earthOrbitPAT->setScale(osg::Vec3d(AU,AU,AU)); |
| | 113 | earthOrbitPAT->setPosition(osg::Vec3d(0.0, AU, 0.0)); |
| | 114 | earthOrbitPAT->addChild(earthOrbitGeode); |
| | 115 | earthOrbitPAT->setName("EarthOrbitPAT"); |
| | 116 | |
| 105 | | viewer.getCameraManipulator()->setHomePosition(osg::Vec3d(0.0,-5.0*r_earth,0.0),osg::Vec3d(0.0,0.0,0.0),osg::Vec3d(0.0,0.0,1.0)); |
| | 159 | viewer.getCameraManipulator()->setHomePosition(osg::Vec3d(0.0,-5.0*r_earth,0.0),osg::Vec3d(0.0,0.0,0.0),osg::Vec3d(0.0,0.0,1.0)); |