glove birth

This commit is contained in:
spatialfree 2022-01-07 10:39:27 -05:00
parent 63acd14576
commit 0c219a748d
8 changed files with 277 additions and 292 deletions

83
.unity/Bitting.cs Normal file
View file

@ -0,0 +1,83 @@
public class Bitting {
public class DrawKey {
public int x, y;
public Key key;
public DrawKey(int x, int y, Key key) {
this.x = x;
this.y = y;
this.key = key;
}
}
Tex tex = new Tex(TexType.Image, TexFormat.Rgba32);
Material material = Default.Material;
Mesh quad = Default.MeshQuad;
int[,] bitchar = new int[,] {
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
};
DrawKey[] drawKeys = new DrawKey[] {
new DrawKey(0, 0, Key.F), new DrawKey(0, 2, Key.D), new DrawKey(0, 4, Key.S), new DrawKey(0, 6, Key.A),
new DrawKey(2, 0, Key.J), new DrawKey(2, 2, Key.K), new DrawKey(2, 4, Key.L), new DrawKey(2, 6, Key.Semicolon),
}; DrawKey lastKey = null;
public void Start() {
tex.SetSize(128, 128);
tex.SampleMode = TexSample.Point;
material.SetTexture("diffuse", tex);
}
public void Step() {
// clear
if (Input.Key(Key.Space).IsJustActive()) {
for (int i = 0; i < bitchar.GetLength(0); i++) {
for (int j = 0; j < bitchar.GetLength(1); j++) {
bitchar[i, j] = 0;
}
}
lastKey = null;
}
for (int i = 0; i < drawKeys.Length; i++) {
DrawKey drawKey = drawKeys[i];
if (Input.Key(drawKey.key).IsJustActive()) {
bitchar[drawKey.x, drawKey.y] = 1;
if (lastKey != null) {
// draw line between last and current
int x1 = lastKey.x;
int y1 = lastKey.y;
int x2 = drawKey.x;
int y2 = drawKey.y;
int dx = Math.Abs(x2 - x1);
int dy = Math.Abs(y2 - y1);
int sx = x1 < x2 ? 1 : -1;
int sy = y1 < y2 ? 1 : -1;
int err = dx - dy;
while (true) {
bitchar[x1, y1] = 1;
if (x1 == x2 && y1 == y2) break;
int e2 = 2 * err;
if (e2 > -dy) { err -= dy; x1 += sx; }
if (e2 < dx) { err += dx; y1 += sy; }
}
}
lastKey = drawKey;
break;
}
}
Color32[] pixels = new Color32[tex.Width * tex.Height];
tex.GetColors(ref pixels);
for (int i = 0; i < pixels.Length; i++) {
pixels[i] = new Color32(0, 0, 0, 0);
int x = i % tex.Width;
int y = i / tex.Width;
if (x < 3 && y < 7 && bitchar[x, y] == 1) {
pixels[i] = new Color32(0, 255, 255, 0);
}
}
tex.SetColors(tex.Width, tex.Height, pixels);
quad.Draw(material, Matrix.TR(Vec3.Zero, Quat.FromAngles(0, 180, 0)));
}
}

View file

