/*

  http://en.wikipedia.org/wiki/Wavefront_.obj_file

  Hunter and Dog Model
  http://www.turbosquid.com/3d-models/free-scan-statue-hunter-dog-3d-model/791511

*/

  #compact
  % filename "t.exe"
  % Title "OBJ VIEWER (F1 Help  F5 Render)"
 '% WindowOpacity 240 'max 255
 '% Animated
  % ScaleUp
 '% PlaceCentral
 '% AnchorCentral
  % NoEscape
  % ColorCodedPick
  % MultiSamples 4
  '
  % SymbolTerm 47 '- /' self delimited symbols

  indexbase 1

  'INCLUDES
  =========
  $filename "t.exe"
 'uses rtl32
  uses parseUtil
  uses consoleG
  uses objinterp


  function main()
  ===============
  '
  static sys    shape
  static string inputs
  '
  'preload
  if not inputs
    inputs="Models/Poly.obj"
    ObjFileName=inputs
    BuildObj()
  endif
  '
  cls 0,0.20,0.20
  picksetup
  '
  shading
  pushstate
  static MoveableObject mover
  if not mover.id then
    mover.set 0x10000,0,0,0,0
    'mover.a.y =180
    'mover.aa.y=180
    mover.mode=0x100
  end if
  sys dt=15
  move dt,-dt,-dt-1
  mover.act
  if pick then
    scale dt
    go sphere
    'touchzone
  else
    'Material Gold
    'Material Silver
    'Material RedShiny
    Material WhiteShiny
    'go sphere
    float f=smax-smin
    if f then scale 2*dt/f
    'scale 1,1,-1.0 'REVERSE Z
    if li=1 then
      'NO MATERIAL SPECIFIED
      Material White
      go glist[1]
    end if
    int j,q
    for j=2 to li
      'SELECT MATERIAL
      q=mlist[j]
      material mat[q]
      texture mat[q+14]
      'EXEC GL DRAWING LIST
      go glist[j]
      texture 0
    next
  end if
  
  popstate
  '
  'USING TAB AS OBJECT SELECTOR
  if not pick then
    if lastchar=9 then
      if picked<>mover.id then
        picked=mover.id
      else
        picked=0
      end if
      lastchar=0
    end if
  end if
  '
  'F5 FILE LOADER
  'SINGLE SHOT F5
  static sys f5t=1
  if key(0x74) 'F5
    if f5t
      ObjFileName=inputs
      q=BuildObj()
      f5t=0
    end if
  else
    f5t=1
  end if
  '
  'LINE INPUT
  '
  if picked<>mover.id then
    flat
    texture 0
    PushState
    color .20,.80,.00,.88
    Scale 1.0
    print "File: "
    color .80,.80,.00,.88
    int a=input inputs
    scale .75
    printl status
    PopState
  end if
  printl
  printl
  '
  if FileDrop then
    inputs=FileDrop
    FileDrop=""
    ObjFileName=inputs
    q=BuildObj()
  end if
  '
  '
  'F1 HELP
  '
  if key[0x70]
    flat
    pushstate
    move 20,0
    color .9,.9,.9
    scale  1.5,1.0
    printl "Active Keys:"
    printl
    scale  1/1.5,1.0
    printl "Esc"    tab "Exit"
    printl "Ctrl-P" tab "Take snapshot"
    printl "F1 This help panel"
    printl "F5 Exec function"
    printl "TAB to Select Object / Text line"
    printl "Arrow keys PgUp PgDn to move"
    printl "Ctrl Arrow keys PgUp PgDn to rotate"
    printl "+ - keys to scale up and scale down"
    printl "Ctrl Home to reset rotation"
    printl "Shift for faster movement"
    printl
    scale 1.5,1.0
    printl "Mouse:"
    printl		
    scale 1/1.5,1.0
    printl "Point to Object, then"
    printl "Left button to move"
    printl "Middle button to scale"
    printl "Right button to rotate"
    printl "Wheel to move in Z direction"
    popstate
  end if
  picklabel 0
  lastkey=0
  lastchar=0

  end function


  EndScript
