;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; DynKit v2.03 ;; ;; Copyright (C) 1998 by Konstantin Kukushkin. ;; ;; ;; ;; An example dynamic library written with FSASM ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Shape included: ; ; A phantasy flying saucer featuring a retractable landing gear and a rotor ; controllable using section 15 instructions. ; Begin ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Includes .include "fsahead.def" .include "dynkit.def" ; The BGL header must contain proper Var0..Var7 values DynLibHeader 0a9h,0cdh,0c2h,000h,0aah,000h,0e1h,0a9h .section 10 ; Object table. For each object defined in section 10, it must contain ; it's offset and a 16-byte ID. Not all possible IDs work. DynLibTableEntry SaucerObject:, \ 0A9h,0CDh,0C2h,000h,0AAh,000h,0E1h,0A9h,\ 0D0h,013h,035h,073h,013h,050h,09Ah,008h DynLibTableEnd ; Flying Saucer example. ; Demonstrates using custom color schemes, gear status, linear timers. ; Dynamic colors used: ; 0 - Main saucer color ; 1 - Top cone color ; 2 - Landing gear color ; 3 - Rotor color ; 5 - Used for DynKit features: ; DynRotorStill/DynRotorSlow/DynRotorFast control the rotor speed SaucerObject: BeginDynShape .PushScope ; -- Generic part, similar in all objects .Relative 0,0, SCALE=0.05 ; Draw the shadow on the ground ShadowRefPtIndirect vDynPos ; Project the object RefPoint on the ground SetScale skip_shadow:,SCALE ; Set the scale factor ; Draw the shadow of the rotated object. ; Unlike a "usual" ShadowCall, RotShadowCallIndirect allows using all ; possible displacements and rotation angles in [Tran]RotCall's inside ; the drawing routine without problems. RotShadowCallIndirect draw_saucer:,vDynPitch skip_shadow: ; Draw the object itself RefPtIndirect skip_draw:, vDynPos ; Load the RefPoint. SetScale skip_draw:,SCALE ; Set the scale factor. RotCallIndirect draw_saucer:,vDynPitch ; Draw the rotated object. skip_draw: ; Set the object extent (in meters) for collision avoidance. SetVar vDynExtent,16 ; We are called from a PerspectiveCall, so return to the caller. Return draw_saucer: ; -- Beginning of the "main" drawing code. ; For simplicity, I didn't use VectorJump's here, so there are a few drawing ; order problems. ; Define points on the top/bottom perimeter. DefPoints 17,0 .For i=0,1,16 Point 20*cos(2*PI*i/16), 20*sin(2*PI*i/16),0 .EndFor DefPoints 17,20 .For i=0,1,16 Point 6*cos(2*PI*i/16), 6*sin(2*PI*i/16),3 .EndFor ; Define two vertices. DefPoints 2,40 Point 0,0,1 Point 0,0,8 VecMode Auto .SurfDir CCW ; Draw the upper side of the rotor. ; vDynColor4 is used to control the rotor speed from section 15. IfVarAnd ru1:,vDynColor4,DynRotorStill Call DrawRotorUpside: ; Standing still. ru1: IfVarAnd ru2:,vDynColor4,DynRotorSlow TranRotCall DrawRotorUpside:, 0,0,0, 0,0,0,0,0,vDynTimer2 ; 1 rotation/sec. ru2: IfVarAnd ru3:,vDynColor4,DynRotorFast TranRotCall DrawRotorUpside:, 0,0,0, 0,0,0,0,0,vDynTimer3 ; 2 rotations/sec. ru3: ; Draw the inside of the landing gear. IfVarAnd ng1:,vDynGear,DynGearMask ; Draw only if gear down. TranRotCall DrawGearInside:, 0,0,0, 0,0,0,0,0,0 TranRotCall DrawGearInside:, 0,0,0, 0,0,0,0,60d,0 TranRotCall DrawGearInside:, 0,0,0, 0,0,0,0,120d,0 TranRotCall DrawGearInside:, 0,0,0, 0,0,0,0,180d,0 TranRotCall DrawGearInside:, 0,0,0, 0,0,0,0,240d,0 TranRotCall DrawGearInside:, 0,0,0, 0,0,0,0,300d,0 ng1: ; Draw the bottom of the saucer. SurfaceColorIndirect vDynColor0 .For i=0,1,15 FlatPoly i,i+1,40 .EndFor ; Draw the "outer surface". SurfaceColorIndirect vDynColor0 .For i=0,1,15 FlatPoly i+1,i,i+20,i+20+1 .EndFor ; Draw the top cone. SurfaceColorIndirect vDynColor1 .For i=0,1,15 FlatPoly 20+i+1,20+i,41 .EndFor ; Draw the outside of the landing gear. IfVarAnd ng2:,vDynGear,DynGearMask ; Draw only if gear down. TranRotCall DrawGearOutside:, 0,0,0, 0,0,0,0,0,0 TranRotCall DrawGearOutside:, 0,0,0, 0,0,0,0,60d,0 TranRotCall DrawGearOutside:, 0,0,0, 0,0,0,0,120d,0 TranRotCall DrawGearOutside:, 0,0,0, 0,0,0,0,180d,0 TranRotCall DrawGearOutside:, 0,0,0, 0,0,0,0,240d,0 TranRotCall DrawGearOutside:, 0,0,0, 0,0,0,0,300d,0 ng2: ; Draw the down side of the rotor. ; vDynColor4 is used to control the rotor speed. IfVarAnd rd1:,vDynColor4,DynRotorStill Call DrawRotorDownside: rd1: IfVarAnd rd2:,vDynColor4,DynRotorSlow TranRotCall DrawRotorDownside:, 0,0,0, 0,0,0,0,0,vDynTimer2 rd2: IfVarAnd rd3:,vDynColor4,DynRotorFast TranRotCall DrawRotorDownside:, 0,0,0, 0,0,0,0,0,vDynTimer3 rd3: Return ; -- End of the "main" drawing code. ; Draw 6 similar rotor blades (upside). DrawRotorUpside: TranRotCall DrawRotorBladeUpside:, 0,0,0, 0,0,0,0,0,0 ;TranRotCall DrawRotorBladeUpside:, 0,0,0, 0,0,0,0,60d,0 TranRotCall DrawRotorBladeUpside:, 0,0,0, 0,0,0,0,120d,0 ;TranRotCall DrawRotorBladeUpside:, 0,0,0, 0,0,0,0,180d,0 TranRotCall DrawRotorBladeUpside:, 0,0,0, 0,0,0,0,240d,0 ;TranRotCall DrawRotorBladeUpside:, 0,0,0, 0,0,0,0,300d,0 Return ; Draw a rotor blade (upside). DrawRotorBladeUpside: DefPoints 4,100 Point 22,-3,0 Point 22,3,0 Point 32,-1,0 Point 32,1,0 SurfaceColorIndirect vDynColor3 FlatPoly 100,101,103,102 ConcavePoly Return ; Draw 6 rotor blades (downside). DrawRotorDownside: TranRotCall DrawRotorBladeDownside:, 0,0,0, 0,0,0,0,0,0 ;TranRotCall DrawRotorBladeDownside:, 0,0,0, 0,0,0,0,60d,0 TranRotCall DrawRotorBladeDownside:, 0,0,0, 0,0,0,0,120d,0 ;TranRotCall DrawRotorBladeDownside:, 0,0,0, 0,0,0,0,180d,0 TranRotCall DrawRotorBladeDownside:, 0,0,0, 0,0,0,0,240d,0 ;TranRotCall DrawRotorBladeDownside:, 0,0,0, 0,0,0,0,300d,0 Return ; Draw a rotor blade (downside). DrawRotorBladeDownside: DefPoints 4,100 Point 22,-3,0 Point 22,3,0 Point 32,-1,0 Point 32,1,0 SurfaceColorIndirect vDynColor3 FlatPoly 101,100,102,103 Return ; Draw the landing gear (outside). DrawGearOutside: DefPoints 8,104 Point 20,0,0 Point 20,0.25,0 Point 20,0,-3 Point 20,0.25,-3 Point 20,-0.25,-3.5 Point 20,0.50,-3.5 Point 20,0,-4 Point 20,0.25,-4 SurfaceColorIndirect vDynColor2 FlatPoly 106,104,105,107 ConcavePoly .SurfDir CW FlatPoly 106,108,110,111,109,107 .SurfDir CCW Return ; Draw the landing gear (inside). DrawGearInside: DefPoints 8,104 Point 20,0,0 Point 20,0.25,0 Point 20,0,-3 Point 20,0.25,-3 Point 20,-0.25,-3.5 Point 20,0.50,-3.5 Point 20,0,-4 Point 20,0.25,-4 SurfaceColorIndirect vDynColor2 ConcavePoly .SurfDir CW FlatPoly 104,106,108,110,111,109,107,105 .SurfDir CCW Return ; SaucerEnd: marks the end of the saucer code and is referenced in the ; object header. SaucerEnd: .PopScope EndDynShape ; EOF ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;