Fast way to rotate screen 180 degrees?

BlitzMax Forums/BlitzMax Programming/Fast way to rotate screen 180 degrees?

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.

And back to topic... I came up with the following code wich I only need to include and replace draw functions for the new ones in the application.

I even upgraded it with the option to shake the screen and zoom in and out :-)

It's not finished yet, needs a lot more draw functions, but it is fast.
When this is finished I will post the code here.

Here is the ZRM.bmx
'########################################
'### Zoom Rotate And Move Version 1.0 ###
'########################################
'
' This file is used to zoom, rotate and move everything that you want by using the ZRM functions
' and can be implemented in your project even when you are almost done
'
' I needed only the rotate function at first to rotate all stuff 180 on the display, so I only need
' ZRM_Rotate (180) to determine how every ZRM draw function should be rotated
'
' DrawImage will be replaced by ZRM_DrawImage
'
' include this file in your Blitzmax application with :
' 
' include "ZRM.bmx"
'
' This needs to be done after the setgraphics command
'
' Functions :
'
' - ZRM_Zoom (x:Float, y:Float)                                : Zooms everything on the screen drawn with ZRM_Draw functions
'                                                                Is used the same as SetScale
'
' - ZRM_Rotate (angle:Float)                                   : Rotates everything on the screen drawn with ZRM_Draw functions
'                                                                Is used the same as SetRotation
'
' - ZRM_Move (x:Float, y:Float)                                : Moves everything from the middle of the screen drawn with ZRM_Draw functions
'                                                                X stands for - or + amount of pixels to go left or right
'                                                                Y stands for - or + amount of pixels to go up or down
'
' - ZRM_SetScale (x:Float, y:Float)                            : Replacement for SetScale
'
' - ZRM_SetRotation (angle:Float)                              : Replacement for SetRotation
' 
' - ZRM_DrawText (Text:String, x:Float, y:Float)               : Replacement for DrawText
'
' - ZRM_DrawImage (Image:TImage, x:Float, y:Float)             : Replacement for DrawImage (Works the same, but won't work with more frames)
'
' - ZRM_DrawRect (x:Float, y:Float, Width:Float, Heigth:Float) : Replacement for DrawRect
'
' - ZRM_DrawRect (x:Float, y:Float, Width:Float, Heigth:Float) : Replacement for DrawOval
'
' - ZRM_DrawLine (x1:Float, y1:Float, x2:Float, y2:Float)      : Replacement for DrawLine
'
' - More functions will be added
'
'Written by Mark Gerritsen

Global ZRM_Zoom_X:Float = 1
Global ZRM_Zoom_Y:Float = 1
Global ZRM_Rotate_Angle:Float = 0
Global ZRM_Move_X:Float = 0
Global ZRM_Move_Y:Float = 0
Global ZRM_SetScale_X:Float = 1
Global ZRM_SetScale_Y:Float = 1
Global ZRM_SetRotation_Angle:Float = 0
Global ZRM_Width:Int
Global ZRM_Height:Int
Global ZRM_Temp_X_X:Float
Global ZRM_Temp_X_Y:Float
Global ZRM_Temp_Y_X:Float
Global ZRM_Temp_Y_Y:Float

ZRM_Width  = GraphicsWidth()
ZRM_Height = GraphicsHeight()

Function ZRM_Zoom (X:Float, Y:Float)
	ZRM_Zoom_X = X
	ZRM_Zoom_Y = Y
End Function

Function ZRM_Rotate (Angle:Float)
	ZRM_Rotate_Angle = Angle
End Function

Function ZRM_Move (X:Float, Y:Float)
	ZRM_Move_X = X
	ZRM_Move_Y = Y
End Function

Function ZRM_SetScale (X:Float, Y:Float)
	ZRM_SetScale_X = X
	ZRM_SetScale_Y = Y
End Function

Function ZRM_SetRotation (Angle:Float)
	ZRM_SetRotation_Angle = Angle
