ambidextrous / dual slash
This commit is contained in:
parent
7c5c09c3b3
commit
75c80316a5
1 changed files with 87 additions and 59 deletions
146
src/Arts.cs
146
src/Arts.cs
|
@ -69,12 +69,17 @@ static class Arts
|
||||||
mat_both.Chain = mat_backface;
|
mat_both.Chain = mat_backface;
|
||||||
|
|
||||||
mat_slash.FaceCull = Cull.None;
|
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
|
// 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 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
|
// [!] hacky offset stepper for noise
|
||||||
public static int offset = 0;
|
public static int offset = 0;
|
||||||
|
@ -241,70 +246,93 @@ static class Arts
|
||||||
// );
|
// );
|
||||||
|
|
||||||
// blade
|
// blade
|
||||||
Mesh mesh = new();
|
for (int i = 0; i < (int)Handed.Max; i++)
|
||||||
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
|
|
||||||
{
|
{
|
||||||
Matrix enemy_m4 = enemy_test.pose.ToMatrix();
|
Quat blade_ori = Rig.pose_hld[i].orientation;
|
||||||
Ray local_ray = enemy_m4.Inverse.Transform(slash_ray);
|
Vec3 blade_pos = Rig.pose_hld[i].position;
|
||||||
bool hit = false;
|
Vec3 tip_pos = blade_pos + blade_ori * V.XYZ(0, 0, -1);
|
||||||
float min_dist = ray_dist;
|
if (!Rig.holding[i]) // [!] generic placeholder check
|
||||||
Vec3 min_hit_pos = Vec3.Zero;
|
|
||||||
for (int i = 0; i < enemy_test.cols.Count; i++)
|
|
||||||
{
|
{
|
||||||
Sphere col = enemy_test.cols[i];
|
// reset tip buffer
|
||||||
Vec3 hit_pos = Vec3.Zero;
|
for (int j = 0; j < tip_count; j++)
|
||||||
if (col.Intersect(local_ray, out hit_pos))
|
|
||||||
{
|
{
|
||||||
float hit_dist = Vec3.Distance(hit_pos, local_ray.position);
|
tip_buffer[i][j] = tip_pos;
|
||||||
if (hit_dist < min_dist)
|
}
|
||||||
|
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;
|
float hit_dist = Vec3.Distance(hit_pos, local_ray.position);
|
||||||
min_dist = hit_dist;
|
if (hit_dist < min_dist)
|
||||||
min_hit_pos = hit_pos;
|
{
|
||||||
|
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)
|
if (hit)
|
||||||
{
|
{
|
||||||
Mesh.Sphere.Draw(
|
Mesh.Sphere.Draw(
|
||||||
mat_unlit,
|
mat_unlit,
|
||||||
Matrix.TS(
|
Matrix.TS(
|
||||||
min_hit_pos,
|
min_hit_pos,
|
||||||
4 * U.cm
|
4 * U.cm
|
||||||
),
|
),
|
||||||
Color.White
|
Color.White
|
||||||
);
|
);
|
||||||
VFX.Play(min_hit_pos);
|
VFX.Play(min_hit_pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue