stretch cursor initial implementation & asset space rotation fixed

This commit is contained in:
spatialfree 2020-06-23 16:41:02 -07:00
parent 09747638d8
commit 92f3fc5df2
3 changed files with 31 additions and 6 deletions

View file

@ -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?

View file

@ -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)

View file

@ -187,6 +187,11 @@ public class Render
matCursor, 0
);
Graphics.DrawMesh(meshCursor,
input.stretchCursor,
Quaternion.identity,
matCursor, 0
);
polyVector.Frame();
}