Howto:Make full spherical panorama

From FlightGear wiki
Revision as of 10:20, 20 November 2010 by Cri (talk | contribs) (Created page with 'In this howto I will explain how to make full spherical panorama in FlightGear. The semi-automated process is useful for everyone that want to contreibute…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

In this howto I will explain how to make full spherical panorama in FlightGear. The semi-automated process is useful for everyone that want to contreibute to the wiki by adding one of this panorama to each aircraft's page in order to display the cockpit.

The tools

In order to take panorama in flightgear you need:

  • of course Flightgear
  • a panorama stitching tool. I suggest to use Hugin: it's free and very powerful.

The automatic process

To make the process easier I've created a [[nasal|Nasal_scripting_language] script that capture automagically the required screenshots. This script can be binded to a keyboard key. Also I've created a standard Hugin file to assemble this screenshots into a full spherical panorama.

Taking the required screenshots

The easier way is to bind the following nasal script to a keyboard key (The "F3" key that is used by default to take screenshots). To do this, open the file keyboard.xml that you can find in the fgdata folder with a text editor and look for the following section:

<key n="259">
 <name>F3</name>
 <desc>Capture screen</desc>
 <binding>
  <command>nasal</command>
  <script>
    var success = fgcommand("screen-capture");
    var path = getprop("/sim/paths/screenshot-last");
    if (success)
        gui.popupTip("Screenshot written to '" ~ path ~ "'");
    else
        gui.popupTip("Error writing screenshot '" ~ path ~ "'");
  </script>
 </binding>
 <mod-shift>
  <desc>Load panel</desc>
  <binding>
   <command>panel-load</command>
  </binding>
 </mod-shift>
</key>

Now substitute the Nasal_scripting_language code between the <script> tags with this:

       var timeint=3;
       var runs=2;
       
         menubarvalue=getprop("/sim/menubar/visibility");
         znearvalue=("sim/rendering/camera-group/znear");
         fovvalue=getprop("/sim/current-view/field-of-view");
         freezemvalue=getprop("/sim/freeze/master");
         freezecvalue=getprop("/sim/freeze/clock");
         headingvalue=getprop("/sim/current-view/heading-offset-deg");
         pitchvalue=getprop("/sim/current-view/pitch-offset-deg");
         
       setprop("/sim/screenshots/runs", runs);
       setprop("/sim/menubar/visibility", 'false');
       setprop("/sim/rendering/camera-group/znear",0.03);
       setprop("/sim/current-view/field-of-view", 120);
       setprop("/sim/freeze/master",'true');
       setprop("/sim/freeze/clock",'true');
       
       var takescreen = func(n,k) {
         var runs=getprop("/sim/screenshots/runs");
         if ( n > 0 ) {          
           var panofov = getprop("/sim/current-view/field-of-view");
           setprop("/sim/current-view/heading-offset-deg", n*90);
           setprop("/sim/current-view/pitch-offset-deg", k);
             settimer( func { var success = fgcommand("screen-capture");
               if (success) { 
                 print ("screen taken with heading= ",n*90 ," and pitch= ", k);
                 takescreen(n-1,k);
               } else {
                  print("screen not taken");}
              }, timeint, timeint );
         }
       }
 var scr_runs = func {
   var runs_left = getprop("/sim/screenshots/runs");
   print("run: ", runs_left);
     if (runs_left > 0) {
       if(runs_left > 1){
         setprop("/sim/screenshots/runs", runs_left-1);
         print("runs_left-1 =",runs_left-1);
         takescreen(4,-45);
       }else{
         setprop("/sim/screenshots/runs", runs_left-1);
         print("runs_left-1 =",runs_left-1);
         takescreen(4,45);
       }
       settimer(scr_runs, timeint*5, timeint*5);
     }else{
       setprop("/sim/menubar/visibility", menubarvalue);
       setprop("/sim/current-view/field-of-view", fovvalue);
       setprop("/sim/current-view/heading-offset-deg", headingvalue);
       setprop("/sim/current-view/pitch-offset-deg", pitchvalue);
       setprop("/sim/freeze/master", freezemvalue);
       setprop("/sim/freeze/clock", freezecvalue);
     }
    }
scr_runs();

Now you are ready to start flightgear. When in the game press the "F3" key and wait. You will see the camera change heading and pitch automatically. When the required screenshots are taken, the original view is restored. Now exit flightgear, look for saved screenshots in png format and follow next step.

Stitching the panorama with Hugin

Copy all the eight screenshots in a new folder named as you want. Open this folder and create in it a new text file called panorama.pto. Open this file and copy the following lines in it:


Save the file and open it with Hugin. In Hugin go to the "stitching" tab and press the "Stitch Now" button. You will be asked where to save the resulting image. Select a path and press ok. When Hugin terminates the stitching process you are done. Browse to where you tell Hugin to save the panorama, and take a look at the image to check if something went wrong.