refactor out rig code from mono
This commit is contained in:
parent
bfe939b2f7
commit
e9c8e96d7f
3 changed files with 55 additions and 45 deletions
|
@ -39,14 +39,14 @@ static class Arts
|
|||
Mesh.Sphere.Draw(
|
||||
mat_unlit,
|
||||
Matrix.TS(
|
||||
Mono.r_con_stick.position,
|
||||
Rig.r_con_stick.position,
|
||||
5 * U.mm
|
||||
),
|
||||
Color.White
|
||||
);
|
||||
Lines.Add(
|
||||
Mono.r_con_stick.position + V.XYZ(0, 0, 0),
|
||||
Mono.r_con_stick.position + Mono.fullstick * U.cm,
|
||||
Rig.r_con_stick.position + V.XYZ(0, 0, 0),
|
||||
Rig.r_con_stick.position + Rig.fullstick * U.cm,
|
||||
Color.White,
|
||||
2 * U.mm
|
||||
);
|
||||
|
@ -72,7 +72,7 @@ static class Arts
|
|||
mat_mono,
|
||||
Matrix.TRS(
|
||||
Mono.snake[0].ToVec3 + fall,
|
||||
Quat.LookDir(Mono.fullstick),
|
||||
Quat.LookDir(Rig.fullstick),
|
||||
V.XYZ(1, 1, 0.666f + Maths.smooth_stop((float)Mono.step_t) * 0.333f)
|
||||
)
|
||||
);
|
||||
|
|
47
src/Mono.cs
47
src/Mono.cs
|
@ -22,9 +22,7 @@ static class Mono
|
|||
];
|
||||
public static int snake_len = 4;
|
||||
public static int grow_buffer = 0;
|
||||
public static Vec3 fullstick = Vec3.Up;
|
||||
public static Pose r_con_stick = Pose.Identity;
|
||||
public static XYZi snake_dir = new(0, 0, 1), last_snake_dir = new(0, 0, 1);
|
||||
public static XYZi snake_dir = new(0, 0, 1);
|
||||
public static DeltaBool in_box = new(true);
|
||||
public static DeltaBool snake_fall = new(false);
|
||||
public static Dictionary<XYZi, XYZi> holes = new();
|
||||
|
@ -32,6 +30,7 @@ static class Mono
|
|||
public static DeltaBool food_fall = new(false);
|
||||
public static double eat_timestamp = 0.0;
|
||||
|
||||
// put in SFX static class
|
||||
static void PlayBox(this Sound sound, XYZi pos)
|
||||
{
|
||||
sound.Play(box_pose.ToMatrix(box_scale) * pos.ToVec3);
|
||||
|
@ -58,51 +57,17 @@ static class Mono
|
|||
float ssx = Maths.smooth_start(sx);
|
||||
box_pose.orientation *= Quat.FromAngles(0, sx * 180.0f * Time.Stepf, 0);
|
||||
}
|
||||
|
||||
if (Input.Key(Key.A).IsJustActive()) snake_dir = new(-1, 0, 0);
|
||||
if (Input.Key(Key.S).IsJustActive()) snake_dir = new(+1, 0, 0);
|
||||
if (Input.Key(Key.W).IsJustActive()) snake_dir = new(0, 0, -1);
|
||||
if (Input.Key(Key.R).IsJustActive()) snake_dir = new(0, 0, +1);
|
||||
if (Input.Key(Key.Shift).IsJustActive()) snake_dir = new(0, -1, 0);
|
||||
if (Input.Key(Key.Space).IsJustActive()) snake_dir = new(0, +1, 0);
|
||||
|
||||
fullstick = snake_dir.ToVec3;
|
||||
}
|
||||
else
|
||||
{
|
||||
Pose head = Input.Head;
|
||||
box_pose.position = head.position + head.orientation * V.XYZ(0, -(SD_Y + 0.5f) * box_scale, -32 * U.cm);
|
||||
|
||||
Hand r_hand = Input.Hand(Handed.Right);
|
||||
Controller r_con = Input.Controller(Handed.Right);
|
||||
bool con_tracked = r_con.trackedPos > TrackState.Lost;
|
||||
Input.HandVisible(Handed.Max, !con_tracked);
|
||||
if (con_tracked)
|
||||
{
|
||||
Vec2 stick = r_con.stick;
|
||||
Quat stick_rot = Quat.FromAngles(stick.y * -90, 0, stick.x * +90);
|
||||
float stick_sign = r_con.IsStickClicked ? -1 : +1;
|
||||
r_con_stick = r_con.pose;
|
||||
r_con_stick.position += r_con_stick.orientation * V.XYZ(0.0065f, -0.012f, -0.05f);
|
||||
r_con_stick.orientation *= Quat.FromAngles(-50, 0, 0);
|
||||
fullstick = r_con_stick.orientation * stick_rot * Vec3.Up * stick_sign;
|
||||
|
||||
// Vec3 fullstick = r_hand.palm.orientation * Vec3.Up;
|
||||
float ax = Maths.abs(fullstick.x);
|
||||
float ay = Maths.abs(fullstick.y);
|
||||
float az = Maths.abs(fullstick.z);
|
||||
if (ax > ay && ax > az) snake_dir = new(Maths.sign(fullstick.x), 0, 0);
|
||||
if (ay > ax && ay > az) snake_dir = new(0, Maths.sign(fullstick.y), 0);
|
||||
if (az > ax && az > ay) snake_dir = new(0, 0, Maths.sign(fullstick.z));
|
||||
}
|
||||
box_pose.position = Rig.head.position + Rig.head.orientation * V.XYZ(0, -(SD_Y + 0.5f) * box_scale, -32 * U.cm);
|
||||
}
|
||||
|
||||
// catch invalid direction and revert to last_dir
|
||||
if (snake[0] + snake_dir == snake[1])
|
||||
// filter out neck breaking from snake_dir value set
|
||||
if (snake[0] + Rig.new_dir != snake[1])
|
||||
{
|
||||
snake_dir = last_snake_dir;
|
||||
snake_dir = Rig.new_dir;
|
||||
}
|
||||
last_snake_dir = snake_dir;
|
||||
}
|
||||
|
||||
public static void Step()
|
||||
|
|
45
src/Rig.cs
45
src/Rig.cs
|
@ -5,6 +5,13 @@ namespace snake;
|
|||
|
||||
static class Rig
|
||||
{
|
||||
public static Pose head = Pose.Identity;
|
||||
|
||||
public static Vec3 fullstick = Vec3.Up;
|
||||
public static Pose r_con_stick = Pose.Identity;
|
||||
|
||||
public static XYZi new_dir = new(0, 0, 1);
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
|
||||
|
@ -12,6 +19,44 @@ static class Rig
|
|||
|
||||
public static void Frame()
|
||||
{
|
||||
Pose head = Input.Head;
|
||||
|
||||
// flatscreen dev controls
|
||||
if (Device.Name == "Simulator")
|
||||
{
|
||||
if (Input.Key(Key.A).IsJustActive()) new_dir = new(-1, 0, 0);
|
||||
if (Input.Key(Key.S).IsJustActive()) new_dir = new(+1, 0, 0);
|
||||
if (Input.Key(Key.W).IsJustActive()) new_dir = new(0, 0, -1);
|
||||
if (Input.Key(Key.R).IsJustActive()) new_dir = new(0, 0, +1);
|
||||
if (Input.Key(Key.Shift).IsJustActive()) new_dir = new(0, -1, 0);
|
||||
if (Input.Key(Key.Space).IsJustActive()) new_dir = new(0, +1, 0);
|
||||
|
||||
fullstick = new_dir.ToVec3;
|
||||
}
|
||||
else
|
||||
{
|
||||
Hand r_hand = Input.Hand(Handed.Right);
|
||||
Controller r_con = Input.Controller(Handed.Right);
|
||||
bool con_tracked = r_con.trackedPos > TrackState.Lost;
|
||||
Input.HandVisible(Handed.Max, !con_tracked);
|
||||
if (con_tracked)
|
||||
{
|
||||
Vec2 stick = r_con.stick;
|
||||
Quat stick_rot = Quat.FromAngles(stick.y * -90, 0, stick.x * +90);
|
||||
float stick_sign = r_con.IsStickClicked ? -1 : +1;
|
||||
r_con_stick = r_con.pose;
|
||||
r_con_stick.position += r_con_stick.orientation * V.XYZ(0.0065f, -0.012f, -0.05f);
|
||||
r_con_stick.orientation *= Quat.FromAngles(-50, 0, 0);
|
||||
fullstick = r_con_stick.orientation * stick_rot * Vec3.Up * stick_sign;
|
||||
|
||||
// Vec3 fullstick = r_hand.palm.orientation * Vec3.Up;
|
||||
float ax = Maths.abs(fullstick.x);
|
||||
float ay = Maths.abs(fullstick.y);
|
||||
float az = Maths.abs(fullstick.z);
|
||||
if (ax > ay && ax > az) new_dir = new(Maths.sign(fullstick.x), 0, 0);
|
||||
if (ay > ax && ay > az) new_dir = new(0, Maths.sign(fullstick.y), 0);
|
||||
if (az > ax && az > ay) new_dir = new(0, 0, Maths.sign(fullstick.z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue