
  '#compact
  $ FileName  "t.exe"
  'uses rtl32
  'uses rtl64
  '
  % ExplicitMain
  $ title        "Help Using Function key F1"
  $ fontA        "Arial",FW_SEMIBOLD
  '
  uses OpenglSceneFrame
  uses glo2\shapes
  '

  indexbase 1
  sys       texn[16]
  sys       GdiplusToken
  float     ang1
  float     li[16]
  float     ma[13]
  sys       cube,pent

  class cones
  ===========
  float  x,y,z
  float  sc,rz,ry,sm
  sys    n,tex
  '
  float  a.x,a.y,a.z
  float  b.x,b.y,b.z
  '
  '
  method Render()
  ===============
  if tex then glBindTexture GL_TEXTURE_2D,tex
  glPushMatrix
  gltranslatef  x,y,z
  glrotatef     a.x,1,0,0 'rotate yz  : pitch
  glrotatef     a.y,0,1,0 'rotate xz  : yaw
  glrotatef     a.z,0,0,1 'rotate xy  : yaw
  glscalef      sc,sc,sc
  ConeFaces     n,rz,ry,sm
  glPopMatrix
  end method
  '
  method anchor()
  ===============
  b.x=x
  b.y=y
  b.z=z
  end method
  '
  method move(single mx,my,mz)
  ============================
  x=b.x+mx
  y=b.y+my
  z=b.z+mz
  limit
  end method
  '
  method limit()
  ==============
  float d=-z,id=-1/z
  if x*id<-0.5 then x=-.5*d
  if y*id<-0.4 then y=-.4*d
  if z>-1.0 then z=-1.0
  if x*id>.5  then x=.5*d
  if y*id>.4 then y=.4*d
  end method
  '
  method drag()
  =============
  float dx,dy,dz
  dx=mposx-sposx
  dy=sposy-mposy
  dz=-z/crect.right
  move dx*dz,dy*dz,0 
  end method
  '
  end class


  sub initialize(sys hWnd)
  ========================
  '
  '
  GDIplus 1
  '
  cube=CompileList : CubeForm    : glEndList
  '
  end sub

  sub Release(sys hwnd)
  '====================
  DeleteAllGlCompiled
  Gdiplus 0
  end sub


  sub scene(sys hWnd)
  ===================
  '
  '#recordof cones
  static single ra,ri,angi1=.5
  '
  Snapshots hwnd 'Ctrl-P to take snapshot
  '
  '
  RebuildScene:
  -------------
  '
  DozyFrame
  glClearColor 0.5, 0.5, 0.7, 0
  StandardLighting li
  'glEnable GL_TEXTURE_2D
  '
  sys   t1=texn[1] 'texture
  '
  static cones c[16]
  '
  'INITIAL DATA
  if c.sc=0
    'shape x   y    z      sc   rz ry  nm n   tex
    ---------------------------------------------
    c[3]<= 6.5,-0.9,-16.0, 0.5, 0, 4. , 0, 10, t1
    c[2]<= 2.5,-0.9,-8.0 , 0.5, 0, 2. , 0, 10, t1
    c[1]<= 0.5,-0.9,-4.0 , 0.5, 0, 3. , 0, 15, t1
  end if
  '
  'PICK OR RENDER MODE
  static sys picking
  if bleft and pick+picking=0
    PickPrep
    picking=1
  elseif bleft+pick=0
    picking=0 'ALLOW NEW PICK PASS
  end if
  '
  'RENDER OBJECTS
  sys i
  for i=1 to 3
  PickLabel i
  if bleft
    if picked=i
      c[i].drag
    end if
  else
    c[i].anchor
  end if
  c[i].render
  next 
  '
  'CONTROL WITH KEYBOARD KEYS
  static int hlps
  int a=lastkey
  select a
  case 49 to 51 : picked=a-48
  end select
  if key[112] 'F1 Help overlay
    hlps=1
  end if
  MoveObjectWithKeys c[picked], 0.01, 1.0
  '
  'PRINTING INFO / LABELS
  '
  'glDisable GL_TEXTURE_2D
  glDisable GL_LIGHTING
  '
  'F1 HELP
  if hlps
    glLoadIdentity
    glPushMatrix
    gltranslatef -.5,.28,-1.
    glColor3f    .00,.99,.99
    glScalef     .07,.07,.01
    gprint       "Help:",.7
    glColor3f    .99,.99,.99
    glScalef     .5,.5,1.
    gprint       "mouse to select object and drag.",1.
    gprint       "number keys to select object 1..3.",1.
    gprint       "arrow keys to move selected object.",1.
    gprint       "shift+arrow keys to rotate.",1.
    glPopMatrix
    hlps=0
  end if
  '
  if picked
    glPushMatrix
    glLoadIdentity
    gltranslatef -.5,.35,-1.0
    float w,h
    glscalef     .07,.07,.01
    GetWordArea  "Cone:",w,h
    if pick
      PutBoxArea   w,h
    else
      glColor3f    .99,.99,.00
      gprint       "Cone: "
      glColor3f    .99,.99,.99
      gprint       picked
    end if
    glPopMatrix
  end if
  '
  'END OF PICK / RENDER OPERATION
  if pick
    PickResult : goto RebuildScene
  end if
  '
  'AUTO ROTATE
  ang1+=angi1
  if ang1>360 then ang1-=360
  '
  sleep 10
  end sub

  MainWindow width,height,WS_OVERLAPPEDWINDOW
