Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Collision detection...
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00769784
Message ID:
00769816
Vues:
18
This message has been marked as a message which has helped to the initial question of the thread.
Gerald, one un-tested solution below ?
* Get coordinates of each shape for program clarity.

WITH THISFORM

  nLeft1 = .shape1.left
  nRght1 = .shape1.left + .shape1.width
  nTops1 = .shape1.top
  nBttm1 = .shape1.top + .shape1.height

  nLeft2 = .shape2.left
  nRght2 = .shape2.left + .shape2.width
  nTops2 = .shape2.top
  nBttm2 = .shape2.top + .shape2.height

ENDWITH


* default to not overlapping/collided

lCollided = .F.


* Test for overlapping. See if any of the four 
* corners of shape1 are within shape2.
* 

DO CASE

* Case 1 -
* Test if the top of shape1 is between the top and bottom of shape2. If so...
* Is the left-most edge within the horizontal span of shape2 or is the 
* right-most edge of shape 1 within the horizontal span of shape2?

CASE   BETWEEN( nTops1, nTops2, nBttm2 ) .AND. ;
     ( BETWEEN( nLeft1, nLeft2, nRght2 ) .OR. ;
       BETWEEN( nRght1, nLeft2, nRght2 ) )

  lCollided = .T.


* Case 2 -
* Test if the bottom of shape1 is between the top and bottom of shape2. If so...
* Is the left-most edge within the horizontal span of shape2 or is the 
* right-most edge of shape 1 within the horizontal span of shape2?

CASE   BETWEEN( nBttm1, nTops2, nBttm2 ) .AND. ;
     ( BETWEEN( nLeft1, nLeft2, nRght2 ) .OR. ;
       BETWEEN( nRght1, nLeft2, nRght2 ) )

  lCollided = .T.


ENDCASE


RETURN( lCollided )
>In an application I have a form in which you can move shapes around.
>I need to know when two shape was in contact to each other.
>
>If one shape was at
>
>left:100
>Top:100
>Height:100
>Width:100
>
>and another one was at
>
>Left:150
>Top:75
>Height:100
>Width:100
>
>
>I need a really fast function to call it in a loop.
>Any help will be appreciated :-)
In the End, we will remember not the words of our enemies, but the silence of our friends - Martin Luther King, Jr.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform