diff --git a/src/phys.c b/src/phys.c index 7ef0930b..7bdbbef2 100644 --- a/src/phys.c +++ b/src/phys.c @@ -743,7 +743,7 @@ struct phys_mouse_joint phys_mouse_joint_from_def(struct phys_mouse_joint_def de struct phys_mouse_joint res = ZI; res.target = def.target; res.point_local_start = def.point_local_start; - res.point_local_end = def.point_local_end; + res.point_end = def.point_end; res.linear_spring_hz = def.linear_spring_hz; res.linear_spring_damp = def.linear_spring_damp; res.angular_spring_hz = def.angular_spring_hz; @@ -856,7 +856,7 @@ void phys_solve_mouse_joints(struct phys_step_ctx *ctx, f32 dt) struct xform xf = sim_ent_get_xform(ent); struct v2 point_start = xform_mul_v2(xf, joint->point_local_start); - struct v2 point_end = xform_mul_v2(xf, joint->point_local_end); + struct v2 point_end = joint->point_end; struct v2 vcp = v2_sub(point_start, xf.og); struct v2 separation = v2_sub(point_start, point_end); diff --git a/src/phys.h b/src/phys.h index 944867d7..d32a12c3 100644 --- a/src/phys.h +++ b/src/phys.h @@ -139,7 +139,7 @@ void phys_solve_motor_joints(struct phys_step_ctx *ctx, f32 dt); struct phys_mouse_joint_def { struct sim_ent_id target; struct v2 point_local_start; - struct v2 point_local_end; + struct v2 point_end; f32 linear_spring_hz; f32 linear_spring_damp; f32 angular_spring_hz; @@ -150,7 +150,7 @@ struct phys_mouse_joint_def { struct phys_mouse_joint { struct sim_ent_id target; struct v2 point_local_start; - struct v2 point_local_end; + struct v2 point_end; f32 linear_spring_hz; f32 linear_spring_damp; f32 angular_spring_hz; diff --git a/src/sim_step.c b/src/sim_step.c index 3f2d906f..c78ef5c8 100644 --- a/src/sim_step.c +++ b/src/sim_step.c @@ -234,7 +234,8 @@ INTERNAL void spawn_test_entities2(struct sim_ent *parent, struct v2 pos) /* Big box */ #if 1 { - struct sim_ent *e = sim_ent_alloc_local(parent); + //struct sim_ent *e = sim_ent_alloc_local(parent); + struct sim_ent *e = sim_ent_alloc_sync_src(parent); f32 r = 0; struct v2 size = V2(0.5, 0.25); @@ -1263,7 +1264,6 @@ void sim_step(struct sim_step_ctx *ctx) sim_ent_enable_prop(joint_ent, SEPROP_ACTIVE); } struct xform xf = sim_ent_get_xform(target_ent); - f32 mass = target_ent->mass_unscaled * math_fabs(xform_get_determinant(xf)); struct phys_mouse_joint_def def = phys_mouse_joint_def_init(); def.target = target_ent->id; @@ -1272,8 +1272,12 @@ void sim_step(struct sim_step_ctx *ctx) } else { def.point_local_start = xform_invert_mul_v2(xf, cursor); } - def.point_local_end = xform_invert_mul_v2(xf, cursor); - def.max_force = mass * 1000; + def.point_end = cursor; + def.max_force = F32_INFINITY; + def.linear_spring_hz = 5; + def.linear_spring_damp = 0.7; + def.angular_spring_hz = 5; + def.angular_spring_damp = 0.1; joint_ent->mouse_joint_data = phys_mouse_joint_from_def(def); } else if (sim_ent_is_valid_and_active(joint_ent)) { joint_ent->mouse_joint_data.target = target_ent->id; diff --git a/src/user.c b/src/user.c index b2ea1569..d160f911 100644 --- a/src/user.c +++ b/src/user.c @@ -1194,14 +1194,13 @@ INTERNAL void user_update(void) if (sim_ent_has_prop(ent, SEPROP_MOUSE_JOINT)) { struct sim_ent *target = sim_ent_from_id(G.ss_blended, ent->mouse_joint_data.target); struct xform target_xf = sim_ent_get_xform(target); - - u32 color = COLOR_YELLOW; - f32 radius = 3; - struct v2 point = xform_mul_v2(target_xf, ent->mouse_joint_data.point_local_end); - point = xform_mul_v2(G.world_to_ui_xf, point); - draw_circle(G.ui_cmd_buffer, point, radius, color, 10); - - DEBUGBREAKABLE; + u32 color = COLOR_WHITE; + struct v2 point_start = xform_mul_v2(target_xf, ent->mouse_joint_data.point_local_start); + struct v2 point_end = G.world_cursor; + point_start = xform_mul_v2(G.world_to_ui_xf, point_start); + point_end = xform_mul_v2(G.world_to_ui_xf, point_end); + draw_arrow_line(G.ui_cmd_buffer, point_start, point_end, 3, 10, color); + draw_circle(G.ui_cmd_buffer, point_start, 4, color, 10); } /* Draw collider */