gun hit test
This commit is contained in:
parent
f5cbacd62e
commit
c4dc1e079f
3 changed files with 58 additions and 12 deletions
59
src/Arts.cs
59
src/Arts.cs
|
@ -55,6 +55,7 @@ static class Arts
|
|||
Matrix m4_world = Mono.world_pose.ToMatrix();
|
||||
Hierarchy.Push(m4_world);
|
||||
|
||||
// mesh test
|
||||
meshes["Food"].Draw(
|
||||
mat_mono,
|
||||
Matrix.TRS(
|
||||
|
@ -64,6 +65,7 @@ static class Arts
|
|||
)
|
||||
);
|
||||
|
||||
// bamboo
|
||||
Mesh.Cube.Draw(
|
||||
mat_unlit,
|
||||
Matrix.TS(
|
||||
|
@ -73,19 +75,30 @@ static class Arts
|
|||
Color.Hex(0xB9E7AFFF)
|
||||
);
|
||||
|
||||
// unit cube
|
||||
Mesh.Cube.Draw(
|
||||
mat_unlit,
|
||||
Matrix.Identity,
|
||||
Color.Hex(0x13180AFF).ToLinear()
|
||||
);
|
||||
|
||||
// enemy
|
||||
Vec3 enemy_pos = V.XYZ(SKMath.Sin(Time.Totalf * 1f) * 1.0f, 0.5f, -1.0f);
|
||||
float enemy_rad = 0.5f;
|
||||
Mesh.Sphere.Draw(
|
||||
mat_unlit,
|
||||
Matrix.TS(enemy_pos, enemy_rad * 2.0f),
|
||||
Color.Hex(0x13180AFF).ToLinear()
|
||||
);
|
||||
|
||||
// blade
|
||||
Mesh mesh = new();
|
||||
Quat hand_rot = Quat.FromAngles(0, 0, SKMath.Sin(Time.Totalf * 6f) * 30f);
|
||||
Vec3 hand_pos = V.XYZ(SKMath.Sin(Time.Totalf * 1f) * 0.1f, 0.5f, 1.0f);
|
||||
Vec3 tip_pos = hand_pos + hand_rot * V.XYZ(0, 1, 0);
|
||||
Quat blade_ori = Quat.FromAngles(0, 0, SKMath.Sin(Time.Totalf * 6f) * 30f);
|
||||
Vec3 blade_pos = V.XYZ(SKMath.Sin(Time.Totalf * 1f) * 0.1f, 0.5f, 1.0f);
|
||||
Vec3 tip_pos = blade_pos + blade_ori * V.XYZ(0, 1, 0);
|
||||
mesh.SetData(
|
||||
new Vertex[] {
|
||||
new( hand_pos, V.XYZ(0,0,1)),
|
||||
new( blade_pos, V.XYZ(0,0,1)),
|
||||
new( tip_pos, V.XYZ(0,0,1)),
|
||||
new(last_tip_pos, V.XYZ(0,0,1))
|
||||
},
|
||||
|
@ -100,6 +113,44 @@ static class Arts
|
|||
);
|
||||
last_tip_pos = Vec3.Lerp(last_tip_pos, tip_pos, Time.Stepf / 0.1f);
|
||||
|
||||
// revolver
|
||||
Quat rvolv_ori = Quat.Identity;
|
||||
Vec3 rvolv_pos = V.XYZ(SKMath.Sin(Time.Totalf * 2f) * 0.6f, 0.5f, 0.5f);
|
||||
|
||||
Lines.Add(
|
||||
rvolv_pos,
|
||||
rvolv_pos + rvolv_ori * V.XYZ(0, 0, -10),
|
||||
Color.Hex(0xF9BF05FF).ToLinear(),
|
||||
U.cm
|
||||
);
|
||||
|
||||
if (true) // hit test
|
||||
{
|
||||
Vec3 hit_delta = rvolv_ori.Inverse * (enemy_pos - rvolv_pos);
|
||||
float flat_z = hit_delta.z;
|
||||
hit_delta.z = 0;
|
||||
float hit_mag = hit_delta.Magnitude;
|
||||
bool hit = hit_mag < enemy_rad;
|
||||
if (hit)
|
||||
{
|
||||
Log.Info("" + hit_mag);
|
||||
float hit_dist = flat_z + (Maths.smooth_stop((enemy_rad - hit_mag) / enemy_rad) * enemy_rad);
|
||||
Vec3 hit_pos = rvolv_pos + rvolv_ori * V.XYZ(0, 0, hit_dist);
|
||||
Mesh.Sphere.Draw(
|
||||
mat_unlit,
|
||||
Matrix.TS(
|
||||
hit_pos,
|
||||
4 * U.cm
|
||||
),
|
||||
Color.White
|
||||
);
|
||||
if (Rig.btn_select.delta == +1)
|
||||
{
|
||||
VFX.Play(hit_pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// particles
|
||||
Particle[] particles = VFX.particles;
|
||||
for (int i = 0; i < particles.Length; i++)
|
||||
|
|
|
@ -64,11 +64,6 @@ static class Mono
|
|||
// orbital_view
|
||||
// box_pose.position = Input.Head.position + Input.Head.orientation * V.XYZ(0, -0 * U.cm, -10 * U.cm);
|
||||
}
|
||||
|
||||
if (Rig.btn_select.delta == +1)
|
||||
{
|
||||
VFX.Play(new XYZi(0, 1, 1));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -16,14 +16,14 @@ static class VFX
|
|||
}
|
||||
}
|
||||
|
||||
public static void Play(XYZi pos)
|
||||
public static void Play(Vec3 pos)
|
||||
{
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
index = (index + 1) % particles.Length;
|
||||
Particle particle = particles[index];
|
||||
particle.pos = pos.ToVec3;
|
||||
particle.vel = Quat.FromAngles(Random.Shared.NextSingle() * 360, 0, 0) * Quat.FromAngles(0, Random.Shared.NextSingle() * 360, 0) * Vec3.Forward * 6.0f;
|
||||
particle.pos = pos;
|
||||
particle.vel = Quat.FromAngles(Random.Shared.NextSingle() * 360, 0, 0) * Quat.FromAngles(0, Random.Shared.NextSingle() * 360, 0) * Vec3.Forward * 1.0f;
|
||||
particle.ori = Quat.Identity;
|
||||
particle.scl = (1.0f / 3) * Maths.smooth_start(Random.Shared.NextSingle());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue