This commit is contained in:
ethan merchant 2024-02-04 01:33:54 -05:00
parent 6589c22037
commit d21cb6c9d3

View file

@ -1,4 +1,4 @@
using System.Security.AccessControl; using System.Security.AccessControl;
namespace Main; namespace Main;
public class Mono { public class Mono {
@ -19,8 +19,6 @@ public class Mono {
Model model_room = Model.FromFile("room.glb"); Model model_room = Model.FromFile("room.glb");
Mesh mesh_room = Mesh.Quad; Mesh mesh_room = Mesh.Quad;
int last_xi = 0;
public class Character { public class Character {
public string character; public string character;
public int[] dots; public int[] dots;
@ -212,6 +210,10 @@ public class Mono {
return layouts[Layout.Colemak][index]; return layouts[Layout.Colemak][index];
} }
Matrix keyboard_m4 = Matrix.Identity;
Rig.Btn keyboard_btn = new();
Vec3 index_pos = Vec3.Zero;
int index_i = 0;
public void Init() { public void Init() {
rig.Init(); rig.Init();
@ -226,7 +228,11 @@ public class Mono {
public void Run() { public void Run() {
rig.Run(); rig.Run();
mat.Run(); // run here or at the end?... or maybe both? keyboard_m4 = Matrix.TRS(
V.XYZ(-0.18f, 1.15f, -0.5f),
Quat.FromAngles(0, 180, 0) * Quat.FromAngles(40, 0, 0),
V.XYZ(-1, -1, 1) * 0.04f
);
// thumb extension // thumb extension
// Matrix palm_ori = rig.hand_1.palm.ToMatrix(); // Matrix palm_ori = rig.hand_1.palm.ToMatrix();
@ -241,54 +247,47 @@ public class Mono {
monoNet.send = true; monoNet.send = true;
} }
int xi = (int)(rig.hand_1.palm.position.x * 25f); Vec3 index_tip = keyboard_m4.Inverse * rig.hand_1.Get(FingerId.Index, JointId.Tip).position;
xi = Math.Clamp(xi + 4, 0, 26); // press
index_pos.z = Math.Clamp(index_tip.z, -0.3f, 0.1f);
keyboard_btn.Frame(index_pos.z > 0.0f, index_pos.z < -0.2f);
Matrix palm_ori = rig.hand_1.palm.ToMatrix(); if (!keyboard_btn.held) {
Vec3 thumb_tip = palm_ori.Inverse * rig.hand_1.Get(FingerId.Thumb, JointId.Tip).position; // snap to grid
Vec3 thumb_minor = palm_ori.Inverse * rig.hand_1.Get(FingerId.Thumb, JointId.KnuckleMinor).position; index_pos.x = (float)Math.Clamp(Math.Round(index_tip.x), 0, 10-1);
if (thumb_tip.x < thumb_minor.x - 0f * U.cm) { index_pos.y = (float)Math.Clamp(Math.Round(index_tip.y), 0, 3-1);
// Log.Info("thumb is out");
xi = 0; index_i = (int)(index_pos.y * 10 + index_pos.x);
} }
if (xi != last_xi) { if (keyboard_btn.frameDown) {
Log.Info($"xi: {xi}"); Log.Info($"index_i: {index_i}");
last_xi = xi; monoNet.value = index_i;
monoNet.value = xi;
monoNet.send = true; monoNet.send = true;
} }
// keyboard // keyboard
Matrix keyboard_m4 = Matrix.TRS(
rig.head_pos + V.XYZ(0, -0.1f, -0.2f),
rig.head_ori * Quat.FromAngles(0, 180, 0),
0.2f
);
Hierarchy.Push(keyboard_m4); Hierarchy.Push(keyboard_m4);
// 3 rows of 10 keys // 3 rows of 10 keys
for (int i = 0; i < 3; i++) { for (int y = 0; y < 3; y++) {
for (int j = 0; j < 10; j++) { for (int x = 0; x < 10; x++) {
Vec3 pos = V.XYZ(x, y, 0);
// background quad // background quad
Mesh.Quad.Draw( Mesh.Quad.Draw(
mat.unlit_clear, mat.unlit_clear,
Matrix.TRS( Matrix.TS(pos, 0.9f),
V.XYZ(j * -0.1f, i * -0.1f, 0.0f) + V.XYZ(0.45f, 0.0f, 0.0f), Color.Hex(0x00000040)
Quat.FromAngles(0, 0, 0),
0.09f
),
Color.Hex(0x00000020)
); );
int index = i * 10 + j; int index = y * 10 + x;
// string text = characters[index].character; // string text = characters[index].character;
string keychar = KeyToChar(index); string keychar = KeyToChar(index);
Text.Add( Text.Add(
keychar, keychar,
Matrix.TS( Matrix.TS(
V.XYZ(j * -0.1f, i * -0.1f, 0.0f) + V.XYZ(0.45f, 0.0f, 0.0f), pos + V.XYZ(-0.3f, -0.3f, 0),
1.0f V.XYZ(-1, -1, 0) * 8.0f
), ),
TextAlign.Center, TextAlign.Center,
TextAlign.Center, TextAlign.Center,
@ -296,17 +295,17 @@ public class Mono {
); );
// show the braille dots(spheres) above the text // show the braille dots(spheres) above the text
for (int k = 0; k < 6; k++) { for (int k = 0; k < 6; k++) {
float spacing = 0.02f; float spacing = 0.2f;
float x_offset = (k % 2) * spacing; float x_offset = (k % 2) * spacing;
float y_offset = (k / 2) * -spacing; float y_offset = (k / 2) * -spacing;
if (char_cell[keychar][k] == 1) { if (char_cell[keychar][k] == 1) {
Mesh.Sphere.Draw( Mesh.Sphere.Draw(
mat.unlit_clear, mat.unlit_clear,
Matrix.TS( Matrix.TS(
V.XYZ(j * -0.1f - x_offset, i * -0.1f + y_offset, 0.0f) + V.XYZ(0.45f + 0.01f, 0.018f, 0.0f), V.XYZ(pos.x + x_offset, pos.y - y_offset, 0) + V.XYZ(-0.1f, -0.18f, 0),
0.01f 0.1f
), ),
Color.Hex(0x80808040) Color.Hex(0xFFFFFFFF)
); );
} }
} }
@ -314,6 +313,16 @@ public class Mono {
} }
Hierarchy.Pop(); Hierarchy.Pop();
// keyboard button
Mesh.Cube.Draw(
mat.unlit_clear,
Matrix.TS(
index_pos * V.XYZ(1, 1, 0.25f),
V.XYZ(0.8f, 0.8f, -index_pos.z * 0.5f)
) * keyboard_m4,
keyboard_btn.held ? Color.Hex(0x00000090) : Color.Hex(0x80808090)
);
// WORLD // WORLD
mesh_room.Draw( mesh_room.Draw(
mat_room, mat_room,
@ -335,5 +344,7 @@ public class Mono {
V.XYZ(2, 2f, 2f) * U.cm, V.XYZ(2, 2f, 2f) * U.cm,
V.XYZ(0, 0, 0) V.XYZ(0, 0, 0)
}; };
mat.Run();
} }
} }