End Function

Function ZRM_Drawtext (Text:String, X:Float, Y:Float)
		
	ZRM_Calculate (X, Y)
	DrawText Text, ((ZRM_Width / 2) + ZRM_Temp_X_X - ZRM_Temp_X_Y + ZRM_Move_X), ((ZRM_Height / 2) + ZRM_Temp_Y_X + ZRM_Temp_Y_Y + ZRM_Move_Y)

End Function

Function ZRM_DrawImage (Image:TImage, X:Float, Y:Float)

	ZRM_Calculate (X, Y)
	DrawImage Image, ((ZRM_Width / 2) + ZRM_Temp_X_X - ZRM_Temp_X_Y + ZRM_Move_X), ((ZRM_Height / 2) + ZRM_Temp_Y_X + ZRM_Temp_Y_Y + ZRM_Move_Y)

End Function

Function ZRM_DrawRect (X:Float, Y:Float, Width:Float, Height:Float)

	ZRM_Calculate (X, Y)
	DrawRect ((ZRM_Width / 2) + ZRM_Temp_X_X - ZRM_Temp_X_Y + ZRM_Move_X), ((ZRM_Height / 2) + ZRM_Temp_Y_X + ZRM_Temp_Y_Y + ZRM_Move_Y), Width, Height

End Function

Function ZRM_DrawOval (X:Float, Y:Float, Width:Float, Height:Float)

	ZRM_Calculate (X, Y)
	DrawOval ((ZRM_Width / 2) + ZRM_Temp_X_X - ZRM_Temp_X_Y + ZRM_Move_X), ((ZRM_Height / 2) + ZRM_Temp_Y_X + ZRM_Temp_Y_Y + ZRM_Move_Y), Width, Height

End Function 

Function ZRM_DrawLine (X1:Float, Y1:Float, X2:Float, Y2:Float)

	ZRM_Calculate (X1, Y1)
	Local X1_New:Float = ((ZRM_Width / 2) + ZRM_Temp_X_X - ZRM_Temp_X_Y + ZRM_Move_X)
	Local Y1_New:Float = ((ZRM_Height / 2) + ZRM_Temp_Y_X + ZRM_Temp_Y_Y + ZRM_Move_Y)
	ZRM_Calculate (X2, Y2)
	Local X2_New:Float = ((ZRM_Width / 2) + ZRM_Temp_X_X - ZRM_Temp_X_Y + ZRM_Move_X)
	Local Y2_New:Float = ((ZRM_Height / 2) + ZRM_Temp_Y_X + ZRM_Temp_Y_Y + ZRM_Move_Y)
	SetScale (1, 1)
	SetRotation (0)
	DrawLine X1_New, Y1_New, X2_New, Y2_New 

End Function 

Function ZRM_Calculate(X:Float, Y:Float)

	SetRotation (ZRM_SetRotation_Angle + ZRM_Rotate_Angle)
	SetScale (ZRM_SetScale_X * ZRM_Zoom_X), (ZRM_SetScale_Y * ZRM_Zoom_Y)
	ZRM_Temp_X_X = ((Cos(ZRM_Rotate_Angle) * (X - (ZRM_Width / 2)) * (ZRM_Zoom_X)))
	ZRM_Temp_X_Y = ((Sin(ZRM_Rotate_Angle) * (Y - (ZRM_Height / 2)) * (ZRM_Zoom_Y)))
	ZRM_Temp_Y_X = ((Sin(ZRM_Rotate_Angle) * (X - (ZRM_Width / 2)) * (ZRM_Zoom_X)))
	ZRM_Temp_Y_Y = ((Cos(ZRM_Rotate_Angle) * (Y - (ZRM_Height / 2)) * (ZRM_Zoom_Y)))

End Function


<Edit : Fixed some small bugs, should work perfectly with all functions now>

I wonder if this is usefull for anyone else, please test it if any flaws are found, please reply.