Sat, 19 Jul 2025 21:29:10 +0200
use new point-of-origin for 2d primitives
src/2d.c | file | annotate | diff | comparison | revisions | |
src/ascension/2d.h | file | annotate | diff | comparison | revisions | |
test/snake/snake.c | file | annotate | diff | comparison | revisions |
--- a/src/2d.c Fri Jul 18 18:01:41 2025 +0200 +++ b/src/2d.c Sat Jul 19 21:29:10 2025 +0200 @@ -193,6 +193,7 @@ asc_scene_node_init(node, ASC_SCENE_NODE_FUNCS(asc_rectangle), .pos2d = ASC_VEC2I(pos_x, pos_y), + .origin2d = ASC_VEC2I(args.origin_x, args.origin_y), .render_group = (args.filled && args.color.alpha < 255) || args.border_color.alpha < 255 ? ASC_RENDER_GROUP_2D_BLEND : ASC_RENDER_GROUP_2D_OPAQUE @@ -311,17 +312,17 @@ float pos_x, pos_y; if (args.bounds.size.width + args.bounds.size.height > 0) { - pos_x = (float) args.bounds.pos.x; - pos_y = (float) args.bounds.pos.y; ellipsis->radii.x = (float) args.bounds.size.width / 2.f; ellipsis->radii.y = (float) args.bounds.size.height / 2.f; + pos_x = (float) args.bounds.pos.x + ellipsis->radii.x; + pos_y = (float) args.bounds.pos.y + ellipsis->radii.y; } else { const unsigned cx = ASC_NONZERO_OR(args.x, args.center.x); const unsigned cy = ASC_NONZERO_OR(args.y, args.center.y); const unsigned rx = ASC_NONZERO_OR(args.radius, args.radius_x); const unsigned ry = ASC_NONZERO_OR(args.radius, args.radius_y); - pos_x = (float) (cx-rx); - pos_y = (float) (cy-ry); + pos_x = (float) cx; + pos_y = (float) cy; ellipsis->radii.x = (float) rx; ellipsis->radii.y = (float) ry; } @@ -347,6 +348,7 @@ asc_scene_node_init(node, ASC_SCENE_NODE_FUNCS(asc_ellipsis), .pos2d = ASC_VEC2I(pos_x, pos_y), + .origin3d = ASC_VEC3F(ellipsis->radii.x, ellipsis->radii.y, 0), // use float to avoid cast .render_group = (args.filled && args.color.alpha < 255) || args.border_color.alpha < 255 ? ASC_RENDER_GROUP_2D_BLEND : ASC_RENDER_GROUP_2D_OPAQUE
--- a/src/ascension/2d.h Fri Jul 18 18:01:41 2025 +0200 +++ b/src/ascension/2d.h Sat Jul 19 21:29:10 2025 +0200 @@ -46,6 +46,8 @@ asc_rect bounds; int x; int y; + int origin_x; + int origin_y; unsigned int width; unsigned int height; /** @@ -92,7 +94,8 @@ /** * The bounds of the ellipsis. * Preferred over all other settings. - * When you specify bounds, you cannot specify a center and radiuses. + * When you specify bounds, you cannot specify a center and radii. + * The origin point will be the center of the rectangle. */ asc_rect bounds; /**
--- a/test/snake/snake.c Fri Jul 18 18:01:41 2025 +0200 +++ b/test/snake/snake.c Sat Jul 19 21:29:10 2025 +0200 @@ -163,8 +163,8 @@ .name = "Player", .texture = TEXTURE_SHIP, // TODO: introduce a function to set the position of a space ship - .x = game_field_tile_size * 8 - game_field_tile_size / 2, - .y = game_field_tile_size * 12 - game_field_tile_size / 2, + .x = game_field_tile_size * 8, + .y = game_field_tile_size * 12, .width = game_field_tile_size, .height = game_field_tile_size, .origin_x = game_field_tile_size / 2, @@ -184,6 +184,7 @@ for (unsigned y = 0; y < game_field_size; y+=game_field_tile_size) { AscSceneNode *tile = asc_rectangle( .x = x, .y = y, .filled = true, .thickness = 1, + .origin_x = game_field_tile_size / 2, .origin_y = game_field_tile_size / 2, .width = game_field_tile_size, .height = game_field_tile_size, .color = ASC_RGB(0, 128, 255), .border_color = ASC_RGB(64, 196, 255), @@ -247,8 +248,8 @@ asc_scene_init(MAIN_SCENE, .type = ASC_CAMERA_ORTHO, .ortho.rect = ASC_RECT( - -game_field_tile_size/2, - -game_field_tile_size/2, + -game_field_tile_size, + -game_field_tile_size, game_field_size+game_field_tile_size, game_field_size+game_field_tile_size ),