Board index FlightGear Development New features

Adding procedurally created osg::Shapes to the scene (RFC)

Discussion and requests for new features. Please note that FlightGear developers are volunteers and may or may not be able to consider these requests.

Adding procedurally created osg::Shapes to the scene (RFC)

Postby Hooray » Thu Dec 17, 2015 9:11 pm

Subject: Implementing moonlight (or not)
bugman wrote:You got my 'reaching for the stars' reference :D The code I'm looking at is a few of the key parts of what needs to be adapted for landing on the moon! The ephemeris code, the lighting code, and the osg scene set up in the FG renderer. I was thinking of exactly what needs to be done for a moon landing (or orbit) as I was looking at all of this.


Referring to the idea of allowing arbitrary 3D spheres to be instantiated/created, textured and updated at run-time (aka Earthview in C++):

The boilerplate code required to add a new subsystem to the FlightGear main loop is this: http://wiki.flightgear.org/Howto:Create_new_subsystems
Adding a new "shape" or "sphere" subsystem would be pretty simple.

Next, it would need to instantiate, and position, an osg::Sphere - i.e. adapting the sample code at: http://trac.openscenegraph.org/document ... gShape.htm

Code: Select all
osg::Sphere* unitSphere = new osg::Sphere( osg::Vec3(0,0,0), 1.0);

osg::PositionAttitudeTransform* sphereXForm =
               new osg::PositionAttitudeTransform();
sphereXForm->setPosition(osg::Vec3(2.5,0,0));
osg::Geode* unitSphereGeode = new osg::Geode();
root->addChild(sphereXForm);
sphereXForm->addChild(unitSphereGeode);
unitSphereGeode->addDrawable(unitSphereDrawable);


Obviously, these are hard-coded values for now - but those could be either re-implemented using the propertyObject<> helper and/or by using the SGPropertyChangeListener interface to treat certain properties as "events", e.g. having /sphere/moon/position, /sphere/moon/size and /sphere/moon/texture nodes etc.

The main osg classes that would seem useful for this would be:
  • osg::LightSource
  • osg::Sphere (the 3D object itself)
  • osg::PositionAttitudeTransformMatrix (PAT, for transforming & positioning the 3D model)
  • osg::LOD to support different LODs
  • osg::StateSet (for setting texturing/shader related attributes and modes)

References:
http://osghelp.com/?p=167
http://www.cuboslocos.com/tutorials/OSG-BasicLighting
http://trac.openscenegraph.org/document ... 00454.html
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 11475
Joined: Tue Mar 25, 2008 8:40 am

Return to New features

Who is online

Users browsing this forum: No registered users and 1 guest