point in rect

BlitzMax Forums/BlitzMax Beginners Area/point in rect

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.

Just draw a single pixel on the collisionmask where the point of the mouse is. Then use it to check for a collision.

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!.

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