point in rect

BlitzMax Forums/BlitzMax Beginners Area/point in rect

slenkar(Posted 2008) [#1]
I have a point in rect collision function here:

Method point_in_rect(mouse_X,Mouse_Y)
If Mouse_X > self.x
If Mouse_X < (self.x + self.width)
If Mouse_Y > self.y
If Mouse_Y < (self.y + self.height)
Return True
EndIf
EndIf
EndIf
EndIf
EndMethod

it works great with images that have not been rotated
but when I rotate an image i fails to detect a collision

I could use collideimages but I dont want to have the mouesimage collide because it would collide with 2 buttons at once if the mouse was close enough to 2 buttons.


TaskMaster(Posted 2008) [#2]
Just draw a single pixel on the collisionmask where the point of the mouse is. Then use it to check for a collision.


Shagwana(Posted 2008) [#3]
You will need to convert it to a point in polygon routine, plenty of examples in the code arc.
A---B
|  /|
| / |
|/  |
C---D


Make a rect out of two triangles and rotate those 4 points. Use point in a polygon (triangle) routine on those!.


DREAM(Posted 2008) [#4]
heres what i use for point inside quad

	Function InsideQuad(px,py,x0,y0,x1,y1,x2,y2,x3,y3) 
	
		If dot(x0, y0, x1, y1, px, py) > 0
			If dot(x1,y1,x2,y2,px,py)>0 
				If dot(x2,y2,x3,y3,px,py)>0 
					If dot(x3,y3,x0,y0,px,py)>0 
						Return True 
					EndIf 
				EndIf 
			EndIf 
		EndIf 
		
	End Function 

	Function dot(x0,y0,x1,y1,x2,y2) 
	
		Return (x1-x0)*(y2-y1)-(x2-x1)*(y1-y0) 
		
	End Function 



Robert Cummings(Posted 2009) [#5]
Sorry to bump this, but Dream, do you know how to calculate the intersection point from your point inside quad function?

Thanks in advance!


matibee(Posted 2009) [#6]
Rob,

I posted some code a while ago that you might be interested in (see the second code posting)..

http://www.blitzbasic.co.nz/Community/posts.php?topic=85634

It's got distance to line and closest point to line functions (amongst other things). I submitted it to the blitzmonkeys code archive the other day as there was talk of platform games and I'd done a platform physics demo using the same code.. (latest code, and it's now a mod too)...

http://www.blitzmonkeys.com/index.php?topic=188.0