static void testTranslate() { Matrix matrix; matrix = Matrix_translated(Matrix_identity(), 3.0f, -1.5f, 1.0f); assertMatrixApproximate(matrix, 1.0f, 0.0f, 0.0f, 3.0f, 0.0f, 1.0f, 0.0f, -1.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, EPSILON); matrix = Matrix_translated(Matrix_fromDirectionVectors(Vector3_init(0.0f, 1.0f, 0.0f), Vector3_init(0.0f, 0.0f, 1.0f), Vector3_init(1.0f, 0.0f, 0.0f)), 2.0f, 3.0f, -1.0f); assertMatrixApproximate(matrix, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 2.0f, 0.0f, 1.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 1.0f, EPSILON); matrix = Matrix_identity(); Matrix_translate(&matrix, 3.0f, -1.5f, 1.0f); assertMatrixApproximate(matrix, 1.0f, 0.0f, 0.0f, 3.0f, 0.0f, 1.0f, 0.0f, -1.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, EPSILON); matrix = Matrix_fromDirectionVectors(Vector3_init(0.0f, 1.0f, 0.0f), Vector3_init(0.0f, 0.0f, 1.0f), Vector3_init(1.0f, 0.0f, 0.0f)); Matrix_translate(&matrix, 2.0f, 3.0f, -1.0f); assertMatrixApproximate(matrix, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 2.0f, 0.0f, 1.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 1.0f, EPSILON); }
static void gezira_snowflake_render (gezira_snowflake_t *flake) { nile_Process_t *pipeline, *gate_, *COI; Matrix_t M = Matrix (); if (gezira_snowflake_offscreen (flake)) return; M = Matrix_translate (M, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2); M = Matrix_scale (M, zoom, zoom); M = Matrix_translate (M, -WINDOW_WIDTH / 2, -WINDOW_HEIGHT / 2); M = Matrix_translate (M, flake->x, flake->y); M = Matrix_rotate (M, flake->angle); M = Matrix_scale (M, flake->scale, flake->scale); COI = gezira_CompositeUniformColorOverImage_ARGB32 (init, FLAKE_ALPHA, FLAKE_RED, FLAKE_GREEN, FLAKE_BLUE, window.pixels, window.width, window.height, window.width); gate_ = nile_Identity (init, 8); nile_Process_gate (COI, gate_); pipeline = nile_Process_pipe ( gezira_TransformBeziers (init, M.a, M.b, M.c, M.d, M.e, M.f), gezira_ClipBeziers (init, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT), gezira_Rasterize (init), gate, COI, NILE_NULL); nile_Process_feed (pipeline, snowflake_path, snowflake_path_n); gate = gate_; }
// Matrix operand to add a 3D translation to the Module. void Module_translate(Module *md, double tx, double ty, double tz) { Matrix m; Element *e; Matrix_identity(&m); Matrix_translate(&m, tx, ty, tz); e = Element_init(ObjMatrix, &m); Module_insert(md, e); }
static void gezira_snowflake_render (gezira_snowflake_t *flake, gezira_Window_t *window, nile_Process_t *init) { nile_Process_t *pipeline; Matrix_t M = Matrix (); if (gezira_snowflake_offscreen (flake)) return; M = Matrix_translate (M, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2); M = Matrix_scale (M, zoom, zoom); M = Matrix_translate (M, -WINDOW_WIDTH / 2, -WINDOW_HEIGHT / 2); M = Matrix_translate (M, flake->x, flake->y); M = Matrix_rotate (M, flake->angle); M = Matrix_scale (M, flake->scale, flake->scale); pipeline = nile_Process_pipe ( gezira_TransformBeziers (init, M.a, M.b, M.c, M.d, M.e, M.f), gezira_ClipBeziers (init, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT), gezira_Rasterize (init), gezira_CompositeUniformColorOverImage_ARGB32 (init, &window->image, FLAKE_ALPHA, FLAKE_RED, FLAKE_GREEN, FLAKE_BLUE), NILE_NULL); nile_Process_feed (pipeline, snowflake_path, snowflake_path_n); }
Matrix Matrix_translated(Matrix matrix, float x, float y, float z) { Matrix_translate(&matrix, x, y, z); return matrix; }