draw collider fast path when radius=0
This commit is contained in:
parent
05668865a7
commit
7229daf49c
36
src/draw.c
36
src/draw.c
@ -239,21 +239,39 @@ void draw_arrow_ray(struct gpu_handle cmd_list, struct v2 pos, struct v2 rel, f3
|
||||
draw_arrow_line(cmd_list, pos, end, thickness, arrowhead_height, color);
|
||||
}
|
||||
|
||||
void draw_collider_line(struct gpu_handle cmd_list, struct xform draw_xf, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail)
|
||||
void draw_collider_line(struct gpu_handle cmd_list, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail)
|
||||
{
|
||||
/* FIXME: Graphics bug when lots of colliders are drawn */
|
||||
DEBUGBREAKABLE;
|
||||
struct arena_temp scratch = scratch_begin_no_conflict();
|
||||
|
||||
struct v2 *points = arena_push_array_no_zero(scratch.arena, struct v2, detail);
|
||||
for (u32 i = 0; i < detail; ++i) {
|
||||
f32 angle = ((f32)i / (f32)detail) * (2 * PI);
|
||||
struct v2 dir = V2(math_cos(angle), math_sin(angle));
|
||||
struct v2 p = collider_get_support_point(&shape, shape_xf, dir).p;
|
||||
p = xform_mul_v2(draw_xf, p);
|
||||
points[i] = p;
|
||||
struct v2_array poly = ZI;
|
||||
|
||||
if (shape.radius == 0) {
|
||||
poly.count = shape.count;
|
||||
poly.points = arena_push_array_no_zero(scratch.arena, struct v2, shape.count);
|
||||
for (u32 i = 0; i < shape.count; ++i) {
|
||||
struct v2 p = xform_mul_v2(shape_xf, shape.points[i]);
|
||||
poly.points[i] = p;
|
||||
}
|
||||
} else {
|
||||
poly.count = detail;
|
||||
poly.points = arena_push_array_no_zero(scratch.arena, struct v2, detail);
|
||||
for (u32 i = 0; i < detail; ++i) {
|
||||
f32 angle = ((f32)i / (f32)detail) * (2 * PI);
|
||||
struct v2 dir = V2(math_cos(angle), math_sin(angle));
|
||||
struct v2 p = collider_get_support_point(&shape, shape_xf, dir).p;
|
||||
poly.points[i] = p;
|
||||
}
|
||||
}
|
||||
|
||||
struct v2_array poly = { .points = points, .count = detail };
|
||||
DEBUGBREAKABLE;
|
||||
#if 1
|
||||
draw_poly_line(cmd_list, poly, true, thickness, color);
|
||||
#else
|
||||
draw_poly(cmd_list, poly, color);
|
||||
(UNUSED)thickness;
|
||||
#endif
|
||||
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ void draw_arrow_line(struct gpu_handle cmd_list, struct v2 start, struct v2 end,
|
||||
|
||||
void draw_arrow_ray(struct gpu_handle cmd_list, struct v2 pos, struct v2 rel, f32 thickness, f32 arrowhead_height, u32 color);
|
||||
|
||||
void draw_collider_line(struct gpu_handle cmd_list, struct xform draw_xf, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail);
|
||||
void draw_collider_line(struct gpu_handle cmd_list, struct collider_shape shape, struct xform shape_xf, f32 thickness, u32 color, u32 detail);
|
||||
|
||||
/* ========================== *
|
||||
* Grid
|
||||
|
||||
@ -1226,7 +1226,7 @@ INTERNAL void user_update(void)
|
||||
b32 skip_debug_draw_transform = sim_ent_has_prop(ent, SEPROP_CAMERA);
|
||||
skip_debug_draw_transform = true;
|
||||
|
||||
struct xform sprite_xform = xf;
|
||||
struct xform sprite_xform = xform_mul(xf, ent->sprite_local_xform);
|
||||
|
||||
/* Draw tracer */
|
||||
if (sim_ent_has_prop(ent, SEPROP_TRACER)) {
|
||||
@ -1269,9 +1269,6 @@ INTERNAL void user_update(void)
|
||||
/* Draw sprite */
|
||||
//if ((false)) {
|
||||
if (!sprite_tag_is_nil(sprite)) {
|
||||
/* Calculate sprite xform */
|
||||
sprite_xform = xform_mul(xf, ent->sprite_local_xform);
|
||||
|
||||
/* Async load */
|
||||
struct sprite_sheet *sheet = sprite_sheet_from_tag_async(sprite_frame_scope, sprite);
|
||||
struct sprite_texture *texture = sprite_texture_from_tag_async(sprite_frame_scope, sprite);
|
||||
@ -1422,7 +1419,8 @@ INTERNAL void user_update(void)
|
||||
{
|
||||
/* Draw collider using support points */
|
||||
u32 detail = 32;
|
||||
draw_collider_line(G.user_gpu_cmd_list, G.world_to_user_xf, collider, xf, thickness, color, detail);
|
||||
struct xform collider_draw_xf = xform_mul(G.world_to_user_xf, xf);
|
||||
draw_collider_line(G.user_gpu_cmd_list, collider, collider_draw_xf, thickness, color, detail);
|
||||
}
|
||||
{
|
||||
/* Draw collider shape points */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user