Here's the code:
Code: Select all
Macro Instr(Begin,OriginalString,StringToFind)
  FindString(OriginalString,StringToFind,Begin)
EndMacro
Structure DSBCAPS
  dwSize.l
  dwFlags.l
  dwBufferBytes.l
  dwUnlockTransferRate.l
  dwPlayCpuOverhead.l
EndStructure
Structure MasterStructure
  nwid.i
  enid.i
  msid.i
  mtid.i
  txid.i  
  mnme.s
  xpos.f
  ypos.f
  zpos.f
  xrot.f
  yrot.f
  zrot.f
  xscl.f
  yscl.f
  zscl.f
EndStructure
Structure Entities Extends MasterStructure
EndStructure
 
Global max_structures = 999
 
Dim Entities.MasterStructure(max_structures)
 
Structure SelectedMasterStructure
  selected.b
  nwid.i
  enid.i
  msid.i
  mtid.i
  txid.i
  mnme.s
  xpos.f
  ypos.f
  zpos.f
  xrot.f
  yrot.f
  zrot.f
  xscl.f
  yscl.f
  zscl.f
EndStructure
Structure SelectedEntities Extends SelectedMasterStructure
EndStructure
 
Global max_selected_structures = 9999999
 
Dim SelectedEntities.SelectedMasterStructure(max_selected_structures)
 
MP_Graphics3D(800, 600, 0, 2)
SetWindowTitle(0, "Multi-Pick Demo")
cam=MP_CreateCamera()
MP_CreateLight(1)
Max = 4
Global objcount
For n = 0 To Max
      Entities.MasterStructure(n)\xpos = 10-Random(20)
      Entities.MasterStructure(n)\ypos = 10-Random(20)
      Entities.MasterStructure(n)\zpos = 24+Random(40)
     
      Entities.MasterStructure(n)\enid = MP_CreateSphere(100)
      MP_PositionEntity (Entities.MasterStructure(n)\enid, Entities.MasterStructure(n)\xpos, Entities.MasterStructure(n)\ypos, Entities.MasterStructure(n)\zpos)
      MP_EntitySetColor(Entities.MasterStructure(n)\enid, RGBA(Random(255, 0), Random(255, 0), Random(255, 0), 255))
      objcount+1
Next n
  max_hex = 999
  Dim Which_Hex(max_hex)
   
  Which_Hex(0) = $FF
  Which_Hex(1) = $FF
  Which_Hex(2) = $00
  Which_Hex(3) = $00
   
  A1 = Which_Hex(0)
  R1 = Which_Hex(1)
  G1 = Which_Hex(2)
  B1 = Which_Hex(3)
  While Not MP_KeyDown(#PB_Key_Escape) And Not Quit
   
    event = WindowEvent()
   
    If event = #PB_Event_CloseWindow
      Quit = 1
    EndIf
 
    If GetAsyncKeyState_(#VK_CONTROL)
           
      If MP_MouseButtonDown(0)
     
        If GetFocus_()=WindowID(0)
               
          SelectedEntities.SelectedMasterStructure(0)\enid = MP_PickCamera (cam,WindowMouseX(0),WindowMouseY(0))
             
          If SelectedEntities.SelectedMasterStructure(0)\enid
                     
            SelectedEntities.SelectedMasterStructure(0)\selected = #True
               
          Else
               
            SelectedEntities.SelectedMasterStructure(0)\selected = #False
                     
          EndIf
         
        EndIf
     
      EndIf
           
    ElseIf MP_MouseButtonHit(0)
     
      If GetFocus_()=WindowID(0)
             
        SelectedEntities.SelectedMasterStructure(0)\enid = MP_PickCamera (cam,WindowMouseX(0),WindowMouseY(0))
           
        If SelectedEntities.SelectedMasterStructure(0)\enid
                   
          SelectedEntities.SelectedMasterStructure(0)\selected = #True
             
        Else
             
          SelectedEntities.SelectedMasterStructure(0)\selected = #False
                   
        EndIf
           
      EndIf
                   
    EndIf
           
    If SelectedEntities.SelectedMasterStructure(0)\selected
             
      If SelectedEntities.SelectedMasterStructure(0)\enid
             
        For i = 1 To MP_CountVertices(SelectedEntities.SelectedMasterStructure(0)\enid)
                         
          color = MP_VertexGetColor(SelectedEntities.SelectedMasterStructure(0)\enid, i)
                           
          MP_VertexSetColor(SelectedEntities.SelectedMasterStructure(0)\enid, i, MP_ARGB(A1, R1, G1, B1))
                           
          If i = MP_CountVertices(SelectedEntities.SelectedMasterStructure(0)\enid)
                             
            Break
                             
          EndIf
                           
        Next
               
      EndIf
             
    EndIf
             
    If mode = 1
               
      If SelectedEntities.SelectedMasterStructure(0)\selected
                 
        If MP_KeyDown(#PB_Key_Up) Or MP_KeyDown(#PB_Key_W): MP_MoveEntity(SelectedEntities.SelectedMasterStructure(0)\enid, 0, 1, 0): EndIf
        If MP_KeyDown(#PB_Key_Down) Or MP_KeyDown(#PB_Key_S): MP_MoveEntity(SelectedEntities.SelectedMasterStructure(0)\enid, 0, -1, 0): EndIf
                               
      EndIf
                 
    EndIf
           
    If MP_MouseButtonDown(1)
           
      If GetFocus_()=WindowID(0)
                     
        SelectedEntities.SelectedMasterStructure(0)\enid = MP_PickCamera (cam,WindowMouseX(0),WindowMouseY(0))
       
        If SelectedEntities.SelectedMasterStructure(0)\enid
          MP_FreeEntity (SelectedEntities.SelectedMasterStructure(0)\enid)
        EndIf
           
      EndIf
                   
    EndIf
   
    MP_DrawText (100,40, "Mesh "+Str(SelectedEntities.SelectedMasterStructure(0)\enid)+" selected",0)
    MP_DrawText (100,60, "Mesh Count: "+Str(MeshCount),0)
   
    MP_RenderWorld()
    MP_Flip ()
 
  Wend
EndMythros




