From b9a5e6d5232e8182d8e8c39127dd5698f0441ccf Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 11 Nov 2018 18:11:13 +0100 Subject: [PATCH] v3 working transformations and working knie offset :D --- Assets/Foot.cs | 26 +++++++++++++++++++++++--- Assets/Leg.cs | 4 ++++ Assets/Leg.prefab | 3 ++- Assets/Main.unity | 19 +++++++++++++------ 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/Assets/Foot.cs b/Assets/Foot.cs index 19607e5..db17b44 100644 --- a/Assets/Foot.cs +++ b/Assets/Foot.cs @@ -25,6 +25,10 @@ public class Foot : Component public double rotationX=0, rotationY=0, rotationZ=0; public double O1, O2, O3; + public Vector3 transformation = new Vector3(0, 0, 0); + + static float temp = 2; + void RL3() { if ((X == 0) && (Z == 0)) @@ -34,6 +38,9 @@ public class Foot : Component if (X < 0) l3 = l3 * -1; + + //todo + l3 -= temp; } double FO1() @@ -55,7 +62,12 @@ public class Foot : Component double y2 = Y * Y; double z2 = Z * Z; - s = Math.Sqrt(x2 + y2 + z2); + double t = Math.Sqrt(x2 + z2); + t -= temp; + t = t * t; + //todo: X,Z remove distance temp. + s = Math.Sqrt(y2 + t); + //s = Math.Sqrt(x2 + y2 + z2); double t1 = 0; double s2 = s * s; @@ -127,10 +139,14 @@ public class Foot : Component Y += translateY; Z += translateZ; + X -= transformation.x; + Y -= transformation.y; + Z -= transformation.z; + /*RotateX(); RotateY(); RotateZ();*/ - + // the order of these rotation transformations is important!!! Vector3 v = new Vector3((float)X, (float)Y, (float)Z); v = Quaternion.Euler((float)0, (float)rotationY, (float)0) * v; @@ -139,7 +155,7 @@ public class Foot : Component X = v.x; Y = v.y; Z = v.z; - + X -= translateX; Y -= translateY; Z -= translateZ; @@ -153,7 +169,11 @@ public class Foot : Component Z = tx * -1; // run IK + // add adjustment from knie + O1 = (90 - FO1()); + // remove adjustment from knie + O2 = T1(); O3 = 180 - T3(); diff --git a/Assets/Leg.cs b/Assets/Leg.cs index d30967f..50cb6be 100644 --- a/Assets/Leg.cs +++ b/Assets/Leg.cs @@ -14,6 +14,8 @@ public class Leg : MonoBehaviour { public Vector3 point = new Vector3(10, 10, 0); public Quaternion rotation = new Quaternion(0, 0, 0, 0); + public Vector3 transformation = new Vector3(0, 0, 0); + public bool invert = false; public double translateX = 0; @@ -45,6 +47,8 @@ public class Leg : MonoBehaviour { foot.translateY = translateY; foot.translateZ = translateZ; + foot.transformation = transformation; + foot.invert = invert; foot.setleg(); diff --git a/Assets/Leg.prefab b/Assets/Leg.prefab index 19039e7..e597d20 100644 --- a/Assets/Leg.prefab +++ b/Assets/Leg.prefab @@ -1834,7 +1834,7 @@ MeshRenderer: m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 m_Materials: - - {fileID: 10756, guid: 0000000000000000e000000000000000, type: 0} + - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} m_StaticBatchInfo: firstSubMesh: 0 subMeshCount: 0 @@ -3050,6 +3050,7 @@ MonoBehaviour: a3: 0 point: {x: 10, y: 10, z: 0} rotation: {x: 0, y: 0, z: 0, w: 0} + transformation: {x: 0, y: 0, z: 0} invert: 0 translateX: 5 translateY: 0 diff --git a/Assets/Main.unity b/Assets/Main.unity index f36fe7d..17e079f 100644 --- a/Assets/Main.unity +++ b/Assets/Main.unity @@ -34421,6 +34421,7 @@ MonoBehaviour: a3: 0 point: {x: 4, y: -10, z: -13} rotation: {x: 0, y: 0, z: 0, w: 0} + transformation: {x: 0, y: 0, z: 0} invert: 1 translateX: 5 translateY: 0 @@ -48734,6 +48735,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 30ea8dc0510444c42ae4b4db1f5ee2bd, type: 3} m_Name: m_EditorClassIdentifier: + transformation: {x: 0, y: 0, z: 0} rotation: {x: 0, y: 0, z: 0, w: 0} rotation2: - {fileID: 636309705} @@ -54484,7 +54486,7 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 349087549} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalPosition: {x: 0, y: 0, z: 2} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 526007731} @@ -92879,6 +92881,7 @@ MonoBehaviour: a3: 0 point: {x: 0, y: -10, z: 15} rotation: {x: 0, y: 0, z: 0, w: 0} + transformation: {x: 0, y: 0, z: 0} invert: 0 translateX: 0 translateY: 0 @@ -99400,6 +99403,7 @@ MonoBehaviour: a3: 0 point: {x: -4, y: -10, z: 13} rotation: {x: 0, y: 0, z: 0, w: 0} + transformation: {x: 0, y: 0, z: 0} invert: 0 translateX: -5 translateY: 0 @@ -138777,7 +138781,7 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 866778528} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalPosition: {x: 0, y: 0, z: 2} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 246942919} @@ -157414,7 +157418,7 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 986205296} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalPosition: {x: 0, y: 0, z: 2} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 1248951963} @@ -234724,6 +234728,7 @@ MonoBehaviour: a3: 0 point: {x: -4, y: -10, z: -13} rotation: {x: 0, y: 0, z: 0, w: 0} + transformation: {x: 0, y: 0, z: 0} invert: 1 translateX: -5 translateY: 0 @@ -252249,7 +252254,7 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 1573589440} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalPosition: {x: 0, y: 0, z: 2} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 952427227} @@ -259155,6 +259160,7 @@ MonoBehaviour: a3: 0 point: {x: 4, y: -10, z: 13} rotation: {x: 0, y: 0, z: 0, w: 0} + transformation: {x: 0, y: 0, z: 0} invert: 0 translateX: 5 translateY: 0 @@ -283853,6 +283859,7 @@ MonoBehaviour: a3: 0 point: {x: 0, y: -10, z: -15} rotation: {x: 0, y: 0, z: 0, w: 0} + transformation: {x: 0, y: 0, z: 0} invert: 1 translateX: 0 translateY: 0 @@ -290809,7 +290816,7 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 1813824933} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalPosition: {x: 0, y: 0, z: 2} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 1534966623} @@ -305949,7 +305956,7 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 1902568238} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalPosition: {x: 0, y: 0, z: 2} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 1164689000}