diff --git a/src/Arts.cs b/src/Arts.cs index 8389899..7418eaa 100644 --- a/src/Arts.cs +++ b/src/Arts.cs @@ -69,12 +69,17 @@ static class Arts mat_both.Chain = mat_backface; mat_slash.FaceCull = Cull.None; + + tip_index = new int[] { 0, 0 }; + tip_buffer = new Vec3[][] { new Vec3[tip_count], new Vec3[tip_count] }; + slashing = new DeltaBool[] { new(false), new(false) }; } // slash tip pos frame circle buffer [!] move out of render class - static int tip_index = 0; static int tip_count = 24; // [!] this needs to be scaled with headset framerate - static Vec3[] tip_buffer = new Vec3[tip_count]; + static int[] tip_index; + static Vec3[][] tip_buffer; + static DeltaBool[] slashing; // [!] hacky offset stepper for noise public static int offset = 0; @@ -241,70 +246,93 @@ static class Arts // ); // blade - Mesh mesh = new(); - Quat blade_ori = Rig.r_hld.orientation; - Vec3 blade_pos = Rig.r_hld.position; - Vec3 tip_pos = blade_pos + blade_ori * V.XYZ(0, 0, -1); - tip_index = (tip_index + 1) % tip_count; - tip_buffer[tip_index] = tip_pos; - Vec3 oldest_tip = tip_buffer[(tip_index + 1) % tip_count]; - Vec3 mid_tip = tip_buffer[(tip_index + (tip_count / 3) * 2) % tip_count]; - mesh.SetData( - new Vertex[] { - new( blade_pos, V.XYZ(0,0,1)), - new( tip_pos, V.XYZ(0,0,1)), - new( mid_tip, V.XYZ(0,0,1)), - new(oldest_tip, V.XYZ(0,0,1)), - }, - new uint[] { - 0, 1, 2, - 0, 2, 3, - } - ); - mesh.Draw( - mat_slash, - Matrix.Identity, - Color.Hex(0xF9BF05FF).ToLinear() - ); - Ray slash_ray = new Ray(tip_pos, Vec3.Direction(tip_pos, oldest_tip)); - float ray_dist = Vec3.Distance(tip_pos, oldest_tip); - // last_tip_pos = Vec3.Lerp(last_tip_pos, tip_pos, Time.Stepf / 0.1f); - - if (true) // hit test + for (int i = 0; i < (int)Handed.Max; i++) { - Matrix enemy_m4 = enemy_test.pose.ToMatrix(); - Ray local_ray = enemy_m4.Inverse.Transform(slash_ray); - bool hit = false; - float min_dist = ray_dist; - Vec3 min_hit_pos = Vec3.Zero; - for (int i = 0; i < enemy_test.cols.Count; i++) + Quat blade_ori = Rig.pose_hld[i].orientation; + Vec3 blade_pos = Rig.pose_hld[i].position; + Vec3 tip_pos = blade_pos + blade_ori * V.XYZ(0, 0, -1); + if (!Rig.holding[i]) // [!] generic placeholder check { - Sphere col = enemy_test.cols[i]; - Vec3 hit_pos = Vec3.Zero; - if (col.Intersect(local_ray, out hit_pos)) + // reset tip buffer + for (int j = 0; j < tip_count; j++) { - float hit_dist = Vec3.Distance(hit_pos, local_ray.position); - if (hit_dist < min_dist) + tip_buffer[i][j] = tip_pos; + } + continue; + } + tip_index[i] = (tip_index[i] + 1) % tip_count; + tip_buffer[i][tip_index[i]] = tip_pos; + Vec3 oldest_tip = tip_buffer[i][(tip_index[i] + 1) % tip_count]; + Vec3 mid_tip = tip_buffer[i][(tip_index[i] + (tip_count / 3) * 2) % tip_count]; + + slashing[i].Step(Vec3.Distance(tip_pos, oldest_tip) > 0.2f); + if (slashing[i].delta == -1) + { + Rig.holding[i] = false; + + // [!] janky placeholder reset + Rig.upper_sheathes[0] = true; + Rig.upper_sheathes[1] = true; + } + + Mesh mesh = new(); + mesh.SetData( + new Vertex[] { + new( blade_pos, V.XYZ(0,0,1)), + new( tip_pos, V.XYZ(0,0,1)), + new( mid_tip, V.XYZ(0,0,1)), + new(oldest_tip, V.XYZ(0,0,1)), + }, + new uint[] { + 0, 1, 2, + 0, 2, 3, + } + ); + mesh.Draw( + mat_slash, + Matrix.Identity, + Color.Hex(0xF9BF05FF).ToLinear() + ); + Ray slash_ray = new Ray(tip_pos, Vec3.Direction(tip_pos, oldest_tip)); + float ray_dist = Vec3.Distance(tip_pos, oldest_tip); + // last_tip_pos = Vec3.Lerp(last_tip_pos, tip_pos, Time.Stepf / 0.1f); + + // hit test + { + Matrix enemy_m4 = enemy_test.pose.ToMatrix(); + Ray local_ray = enemy_m4.Inverse.Transform(slash_ray); + bool hit = false; + float min_dist = ray_dist; + Vec3 min_hit_pos = Vec3.Zero; + for (int j = 0; j < enemy_test.cols.Count; j++) + { + Sphere col = enemy_test.cols[j]; + Vec3 hit_pos = Vec3.Zero; + if (col.Intersect(local_ray, out hit_pos)) { - hit = true; - min_dist = hit_dist; - min_hit_pos = hit_pos; + float hit_dist = Vec3.Distance(hit_pos, local_ray.position); + if (hit_dist < min_dist) + { + hit = true; + min_dist = hit_dist; + min_hit_pos = hit_pos; + } } } - } - min_hit_pos = enemy_m4.Transform(min_hit_pos); + min_hit_pos = enemy_m4.Transform(min_hit_pos); - if (hit) - { - Mesh.Sphere.Draw( - mat_unlit, - Matrix.TS( - min_hit_pos, - 4 * U.cm - ), - Color.White - ); - VFX.Play(min_hit_pos); + if (hit) + { + Mesh.Sphere.Draw( + mat_unlit, + Matrix.TS( + min_hit_pos, + 4 * U.cm + ), + Color.White + ); + VFX.Play(min_hit_pos); + } } }