Pixel Perfect Collision Detection
Pixel Perfect Collision Detection
Pixel Perfect Collision Detection
Pixel Perfect Collision Detection
Pixel Perfect Collision Detection
Pixel Perfect Collision Detection Pixel Perfect Collision Detection Pixel Perfect Collision Detection Pixel Perfect Collision Detection Pixel Perfect Collision Detection Pixel Perfect Collision Detection Pixel Perfect Collision Detection Pixel Perfect Collision Detection
Pixel Perfect Collision Detection Pixel Perfect Collision Detection
Pixel Perfect Collision Detection
Go Back  Xtreme Visual Basic Talk > > > > Pixel Perfect Collision Detection


Reply
 
Thread Tools Display Modes
  #1  
Old 09-05-2005, 08:36 AM
amigaxtreme amigaxtreme is offline
Newcomer
 
Join Date: Feb 2005
Posts: 6
Unhappy Pixel Perfect Collision Detection (Again)


I really need help...

How to code a Pixel Perfect Collision Detection Function?

have a look at this code. (is for vb6 and dx7) HOW TO TRANSLATE to vb.net direct3d sprite class?

Public Function CheckForPPCollision(DDSurf1 As DirectDrawSurface7, DDSurf2 As DirectDrawSurface7, RECT1 As RECT, RECT2 As RECT, BlitCOLORKEY As Integer) As Boolean

Dim RECTOverlap As RECT 'Used to record the overlap from RECT1 and RECT2
Dim RECT1Overlap As RECT 'Overlaped portions of RECT1
Dim RECT2Overlap As RECT 'Overlaped portions of RECT2
Dim OverlapWidth As Integer 'Determine the width of the overlap
Dim OverlapHeight As Integer 'Determine the height of the overlap
Dim ByteObj1() As Byte 'Used to analyse a pixel
Dim ByteObj2() As Byte 'Used to analyse a pixel
Dim DDSDBlank As DDSURFACEDESC2 'For use in (DDSurf1.Lock) (DDSurf2.Lock)
Dim i As Integer, j As Integer 'Just for use in loops
Dim PPCollision As Boolean 'States whether we have PixelPerfect collision
'Check for rectangular collisions
If IntersectRect(RECTOverlap, RECT1, RECT2) Then
'RECTANGULAR COLLISION

'Get the RECT structures for the overlapped portions of both surfaces
With RECT1Overlap 'Find the overlap difference in the first RECT
.Top = RECTOverlap.Top - RECT1.Top
.Bottom = RECTOverlap.Bottom - RECT1.Top
.Right = RECTOverlap.Right - RECT1.Left
.Left = RECTOverlap.Left - RECT1.Left
End With

With RECT2Overlap 'Find the overlap difference in the second RECT
.Top = RECTOverlap.Top - RECT2.Top
.Bottom = RECTOverlap.Bottom - RECT2.Top
.Right = RECTOverlap.Right - RECT2.Left
.Left = RECTOverlap.Left - RECT2.Left
End With

'Determine the width and height of the ovrelas (we will use this information for the loop)
OverlapWidth = RECTOverlap.Right - RECTOverlap.Left - 1
OverlapHeight = RECTOverlap.Bottom - RECTOverlap.Top - 1

'Use Lock and GetLockedArray on each surface
DDSurf1.Lock RECT1Overlap, DDSDBlank, DDLOCK_READONLY Or DDLOCK_WAIT, 0
DDSurf1.GetLockedArray ByteObj1
DDSurf2.Lock RECT2Overlap, DDSDBlank, DDLOCK_READONLY Or DDLOCK_WAIT, 0
DDSurf2.GetLockedArray ByteObj2

'Compare the surface data from the overlapping portions of the rectangles
For i = 0 To OverlapWidth
For j = 0 To OverlapHeight
'If BOTH surfaces are non-tranparent at this pixel...
If (ByteObj1(i + RECT1Overlap.Left, j + RECT1Overlap.Top) <> BlitCOLORKEY) And (ByteObj2(i + RECT2Overlap.Left, j + RECT2Overlap.Top) <> BlitCOLORKEY) Then PPCollision = True
'We have Pixel Perfect Collision
If PPCollision = True Then
CheckForPPCollision = True
Exit For 'Exit because we don't need to check anymore, we already have pixel perfect collision
End If
Next j
If PPCollision = True Then
CheckForPPCollision = True
Exit For 'Exit because we don't need to check anymore, we already have pixel perfect collision
End If
Next i

'Unlock the sufaces
DDSurf1.Unlock RECT1Overlap 'unlock DDsurf1
DDSurf2.Unlock RECT2Overlap 'Unlock DDSurf2
End If
End Function

I hope someone can give me a sample code

Thank you

P.S. maybe sgt_pinky can translate the code

[COLOR=DarkGreen]

Last edited by amigaxtreme; 09-06-2005 at 02:50 AM. Reason: Title Change
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Pixel Perfect Collision Detection
Pixel Perfect Collision Detection
Pixel Perfect Collision Detection Pixel Perfect Collision Detection
Pixel Perfect Collision Detection
Pixel Perfect Collision Detection
Pixel Perfect Collision Detection Pixel Perfect Collision Detection Pixel Perfect Collision Detection Pixel Perfect Collision Detection Pixel Perfect Collision Detection Pixel Perfect Collision Detection Pixel Perfect Collision Detection
Pixel Perfect Collision Detection
Pixel Perfect Collision Detection
 
Pixel Perfect Collision Detection
Pixel Perfect Collision Detection
 
-->