23 #include <LLVG_MATRIX_impl.h> 32 void LLVG_MATRIX_IMPL_identity(jfloat* matrix) {
33 LLVG_MATRIX_IMPL_setTranslate(matrix, 0, 0);
37 void LLVG_MATRIX_IMPL_copy(jfloat* dest, jfloat* src) {
38 (void)memcpy((
void*)dest, (
void*)src,
sizeof(
float) * LLVG_MATRIX_SIZE);
42 void LLVG_MATRIX_IMPL_setTranslate(jfloat* matrix, jfloat x, jfloat y) {
55 void LLVG_MATRIX_IMPL_setScale(jfloat* matrix, jfloat sx, jfloat sy) {
56 LLVG_MATRIX_IMPL_identity(matrix);
57 LLVG_MATRIX_IMPL_scale(matrix, sx, sy);
61 void LLVG_MATRIX_IMPL_setRotate(jfloat* matrix, jfloat degrees) {
62 LLVG_MATRIX_IMPL_identity(matrix);
63 LLVG_MATRIX_IMPL_rotate(matrix, degrees);
67 void LLVG_MATRIX_IMPL_setConcat(jfloat* dest, jfloat* a, jfloat* b) {
68 LLVG_MATRIX_IMPL_copy(dest, a);
69 LLVG_MATRIX_IMPL_concatenate(dest, b);
73 void LLVG_MATRIX_IMPL_translate(jfloat* matrix, jfloat x, jfloat y) {
74 matrix[2] = (matrix[0] * x) + (matrix[1] * y) + matrix[2];
75 matrix[5] = (matrix[3] * x) + (matrix[4] * y) + matrix[5];
76 matrix[8] = (matrix[6] * x) + (matrix[7] * y) + matrix[8];
80 void LLVG_MATRIX_IMPL_scale(jfloat* matrix, jfloat scaleX, jfloat scaleY) {
90 void LLVG_MATRIX_IMPL_rotate(jfloat* matrix, jfloat angleDegrees) {
92 float angleRadians = DEG_TO_RAD(angleDegrees);
95 float cosAngle = cosf(angleRadians);
96 float sinAngle = sinf(angleRadians);
100 tmp = (cosAngle * matrix[0]) + (sinAngle * matrix[1]);
101 matrix[1] = (cosAngle * matrix[1]) - (sinAngle * matrix[0]);
104 tmp = (cosAngle * matrix[3]) + (sinAngle * matrix[4]);
105 matrix[4] = (cosAngle * matrix[4]) - (sinAngle * matrix[3]);
108 tmp = (cosAngle * matrix[6]) + (sinAngle * matrix[7]);
109 matrix[7] = (cosAngle * matrix[7]) - (sinAngle * matrix[6]);
114 void LLVG_MATRIX_IMPL_concatenate(jfloat* matrix, jfloat* other) {
116 float temp[LLVG_MATRIX_SIZE];
118 temp[0] = (matrix[0] * other[0]) + (matrix[1] * other[3]) + (matrix[2] * other[6]);
119 temp[1] = (matrix[0] * other[1]) + (matrix[1] * other[4]) + (matrix[2] * other[7]);
120 temp[2] = (matrix[0] * other[2]) + (matrix[1] * other[5]) + (matrix[2] * other[8]);
122 temp[3] = (matrix[3] * other[0]) + (matrix[4] * other[3]) + (matrix[5] * other[6]);
123 temp[4] = (matrix[3] * other[1]) + (matrix[4] * other[4]) + (matrix[5] * other[7]);
124 temp[5] = (matrix[3] * other[2]) + (matrix[4] * other[5]) + (matrix[5] * other[8]);
126 temp[6] = (matrix[6] * other[0]) + (matrix[7] * other[3]) + (matrix[8] * other[6]);
127 temp[7] = (matrix[6] * other[1]) + (matrix[7] * other[4]) + (matrix[8] * other[7]);
128 temp[8] = (matrix[6] * other[2]) + (matrix[7] * other[5]) + (matrix[8] * other[8]);
131 LLVG_MATRIX_IMPL_copy(matrix, temp);
135 void LLVG_MATRIX_IMPL_postTranslate(jfloat* matrix, jfloat dx, jfloat dy) {
137 float temp[LLVG_MATRIX_SIZE];
138 LLVG_MATRIX_IMPL_setTranslate(temp, dx, dy);
139 LLVG_MATRIX_IMPL_concatenate(temp, matrix);
140 LLVG_MATRIX_IMPL_copy(matrix, temp);
144 void LLVG_MATRIX_IMPL_postScale(jfloat* matrix, jfloat sx, jfloat sy) {
146 float temp[LLVG_MATRIX_SIZE];
147 LLVG_MATRIX_IMPL_identity(temp);
148 LLVG_MATRIX_IMPL_scale(temp, sx, sy);
149 LLVG_MATRIX_IMPL_concatenate(temp, matrix);
150 LLVG_MATRIX_IMPL_copy(matrix, temp);
154 void LLVG_MATRIX_IMPL_postRotate(jfloat* matrix, jfloat degrees) {
156 float temp[LLVG_MATRIX_SIZE];
157 LLVG_MATRIX_IMPL_identity(temp);
158 LLVG_MATRIX_IMPL_rotate(temp, degrees);
159 LLVG_MATRIX_IMPL_concatenate(temp, matrix);
160 LLVG_MATRIX_IMPL_copy(matrix, temp);
164 void LLVG_MATRIX_IMPL_postConcat(jfloat* matrix, jfloat* other) {
166 float temp[LLVG_MATRIX_SIZE];
167 LLVG_MATRIX_IMPL_copy(temp, other);
168 LLVG_MATRIX_IMPL_concatenate(temp, matrix);
169 LLVG_MATRIX_IMPL_copy(matrix, temp);
MicroEJ MicroVG library low level API: helper to implement library natives methods.