@ -58,9 +58,10 @@ class BlockCon {
float lastPressed = 0;
bool pressed = false;
public void Step(Controller con, Controller otherCon, Vec3 cursor, ref BlockCon otherBlockCon, ref Block[] blocks) {
public void Step(Con con, Con otherCon, Vec3 cursor, ref BlockCon otherBlockCon, ref Block[] blocks) {
bool doublePressed = false;
if (con.trigger > 0.5f) {
if (con.device.trigger > 0.5f) {
if (!pressed) {
if (lastPressed > Time.Totalf - 0.5f) {
doublePressed = true;
@ -91,9 +92,9 @@ class BlockCon {
}
}
Quat conRotDelta = (con.aim.orientation * oldConRot.Inverse).Normalized;
Quat conRotDelta = (con.ori * oldConRot.Inverse).Normalized;
if (con.trigger > 0.1f) {
if (con.device.trigger > 0.1f) {
if (index < 0) {
// BLOCK EXCHANGE
// loop over peer blocks as well
@ -115,7 +116,7 @@ class BlockCon {
blocks[i].solid.SetAngularVelocity(Vec3.Zero);
blocks[i].solid.SetVelocity(Vec3.Zero);
// set
heldRot = (con.aim.orientation.Inverse * blockPose.orientation).Normalized;
heldRot = (con.ori.Inverse * blockPose.orientation).Normalized;
offset = blockPose.orientation.Inverse * (blockPose.position - cursor);
//
@ -125,9 +126,9 @@ class BlockCon {
}
if (index >= 0) {
Quat newRot = (con.aim.orientation * heldRot * spinRot).Normalized;
Quat newRot = (con.ori * heldRot * spinRot).Normalized;
// trackballer
if (con.trigger > 0.99f) {
if (con.device.trigger > 0.99f) {
spinDelta = Quat.Slerp(
spinDelta.Normalized,
(newRot.Inverse * conRotDelta * newRot).Normalized,
@ -135,10 +136,10 @@ class BlockCon {
);
}
spinRot *= spinDelta * spinDelta;
Quat toRot = (con.aim.orientation * heldRot * spinRot).Normalized;
Vec3 toPos = cursor + (con.aim.orientation * heldRot * spinRot).Normalized * offset;
Quat toRot = (con.ori * heldRot * spinRot).Normalized;
Vec3 toPos = cursor + (con.ori * heldRot * spinRot).Normalized * offset;
// cursor - offset;
if (con.stick.y > 0.1f) {
if (con.device.stick.y > 0.1f) {
toRot = blocks[index].solid.GetPose().orientation;
}
blocks[index].solid.Move(toPos, toRot);
@ -147,7 +148,7 @@ class BlockCon {
angularMomentum = Vec3.Lerp(angularMomentum, PullRequest.AngularDisplacement((newHeldRot * oldHeldRot.Inverse).Normalized), Time.Elapsedf / 0.1f);
oldHeldRot = newHeldRot;
delta = (cursor + (con.aim.orientation * heldRot * spinRot).Normalized * offset) - blocks[index].solid.GetPose().position;
delta = (cursor + (con.ori * heldRot * spinRot).Normalized * offset) - blocks[index].solid.GetPose().position;
momentum = Vec3.Lerp(momentum, delta, Time.Elapsedf / 0.1f);
}
} else {
@ -158,6 +159,6 @@ class BlockCon {
index = -1;
}
oldConRot = con.aim.orientation;
oldConRot = con.ori;
}
}

View file

@ -2,7 +2,6 @@ using System;
using StereoKit;
class ColorCube {
static Mesh orb = Default.MeshSphere;
static Mesh cube = Default.MeshCube;
static Material mat = new Material(Shader.FromFile("colorcube.hlsl"));
static Material unlit = Default.MaterialUnlit;
@ -10,7 +9,7 @@ class ColorCube {
public float ogSize = 0.05f;
public float size = 0.05f;
public Vec3 center = Vec3.Zero;
public Vec3 p0 = Vec3.Zero;
public Vec3 cursor = Vec3.Zero;
public Color color = Color.White * 0.5f;
@ -35,8 +34,8 @@ class ColorCube {
float thinn = thicc / 3;
// Vec3 p0s = pos + new Vec3((float)Math.Sin(Time.Totalf) * offset, (float)Math.Sin(Time.Totalf* 2) * offset, (float)Math.Sin(Time.Totalf * 4) * offset);
Vec3 raw = center + (p0 * offset);
Vec3 p00 = p0;
Vec3 raw = center + (cursor * offset);
Vec3 p00 = cursor;
p00.x = Math.Clamp(p00.x, -1, 1);
p00.y = Math.Clamp(p00.y, -1, 1);
p00.z = Math.Clamp(p00.z, -1, 1);
@ -53,7 +52,7 @@ class ColorCube {
}
// everyone get their own color cube? * held in sub hand *
// everyone get their own color cube? * held in off hand *
// or just one?
// or context sensitive?
// can it be networked effectively? well its just a bounds with a shader and cursor, should be easy enough :)

View file

@ -32,8 +32,8 @@ class Cubic {
}
class CubicCon {
public void Step(Controller domCon, Controller subCon, Peer peer, ref Cubic[] cubics) {
bool place = domCon.IsStickJustClicked || subCon.IsStickJustClicked;
public void Step(Con domCon, Con subCon, Peer peer, ref Cubic[] cubics) {
bool place = domCon.device.IsStickJustClicked || subCon.device.IsStickJustClicked;
if (place) {
for (int i = 0; i < cubics.Length; i++) {
if (!cubics[i].active) {

96
app/Glove.cs Normal file
View file

@ -0,0 +1,96 @@
using System;
using StereoKit;
public enum Grab {
Stretch, Backhanded
}
public class Glove {
Monolith mono;
bool chirality;
public ReachCursor reachCursor;
public Glove(Monolith mono, bool chirality) {
this.mono = mono;
this.chirality = chirality;
this.reachCursor = new ReachCursor(mono, chirality);
}
public Vec3 cursor;
public Grab? grabbed = null;
float stretchDeadzone = 0;
Vec3 pullPoint;
// bool rightPlanted = false;
public void Step() {
Pose shoulder = mono.Shoulder(chirality);
Con con = mono.Con(chirality); // !chirality
pullPoint = con.pos;
switch (grabbed) {
case Grab.Stretch:
break;
case Grab.Backhanded:
break;
default:
if (con.gripBtn.frameDown) {
// comparison evaluation
grabbed = Grab.Stretch;
}
break;
}
if (!con.gripBtn.held) {
// null
grabbed = null;
}
// Vec3 from = (shoulder.orientation * origin) + shoulder.position;
float stretch = Vec3.Distance(pullPoint, con.pos);
stretch = Math.Max(stretch - stretchDeadzone, 0);
cursor = con.pos + (con.pos - pullPoint).Normalized * stretch * 3;
Lines.Add(pullPoint, con.pos, new Color(1, 0, 1), 0.005f);
Lines.Add(con.pos, cursor, new Color(0, 1, 1), 0.005f);
// if (con.stick.Magnitude > 0.1f) {
// if (con.stick.y < 0f) {
// rightPlanted = true;
// }
// } else {
// rightPlanted = false;
// }
// if (!rightPlanted) {
// reachCursor.p0 = con.pose.position;
// reachCursor.Calibrate();
// }
// if (con.grip > 0.5f) {
// Vec3 toPos = shoulder.orientation.Inverse * (con.pose.position - shoulder.position);
// if (!rightGripDown) {
// float deadzone = Vec3.Distance(leftReachCursor.origin, toPos);
// if (deadzone < 0.1f) {
// leftReachCursor.deadzone = deadzone;
// rightGripDown = true;
// }
// }
// if (rightGripDown) {
// leftReachCursor.origin = toPos;
// }
// } else {
// leftReachCursor.deadzone = 0;
// rightGripDown = false;
// }
}
}

View file

@ -304,11 +304,11 @@ class Peer {
CubicCon cubicCon = new CubicCon();
public void Step(Controller domCon, Controller subCon) {
dBlock.Step(domCon, subCon, cursor0, ref sBlock, ref blocks);
sBlock.Step(subCon, domCon, cursor3, ref dBlock, ref blocks);
public void Step(Con rCon, Con lCon) {
dBlock.Step(rCon, lCon, cursor0, ref sBlock, ref blocks);
sBlock.Step(lCon, rCon, cursor3, ref dBlock, ref blocks);
cubicCon.Step(domCon, subCon, this, ref cubics);
cubicCon.Step(rCon, lCon, this, ref cubics);
Draw(false);
}

View file

@ -17,19 +17,50 @@ Input.HandVisible(Handed.Max, false);
Monolith mono = new Monolith();
mono.Run();
public class Con {
public Controller device;
public Vec3 pos;
public Quat ori;
public Btn gripBtn;
public Btn triggerBtn;
public void Step(bool chirality) {
device = Input.Controller(Handed.Right);
pos = device.pose.position;
ori = device.aim.orientation;
gripBtn.Step(device.grip > 0.5f);
triggerBtn.Step(device.trigger > 0.5f);
}
}
public class Btn {
public bool frameDown, held, frameUp;
public void Step(bool down) {
frameDown = down && !held;
frameUp = !down && held;
held = down;
}
}
public class Monolith {
public Mic mic;
public Controller rCon, lCon;
public Controller Con(bool chirality) {
return chirality ? rCon : lCon;
public Pose rShoulder, lShoulder;
public Pose Shoulder(bool chirality) {
return chirality ? rShoulder : lShoulder;
}
public Pose rWrist, lWrist;
public Pose Wrist(bool chirality) {
return chirality ? rWrist : lWrist;
}
public Pose rShoulder, lShoulder;
public Pose Shoulder(bool chirality) {
return chirality ? rShoulder : lShoulder;
public Glove lGlove, rGlove;
public Glove Glove(bool chirality) {
return chirality ? rGlove : lGlove;
}
public Con rCon, lCon;
public Con Con(bool chirality) {
return chirality ? rCon : lCon;
}
public Vec3 rDragStart, lDragStart;
@ -73,11 +104,6 @@ public class Monolith {
ColorCube colorCube = new ColorCube();
Vec3 oldLPos = Vec3.Zero;
ReachCursor rightReachCursor = new ReachCursor(this, true);
ReachCursor leftReachCursor = new ReachCursor(this, false);
bool rightPlanted = false;
bool leftPlanted = false;
SpatialCursor cubicFlow = new CubicFlow(this);
Tex camTex = new Tex(TexType.Rendertarget);
@ -87,10 +113,6 @@ public class Monolith {
Mesh quad = Default.MeshQuad;
Vec3 gripPos = Vec3.Zero;
bool rightGripping = false, leftGripping = false;
bool gripLeft = false;
bool rightGripDown = false, leftGripDown = false;
float grindDir = 1f;
@ -101,157 +123,27 @@ public class Monolith {
while (SK.Step(() => {
Renderer.CameraRoot = Matrix.T(pos);
rCon = Input.Controller(Handed.Right);
lCon = Input.Controller(Handed.Left);
cube.Draw(matFloor, floor.GetPose().ToMatrix(floorScale), Color.White * 0.666f);
rCon.Step(true);
lCon.Step(false);
// Shoulders
Vec3 headPos = Input.Head.position + Input.Head.Forward * -0.15f;
Vec3 toLeft = (lCon.pose.position.X0Z - headPos.X0Z).Normalized;
Vec3 toRight = (rCon.pose.position.X0Z - headPos.X0Z).Normalized;
Vec3 middl = (toLeft + toRight).Normalized;
Vec3 shoulderDir = (
(lCon.pos.X0Z - headPos.X0Z).Normalized +
(rCon.pos.X0Z - headPos.X0Z).Normalized
).Normalized;
if (Vec3.Dot(middl, Input.Head.Forward) < 0) {
middl = -middl;
}
// Lines.Add(headPos.X0Z, headPos.X0Z + toLeft.X0Z, Color.White, 0.005f);
// Lines.Add(headPos.X0Z, headPos.X0Z + toRight.X0Z, Color.White, 0.005f);
// Lines.Add(headPos.X0Z, headPos.X0Z + middl.X0Z, Color.White, 0.005f);
// cube.Draw(mat, Matrix.TRS(headPos, Input.Head.orientation, new Vec3(0.3f, 0.3f, 0.3f)));
rShoulder = new Pose(
headPos + Quat.LookDir(middl) * new Vec3(0.2f, -0.2f, 0),
Quat.LookDir(middl)
);
lShoulder = new Pose(
headPos + Quat.LookDir(middl) * new Vec3(-0.2f, -0.2f, 0),
Quat.LookDir(middl)
);
rWrist = new Pose(
rCon.pose.position + rCon.aim.orientation * new Vec3(0, 0, 0.052f),
rCon.aim.orientation
);
lWrist = new Pose(
lCon.pose.position + lCon.aim.orientation * new Vec3(0, 0, 0.052f),
lCon.aim.orientation
);
// cube.Draw(mat, Matrix.TRS(headPos, Input.Head.orientation, new Vec3(0.25f, 0.3f, 0.3f)), new Color(1,0,0));
// Lines.Add(headPos + Vec3.Up * -0.2f, rShoulder, new Color(1, 0, 0), 0.01f);
// Lines.Add(headPos + Vec3.Up * -0.2f, lShoulder, new Color(1, 0, 0), 0.01f);
// if (domCon.IsX1JustPressed) {
// domPlanted = !domPlanted;
// }
// if (subCon.IsX1JustPressed) {
// subPlanted = !subPlanted;
// }
if (Vec3.Dot(shoulderDir, Input.Head.Forward) < 0) { shoulderDir = -shoulderDir; }
rShoulder = new Pose(headPos + Quat.LookDir(shoulderDir) * new Vec3(0.2f, -0.2f, 0), Quat.LookDir(shoulderDir));
lShoulder = new Pose(headPos + Quat.LookDir(shoulderDir) * new Vec3(-0.2f, -0.2f, 0), Quat.LookDir(shoulderDir));
rWrist = new Pose(rCon.pos + rCon.ori * new Vec3(0, 0, 0.052f), rCon.ori);
lWrist = new Pose(lCon.pos + lCon.ori * new Vec3(0, 0, 0.052f), lCon.ori);
// past this point more questions arise
// there is a lot of stuff in this class that needs to move out
// as we need to make way for an oriel game, for god's sake
// start with the largest and work our way down
// is there someway to package these systems in a sensible way
// there is something about a player here... though that may be to general...
// don't crash if server isn't up
// its not tho...
if (rCon.stick.Magnitude > 0.1f) {
if (rCon.stick.y < 0f) {
rightPlanted = true;
}
} else {
rightPlanted = false;
}
if (lCon.stick.Magnitude > 0.1f) {
if (lCon.stick.y < 0f) {
leftPlanted = true;
}
} else {
leftPlanted = false;
}
if (!rightPlanted) {
rightReachCursor.p0 = rCon.pose.position;
rightReachCursor.Calibrate();
}
if (!leftPlanted) {
leftReachCursor.p0 = lCon.pose.position;
leftReachCursor.Calibrate();
}
if (rCon.grip > 0.5f) {
Vec3 toPos = lShoulder.orientation.Inverse * (rCon.pose.position - lShoulder.position);
if (!rightGripDown) {
float deadzone = Vec3.Distance(leftReachCursor.origin, toPos);
if (deadzone < 0.1f) {
leftReachCursor.deadzone = deadzone;
rightGripDown = true;
}
}
if (rightGripDown) {
leftReachCursor.origin = toPos;
}
} else {
leftReachCursor.deadzone = 0;
rightGripDown = false;
}
if (lCon.grip > 0.5f) {
Vec3 toPos = rShoulder.orientation.Inverse * (lCon.pose.position - rShoulder.position);
if (!leftGripDown) {
float deadzone = Vec3.Distance(rightReachCursor.origin, toPos);
if (deadzone < 0.1f) {
rightReachCursor.deadzone = deadzone;
leftGripDown = true;
}
}
if (leftGripDown) {
rightReachCursor.origin = toPos;
}
} else {
rightReachCursor.deadzone = 0;
leftGripDown = false;
}
rightReachCursor.Step(new Pose[] { rCon.pose }, 0.2f);
leftReachCursor.Step(new Pose[] { lCon.pose }, 0.2f);
// enum GripState {
// None,
// Grip,
// Release,
// }
// GripState rightState = GripState.None;
// GripState leftState = GripState.None;
// switch ()
cubicFlow.Step(new Pose[] { new Pose(rightReachCursor.p0, rCon.aim.orientation), new Pose(leftReachCursor.p0, lCon.aim.orientation) }, 1);
cubicFlow.Step(new Pose[] { new Pose(rightReachCursor.p0, rCon.ori), new Pose(leftReachCursor.p0, lCon.ori) }, 1);
if (rCon.stick.y > 0.1f || lCon.stick.y > 0.1f) {
Bezier.Draw(cubicFlow.p0, cubicFlow.p1, cubicFlow.p2, cubicFlow.p3, Color.White);
net.me.cursor0 = cubicFlow.p0; net.me.cursor1 = cubicFlow.p1; net.me.cursor2 = cubicFlow.p2; net.me.cursor3 = cubicFlow.p3;
@ -334,7 +226,7 @@ public class Monolith {
// };
// Bezier.Draw(rail);
if (rCon.grip > 0.5f) {
if (rCon.device.grip > 0.5f) {
if (!grinded) {
if (!grinding) {
int closest = 0;
@ -351,7 +243,7 @@ public class Monolith {
};
for (int j = 0; j < rail.Length; j++) {
Vec3 point = Bezier.Sample(rail, (float)j / (rail.Length - 1f));
float dist = Vec3.Distance(point, rCon.pose.position + vel.Normalized * 0.25f);
float dist = Vec3.Distance(point, rCon.pos + vel.Normalized * 0.25f);
if (dist < closestDist && dist < 0.5f) {
closest = j;
closestRail = i;
@ -384,7 +276,7 @@ public class Monolith {
// vel += (toPos - fromPos);
pos = -(rCon.pose.position - Input.Head.position) + grindPos - (Input.Head.position - pos);
pos = -(rCon.pos - Input.Head.position) + grindPos - (Input.Head.position - pos);
vel = Vec3.Zero;
railT += Time.Elapsedf * grindVel.Magnitude * grindDir; // scale based on length of rail * calculate and cache on place
@ -439,35 +331,34 @@ public class Monolith {
vel *= 1 - Time.Elapsedf * 0.2f;
// COLOR CUBE
// reveal when palm up
float reveal = lCon.pose.Right.y * 1.666f;
float look = 1 - Math.Clamp((1 - Math.Clamp(Vec3.Dot((lCon.pose.position - Input.Head.position).Normalized, Input.Head.Forward), 0f, 1f)) * 5f, 0f, 1f);
float reveal = lCon.device.pose.Right.y * 1.666f;
float look = 1 - Math.Clamp((1 - Math.Clamp(Vec3.Dot((lCon.device.pose.position - Input.Head.position).Normalized, Input.Head.Forward), 0f, 1f)) * 5f, 0f, 1f);
reveal *= look;
colorCube.size = colorCube.ogSize * Math.Clamp(reveal, 0, 1);
colorCube.center = lCon.pose.position + lCon.pose.Right * 0.0666f;
colorCube.center = lCon.device.pose.position + lCon.device.pose.Right * 0.0666f;
// move with grip
if (reveal > colorCube.thicc && !leftPlanted) {
if (reveal > 1f && lCon.trigger > 0.5f) {
colorCube.p0 -= (lCon.pose.position - oldLPos) / colorCube.ogSize * 2;
if (reveal > colorCube.thicc) { // !leftPlanted
if (reveal > 1f && lCon.device.trigger > 0.5f) {
colorCube.cursor -= (lCon.device.pose.position - oldLPos) / colorCube.ogSize * 2;
} else {
// clamp 0 - 1
colorCube.p0.x = Math.Clamp(colorCube.p0.x, -1, 1);
colorCube.p0.y = Math.Clamp(colorCube.p0.y, -1, 1);
colorCube.p0.z = Math.Clamp(colorCube.p0.z, -1, 1);
colorCube.cursor.x = Math.Clamp(colorCube.cursor.x, -1, 1);
colorCube.cursor.y = Math.Clamp(colorCube.cursor.y, -1, 1);
colorCube.cursor.z = Math.Clamp(colorCube.cursor.z, -1, 1);
}
colorCube.Step();
}
oldLPos = lCon.pose.position;
oldLPos = lCon.device.pose.position;
// net.me.cursorA = Vec3.Up * (float)Math.Sin(Time.Total);
net.me.color = colorCube.color;
// net.me.cursor0 = cubicFlow.p0; net.me.cursor1 = cubicFlow.p1;
// net.me.cursor2 = cubicFlow.p2; net.me.cursor3 = cubicFlow.p3;
net.me.headset = Input.Head;
net.me.mainHand = rCon.aim; net.me.offHand = lCon.aim;
net.me.mainHand = new Pose(rCon.pos, rCon.ori);
net.me.offHand = new Pose(lCon.pos, lCon.ori);
for (int i = 0; i < net.peers.Length; i++) {
Peer peer = net.peers[i];
if (peer != null) {
@ -494,6 +385,7 @@ public class Monolith {
// Renderer.RenderTo(camTex, Matrix.TR(Input.Head.position + Vec3.Up * 10, Quat.FromAngles(-90f, 0, 0)), Matrix.Orthographic(2f, 2f, 0.1f, 100f), RenderLayer.All, RenderClear.All);
// quad.Draw(camMat, Matrix.TR(Input.Head.Forward, Quat.FromAngles(0, 180, 0)));
cube.Draw(matFloor, floor.GetPose().ToMatrix(floorScale), Color.White * 0.666f);
})) ;
SK.Shutdown();
}
@ -529,90 +421,6 @@ public class Lerper {
}
}
public class Bitting {
public class DrawKey {
public int x, y;
public Key key;
public DrawKey(int x, int y, Key key) {
this.x = x;
this.y = y;
this.key = key;
}
}
Tex tex = new Tex(TexType.Image, TexFormat.Rgba32);
Material material = Default.Material;
Mesh quad = Default.MeshQuad;
int[,] bitchar = new int[,] {
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0},
};
DrawKey[] drawKeys = new DrawKey[] {
new DrawKey(0, 0, Key.F), new DrawKey(0, 2, Key.D), new DrawKey(0, 4, Key.S), new DrawKey(0, 6, Key.A),
new DrawKey(2, 0, Key.J), new DrawKey(2, 2, Key.K), new DrawKey(2, 4, Key.L), new DrawKey(2, 6, Key.Semicolon),
}; DrawKey lastKey = null;
public void Start() {
tex.SetSize(128, 128);
tex.SampleMode = TexSample.Point;
material.SetTexture("diffuse", tex);
}
public void Step() {
// clear
if (Input.Key(Key.Space).IsJustActive()) {
for (int i = 0; i < bitchar.GetLength(0); i++) {
for (int j = 0; j < bitchar.GetLength(1); j++) {
bitchar[i, j] = 0;
}
}
lastKey = null;
}
for (int i = 0; i < drawKeys.Length; i++) {
DrawKey drawKey = drawKeys[i];
if (Input.Key(drawKey.key).IsJustActive()) {
bitchar[drawKey.x, drawKey.y] = 1;
if (lastKey != null) {
// draw line between last and current
int x1 = lastKey.x;
int y1 = lastKey.y;
int x2 = drawKey.x;
int y2 = drawKey.y;
int dx = Math.Abs(x2 - x1);
int dy = Math.Abs(y2 - y1);
int sx = x1 < x2 ? 1 : -1;
int sy = y1 < y2 ? 1 : -1;
int err = dx - dy;
while (true) {
bitchar[x1, y1] = 1;
if (x1 == x2 && y1 == y2) break;
int e2 = 2 * err;
if (e2 > -dy) { err -= dy; x1 += sx; }
if (e2 < dx) { err += dx; y1 += sy; }
}
}
lastKey = drawKey;
break;
}
}
Color32[] pixels = new Color32[tex.Width * tex.Height];
tex.GetColors(ref pixels);
for (int i = 0; i < pixels.Length; i++) {
pixels[i] = new Color32(0, 0, 0, 0);
int x = i % tex.Width;
int y = i / tex.Width;
if (x < 3 && y < 7 && bitchar[x, y] == 1) {
pixels[i] = new Color32(0, 255, 255, 0);
}
}
tex.SetColors(tex.Width, tex.Height, pixels);
quad.Draw(material, Matrix.TR(Vec3.Zero, Quat.FromAngles(0, 180, 0)));
}
}
public static class PullRequest {
public static void BoundsDraw(Bounds b, float thickness, Color color) {
Vec3 c = Vec3.One / 2;

View file

@ -29,7 +29,6 @@ public class StretchCursor : SpatialCursor {
public override void Calibrate() {}
}
// this is just a stretch cursor derivative
public class ReachCursor : SpatialCursor {
Monolith mono;
bool chirality;
@ -41,11 +40,10 @@ public class ReachCursor : SpatialCursor {
this.max = 10f;
this.deadzone = 0;
}
Vec3 pos;
public Vec3 origin;
public float deadzone;
public override void Step(Pose[] poses, float scalar) {
pos = poses[0].position;
Vec3 pos = poses[0].position;
Vec3 wrist = mono.Wrist(chirality).position;
Pose shoulder = mono.Shoulder(chirality);
@ -83,7 +81,7 @@ public class TwistCursor : SpatialCursor {
public override void Step(Pose[] poses, float scalar) {
Vec3 pos = poses[0].position;
Quat quat = mono.Con(chirality).aim.orientation;
Quat quat = mono.Con(chirality).ori;
Quat from = Quat.LookAt(Vec3.Zero, quat * Vec3.Forward, twistFrom);
float twist = (float)(Math.Acos(Vec3.Dot(from * Vec3.Up, quat * Vec3.Up)) / Math.PI);
outty = Vec3.Dot(from * Vec3.Up, quat * Vec3.Right * (chirality ? 1 : -1)) > 0;
@ -106,7 +104,7 @@ public class TwistCursor : SpatialCursor {
}
}
public override void Calibrate() {
Quat quat = mono.Con(chirality).aim.orientation;
Quat quat = mono.Con(chirality).ori;
twistFrom = quat * Vec3.Up;
}
@ -131,23 +129,23 @@ public class CubicFlow : SpatialCursor {
Pose dom = poses[0];
Pose sub = poses[1];
if (mono.rCon.stick.y < 0.1f) {
if (mono.rCon.device.stick.y < 0.1f) {
domTwist.Calibrate();
domTwisting = false;
} else {
if (!domTwisting) {
domUp = mono.rCon.stick.x > 0;
domUp = mono.rCon.device.stick.x > 0;
domTwisting = true;
}
}
domTwist.Step(new Pose[] { dom }, scalar);
if (mono.lCon.stick.y < 0.1f) {
if (mono.lCon.device.stick.y < 0.1f) {
subTwist.Calibrate();
subTwisting = false;
} else {
if (!subTwisting) {
subUp = mono.lCon.stick.x < 0;
subUp = mono.lCon.device.stick.x < 0;
subTwisting = true;
}
}