Help with multiple object select?

Advanced game related topics
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Help with multiple object select?

Post by Mythros »

Hello peepz. I was working on my level editor again as it hasn't been worked on in quite a while, and I was wondering how to switch between 2 objects when mousing over them while holding CONTROL, and the ability to move multi-selected objects at the same time.

I have it sorta working, but it only selects 1 object at the same time, without regards to switching to the correct selected / unselected color, or multi-object movement.

Please forgive me if I did not explain good enough. If you ask me, however, I will try to go into as much detail in it as possible.

So anyway, this code uses the MP3D (Alpha) plugin (the commands are mostly the same except for a few added ones and different parameters) as Purebasic.

Here's a link to the MP3D (Alpha) engine:

viewtopic.php?f=27&t=43601&hilit=MP3D

NOTE: If you wish to test anything to do with this plugin, you must go to "Compiler Options", and then in the blank box where it says: "Library Subsystem", type: "dx9" without the quotes.

And now without further delay, the code:

LevelEditor.pb:

Code: Select all

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 = 1
 
 Dim Entities.MasterStructure(max_structures)
 
 Structure SelectedMasterStructure
   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 = 40

Global objcount

For n = 0 To Max
      Entities.MasterStructure(0)\xpos = 10-Random(20)
      Entities.MasterStructure(0)\ypos = 10-Random(20)
      Entities.MasterStructure(0)\zpos = 24+Random(40)
      
      Entities.MasterStructure(0)\enid = MP_CreateSphere(100)
      MP_PositionEntity (Entities.MasterStructure(0)\enid, Entities.MasterStructure(0)\xpos, Entities.MasterStructure(0)\ypos, Entities.MasterStructure(0)\zpos)
      MP_EntitySetColor(Entities.MasterStructure(0)\enid, RGBA(Random(255, 0), Random(255, 0), Random(255, 0), 255))
      objcount+1
Next n

max_hex = 3
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 MP_MouseButtonDown(0)
    
            If GetFocus_()=WindowID(0)
           
               SelectedEntities.SelectedMasterStructure(0)\enid = MP_PickCamera (cam,WindowMouseX(0),WindowMouseY(0))
                 
               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
                                      
                   If color = R1 & G1 & B1
                   
                     mode = 1
                     
                   EndIf
                 
                 EndIf
                 
               EndIf
                 
             MP_DrawText (100,40, "Mesh "+Str(SelectedEntities.SelectedMasterStructure(0)\enid)+" selected",0)
             MP_DrawText (100,60, "Mesh Count: "+Str(MeshCount),0)
   
           EndIf
           
           If mode = 1
               
               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
          
          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_RenderWorld()
          MP_Flip ()

Wend
Thank you once again peepz! =)
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Re: Help with multiple object select?

Post by Mythros »

Anyone? :/ I could really use the help. I have patiently waited at LEAST 3 days. :/ I don't mean to sound impatient or rude, but this is my top priority project, and some help would really be awesome! Thank you guys! =)
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Re: Help with multiple object select?

Post by Mythros »

I've made it so you can select 1 object by hitting the mouse, or multiple objects while holding control and the mouse.

Problem is, i can't get them all to move around with the keys if they're selected.

If someone could help me fix this, I would be eternally greatful!

Thank You!

And without further delay,

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 = 40

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

End
Thank You & have a great day! =)
Post Reply