Search Tools Links Login

OPTIMISED circular collision detection -100% performance speed upgrade from most traditional methods

This code performs a collission-detection calculation between two circles using some really basic trig. Usefull for games... Performance much higher than traditional circle-collision detection... only takes 45% the amount of time to do the same thing as most circle collision detection functions!!! thats over 100 percent performance increase. Just thought it'd be usefull to game programmers and such...
I bet your wondering "What did this guy do to speed things up so much?" Well thats plain and simple!!! I just replaced the (A)^2 part of the equation, where A = Y2 - Y1 or X2 - X1, with A * A, because its ALOT faster... just doing that, AND storing A in its own variable, speeds things up ALOT, it only takes aprox 45% of the time to do the same collision dectection task!!! Woopty-Dooo!!!! =)

Original Author: (Tim Miron) yar-interactive software


'USE THIS in place of your regular
'circle collision detection function
'Only takes APROX. 45% of the time of
'traditional circle collision dectect
Public Function OptCircCollide(X1 As Long, _
Y1 As Long, X2 As Long, Y2 As Long, _
R1 As Long, R2 As Long) _
As Boolean
Dim X2mX1 As Long 'pre-calculate x2 - x1
Dim Y2mY1 As Long 'pre-calculate y2 - y1
X2mX1 = X2 - X1
Y2mY1 = Y2 - Y1
'calculate distance between 2 points on
'a X-Y grid:
If Sqr((X2mX1 * X2mX1) + (Y2mY1 * Y2mY1)) _
<= R2 + R1 Then OptCircCollide = True
End Function

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 78 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.