Files
Citadel-Station-13-RP/code/__HELPERS/matrices/transform_matrix.dm
Zandario ed05e01a95 __HELPERS Cleaning and other things I decided to do. (#4584)
* Schizoposting

* The Crungly

* Tabbin' the JSON y'all

* Strings
2022-10-21 01:56:59 -07:00

96 lines
2.0 KiB
Plaintext

/matrix/proc/TurnTo(old_angle, new_angle)
. = new_angle - old_angle
Turn(.) //BYOND handles cases such as -270, 360, 540 etc. DOES NOT HANDLE 180 TURNS WELL, THEY TWEEN AND LOOK LIKE SHIT
/atom/proc/SpinAnimation(speed = 10, loops = -1, clockwise = 1, segments = 3, parallel = TRUE)
if(!segments)
return
var/segment = 360/segments
if(!clockwise)
segment = -segment
var/list/matrices = list()
for(var/i in 1 to segments-1)
var/matrix/M = matrix(transform)
M.Turn(segment*i)
matrices += M
var/matrix/last = matrix(transform)
matrices += last
speed /= segments
if(parallel)
animate(src, transform = matrices[1], time = speed, loops , flags = ANIMATION_PARALLEL)
else
animate(src, transform = matrices[1], time = speed, loops)
for(var/i in 2 to segments) //2 because 1 is covered above
animate(transform = matrices[i], time = speed)
//doesn't have an object argument because this is "Stacking" with the animate call above
//3 billion% intentional
/**
* Dumps the matrix data in format a-f.
*/
/matrix/proc/tolist()
. = list()
. += a
. += b
. += c
. += d
. += e
. += f
/**
* Dumps the matrix data in a matrix-grid format.
*
* a d 0
* b e 0
* c f 1
*/
/matrix/proc/togrid()
. = list()
. += a
. += d
. += 0
. += b
. += e
. += 0
. += c
. += f
. += 1
/**
* The X pixel offset of this matrix.
*/
/matrix/proc/get_x_shift()
. = c
/**
* The Y pixel offset of this matrix.
*/
/matrix/proc/get_y_shift()
. = f
/matrix/proc/get_x_skew()
. = b
/matrix/proc/get_y_skew()
. = d
/**
* Skews a matrix in a particular direction.
* Missing arguments are treated as no skew in that direction.
*
* As Rotation is defined as a scale+skew, these procs will break any existing rotation.
* Unless the result is multiplied against the current matrix.
*/
/matrix/proc/set_skew(x = 0, y = 0)
b = x
d = y
/**
* Constructs a transform matrix, defaulting to identity.
*/
/proc/transform_matrix_construct(a = 1, b, c, d = 1, e, f)
return matrix(a, b, c, d, e, f)