gah! How to clip rotated rectangles.

BlitzMax Forums/BlitzMax Programming/gah! How to clip rotated rectangles.

I have not found time to work on a bmax conversion, but here is some blitzplus code which does rotate a 256x256 image. I will still try and find time to convert it, but unfortunately time to code is not something I have plenty of these days.

Graphics 640,480,32,2

demoImg = LoadImage("tiger.bmp") 

Dim RGB(256,256) 
SetBuffer ImageBuffer(demoImg) 
LockBuffer 
For y=0 To 255 
For x=0 To 255 
RGB(x,y)=ReadPixel(x,y) 
Next 
Next 
UnlockBuffer 
angel=0 

Dim sn#(360),cs#(360) 
For a=0 To 359 
sn(a) = Sin(a) 
cs(a) = Cos(a) 
Next 

FPS_Real = 60
FPS_Temp = 0

SetBuffer BackBuffer() 
timer = MilliSecs()

While Not KeyHit(1) 

If MilliSecs() > timer+1000 Then
	timer = MilliSecs()
	FPS_Real = FPS_Temp
	FPS_Temp = 0
End If

LockBuffer BackBuffer() 

For y=-127 To 128 
For x=-127 To 128 

;// USING REGULAR COS AND SIN 
;tx=x * Cos(angel) - y * Sin(angel)
;ty=y * Cos(angel) + x * Sin(angel)

;// USING LOOKUP TABLES 
tx=x * Cs(angel) - y * Sn(angel)
ty=y * Cs(angel) + x * Sn(angel)

While tx<-128: tx = tx +256: Wend 
While tx>127: tx = tx - 256: Wend 
While ty<-128: ty = ty +256: Wend 
While ty>127: ty = ty - 256: Wend 

WritePixelFast 320+x,240+y,RGB(tx+128,ty+128) 

Next 
Next 

UnlockBuffer BackBuffer() 

angel=angel+2 
If angel > 359 Then angel = angel - 359 

Color 255,0,0
Rect 320-129,240-129,258,258,0
Color 255,255,255
Text 0,0,"FPS: "+FPS_Real
Flip
Cls
FPS_Temp = FPS_Temp + 1
Wend 

End