Re: MP3D Engine Alpha 32
Posted: Sat Jan 18, 2014 11:02 pm
				
				Hi all. Can someone please help me with my 3D object selector? I basically need to be able to hold control & hold down left mouse button to select multiple objects and turn them to half alpha to show they are selected, and when control is NOT held, the ability to hold down the left mouse button, and select only ONE object at a time, halving it's alpha as well until the next object is selected. When you click the background, all objects with half alpha go back to completely non-alpha, same thing when you click on the same object or objects that have been already highlighted. I would be eternally greatful for someones help!
Here's the code:
Thank You so much and have a good day!
Mythros
			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

