| Description | A script to generate a panoramic AVI video file using the Sapphire 3D renderer. | 
|---|---|
| Author | Aaron | 
| Created | 2010/05/09 | 
| Requires | L3DT 11.07 beta 2 or later | 
| Download | SapphirePanoramaAVI.zs | 
To use this script, first open Sapphire and move the camera to the vantage point from which you would like the panorama generated. Then, in the Sapphire menu, select the 'Scripts→Run script file' menu option, and select this script file.
//
// Title:   Sapphire Panorama AVI script
// Author:  Aaron Torpy
// Date:    5 Mar 2009
// URL:     http://www.bundysoft.com/wiki/doku.php?id=tutorials:l3dt:panorama
// Updated: 14 Jul 2011
//
hvar pHF
set pHF <GetMap "HF">
float scale
set scale <map.GetHorizScale pHF>
// create settings variables
float ls.PositionX
float ls.PositionY
float ls.Heading
float ls.Altitude
int ls.nFrames
// initialise settings with default values
set ls.PositionX <div <map.GetWidth pHF> 2>
set ls.PositionY <div <map.GetWidth pHF> 2>
set ls.nFrames 360
set ls.Altitude 500
set ls.Heading 0
// get position from Sapphire if open
if <Sapphire.IsShown>
  set ls.PositionX <Sapphire.Camera.GetPosX>
  set ls.PositionY <Sapphire.Camera.GetPosY>
  set ls.Altitude <Sapphire.Camera.GetPosZ>
  set ls.Altitude <mul ls.Altitude scale> // convert from reduced units to metres
  set ls.Heading <Sapphire.Camera.GetAzim>
  set ls.Heading <RadToDeg ls.Heading> // convert to degrees
endif
// ask user for settings
if <not <EditUI &ls "Enter movie settings">>
  return false
endif
// ask user for filename
filesel FS
filesel.Init &FS false NULL "AVI movie file (*.avi)|*.avi|" "avi" NULL
if <not <EditUI &FS "Enter output file">>
  return false
endif
string FileName
set FileName <filesel.GetPathA &FS>
float alt
set alt <div ls.Altitude scale>
float azim
set azim <DegToRad ls.Heading>
Sapphire.ShowWnd
Sapphire.SetPause true
Sapphire.Camera.SetElev 0
Sapphire.Camera.SetAzim azim
Sapphire.Camera.SetPos3d ls.PositionX ls.PositionY alt
// calculate angle step size
float dtheta
set dtheta <div <DegToRad 360> ls.nFrames>
// prepare progres box
progbox prog
progbox.SetTitle &prog "Recording movie"
progbox.ShowWnd &prog
// prepare some variables for the loop
int k kmax
set k 0
set kmax ls.nFrames
map Frame
// run a few frames to make Sapphire settle
do 
  Sapphire.RenderFrame 0
while <islt <incr k> 10>
// now run the panorama loop
set k 0
do
  // update progress display
  progbox.SetProgress &prog k kmax
  Sapphire.Camera.SetAzim azim  // set camera angle
  Sapphire.RenderFrame 0        // render a frame
  Sapphire.ScreenCap2 &Frame    // capture frame to 'Frame' image
  // if first frame, initialise AVI stream
  if <iseq k 0>
    assert <file.AVI_VFW.OpenStream FileName <map.GetWidth &Frame> <map.GetHeight &Frame> 25 "CVID"> "Error: cannot open file stream"
  endif
  file.AVI_VFW.AddFrame &Frame     // add 'Frame' image to AVI stream
  // increment azimuth
  set azim <add azim dtheta>
while <islt <incr k> kmax>
// finalise AVI stream
file.AVI_VFW.CloseStream
// finish by setting Sapphire free
if <Sapphire.IsPaused>
  Sapphire.SetPause false
endif