Challenge: 
Winner?: 
Yes
Code Snippet: 
Rem TDK's Entry In The 3D Modeller DBPro Challenge
Rem 14th November 2005
Gosub Setup

Do
  Mx=MouseX(): My=MouseY(): Mc=MouseClick(): MMz=MouseMoveZ(): I$=Upper$(Inkey$())
  MenuSelect$ = CheckMenu(DropDowns,0): Rem This checks for any action on the menu system
  If MenuSelect$ <> ""
    Entry = Asc(Left$(MenuSelect$,1))-64: Rem This extracts the dropdown which was used
    Item = Val(Right$(MenuSelect$,Len(MenuSelect$)-1)): Rem This extracts the selected item on the dropdown
    If Entry > 0 And Item > 0
      Gosub Action: Rem This processes the results from the menu
    Endif
  Endif
  If SelectedMenu = 0 Then Gosub CheckInput
Loop

Rem ******************** Procedures ********************
CheckInput:

  Rem Keyboard Shortcuts

  If ScanCode()=205 and NumObjects>0: Rem Right Cursor (Scroll through objects)
    Inc ObjClickedOn
    If ObjClickedOn >= NumObjects+1 Then ObjClickedOn=1
    Gosub HighlightObjOn
    Repeat
    Until ScanCode()=0
  Endif
  If ScanCode()=203 and NumObjects>0: Rem Left Cursor (Scroll through objects)
    Dec ObjClickedOn
    If ObjClickedOn = 0 Then ObjClickedOn=NumObjects
    Gosub HighlightObjOn
    Repeat
    Until ScanCode()=0
  Endif

  If ScanCode()=210: Rem Ins Key (Duplicate Current Object)
    Gosub Duplicate
    Repeat
    Until ScanCode()=0
  Endif

  If ScanCode()=211: Rem Del Key (Delete Current Object)
    Gosub DeleteObj
    Repeat
    Until ScanCode()=0
  Endif

  If ScanCode()=20: Rem Texture Key (T)
    Gosub LoadTexture
    Repeat
    Until ScanCode()=0
  Endif

  If ScanCode()=38: Rem Load Key (L)
    Gosub LoadFile
    Repeat
    Until ScanCode()=0
  Endif

  If ScanCode()=31: Rem Save Key (S)
    Gosub SaveFile
    Repeat
    Until ScanCode()=0
  Endif

  If ScanCode()=97: Rem Save As Key (A)
    Gosub SaveFileAs
    Repeat
    Until ScanCode()=0
  Endif

  Rem Object Positions X, Y, Z
  If Mx>555 and My>23 and Mx<555+55 and My<23+16 and Mc=1: Rem Object Position X
    If ObjClickedOn>0
      BlackBox(555,23,55,16): Ink RGB(255,255,255),0
      Set Cursor 559,24: Input NewValue#
      Position Object ObjClickedOn, NewValue#, Object Position Y(ObjClickedOn), Object Position Z(ObjClickedOn)
      Position Object 1000, NewValue#, Object Position Y(ObjClickedOn), Object Position Z(ObjClickedOn)
      DispX#=Object Position X(ObjClickedOn): DispY#=Object Position Y(ObjClickedOn): DispZ#=Object Position Z(ObjClickedOn)
      Gosub DisplayXYZ
    Endif
  Endif
  If Mx>621 and My>23 and Mx<621+55 and My<23+16 and Mc=1: Rem Object Position Y
    If ObjClickedOn>0
      BlackBox(621,23,55,16): Ink RGB(255,255,255),0
      Set Cursor 625,24: Input NewValue#
      Position Object ObjClickedOn, Object Position X(ObjClickedOn), NewValue#, Object Position Z(ObjClickedOn)
      Position Object 1000, Object Position X(ObjClickedOn), NewValue#, Object Position Z(ObjClickedOn)
      DispX#=Object Position X(ObjClickedOn): DispY#=Object Position Y(ObjClickedOn): DispZ#=Object Position Z(ObjClickedOn)
      Gosub DisplayXYZ
    Endif
  Endif
  If Mx>687 and My>23 and Mx<687+55 and My<23+16 and Mc=1: Rem Object Position Z
    If ObjClickedOn>0
      BlackBox(687,23,55,16): Ink RGB(255,255,255),0
      Set Cursor 691,24: Input NewValue#
      Position Object ObjClickedOn, Object Position X(ObjClickedOn), Object Position Y(ObjClickedOn), NewValue#
      Position Object 1000, Object Position X(ObjClickedOn), Object Position Y(ObjClickedOn), NewValue#
      DispX#=Object Position X(ObjClickedOn): DispY#=Object Position Y(ObjClickedOn): DispZ#=Object Position Z(ObjClickedOn)
      Gosub DisplayXYZ
    Endif
  Endif

  Rem Object Sizes W, H, D
  If Mx>153 and My>313 and Mx<153+55 and My<313+16 and Mc=1: Rem Object Size W
    If ObjClickedOn>0
      BlackBox(153,313,55,16): Ink RGB(255,255,255),0
      Set Cursor 157,314: Input NewValue#
      ScaleFactor#=(NewValue#/50.0)*100.0
      ObjData#(ObjClickedOn,4)=ScaleFactor#
      Scale Object ObjClickedOn, ObjData#(ObjClickedOn,4), ObjData#(ObjClickedOn,5), ObjData#(ObjClickedOn,6)
      Gosub HighlightObjOn: Gosub DisplaySize
    Endif
  Endif
  If Mx>220 and My>313 and Mx<220+55 and My<313+16 and Mc=1: Rem Object Size H
    If ObjClickedOn>0
      BlackBox(220,313,55,16): Ink RGB(255,255,255),0
      Set Cursor 224,314: Input NewValue#
      ScaleFactor#=(NewValue#/50.0)*100.0
      ObjData#(ObjClickedOn,5)=ScaleFactor#
      Scale Object ObjClickedOn, ObjData#(ObjClickedOn,4), ObjData#(ObjClickedOn,5), ObjData#(ObjClickedOn,6)
      Gosub HighlightObjOn: Gosub DisplaySize
    Endif
  Endif
  If Mx>287 and My>313 and Mx<287+55 and My<313+16 and Mc=1: Rem Object Size D
    If ObjClickedOn>0
      BlackBox(287,313,55,16): Ink RGB(255,255,255),0
      Set Cursor 291,314: Input NewValue#
      ScaleFactor#=(NewValue#/50.0)*100.0
      ObjData#(ObjClickedOn,6)=ScaleFactor#
      Scale Object ObjClickedOn, ObjData#(ObjClickedOn,4), ObjData#(ObjClickedOn,5), ObjData#(ObjClickedOn,6)
      Gosub HighlightObjOn: Gosub DisplaySize
    Endif
  Endif

  Rem Object Angles X, Y, Z
  If Mx>237 and My>23 and Mx<237+26 and My<23+16 and Mc=1: Rem Object Angle X
    If ObjClickedOn>0
      BlackBox(237,23,26,16): Ink RGB(255,255,255),0
      Set Cursor 241,24: Input NewValue#
      Rotate Object ObjClickedOn, WrapValue(NewValue#), Object Angle Y(ObjClickedOn), Object Angle Z(ObjClickedOn)
      Gosub HighlightObjOn: Gosub DisplayAngle
    Endif
  Endif
  If Mx>276 and My>23 and Mx<276+26 and My<23+16 and Mc=1: Rem Object Angle Y
    If ObjClickedOn>0
      BlackBox(276,23,26,16): Ink RGB(255,255,255),0
      Set Cursor 280,24: Input NewValue#
      Rotate Object ObjClickedOn, Object Angle X(ObjClickedOn), WrapValue(NewValue#), Object Angle Z(ObjClickedOn)
      Gosub HighlightObjOn: Gosub DisplayAngle
    Endif
  Endif
  If Mx>315 and My>23 and Mx<315+26 and My<23+16 and Mc=1: Rem Object Angle Z
    If ObjClickedOn>0
      BlackBox(315,23,26,16): Ink RGB(255,255,255),0
      Set Cursor 319,24: Input NewValue#
      Rotate Object ObjClickedOn, Object Angle X(ObjClickedOn), Object Angle Y(ObjClickedOn), WrapValue(NewValue#)
      Gosub HighlightObjOn: Gosub DisplayAngle
    Endif
  Endif

  Rem Snap Value
  If Mx>87 and My>313 and Mx<87+26 and My<313+16 and Mc=1
    BlackBox(87,313,26,16): Ink RGB(255,255,255),0
    Set Cursor 91,314: Input SnapVal
    SV$=Str$(SnapVal)
    While Len(SV$)<3
      SV$="0"+SV$
    EndWhile
    Ink RGB(0,255,255),0: Text 91,314,SV$
  Endif

  Rem Select Current Object
  If Mx>124 and My>23 and Mx<124+26 and My<23+16 and Mc=1
    BlackBox(124,23,26,16): Ink RGB(255,255,255),0
    Set Cursor 128,24: Input NewObjClickedOn
    If NewObjClickedOn <= NumObjects
      ObjClickedOn = NewObjClickedOn
      OCO$=Str$(ObjClickedOn)
      While Len(OCO$) < 3
        OCO$ = "0"+OCO$
      EndWhile
      Gosub HighlightObjOn
    Endif
    Ink RGB(255,255,0),0: Text 128,24,OCO$
  Endif

  Rem Camera Zoom (All Windows)
  Camzoom:
  If ScanCode()=42 or ScanCode()=54
    Dist#=3
  Else
    Dist#=30
  Endif
  If MMz > 0
    Move Camera CurrentCam,Dist#
  Else
    If MMz < 0
      Move Camera CurrentCam,0-Dist#
    Endif
  Endif

  Rem Axis Buttons
  Set Text Transparent: Ink 0,0
  ClickAxisButtons:
  If Mx>351 and My>23 and Mx<363 and My<38 and Mc=1: Rem Front X
    If FrontX = 0
      FrontX = 1
      ButtonDown(351,23,13,16,"X")
    Else
      FrontX = 0
      ButtonUp(351,23,13,16,"X")
    Endif
    Repeat
    Until MouseClick()=0
  Endif
  If Mx>366 and My>23 and Mx<378 and My<38 and Mc=1: Rem Front Y
    If FrontY = 0
      FrontY = 1
      ButtonDown(366,23,13,16,"Y")
    Else
      FrontY = 0
      ButtonUp(366,23,13,16,"Y")
    Endif
    Repeat
    Until MouseClick()=0
  Endif
  If Mx>381 and My>23 and Mx<393 and My<38 and Mc=1: Rem Front Z
    If FrontZ = 0
      FrontZ = 1
      ButtonDown(381,23,13,16,"Z")
    Else
      FrontZ = 0
      ButtonUp(381,23,13,16,"Z")
    Endif
    Repeat
    Until MouseClick()=0
  Endif
  If Mx>751 and My>23 and Mx<763 and My<38 and Mc=1: Rem Right X
    If RightX = 0
      RightX = 1
      ButtonDown(751,23,13,16,"X")
    Else
      RightX = 0
      ButtonUp(751,23,13,16,"X")
    Endif
    Repeat
    Until MouseClick()=0
  Endif
  If Mx>766 and My>23 and Mx<778 and My<38 and Mc=1: Rem Right Y
    If RightY = 0
      RightY = 1
      ButtonDown(766,23,13,16,"Y")
    Else
      RightY = 0
      ButtonUp(766,23,13,16,"Y")
    Endif
    Repeat
    Until MouseClick()=0
  Endif
  If Mx>781 and My>23 and Mx<793 and My<38 and Mc=1: Rem Right Z
    If RightZ = 0
      RightZ = 1
      ButtonDown(781,23,13,16,"Z")
    Else
      RightZ = 0
      ButtonUp(781,23,13,16,"Z")
    Endif
    Repeat
    Until MouseClick()=0
  Endif
  If Mx>351 and My>313 and Mx<363 and My<328 and Mc=1: Rem Top X
    If TopX = 0
      TopX = 1
      ButtonDown(351,313,13,16,"X")
    Else
      TopX = 0
      ButtonUp(351,313,13,16,"X")
    Endif
    Repeat
    Until MouseClick()=0
  Endif
  If Mx>366 and My>313 and Mx<378 and My<328 and Mc=1: Rem Top Y
    If TopY = 0
      TopY = 1
      ButtonDown(366,313,13,16,"Y")
    Else
      TopY = 0
      ButtonUp(366,313,13,16,"Y")
    Endif
    Repeat
    Until MouseClick()=0
  Endif
  If Mx>381 and My>313 and Mx<393 and My<328 and Mc=1: Rem Top Z
    If TopZ = 0
      TopZ = 1
      ButtonDown(381,313,13,16,"Z")
    Else
      TopZ = 0
      ButtonUp(381,313,13,16,"Z")
    Endif
    Repeat
    Until MouseClick()=0
  Endif

  Rem Mode Buttons
  ClickModeButtons:
  If (Mx>448 and My>313 and Mx<448+42 and My<328 and Mc=1) or I$="M": Rem Move
    If MoveMode=0
      MoveMode=1
      ResizeMode=0
      RotateMode=0
      ButtonDown(448,313,42,16,"Move")
      ButtonUp(492,313,42,16,"Resize")
      ButtonUp(536,313,42,16,"Rotate")
    Endif
  Endif
  If (Mx>492 and My>313 and Mx<492+42 and My<328 and Mc=1) or I$="S": Rem Resize
    If ResizeMode=0
      MoveMode=0
      ResizeMode=1
      RotateMode=0
      ButtonUp(448,313,42,16,"Move")
      ButtonDown(492,313,42,16,"Resize")
      ButtonUp(536,313,42,16,"Rotate")
    Endif
  Endif
  If (Mx>536 and My>313 and Mx<536+42 and My<328 and Mc=1) or I$="R": Rem Rotate
    If RotateMode=0
      MoveMode=0
      ResizeMode=0
      RotateMode=1
      ButtonUp(448,313,42,16,"Move")
      ButtonUp(492,313,42,16,"Resize")
      ButtonDown(536,313,42,16,"Rotate")
    Endif
  Endif

  ColourButton:
  Rem Colour Button
  If (Mx>580 and My>313 and Mx<580+27 and My<313+16 and Mc=1) or I$="C": Rem Colour
    If ObjClickedOn>0
      Paste Image 1006,580,313
      TS=Text size(): Tf$=TEXT FONT$()
      Set Text Font "Tahoma"
      Set Text Size 14
      Gosub AllCamsOff
      OldR=ObjData#(ObjClickedOn,1)
      OldG=ObjData#(ObjClickedOn,2)
      OldB=ObjData#(ObjClickedOn,3)
      X=Screen Width()/2-100: Y=Screen Height()/2-130
      Finished=0: Set Text Transparent
      W=200: H=260: C1=16777215: C2=12632256: C3=3618615
      Ink C3,0: Box X,Y,X+W,Y+H
      Ink C1,0: Box X,Y,X+W-1,Y+H-1
      Ink C2,0: Box X+1,Y+1,X+W-1,Y+H-1: Rem Panel Face
      Ink C1,0: Box X+5,Y+235,X+5+90,Y+253: Box X+105,Y+235,X+5+189,Y+253: Rem Black & White
      Ink C3,0: Box X+6,Y+236,X+96,Y+253: Box X+106,Y+236,X+195,Y+253
      Ink C2,0: Box X+6,Y+236,X+6+89,Y+252
      Box X+106,Y+236,X+6+188,Y+252
      Ink C3,0: Box X+5,Y+210,X+5+190,Y+228
      Ink C1,0: Box X+6,Y+211,X+5+190,Y+228
      Ink RGB(ObjData#(ObjClickedOn,1),ObjData#(ObjClickedOn,2),ObjData#(ObjClickedOn,3)),0
      Box X+6,Y+211,X+100,Y+227: Rem Current Colour
      Ink 0,0: Box X+101,Y+211,X+194,Y+227: Rem New Colour
      Ink 0,0: Box X+5,Y+21,X+195,Y+200+5: Rem Colour Palette
      Box X+6,Y+22,X+194,Y+22+20,     RGB(0,0,0),      RGB(255,0,0),  RGB(255,255,255),  RGB(255,0,0)
      Box X+6,Y+22+20,X+194,Y+22+40,  RGB(0,0,0),      RGB(0,255,0),  RGB(255,255,255),  RGB(0,255,0)
      Box X+6,Y+22+40,X+194,Y+22+60,  RGB(0,0,0),      RGB(0,0,255),  RGB(255,255,255),  RGB(0,0,255)
      Box X+6,Y+22+60,X+194,Y+22+80,  RGB(255,255,255),RGB(0,0,0),    RGB(255,255,255),  RGB(0,0,0)
      Box X+6,Y+22+80,X+194,Y+22+100, RGB(255,0,0),    RGB(0,0,0),    RGB(0,255,0),      RGB(0,0,0)
      Box X+6,Y+22+100,X+194,Y+22+120,RGB(0,0,255),    RGB(0,0,0),  RGB(255,0,0),      RGB(0,0,0)
      Box X+6,Y+22+120,X+194,Y+22+140,RGB(0,255,0),    RGB(0,0,0),  RGB(0,0,255),      RGB(0,0,0)
      Box X+6,Y+22+140,X+194,Y+22+161,RGB(255,255,0),  RGB(0,0,0),      RGB(0,255,255),  RGB(255,0,255)
      Box X+6,Y+22+161,X+194,Y+22+182,RGB(255,255,255),  RGB(255,255,0),RGB(255,0,255),  RGB(0,255,255)
      Ink RGB(255,255,255),0: Center Text X+100,Y+2,"Select Colour"
      Ink 0,0: Center Text X+100,Y+3,"Select Colour"
      Text X+44,Y+237,"OK"
      Text X+134,Y+237,"Cancel"
      Repeat
        Mx=MouseX(): My=MouseY(): Mc=MouseClick()
        If Mx>X+5 and Mx<X+195 and My>Y+21 and My<Y+206
          Rem Over Palette
          NewCol = Point(Mx,My)
          R=RGBR(NewCol): G=RGBG(NewCol): B=RGBB(NewCol)
          Ink RGB(R,G,B),0: Box X+101,Y+211,X+194,Y+227: Rem Hover Colour Box
          If Mc=1
            SelR=R: SelG=G: SelB=B
            Ink RGB(SelR,SelG,SelB),0: Box X+6,Y+211,X+100,Y+227
            Color Object ObjClickedOn, RGB(SelR,SelG,SelB)
          Endif
        Endif
        If Mx>X+5 and Mx<X+96 and My>Y+236 and My<Y+253 and Mc=1
          Rem OK
          ObjData#(ObjClickedOn,1)=SelR
          ObjData#(ObjClickedOn,2)=SelG
          ObjData#(ObjClickedOn,3)=SelB
          TextureNum(ObjClickedOn)=0
          ObjData#(ObjClickedOn,7)=0
          Finished=1
        Endif
        If Mx>X+106 and Mx<X+195 and My>Y+236 and My<Y+253 and Mc=1
          Rem Cancel
          ObjData#(ObjClickedOn,1)=OldR
          ObjData#(ObjClickedOn,2)=OldG
          ObjData#(ObjClickedOn,3)=OldB
          Color Object ObjClickedOn, RGB(OldR,OldG,OldB)
          Finished=1
        Endif
      Until Finished=1
      Set Text Font Tf$
      Set Text Size TS
      Gosub AllCamsOn
      Repeat
      Until MouseClick()=0
      Paste Image 1005,580,313
    Endif
  Endif

  Rem Undo Button
  If (Mx>609 and My>313 and Mx<609+36 and My<313+15 and Mc=1) or I$="U"
    ButtonDown(609,313,36,16,"Undo")
    Sync
    If ObjClickedOn>0
      If MoveMode=1
        Position Object ObjClickedOn, UndoA#, UndoB#, UndoC#
        Position Object 1000, UndoA#, UndoB#, UndoC#
        DispX#=Object Position X(ObjClickedOn): DispY#=Object Position Y(ObjClickedOn): DispZ#=Object Position Z(ObjClickedOn)
        Gosub DisplayXYZ
        Sync
      Endif
      If ResizeMode=1
        NewSizeX#=UndoA#: NewSizeY#=UndoB#: NewSizeZ#=UndoC#
        Scale Object ObjClickedOn,NewSizeX#,NewSizeY#,NewSizeZ#
        ObjData#(ObjClickedOn,4)=NewSizeX#
        ObjData#(ObjClickedOn,5)=NewSizeY#
        ObjData#(ObjClickedOn,6)=NewSizeZ#
        Dx=OldDx: Dy=OldDy: Dz=OldDz
        Gosub DisplaySize
        Gosub HighlightObjOn
        Sync
      Endif
      If RotateMode=1
        Rotate Object ObjClickedOn,UndoA#,UndoB#,UndoC#
        Rotate Object 1000,UndoA#,UndoB#,UndoC#
        Gosub DisplayAngle
        Sync
      Endif
      Repeat
      Until MouseClick()=0
    Endif
    ButtonUp(609,313,36,16,"Undo")
  Endif

  Rem ******************************************************
  Rem  Axis Zero, Cam View Reset & Centre On Object Buttons
  Rem ******************************************************

  Rem Front Object X Axis Zero
  If Mx>44 and My>23 and Mx<44+15 and My<23+15 and Mc=1
    ButtonDown(44,23,15,16,"A")
    CurrentCam=1: SET CURRENT CAMERA CurrentCam
    Sync
    If ObjClickedOn>0
      Position Object ObjClickedOn,0,Object Position Y(ObjClickedOn),Object Position Z(1)
      Position Object 1000,0,Object Position Y(ObjClickedOn),Object Position Z(1)
    Endif
    ButtonUp(44,23,15,16,"A")
  Endif
  Rem Right Object Y Axis Zero
  If Mx>442 and My>23 and Mx<442+15 and My<23+15 and Mc=1
    ButtonDown(442,23,15,16,"A")
    CurrentCam=2: SET CURRENT CAMERA CurrentCam
    Sync
    If ObjClickedOn>0
      Position Object ObjClickedOn,Object Position X(ObjClickedOn),0,Object Position Z(1)
      Position Object 1000,Object Position X(ObjClickedOn),0,Object Position Z(1)
    Endif
    ButtonUp(442,23,15,16,"A")
  Endif
  Rem Top Object Z Axis Zero
  If Mx>26 and My>313 and Mx<26+15 and My<313+15 and Mc=1
    ButtonDown(26,313,15,16,"A")
    CurrentCam=3: SET CURRENT CAMERA CurrentCam
    Sync
    If ObjClickedOn>0
      Position Object ObjClickedOn,Object Position X(ObjClickedOn),Object Position Y(ObjClickedOn),0
      Position Object 1000,Object Position X(ObjClickedOn),Object Position Y(ObjClickedOn),0
    Endif
    ButtonUp(26,313,15,16,"A")
  Endif
  Rem Front View Centre On Object
  If Mx>62 and My>23 and Mx<62+15 and My<23+15 and Mc=1
    ButtonDown(62,23,15,16,"O")
    CurrentCam=1: SET CURRENT CAMERA CurrentCam
    Sync
    If ObjClickedOn>0
      Position Camera 1,Object Position X(ObjClickedOn),Object Position Y(ObjClickedOn),Camera Position Z(1)
    Endif
    ButtonUp(62,23,15,16,"O")
  Endif
  Rem Right View Centre On Object
  If Mx>460 and My>23 and Mx<460+15 and My<23+15 and Mc=1
    ButtonDown(460,23,15,16,"O")
    CurrentCam=2: SET CURRENT CAMERA CurrentCam
    Sync
    If ObjClickedOn>0
      Position Camera 2,Camera Position X(2),Object Position Y(ObjClickedOn),Object Position Z(ObjClickedOn)
    Endif
    ButtonUp(460,23,15,16,"O")
  Endif
  Rem Top View Centre On Object
  If Mx>44 and My>313 and Mx<44+15 and My<313+15 and Mc=1
    ButtonDown(44,313,15,16,"O")
    CurrentCam=3: SET CURRENT CAMERA CurrentCam
    Sync
    If ObjClickedOn>0
      Position Camera 3,Object Position X(ObjClickedOn),Camera Position Y(3),Object Position Z(ObjClickedOn)
    Endif
    ButtonUp(44,313,15,16,"O")
  Endif
  Rem Camera View Centre On Object
  If Mx>761 and My>313 and Mx<761+15 and My<313+15 and Mc=1
    ButtonDown(761,313,15,16,"O")
    CurrentCam=0: SET CURRENT CAMERA CurrentCam
    Sync
    If ObjClickedOn>0
      Point Camera 0,Object Position Y(ObjClickedOn),Object Position X(ObjClickedOn),Object Position Z(ObjClickedOn)
    Endif
    ButtonUp(761,313,15,16,"O")
  Endif
  Rem Front View Reset Button
  If Mx>80 and My>23 and Mx<80+15 and My<23+15 and Mc=1
    ButtonDown(80,23,15,16,"R")
    CurrentCam=1: SET CURRENT CAMERA CurrentCam
    Sync
    Position Camera 1,0,0,0-CamDist
    ButtonUp(80,23,15,16,"R")
  Endif
  Rem Right View Reset Button
  If Mx>478 and My>23 and Mx<478+15 and My<23+15 and Mc=1
    ButtonDown(478,23,15,16,"R")
    CurrentCam=2: SET CURRENT CAMERA CurrentCam
    Sync
    Position Camera 2,0+CamDist,0,0
    ButtonUp(478,23,15,16,"R")
  Endif
  Rem Top View Reset Button
  If Mx>62 and My>313 and Mx<62+15 and My<313+15 and Mc=1
    ButtonDown(62,313,15,16,"R")
    CurrentCam=3: SET CURRENT CAMERA CurrentCam
    Sync
    Position Camera 3,0,CamDist,0
    ButtonUp(62,313,15,16,"R")
  Endif
  Rem Camera View Reset Button
  If Mx>779 and My>313 and Mx<779+15 and My<313+15 and Mc=1
    ButtonDown(779,313,15,16,"R")
    CurrentCam=0: SET CURRENT CAMERA CurrentCam
    Sync
    Position Camera 0,0-CamDist,CamDist,0-CamDist
    Point Camera 0,0,0,0
    ButtonUp(779,313,15,16,"R")
  Endif

  Rem 3D Screens
  Set Text Opaque: Ink RGB(255,255,255),0

  FrontView:
  If Mx>5 and My>41 and Mx<393 and My<303: Rem Front View
    If MouseClick() Then CurrentCam=1: SET CURRENT CAMERA CurrentCam: Hide Mouse
    If MouseClick() = 1 or MouseClick() = 3
      If Pickmode = 0
        OldObj=ObjClickedOn
        ObjClickedOn = Pick object(Mousex(),Mousey(),1,NumObjects)
        BlackBox(657,313,100,16)
        If ObjClickedOn > 0
          If ObjData#(ObjClickedOn,7)=1
            Ink RGB(255,255,255),0: Text 660,314,TextureTable$(TextureNum(ObjClickedOn))
          Endif
          Pickmode = 1
          Vdist# = Get Pick Distance()
          VStartX# = Get Pick vector x()
          VStartY# = Get Pick vector y()
          VStartZ# = Get Pick vector z()
          objx# = Object position x(ObjClickedOn)
          objy# = Object position y(ObjClickedOn)
          objz# = Object position z(ObjClickedOn)
          Gosub HighlightObjOn
        Else
          Rem Clicked Off Object (Deselect it)
          Pickmode = 0: ObjClickedOn = 0
          Gosub HighlightObjOff
          Gosub DisplayNumObj
        Endif
      Endif
      If Pickmode = 1: Rem If Object is now selected
        If MoveMode=1
          AllowX=FrontX: AllowY=FrontY: AllowZ=FrontZ
          Gosub MoveObject
        Endif
        If ResizeMode=1
          If OldObj<>ObjClickedOn
            Rem Selected new object so get new details
            OldDx = ObjData#(ObjClickedOn,4)-100: Rem Scale Size - 100=50  200=100 etc
            OldDy = ObjData#(ObjClickedOn,5)-100
            OldDz = ObjData#(ObjClickedOn,6)-100
            Scale Object ObjClickedOn,ObjData#(ObjClickedOn,4),ObjData#(ObjClickedOn,5),ObjData#(ObjClickedOn,6)
          Endif
          AllowX=FrontX: AllowY=FrontY: AllowZ=0
          Gosub ResizeObject
        Endif
        If RotateMode=1
          AllowX=FrontX: AllowY=FrontY: AllowZ=FrontZ
          Gosub RotateObject
        Endif
      Endif
    Endif
    If MouseClick() = 2
      Gosub MoveCamView
    Endif
    Show Mouse
  Endif

  RightView:
  If Mx>405 and My>41 and Mx<793 and My<303: Rem Right View
    If MouseClick() Then CurrentCam=2: SET CURRENT CAMERA CurrentCam: Hide Mouse
    If MouseClick() = 1
      If Pickmode = 0
        ObjClickedOn = Pick object(Mousex(),Mousey(), 1, NumObjects)
        BlackBox(657,313,100,16)
        If ObjData#(ObjClickedOn,7)=1
          Ink RGB(255,255,255),0: Text 660,314,TextureTable$(TextureNum(ObjClickedOn))
        Endif
        If ObjClickedOn > 0
          Pickmode = 1
          Vdist# = Get Pick Distance()
          VStartX# = Get Pick vector x()
          VStartY# = Get Pick vector y()
          VStartZ# = Get Pick vector z()
          objx# = Object position x(ObjClickedOn)
          objy# = Object position y(ObjClickedOn)
          objz# = Object position z(ObjClickedOn)
        Else
          Rem Clicked Off Object (Deselect it)
          If Object Exist(1000) Then Hide Object 1000
          Pickmode = 0: ObjClickedOn = 0
          Gosub DisplayNumObj
          Gosub HighlightObjOff
        Endif
      Endif
      If Pickmode = 1: Rem If Object is now selected
        If MoveMode=1
          AllowX=RightZ: AllowY=RightY: AllowZ=RightX
          Gosub MoveObject
        Endif
        If ResizeMode=1
          AllowX=RightX: AllowY=RightY: AllowZ=0
          Gosub ResizeObject
        Endif
        If RotateMode=1
          AllowX=RightX: AllowY=RightY: AllowZ=RightZ
          Gosub RotateObject
        Endif
      Endif
    Endif
    If MouseClick() = 2
      Gosub MoveCamView
    Endif
    Show Mouse
  Endif

  TopView:
  If Mx>5 and My>331 and Mx<393 and My<593: Rem Top View
    If MouseClick() Then CurrentCam=3: SET CURRENT CAMERA CurrentCam: Hide Mouse
    If MouseClick() = 1
      If Pickmode = 0
        ObjClickedOn = Pick object(Mousex(),Mousey(), 1, NumObjects)
        BlackBox(657,313,100,16)
        If ObjData#(ObjClickedOn,7)=1
          Ink RGB(255,255,255),0: Text 660,314,TextureTable$(TextureNum(ObjClickedOn))
        Endif
        If ObjClickedOn > 0
          Pickmode = 1
          Vdist# = Get Pick Distance()
          VStartX# = Get Pick vector x()
          VStartY# = Get Pick vector y()
          VStartZ# = Get Pick vector z()
          objx# = Object position x(ObjClickedOn)
          objy# = Object position y(ObjClickedOn)
          objz# = Object position z(ObjClickedOn)
        Else
          Rem Clicked Off Object (Deselect it)
          If Object Exist(1000) Then Hide Object 1000
          Pickmode = 0: ObjClickedOn = 0
          Gosub DisplayNumObj
          Gosub HighlightObjOff
        Endif
      Endif
      If Pickmode = 1: Rem If Object is now selected
        If MoveMode=1
          AllowX=TopX: AllowY=0: AllowZ=TopY
          Gosub MoveObject
        Endif
        If ResizeMode=1
          AllowX=TopX: AllowY=0: AllowZ=TopY
          Gosub ResizeObject
        Endif
        If RotateMode=1
          AllowX=TopX: AllowY=TopY: AllowZ=TopZ
          Gosub RotateObject
        Endif
      Endif
    Endif
    If MouseClick() = 2
      Gosub MoveCamView
    Endif
    Show Mouse
  Endif

  CamView:
  If Mx>405 and My>331 and Mx<793 and My<593: Rem Camera View
    If MouseClick()=2 and ObjClickedOn = 0
      Rem Point Camera
      CX#=CAMERA ANGLE X(): CY#=CAMERA ANGLE Y(): CZ#=CAMERA ANGLE Z()
      MMx=mousemovex(): MMy=mousemovey(): Hide Mouse
      Repeat
        CX#=Wrapvalue(CX#+mousemovey())
        CY#=Wrapvalue(CY#+mousemovex())
        Rotate Camera 0,CX#,CY#,CZ#
      Until MouseClick()=0
      Show Mouse
    Endif
    If MouseClick()=4
      Rem Rotate Camera
      MMx=mousemovex(): MMy=mousemovey(): Hide Mouse
      XDist#=Camera Position X(0): YDist#=Camera Position Y(0): ZDist#=ABS(Camera Position Z(0))
      Repeat
        MMx=mousemovex(): X# = WrapValue(X# + MMx): Z# = WrapValue(Z# + MMx)
        Position Camera 0, newxvalue(0,X#,XDist#),YDist#,newzvalue(0,Z#,ZDist#)
        Point Camera 0,0,0,0
      Until MouseClick()=0
      Show Mouse
    Endif
    If MouseClick() > 0
      CurrentCam=0: SET CURRENT CAMERA CurrentCam: Hide Mouse
      If Pickmode = 0
        ObjClickedOn = Pick object(Mousex(),Mousey(), 1, NumObjects)
        BlackBox(657,313,100,16)
        If ObjData#(ObjClickedOn,7)=1
          Ink RGB(255,255,255),0: Text 660,314,TextureTable$(TextureNum(ObjClickedOn))
        Endif
        If ObjClickedOn > 0
          Pickmode = 1
          Vdist# = Get Pick Distance()
          VStartX# = Get Pick vector x()
          VStartY# = Get Pick vector y()
          VStartZ# = Get Pick vector z()
          objx# = Object position x(ObjClickedOn)
          objy# = Object position y(ObjClickedOn)
          objz# = Object position z(ObjClickedOn)
        Else
          Rem Clicked Off Object (Deselect it)
          If Object Exist(1000) Then Hide Object 1000
          Pickmode = 0: ObjClickedOn = 0
          Gosub DisplayNumObj
          Gosub HighlightObjOff
        Endif
      Endif
      If Pickmode = 1: Rem If Object is now selected
        If MoveMode=1
          AllowX=(MouseClick()=1): AllowY=(MouseClick()=2): AllowZ=(MouseClick()=1)
          Gosub MoveObject
        Endif
        If ResizeMode=1
          If MouseClick()=1
            AllowX=1: AllowY=0: AllowZ=1
          Endif
          If MouseClick()=2
            AllowX=0: AllowY=1: AllowZ=0
          Endif
          If MouseClick()=3
            AllowX=1: AllowY=1: AllowZ=1
          Endif
          Gosub ResizeObject
        Endif
        If RotateMode=1
          AllowX=(MouseClick()=1): AllowY=(MouseClick()=2): AllowZ=(MouseClick()=1)
          Gosub RotateObject
        Endif
      Else
        If MouseClick() = 2
          Gosub MoveCamView