MaxPhysics Community Project : Main

BlitzMax Forums/BlitzMax Programming/MaxPhysics Community Project : Main

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

The Collition detection with a Line
If you put in the above John's example those two functions
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''	COLLIDE WITH LINE
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function Collide:TList(Constraints:TList , x1:Float , y1:Float , x2:Float , y2:Float )
	Local ConList:TList = Null
	If Constraints <> Null
		For Local Constraint:VerletConstraint = EachIn Constraints 
			Local x3:Float = Constraint.ParticleA.x
			Local y3:Float = Constraint.ParticleA.y
			Local x4:Float = Constraint.ParticleB.x
			Local y4:Float = Constraint.ParticleB.y
			Local A:Double =  (y4 - y3)*(x2 - x1) - (x4 - x3)*(y2 - y1)
			
			If Not A = 0
				Local ua:Float = ( (x4 - x3)*(y1 - y3) - (y4 - y3)*(x1 - x3) ) /  A 
				Local ub:Float = ( (x2 - x1)*(y1 - y3) - (y2 - y1)*(x1 - x3) ) /  A 
				If ua >=0 And ua <=1 
					If ub >=0 And ub <=1 
						If ConList = Null 
							ConList = CreateList()
						End If
						Local P:Vector2d =  Point( x1 + ua*(x2 - x1) ,  y1 + ua*(y2 - y1) )
						ListAddLast ConList, P
						
					EndIf
				Endif
			EndIf
		Next
	End If
	Return ConList
End Function

Function Test(Constraints:TList)
	Local x1:Float = 20
	Local y1:Float = 20
	Local x2:Float = 400
	Local y2:Float = 400
	SetColor 255 , 0 , 0
	DrawLine x1 , y1 , x2 , y2
	Local CP:TList = Collide(Constraints , x1 , y1 , x2 , y2)
	If CP <> Null
		DrawText "Collide" , 20 , 20
	End If
End Function

At the begining of the example
import "Vector2d.Bmx"

And before the flip 1
	Test(Physics.Constraints)	


You have a visual of a basic collision detection
Also the collide function returns a TList with all the intersection points.

IMPORTANT : This is not coming from a tutorial so the whole idea may become a failure.
If you have any suggestion pls post

Also If anyone ever worked with collision stuff pls post