From 92f3fc5df2f603335cf9b14c7f49cdbd39f63643 Mon Sep 17 00:00:00 2001 From: spatialfree Date: Tue, 23 Jun 2020 16:41:02 -0700 Subject: [PATCH] stretch cursor initial implementation & asset space rotation fixed --- Assets/Scripts/AssetSpace.cs | 22 +++++++++++++++++----- Assets/Scripts/Input.cs | 8 ++++++++ Assets/Scripts/Render.cs | 7 ++++++- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/AssetSpace.cs b/Assets/Scripts/AssetSpace.cs index fa5f8c4..7c85551 100644 --- a/Assets/Scripts/AssetSpace.cs +++ b/Assets/Scripts/AssetSpace.cs @@ -31,6 +31,8 @@ public class AssetSpace Mesh mesh = new Mesh(); mesh = polyVector.ToMesh(pgon.vectors); Asset asset = new Asset(); + asset.pos = Vector3.zero; + asset.rot = Quaternion.identity; asset.mesh = mesh; assets.Add(name, asset); } @@ -40,8 +42,11 @@ public class AssetSpace string held = null; Vector3 grabOffset; + // Vector3 oldCursorPos; + Quaternion oldOffConRot; public void Frame(Input input, Render render) { + Vector3 cursorPos = input.stretchCursor; // instead of a rigid uniform list // make it a space where you can lay things out float closest = 1000f; @@ -55,32 +60,36 @@ public class AssetSpace if (input.mainCon.trigger.down) { - float reachDist = Vector3.Distance(asset.pos, input.twistCursor); + float reachDist = Vector3.Distance(asset.pos, cursorPos); if (reachDist < closest) { held = loadedNames[i]; closest = reachDist; - grabOffset = asset.pos - input.twistCursor; + grabOffset = asset.pos - cursorPos; } } } + if (input.mainCon.trigger.held) { if (held != null) { if (input.mainCon.one.up) { - grabOffset = assets[held].pos - input.twistCursor; + grabOffset = assets[held].pos - cursorPos; } if (input.mainCon.one.held) { - assets[held].rot = Quaternion.LookRotation(input.twistCursor - assets[held].pos); + assets[held].rot *= input.offCon.physical.Rot() * Quaternion.Inverse(oldOffConRot); + // assets[held].rot *= Quaternion.LookRotation(cursorPos - assets[held].pos) * + // Quaternion.Inverse(Quaternion.LookRotation(oldCursorPos - assets[held].pos)); + } else { - assets[held].pos = input.twistCursor + grabOffset; + assets[held].pos = cursorPos + grabOffset; } } } @@ -89,6 +98,9 @@ public class AssetSpace held = null; } + oldOffConRot = input.offCon.physical.Rot(); + // oldCursorPos = cursorPos; + // where to store persistent position and rotation? // needs to be saved in the .pixelgon file then // can assetspace have its own save file instead? diff --git a/Assets/Scripts/Input.cs b/Assets/Scripts/Input.cs index ec3d91b..5e25cef 100644 --- a/Assets/Scripts/Input.cs +++ b/Assets/Scripts/Input.cs @@ -15,6 +15,8 @@ public class Input [HideInInspector] public Vector3 twistCursor; + [HideInInspector] + public Vector3 stretchCursor; Vector3 mainCalibDir; Quaternion mainCalibRot; @@ -47,6 +49,12 @@ public class Input Quaternion rot = mainCon.physical.Rot() * Quaternion.Inverse(mainCalibRot); twistCursor = WorldPos(mainCon) + rot * mainCalibDir * calibDist * zValue; + + float stretch = Vector3.Distance(WorldPos(mainCon), WorldPos(offCon)); + stretchCursor = WorldPos(mainCon) + mainCon.physical.Rot() * Vector3.forward * stretch * 3; + + // Some way to switch between + // based on implementation (where switching needs to occur) } public Vector3 WorldPos(Con con) diff --git a/Assets/Scripts/Render.cs b/Assets/Scripts/Render.cs index 7bbf3ed..48c677f 100644 --- a/Assets/Scripts/Render.cs +++ b/Assets/Scripts/Render.cs @@ -180,13 +180,18 @@ public class Render Quaternion.identity, matCursor, 0 ); - + Graphics.DrawMesh(meshCursor, input.twistCursor, Quaternion.identity, matCursor, 0 ); + Graphics.DrawMesh(meshCursor, + input.stretchCursor, + Quaternion.identity, + matCursor, 0 + ); polyVector.Frame(); }