Howto:Use a Camera View in an Instrument

From FlightGear wiki
Jump to navigation Jump to search
IMPORTANT: Some, and possibly most, of the features/ideas discussed here are likely to be affected, and possibly even deprecated, by the ongoing work on providing a property tree-based 2D drawing API accessible from Nasal using the new Canvas system available since FlightGear 2.80 (08/2012). Please see: Hackathon Proposal: CompositeViewer and Canvas for further information

You are advised not to start working on anything directly related to this without first discussing/coordinating your ideas with other FlightGear contributors using the FlightGear developers mailing list or the Canvas subforum This is a link to the FlightGear forum.. Anything related to Canvas Core Development should be discussed first of all with TheTom and Zakalawe. Nasal-space frameworks are being maintained by Philosopher and Hooray currently. talk page.

Canvasready.png

Background

Note  There is a related patch available at https://forum.flightgear.org/viewtopic.php?p=317448#p317448


This was inspired by the ongoing effort to create a realistic 787 for FlightGear, including support for rendering external camera views on instruments: Boeing 787-8 Dreamliner#Camera.2FVideo Surveillance Instrument. The "Tail Camera" is also a feature found on the A380.

Objective

To create a 2D instrument which shows a camera view. Write C++ code, preferably an instrument that renders a Camera View (i.e. from the property tree) to a texture.

The steps involved in creating such an instrument would be:*

  • create a new topic branch: FlightGear and Git#Local_Branch
  • Add a new set of cxx/hxx files to $FG_SRC/Instrumentation/ (e.g. camera-texture.cxx and camera-texture.hxx): to get started quickly, just copy and customize the gyro.* files
  • implement the SGSubsystem interface for the new subsystem [1]
  • add the new files to the CMake build system: Developing using CMake#Adding_new_files_to_the_build
  • add the new subsystem to the instrument_mgr (FGInstrumentMgr::build method)[2]
  • implement the interface for the od_gauge instrument to dynamically create a texture and display update it as a cockpit instrument
  • implement SGPropertyChangeListener to process property tree events and updates [3]
  • Render a property-driven camera view to the created texture (Zan has already code doing this sort of thing [4] This is a link to the FlightGear forum.)
  • Write an XML 2D Instrument file that displays the texture


There are obviously more steps involved here, some of which covered here Howto: Create a 2D drawing API for FlightGear.

Pre-Requisites

The following are required before we continue...

  • To be able to build FlightGear from Source (with or without an IDE)
  • To be able to create new instruments (that would be taking a simple one like gyro, copying it's files and changing the content)
  • A Gitorious account to be able to clone the Flightgear Repository
  • Basic Knowledge of FlightGear and XML

osgViewer::CompositeViewer

This section has been moved to a dedicated article: CompositeViewer Support.

Part 1: Rendering a Camera View to Texture

There're probably many ways to do that, you could do it the way the ground radar instrument does, or how you take a screenshot etc.

A couple nice guides on OpenSceneGraph Rendering are available at:

The OSG Quick Start guide can be download at: http://www.lulu.com/items/volume_51/767000/767629/3/print/OSGQSG.pdf

The OSG API reference is available here: http://www.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/annotated.html

The OpenSceneGraph Beginners Guide is also available on line.

Also see: http://www.openscenegraph.org/projects/osg/wiki/Support/GettingStarted

The OSG FAQ can be found at: http://www.3drealtimesimulation.com/osg/osg_faq_1.htm

Programming Resources#OSG.2FOpenSceneGraph_related

Screenshot Method

This is a very simple method and is used normally for taking screen-shots.

OpenSceneGraph C++ Code:

osg::Image* shot = new osg::Image();
shot->allocateImage(width, height, 24, GL_RGB, GL_UNSIGNED_BYTE);
camera->attach(osg::Camera::COLOR_BUFFER, shot);
osgDB::writeImageFile(*shot,"image_file.png");

Related