From 02e145cb923d601395acc7f15ae9e13f85ef2fbb Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Mon, 02 Jul 2018 21:38:58 -0400 Subject: [PATCH] Hip orientation. --- Mocap.java | 138 ++++++++++++++++++++++++++++++++++++++------- 1 files changed, 116 insertions(+), 22 deletions(-) diff --git a/Mocap.java b/Mocap.java index 93dd7ac..172ab78 100644 --- a/Mocap.java +++ b/Mocap.java @@ -283,28 +283,28 @@ poship.x = hip.get(0).toParent[3][0]; poship.y = hip.get(0).toParent[3][1]; poship.z = hip.get(0).toParent[3][2]; + + temp.x = 1; + temp.y = 0; + temp.z = 0; + + LA.xformDir(temp, hip.get(0).toParent, temp); + + angleYhip = Math.atan2(-temp.z, temp.x); - // AT*AR = A'T*BT*A'R*BR - // - LA.matInvert(hip.get(0).toParent, matrix); + LA.matIdentity(matrix); + LA.matYRotate(matrix, angleYhip); + LA.matTranslate(matrix, poship.x, poship.y, poship.z); + + //LA.matInvert(hip.get(0).toParent, matrix); + LA.matInvert(matrix, matrix); //LA.matIdentity(matrix); //LA.matTranslate(matrix, -poship.x, -poship.y, -poship.z); LA.matConcat(toParent, matrix, toParent); -// poship.x = hip.get(0).toParent[3][0]; -// poship.y = hip.get(0).toParent[3][1]; -// poship.z = hip.get(0).toParent[3][2]; -// -// temp.x = 1; -// temp.y = 0; -// temp.z = 0; -// -// LA.xformDir(temp, hip.get(0).toParent, temp); -// -// angleYhip = Math.atan2(-temp.z, temp.x); - + LA.matConcat(toParent, hip.get(0).toParent, matrix); pos.x = hip.get(0).toParent[3][0]; pos.y = hip.get(0).toParent[3][1]; @@ -476,6 +476,94 @@ currenthip[i] = data[frame3 + i]; } } + + void SetHipOrientation() + { + Object3D hip = get(0); + + LA.matConcat(toParent, hip.get(0).toParent, matrix); + + cVector centroid = new cVector(); + centroid.x = matrix[3][0]; + centroid.y = matrix[3][1]; + centroid.z = matrix[3][2]; + this.getCentroid(centroid, true); + + cVector goal = GetGoal(centroid); + if (goal != null) + { + System.err.println("GOAL change (" + this + "): " + goal + " (was " + goalx + ", " + goalz + ")"); + + goalx = goal.x; + goalz = goal.z; + targetx = targetz = 0; + } + + if (goalx == 0 && goalz == 0) + { + // No target + if (ScriptNode.speaker != null) + { + Object3D sourcenode = GetFileRoot(); + Object3D speakernode = ScriptNode.speaker.GetFileRoot(); + + //System.err.println("speaker is " + speakernode + "; last was " + ScriptNode.lastspeaker); + + Object3D speaker = ScriptNode.speaker; + + if (speakernode == sourcenode) + { + if (ScriptNode.lastspeaker != null) + { + speakernode = ScriptNode.lastspeaker.GetFileRoot(); + speaker = ScriptNode.lastspeaker; + } + else + return; + } + + cVector dst = new cVector(); + + boolean success = speakernode.getCentroid(dst); // , true); + + if (!success) + new Exception().printStackTrace(); + + //speakernode.parent.TransformToWorld(dst); + //sourcenode.parent.TransformToLocal(dst); + this.parent.TransformToLocal(dst); + + goalx = dst.x; + goalz = dst.z; + } + else + return; + } + + cVector temp = new cVector(); + + temp.x = 1; + temp.y = 0; + temp.z = 0; + + LA.xformDir(temp, matrix, temp); + + double angleYhip = Math.atan2(-temp.z, temp.x); + + double angleYtarget = Math.atan2(goalx - centroid.x, goalz - centroid.z); + + LA.matIdentity(matrix); + LA.matTranslate(matrix, -centroid.x, -centroid.y, -centroid.z); + double angle = CurveAngle(0, angleYtarget - angleYhip, 1); // 0.1f); + LA.matYRotate(matrix, angle); + LA.matTranslate(matrix, centroid.x, centroid.y, centroid.z); + + LA.matConcat(matrix, toParent, toParent); + + LA.matInvert(toParent, fromParent); + + CheckForAction(centroid); + } void WriteTo(java.io.Writer writer) throws Exception { @@ -552,8 +640,8 @@ double targetx; double targetz; - double goalx; - double goalz; + double goalx = -20; + double goalz = -10; boolean followpath; @@ -910,6 +998,8 @@ testvect.set(from); testvect.sub(fromto.from); + testvect.y = 0; // PATCH + int factor = 1; //if (CameraPane.FAST) @@ -951,6 +1041,8 @@ testvect.set(from); testvect.sub(fromto.from); + + testvect.y = 0; // PATCH int factor = 1; @@ -2243,6 +2335,8 @@ e.printStackTrace(); } + SetHipOrientation(); + if (true) return; @@ -2670,8 +2764,8 @@ // set rotation //if (bone._rotationEnabled) if (//frame > 0 && - !bone.skipmocap //&& - //!bone.name.contains("head") && + !bone.skipmocap && + !bone.name.contains("head") // && // !bone.name.contains("rFoot") && // !bone.name.contains("lFoot") && // !bone.name.contains("Pinky") && @@ -3056,8 +3150,8 @@ void Reset() { - if (fullname != null) - ReadBVH(); +// if (fullname != null) +// ReadBVH(); Object3D hip = get(0); @@ -3096,7 +3190,7 @@ // LA.matIdentity(rot.fromParent); // july 2014 - goalx = goalz = 0; +// goalx = goalz = 0; targetx = targetz = 0; //SetPositionDelta(true, true, true, false); -- Gitblit v1.6.2