refactor and prep Arts for a first person game

This commit is contained in:
ethan merchant 2024-11-29 13:23:21 -05:00
parent 104617e55e
commit caf4608310
2 changed files with 18 additions and 252 deletions

View file

@ -13,13 +13,8 @@ static class Arts
static Material mat_backface = new Material("backface.hlsl"); static Material mat_backface = new Material("backface.hlsl");
static Material mat_justcolor = new Material("justcolor.hlsl"); static Material mat_justcolor = new Material("justcolor.hlsl");
public static Vec3 box_shake = new(0, 0, 0); public static Vec3 shake = new(0, 0, 0);
static Quat food_ori = Quat.Identity; // static Quat spin_ori = Quat.Identity;
static XYZi last_headpos = new(0, 0, 0);
static DeltaBool headmove = new(false);
static XYZi last_tailpos = new(0, 0, 0);
static DeltaBool tailmove = new(false);
static TextStyle text_style; static TextStyle text_style;
@ -57,224 +52,14 @@ static class Arts
// background standin if no passthrough // background standin if no passthrough
} }
// fullstick
Mesh.Sphere.Draw(
mat_unlit,
Matrix.TS(
Rig.r_con_stick.position,
5 * U.mm
),
Color.White
);
Lines.Add(
Rig.r_con_stick.position + V.XYZ(0, 0, 0),
Rig.r_con_stick.position + Rig.fullstick * 1.5f * U.cm,
Color.White,
2 * U.mm
);
// box
box_shake = Vec3.Lerp(box_shake, Vec3.Zero, Time.Stepf / 0.333f);
// scale in
float box_scale = Mono.box_scale; // Maths.min(Maths.smooth_stop(Maths.u_scalar(Time.Totalf - 3)) * Mono.box_scale, Mono.box_scale);
Vec3 box_pos = Mono.box_pose.position + (box_shake * U.cm * 0.333f);
Matrix box_m4 = Matrix.TRS(
box_pos,
Mono.box_pose.orientation,
box_scale
);
// hanger
if (Mono.in_cone.state && Mono.box_mode == Mono.BoxMode.Hold || Mono.box_mode == Mono.BoxMode.Mount)
{
float box_head_dist = Vec3.Distance(box_pos, Rig.head.position);
Lines.Add(
box_m4 * V.XYZ(0, Mono.SD_Y - 0.5f, 0),
Rig.head.position + Rig.head.orientation * V.XYZ(0, 6 * U.cm, -box_head_dist),
Color.Hex(0x808080FF).ToLinear(),
1.0f * U.mm
);
Lines.Add(
Rig.head.position + Rig.head.orientation * V.XYZ(0, 6 * U.cm, -box_head_dist),
Rig.head.position + Rig.head.orientation * V.XYZ(0, 6 * U.cm, 0),
Color.Hex(0x808080FF).ToLinear(),
1.0f * U.mm
);
}
// box contents
Hierarchy.Push(box_m4);
// meshes["InsideOut"].Draw(mat_unlit, Matrix.Identity);
meshes["InsideOut"].Draw(
mat_both,
Matrix.Identity
);
meshes["Corrugation"].Draw(
Mono.in_dist.state ? mat_justcolor : mat_unlit,
Matrix.Identity
);
if (Mono.menu)
{
meshes["Tape"].Draw(mat_mono, Matrix.Identity);
meshes["uiRestart"].Draw(
mat_unlit,
Matrix.TR(
V.XYZ(-1.333f, 0, Mono.SD_Z - 0.5f + 0.1f),
Quat.FromAngles(90, 0, 0)
),
Color.Hex(0x928CA7FF).ToLinear()
);
meshes["uiPlay"].Draw(
mat_unlit,
Matrix.TR(
V.XYZ(0, 0, Mono.SD_Z - 0.5f + 0.1f),
Quat.FromAngles(90, 0, 0)
),
Color.Hex(0x333333FF).ToLinear()
);
meshes["uiConfig"].Draw(
mat_unlit,
Matrix.TR(
V.XYZ(+1.333f, 0, Mono.SD_Z - 0.5f + 0.1f),
Quat.FromAngles(90, 0, 0)
),
Color.Hex(0x928CA7FF).ToLinear()
);
meshes["uiCursor"].Draw(
mat_unlit,
Matrix.TR(
V.XYZ(0, 0, Mono.SD_Z - 0.5f + 0.2f),
Quat.FromAngles(90, 0, 0)
)
);
}
// slash
float slash_t = headmove.state ? Maths.u_clamp(Maths.smooth_stop((float)Mono.step_t) * 3.0f) : 1.0f;
if (!Mono.menu && !Mono.food_next.state)
{
meshes["Tongue"].Draw(
mat_mono,
Matrix.TRS(
Mono.slash[0].ToVec3,
Quat.LookDir(Rig.fullstick),
V.XYZ(1, 1, 0.666f + Maths.smooth_stop((float)Mono.step_t) * 0.333f)
)
);
}
string face = "Face0Default";
face = Mono.grow_buffer > 0 ? "Face2Eaten" : face;
face = Mono.in_box.delta != 0 ? "Face3Bump" : face;
face = Mono.food_next.state ? "Face1Eat" : face;
meshes[face].Draw(
mat_mono,
Matrix.TRS(
Mono.slash[0].ToVec3 - (Mono.slash_dir.ToVec3 * (float)(1.0 - slash_t) * 0.3f),
Quat.LookDir(Mono.slash_dir.ToVec3),
V.XYZ(1, 1, (float)(slash_t))
)
);
for (int i = 1; i < Mono.slash_len; i++)
{
float scale = 1.0f;
if ((int)((Time.Total - Mono.eat_timestamp) * Mono.slash_len / Mono.step_step) == i)
{
scale = 1.1f;
}
meshes["Segment"].Draw(
mat_mono,
Matrix.TRS(
Mono.slash[i].ToVec3,
Quat.LookAt(Mono.slash[i].ToVec3, Mono.slash[i - 1].ToVec3),
scale
)
);
}
// false tail
if (tailmove.state && slash_t < 1.0f)
{
int i_tail = Maths.min(Mono.slash_len, Mono.slash.Length - 1);
Vec3 tail_dir = Vec3.Direction(Mono.slash[i_tail - 1].ToVec3, Mono.slash[i_tail].ToVec3);
meshes["Segment"].Draw(
mat_mono,
Matrix.TRS(
Mono.slash[i_tail].ToVec3 + (tail_dir * (float)(slash_t) * 0.7f),
Quat.LookDir(tail_dir),
V.XYZ(1, 1, (float)(1.0 - slash_t))
)
);
}
// holes
foreach (KeyValuePair<XYZi, XYZi> hole in Mono.holes)
{
Vec3 hole_normal = V.XYZ(
Maths.abs(hole.Value.x) * Maths.sign(hole.Key.x),
Maths.abs(hole.Value.y) * Maths.sign(hole.Key.y),
Maths.abs(hole.Value.z) * Maths.sign(hole.Key.z)
);
// Vec3 hole_world_normal = Mono.box_pose.orientation * hole_normal;
// Vec3 hole_world = Mono.box_pose.ToMatrix(Mono.box_scale) * V.XYZ(
// hole.Key.x - hole.Value.x * 0.5f,
// hole.Key.y - hole.Value.y * 0.5f,
// hole.Key.z - hole.Value.z * 0.5f
// );
// Vec3 cam_dir = (Rig.head.orientation * Vec3.Forward);
// Vec3 hole_view_dir = Vec3.Direction(hole_world, Rig.head.position);
// bool back_hole = Vec3.Dot(hole_world_normal, hole_view_dir) < 0.0;
bool hole_flip = Vec3.Dot(hole_normal, hole.Value.ToVec3) < 0.0;
meshes[hole_flip ? "Hole" : "HoleFlip"].Draw(
mat_both,
Matrix.TRS(
hole.Key.ToVec3,
Quat.LookDir(hole.Value.ToVec3),
1
)
);
}
// food
if (!Mono.food_next.state)
{
food_ori *= Quat.FromAngles(
90 * Time.Stepf,
30 * Time.Stepf,
10 * Time.Stepf
);
}
if (Mono.eaten == 0)
{
// starting egg
bool in_slash = Mono.s_array[new XYZi(0, 0, 0)] > -1;
meshes["Egg"].Draw(
mat_mono,
Matrix.TRS(
Vec3.Zero,
in_slash ? Quat.Identity : food_ori,
in_slash ? 1 : 0.5f
)
);
}
else
{
// food
if (!Mono.eaten_latch.state)
{
float food_t = Mono.eaten_latch.delta == -1 ? Maths.smooth_stop((float)Mono.step_t) : 1;
meshes["Food"].Draw( meshes["Food"].Draw(
mat_mono, mat_mono,
Matrix.TRS( Matrix.TRS(
Mono.food.ToVec3, Vec3.Zero,
food_ori, Quat.Identity,
food_t 1.0f
) )
); );
}
}
// particles // particles
Particle[] particles = VFX.particles; Particle[] particles = VFX.particles;
@ -291,17 +76,22 @@ static class Arts
); );
} }
// menu
Matrix m4_menu = Matrix.TRS(
Vec3.Zero,
Quat.Identity,
U.cm
);
Hierarchy.Push(m4_menu);
// score // score
char[] score_txt = Mono.slash_len.ToString("000").ToCharArray(); char[] score_txt = Mono.slash_len.ToString("000").ToCharArray();
Quat score_ori = Quat.LookDir(Rig.head.position - Mono.box_pose.position);
Vec3 score_pos = score_ori * V.XYZ(0, -Mono.SD_Y - 1.5f, -Mono.SD_Z - 1);
for (int i = 0; i < score_txt.Length; i++) for (int i = 0; i < score_txt.Length; i++)
{ {
Text.Add( Text.Add(
score_txt[i].ToString(), score_txt[i].ToString(),
Matrix.TRS( Matrix.TS(
score_pos + score_ori * V.XYZ((1 - i) * 0.4f, 0, 0), V.XYZ(0, 0, 0),
score_ori,
48 48
), ),
text_style text_style
@ -309,34 +99,10 @@ static class Arts
} }
Hierarchy.Pop(); Hierarchy.Pop();
// for (int sx = -Mono.head_fill.Xslen; Mono.head_fill.InX(sx); sx++)
// {
// for (int sy = -Mono.head_fill.Yslen; Mono.head_fill.InY(sy); sy++)
// {
// for (int sz = -Mono.head_fill.Zslen; Mono.head_fill.InZ(sz); sz++)
// {
// Vec3 pos = Mono.box_pose.ToMatrix(U.cm) * V.XYZ(sx, sy, sz);
// Text.Add(
// (Mono.head_fill[new XYZi(sx, sy, sz)] + Mono.tail_fill[new XYZi(sx, sy, sz)]).ToString(),
// Matrix.TRS(
// pos,
// Quat.LookAt(pos, Input.Head.position),
// 0.1f
// )
// );
// }
// }
// }
} }
public static void Step() public static void Step()
{ {
XYZi slash_head = Mono.slash[0];
XYZi slash_tail = Mono.slash[Mono.slash_len - 1];
headmove.Step(slash_head != last_headpos);
tailmove.Step(slash_tail != last_tailpos);
last_headpos = slash_head;
last_tailpos = slash_tail;
} }
} }

View file

@ -200,7 +200,7 @@ static class Mono
{ {
holes.Add(slash[0], slash_dir); holes.Add(slash[0], slash_dir);
SFX.punch_through.PlayBox(slash[0]); SFX.punch_through.PlayBox(slash[0]);
Arts.box_shake += slash_dir.ToVec3; Arts.shake += slash_dir.ToVec3;
} }
if (holes.ContainsKey(slash[slash_len - 1])) if (holes.ContainsKey(slash[slash_len - 1]))
{ {