Jump to content
  • Advertisement
Sign in to follow this  
afsajghfd

high CPU consumption in Picking

This topic is 3623 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi all, I'm having too much CPU consumption in picking method for simply boxes. I know that try to find what the cursor it's touching consume CPU time, but i'm talking about 45%-55% ! So my idea it's do the picking only if the box (polygon) has been selected to slowdown the CPU consumption
 
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
         
            Dim resultAction As action 'Enum (move, changeSizeNS, etc.)
            vt = getCursorPosition(device, e.X, e.Y) ' vt vector3  global variable. Function from screen to space coords
            resultAction = detect2DMouseAction(mbuttons) ' mbuttons true if left mouse button its hold
            do2DMouseAction(resultAction, mbuttons)
      
End Sub

Private Function detect2DMouseAction(ByVal mbuttons As Boolean) As action
        For Each polig As Integer In polygonosSelec ' global integer() variable, has the ID of the selected polygons
            If Not poligonos(polig).Disposed Then 'poligonos as polygon. Class for boxes and other stuffs
                If mbuttons AndAlso resultPick <> action.none Then
                    Return resultPick
                Else
                    resultPick = poligonos(polig).Picking(vt.X, vt.Y)
                    If resultPick <> action.none Then
                        Return resultPick
                    Else
                        Me.Cursor = Cursors.Default
                        Return action.none
                    End If
                End If
            End If
        Next
     
End Function

Private Sub do2DMouseAction(ByVal accion As action, ByVal mbuttons As Boolean)
        If mbuttons AndAlso accion <> action.none Then  
            For Each polig As Integer In polygonSelec
                If Not poligonos(polig).Disposed Then
                    Select Case accion
                        Case action.moveMesh
                            poligonos(polig).move(vt)
                            Me.Cursor = Cursors.Hand
                        Case action.ChangeSizeUP_Center
                                  .
                                  .
                                  .
                                  .
                 End If
            Next
        End If
End Sub

Public Function Picking(ByVal v2 As Vector2) As action 'FROM polygon class
       'rctngl has the coords of the box in the space

        If v2.X  >= rctngl.left And v2.X  <= rctngl.right And _
           v2.Y  >= rctngl.bottom And v2.Y <= rctngl.top Then
            Return action.move
        Else
            Return action.none
        End If
End Function

I change minimal things to do it more readable (I hope), but it's this Now I'm reading, I wonder how bad it's change coords from screen to space in the MouseMove event :S (using unproject .. ) (I check out right now and it's still consuming the same CPU even if I comment the function ) Im using DX9 and VS05 Thanks in advance and sorry all the flood

Share this post


Link to post
Share on other sites
Advertisement
It appears that you do the picking on every mouse move but you're only interested in picking if there's a mouse button down.

You would reduce the load on the CPU a lot if you wait until the mouse button is down, get the mouse position, and then do the pick.

I think there's a picturebox_mouseclick event which you should use instead of mousemove.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!