home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Pascal / Applications / Flight Stability / Flight Stability Source / FSIntf.p < prev   
Encoding:
Text File  |  1995-07-15  |  6.5 KB  |  297 lines  |  [TEXT/PJMM]

  1. {****************************************************}
  2. {}
  3. {        FSIntf.p                                                                                                                                                                                                                        }
  4. {}
  5. {        Interface file for the Flight Stability application.                                                                                            }
  6. {}
  7. {        Copyright © 1995, Patrick Hew. All rights reserved.                                                                            }
  8. {}
  9. {****************************************************}
  10.  
  11.  
  12. unit FSIntf;
  13.  
  14. interface
  15.  
  16.     uses
  17.         TCL, TCL_Controls, FW_Tearoffs, CBitmapWindow, Vector3;
  18.  
  19.     const
  20.  
  21.  
  22.     { Window dimensions. Used to locate at the centre of the main screen. }
  23.  
  24.         kFSGameWindh = 318;
  25.         kFSGameWindv = 434;
  26.  
  27.         kFSHelpWindh = 318;
  28.         kFSHelpWindv = 434;
  29.  
  30.  
  31.     { Resource IDs. }
  32.  
  33.         WINDGame = 3000;
  34.         WINDHelp = 4000;
  35.  
  36.         PICTHelpCredits = 4000;
  37.         PICTHelpFlying = 4001;
  38.         PICTHelpStability = 4002;
  39.         PICTHelpDrawing = 4003;
  40.  
  41.     { Command IDs. }
  42.  
  43.         cmdTakeControl = 3000;
  44.         cmdReleaseControl = 3001;
  45.  
  46.         cmdModeCredits = 4000;
  47.         cmdModeFlying = 4001;
  48.         cmdModeStability = 4002;
  49.         cmdModeDrawing = 4003;
  50.  
  51.  
  52. {****}
  53. { * CFSAircraftPane }
  54. { *}
  55. { *    Pane class to draw the perspective projection of the aircraft }
  56. { * which it is also responsible for. This is in lieu of making the }
  57. { * aircraft a separate object, which would have been the correct }
  58. { * thing to do, if it didn't look like being so involved to get it right. }
  59. { *}
  60. { * The aircraft model isn't quite right either, but its the way it is }
  61. { * because it is a lot easier to draw. }
  62. { *}
  63. { ****}
  64.  
  65.     const
  66.         kAircraftPaneLenh = 300;
  67.         kAircraftPaneLenv = 240;
  68.  
  69.     type
  70.         CFSAircraftPane = object(CPane)
  71.  
  72.                 { Parts of the aircraft. }
  73.                 noseCentre, noseLeft, noseRight: array[1..3] of V3Type;
  74.                 cockpitFront, cockpitBack: array[1..4] of V3Type;
  75.                 fuselageTopLeft, fuselageTopCentre, fuselageTopRight: array[1..4] of V3Type;
  76.                 fuselageBottomLeft, fuselageBottomCentre, fuselageBottomRight: array[1..4] of V3Type;
  77.                 leftWing, rightWing, leftTail, rightTail, tailFin: array[1..4] of V3Type;
  78.                 intake: array[1..2] of V3Type;
  79.  
  80.                 { The current dynamics of the aircraft. }
  81.                 itsBank, itsAOA: Real;
  82.  
  83.                 procedure IFSAircraftPane (anEnclosure: CView; aSupervisor: CBureaucrat; aWidth, aHeight, aHEncl, aVEncl: integer; aHSizing, aVSizing: SizingOption);
  84.  
  85.                 procedure UpdateAircraft (aBank, aAOA: Real);
  86.  
  87.                 procedure Draw (var area: Rect);
  88.                 override;
  89.  
  90.             end;
  91.  
  92.  
  93. {****}
  94. { * CFSApp}
  95. { *}
  96. { *    Application class for Flight Stability.}
  97. { *}
  98. { ****}
  99.  
  100.     type
  101.         CFSApp = object(CApplication)
  102.  
  103.                 itsGameDirector: CFSGameDirector;
  104.                 itsHelpDirector: CFSHelpDirector;
  105.  
  106.                 procedure IFSApp;
  107.  
  108.                 procedure SetUpFileParameters;
  109.                 override;
  110.  
  111.                 procedure MakeDesktop;
  112.                 override;
  113.  
  114.                 procedure DoCommand (theCommand: longint);
  115.                 override;
  116.  
  117.                 procedure StartUpAction (numPreloads: Integer);
  118.                 override;
  119.  
  120.                 procedure ExitApp;
  121.                 override;
  122.  
  123.             end;
  124.  
  125.  
  126. {****}
  127. { * CFSGameDirector}
  128. { *}
  129. { *    Director class for the Flight Stability application's game window.}
  130. { *}
  131. { ****}
  132.  
  133.     type
  134.         CFSGameDirector = object(CDirector)
  135.  
  136.                 itsAircraftPane: CFSAircraftPane;
  137.                 itsAutopilotButton: CButton;
  138.                 itsBankCheckBox, itsAOACheckBox: CCheckBox;
  139.                 itsDirFieldPane: CFSDirFieldPane;
  140.                 itsStickPane: CFSStickPane;
  141.  
  142.               { Whether we are on manual or automatic pilot. }
  143.                 isManual: Boolean;
  144.  
  145.                 procedure IFSGameDirector (aSupervisor: CDirectorOwner);
  146.  
  147.                 procedure Free;
  148.                 override;
  149.  
  150.                 procedure BuildWindow;
  151.  
  152.                 procedure UpdateMenus;
  153.                 override;
  154.  
  155.                 procedure DoCommand (theCommand: longint);
  156.                 override;
  157.  
  158.                 procedure DoKeyDown (theChar: char; keyCode: Byte; macEvent: EventRecord);
  159.                 override;
  160.  
  161.                 procedure ProviderChanged (aProvider: CCollaborator; reason: Longint; info: univ Ptr);
  162.                 override;
  163.  
  164.                 procedure Dawdle (var maxSleep: longint);
  165.                 override;
  166.  
  167.             end;
  168.  
  169.  
  170. {***}
  171. { * CFSHelpDirector}
  172. { *}
  173. { *    Director class for the Flight Stability application's help window.}
  174. { *}
  175. { ***}
  176.  
  177.     type
  178.         HelpMode = (ModeCredits, ModeFlying, ModeStability, ModeDrawing);
  179.  
  180.     type
  181.         CFSHelpDirector = object(CDirector)
  182.  
  183.                 itsMode: HelpMode;
  184.                 itsPicture: CPicture;
  185.                 itsCreditsButton, itsFlyingButton, itsStabilityButton, itsDrawingButton: CButton;
  186.  
  187.                 procedure IFSHelpDirector (aSupervisor: CDirectorOwner);
  188.  
  189.                 procedure Free;
  190.                 override;
  191.  
  192.                 procedure BuildWindow;
  193.  
  194.                 procedure DoCommand (theCommand: longint);
  195.                 override;
  196.  
  197.                 procedure DrawHelpWindow (aMode: HelpMode);
  198.  
  199.             end;
  200.  
  201.  
  202. {***}
  203. { * CFSDirFieldPane}
  204. { *}
  205. { *    Pane class for the direction field.}
  206. { *}
  207. { ***}
  208.  
  209.     const
  210.         kDirFieldHalfWidth = 32 * 3;
  211.         kDirFieldHalfHeight = 32 * 2;
  212.  
  213.         { Bank ranges from -pi to pi }
  214.         { AOA ranges from -pi/2 to pi/2 }
  215.         { Edges of direction field pane are ± pi }
  216.  
  217.         kBankToFrame = 30.558;        { kDirFieldHalfWidth / pi }
  218.         kFrameToBank = 0.0327;        { pi / kDirFieldHalfWidth }
  219.         kAOAToFrame = 40.744;         { kDirFieldHalfHeight / (pi/2) }
  220.         kFrameToAOA = 0.0245;        { (pi/2) / kDirFieldHalfHeight }
  221.  
  222.     type
  223.         CFSDirFieldPane = object(CPane)
  224.  
  225.                 fBankStable, fAOAStable: Boolean;
  226.  
  227.                 oldBank, oldAOA: Real;
  228.                 currBank, currAOA: Real;
  229.  
  230.                 procedure IFSDirFieldPane (anEnclosure: CView; aSupervisor: CBureaucrat; aWidth, aHeight, aHEncl, aVEncl: integer; aHSizing, aVSizing: SizingOption);
  231.  
  232.                 procedure Draw (var area: Rect);
  233.                 override;
  234.  
  235.                 procedure SetBankStability (fStable: Boolean);
  236.  
  237.                 procedure SetAOAStability (fStable: Boolean);
  238.  
  239.                 procedure GetDirection (aBank, aAOA: Real; var aBankRate, aAOARate: Real);
  240.  
  241.                 procedure GetCurrPosition (var aCurrBank, aCurrAOA: Real);
  242.  
  243.                 procedure SetCurrPosition (aCurrBank, aCurrAOA: Real);
  244.  
  245.                 procedure UpdatePosition (aBankChange, aAOAChange: Real);
  246.  
  247.             end;
  248.  
  249.  
  250. {***}
  251. { * CFSStickPane}
  252. { *}
  253. { *    Pane class for the "joystick".}
  254. { *}
  255. { ***}
  256.  
  257.     const
  258.         kStickHalfWidth = 16;
  259.         kStickHalfHeight = 16;
  260.  
  261.     type
  262.         StickHorRange = -kStickHalfWidth..kStickHalfWidth;
  263.         StickVerRange = -kStickHalfHeight..kStickHalfHeight;
  264.  
  265.     type
  266.         CFSStickPane = object(CPane)
  267.  
  268.                 stickh: StickHorRange;
  269.                 stickv: StickVerRange;
  270.  
  271.                 { On each update loop, compare the current mouse }
  272.                 { position with the position on the previous iteration. }
  273.                 { The offset is the control. }
  274.                 oldMousePt: Point;
  275.  
  276.                 procedure IFSStickPane (anEnclosure: CView; aSupervisor: CBureaucrat; aWidth, aHeight, aHEncl, aVEncl: integer; aHSizing, aVSizing: SizingOption);
  277.  
  278.                 procedure Draw (var area: Rect);
  279.                 override;
  280.  
  281.                 procedure InitOldMousePt;
  282.  
  283.                 procedure GetControl (var aBankChange, aAOAChange: Real);
  284.                 { GetControl is the responsibility of CFSStickPane }
  285.                 { so that we can also update the drawing arrow. }
  286.                 { We are able to impose a natural limit on how far }
  287.                 { we can push the stick, namely StickHorRange and }
  288.                 { StickVerRange. }
  289.  
  290.                 procedure CentreStick;
  291.  
  292.             end;
  293.  
  294.  
  295. implementation
  296.  
  297. end. { FSIntf }