From 19b2a23a6df6a50ff267dc910110cb736d9ce85e Mon Sep 17 00:00:00 2001 From: spatialfree Date: Mon, 6 Dec 2021 13:00:49 -0500 Subject: [PATCH] oriel manipulation --- Assets/oriel.hlsl | 23 ++++++++++++++++------- Program.cs | 33 ++++++++++++++++++++++++++++----- SpatialCursor.cs | 6 +++--- 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/Assets/oriel.hlsl b/Assets/oriel.hlsl index 3967d26..eb99009 100644 --- a/Assets/oriel.hlsl +++ b/Assets/oriel.hlsl @@ -104,15 +104,19 @@ float sdOctahedron(float3 p, float s) } float map(float3 pos) { - float sphere = sdSphere(pos + float3(0, 0.5, 0), 0.1); + // pos.x = _center.x + pos.x; + // pos.y = _center.y + pos.y; + // pos.z = _center.z - pos.z; + float sphere = sdSphere(pos + float3(0, 0.5, 0) - _center, 0.1); // return sdLink(pos, 0.1, 0.1, 0.1); - float octo = sdOctahedron(pos, 0.1); + float octo = sdOctahedron(pos - _center, 0.1); // return lerp(sphere, octo, windStrength); - float plane = sdPlane(pos, float3(0, 1, 0), 0); + float plane = sdPlane(pos - _center, float3(0, 1, 0), 0); float phere = lerp(plane, sphere, windStrength); return min(phere, octo); + // return octo; } float3 calcNormal(float3 pos) @@ -157,12 +161,17 @@ float calcAO(float3 pos, float3 nor) float4 ps(psIn input) : SV_TARGET { float3 ro = input.world; // ray origin - if (!(sdBox(input.campos, _dimensions / 2) > 0.0)) { + // if (!(sdBox(input.campos, _dimensions / 2) > 0.0)) { + // ro = input.campos; + // // always cull front + // // then replace the input.world with a raymarched box position + // // brings hands into the space + // } + + if (dot(input.norm, input.campos - ro) < 0.0) { ro = input.campos; - // always cull front - // then replace the input.world with a raymarched box position - // brings hands into the space } + float3 rd = normalize(input.world - input.campos); // ray direction // input.color = float4(float3(1,1,1) * max(tri_raycast(input.world, ray), 0.0), 1); diff --git a/Program.cs b/Program.cs index 45b47f0..0d875eb 100644 --- a/Program.cs +++ b/Program.cs @@ -51,11 +51,12 @@ public class Mono { Oriel oriel = new Oriel(); oriel.Start(3); + - // Oriel otherOriel = new Oriel(); - // otherOriel.Start(4); + // Oriel otherOriel = new Oriel(); + // otherOriel.Start(4); - MonoNet net = new MonoNet(this); + MonoNet net = new MonoNet(this); net.Start(); ColorCube colorCube = new ColorCube(); @@ -74,6 +75,9 @@ public class Mono { camMat.SetTexture("diffuse", camTex); Mesh quad = Default.MeshQuad; + bool draggingOriel = false; + Vec3 orielOffset = Vec3.Zero; + Vec3 gripPos = Vec3.Zero; bool domGripping = false, subGripping = false; @@ -378,6 +382,25 @@ public class Mono { + + if (domCon.trigger > 0.5f && subCon.trigger > 0.5f) { + if (!draggingOriel) { + if (oriel.bounds.Contains(net.me.cursor0) || oriel.bounds.Contains(net.me.cursor3)) { + draggingOriel = true; + } + } else { + + oriel.bounds.center = Vec3.Lerp(net.me.cursor0, net.me.cursor3, 0.5f); + // + float distX = Math.Abs(net.me.cursor0.x - net.me.cursor3.x); + float distY = Math.Abs(net.me.cursor0.y - net.me.cursor3.y); + float distZ = Math.Abs(net.me.cursor0.z - net.me.cursor3.z); + oriel.bounds.dimensions = new Vec3(distX, distY, distZ); + } + } else { + draggingOriel = false; + } + oriel.Step(); // otherOriel.bounds.center = Vec3.Forward * -2; @@ -574,7 +597,7 @@ public class Oriel { MaterialBuffer buffer; public void Start(int bufferIndex) { - bounds = new Bounds(Vec3.Zero, new Vec3(1f, 0.5f, 0.5f)); + bounds = new Bounds(Vec3.Forward * 2, new Vec3(1f, 0.5f, 0.5f)); _dimensions = bounds.dimensions; buffer = new MaterialBuffer(bufferIndex); } @@ -626,7 +649,7 @@ public class Oriel { // instead of a quad, just slap the same mesh to the head - + // crown.SetVector("_center", bounds.center); crown.SetFloat("_height", bounds.dimensions.y); crown.SetFloat("_ypos", bounds.center.y); crown.FaceCull = Cull.Front; diff --git a/SpatialCursor.cs b/SpatialCursor.cs index ca17efe..9e1f87d 100644 --- a/SpatialCursor.cs +++ b/SpatialCursor.cs @@ -141,7 +141,7 @@ public class CubicFlow : SpatialCursor { domTwisting = false; } else { if (!domTwisting) { - domUp = domCon.stick.y > 0; + domUp = domCon.stick.x > 0; domTwisting = true; } } @@ -152,7 +152,7 @@ public class CubicFlow : SpatialCursor { subTwisting = false; } else { if (!subTwisting) { - subUp = subCon.stick.y > 0; + subUp = subCon.stick.x < 0; subTwisting = true; } } @@ -164,7 +164,7 @@ public class CubicFlow : SpatialCursor { p3 = sub.position; - if (domUp) { + if (domUp) { // domUp p0 = domTwist.p0; p1 = dom.position; }