From 57bfd19c592bb4164d00639e14c32e434f0171ff Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 27 Oct 2016 21:00:42 +0530 Subject: [PATCH] Convenience functions for creating matrices --- kitty/shaders.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/kitty/shaders.py b/kitty/shaders.py index 03cd67a67..d9f5a4cd6 100644 --- a/kitty/shaders.py +++ b/kitty/shaders.py @@ -18,6 +18,42 @@ def array(*args, dtype=gl.GLfloat): return (dtype * len(args))(*args) +def translation_matrix(x, y): + return array( + 1, 0, x, + 0, 1, y, + 0, 0, 1 + ) + + +def scaling_matrix(x, y): + return array( + x, 0, 0, + 0, y, 0, + 0, 0, 1 + ) + + +def multiply(a, b): + # 0 1 2 + # 3 4 5 + # 6 7 8 + return array( + # Row 1 + a[0] * b[0] + a[1] * b[3] + a[2] * b[6], + a[0] * b[1] + a[1] * b[4] + a[2] * b[7], + a[0] * b[2] + a[1] * b[5] + a[2] * b[8], + # Row 2 + a[3] * b[0] + a[4] * b[3] + a[5] * b[6], + a[3] * b[1] + a[4] * b[4] + a[5] * b[7], + a[3] * b[2] + a[4] * b[5] + a[5] * b[8], + # Row 3 + a[6] * b[0] + a[7] * b[3] + a[8] * b[6], + a[6] * b[1] + a[7] * b[4] + a[8] * b[7], + a[6] * b[2] + a[7] * b[5] + a[8] * b[8] + ) + + class Sprites: ''' Maintain sprite sheets of all rendered characters on the GPU as a texture array with each texture being a sprite sheet. '''