From 6ed65dcb597fb2153cef75bf1845978f1115658c Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Fri, 14 Dec 2018 22:53:55 -0500 Subject: [PATCH] Repair shadow, normal push + attractor mesh. --- Mocap.java | 264 +++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 195 insertions(+), 69 deletions(-) diff --git a/Mocap.java b/Mocap.java index 5b79812..f451172 100644 --- a/Mocap.java +++ b/Mocap.java @@ -261,9 +261,9 @@ // LA.matConcat(toParent, hip.get(0).toParent, toParent); - CameraPane.debugpoint.toParent[3][0] = poship.x; - CameraPane.debugpoint.toParent[3][1] = poship.y; - CameraPane.debugpoint.toParent[3][2] = poship.z; + CameraPane.debugpointG.toParent[3][0] = poship.x; + CameraPane.debugpointG.toParent[3][1] = poship.y; + CameraPane.debugpointG.toParent[3][2] = poship.z; LA.matInvert(toParent, fromParent); @@ -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]; @@ -324,21 +324,21 @@ // LA.matYRotate(toParent, angleY - angleYhip); // LA.matTranslate(toParent, pos.x - poship.x, pos.y - poship.y, pos.z - poship.z); - CameraPane.debugpoint2.toParent[3][0] = pos.x; - CameraPane.debugpoint2.toParent[3][1] = pos.y; - CameraPane.debugpoint2.toParent[3][2] = pos.z; + CameraPane.debugpointP.toParent[3][0] = pos.x; + CameraPane.debugpointP.toParent[3][1] = pos.y; + CameraPane.debugpointP.toParent[3][2] = pos.z; - CameraPane.debugpoint3.toParent[3][0] = poship.x; - CameraPane.debugpoint3.toParent[3][1] = poship.y; - CameraPane.debugpoint3.toParent[3][2] = poship.z; + CameraPane.debugpointC.toParent[3][0] = poship.x; + CameraPane.debugpointC.toParent[3][1] = poship.y; + CameraPane.debugpointC.toParent[3][2] = poship.z; poship.x = toParent[3][0]; poship.y = toParent[3][1]; poship.z = toParent[3][2]; - CameraPane.debugpoint4.toParent[3][0] = poship.x; - CameraPane.debugpoint4.toParent[3][1] = poship.y; - CameraPane.debugpoint4.toParent[3][2] = poship.z; + CameraPane.debugpointR.toParent[3][0] = poship.x; + CameraPane.debugpointR.toParent[3][1] = poship.y; + CameraPane.debugpointR.toParent[3][2] = poship.z; LA.matInvert(toParent, fromParent); } @@ -476,6 +476,118 @@ currenthip[i] = data[frame3 + i]; } } + + static cVector centroid = new cVector(); + static cVector mocaporigin = new cVector(); + + void SetHipOrientation() + { + Object3D hip = get(0); + + LA.matConcat(toParent, hip.get(0).toParent, matrix); + + mocaporigin.x = matrix[3][0]; + mocaporigin.y = matrix[3][1]; + mocaporigin.z = matrix[3][2]; + + centroid.x = matrix[3][0]; + centroid.y = matrix[3][1]; + centroid.z = matrix[3][2]; +// this.getCentroid(centroid, true); + + CameraPane.debugpointG.name = ""; + CameraPane.debugpointG.toParent[3][0] = mocaporigin.x; + CameraPane.debugpointG.toParent[3][1] = mocaporigin.y; + CameraPane.debugpointG.toParent[3][2] = mocaporigin.z; + + CameraPane.debugpointP.name = ""; + CameraPane.debugpointP.toParent[3][0] = centroid.x; + CameraPane.debugpointP.toParent[3][1] = centroid.y; + CameraPane.debugpointP.toParent[3][2] = centroid.z; + + cVector goal = GetGoal(centroid); + if (goal != null) + { + System.err.println("GOAL change (" + this + "): " + goal + " (was " + goalposx + ", " + goalposz + ")"); + + goalposx = goal.x; + goalposz = goal.z; + targetdirx = targetdirz = 0; + } + + if (goalposx == 0 && goalposz == 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); + + goalposx = dst.x; + goalposz = 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(goalposx - centroid.x, goalposz - centroid.z); + + LA.matIdentity(matrix); + LA.matTranslate(matrix, -centroid.x, -centroid.y, -centroid.z); + double angle = CurveAngle(0, angleYtarget - angleYhip, 0.1f); + LA.matYRotate(matrix, angle); + LA.matTranslate(matrix, centroid.x, centroid.y, centroid.z); + + LA.matConcat(matrix, toParent, toParent); + + LA.matInvert(toParent, fromParent); + + LA.matConcat(toParent, hip.get(0).toParent, matrix); + + centroid.x = matrix[3][0]; + centroid.y = matrix[3][1]; + centroid.z = matrix[3][2]; + + double dist = LA.distance(centroid, mocaporigin); + + CheckForAction(centroid); + } void WriteTo(java.io.Writer writer) throws Exception { @@ -549,11 +661,11 @@ double pinx; double pinz; - double targetx; - double targetz; + double targetdirx; + double targetdirz; - double goalx; - double goalz; + double goalposx = -20; + double goalposz = -10; boolean followpath; @@ -624,7 +736,7 @@ scriptactions.clear(); } - static double EPSACTION = 0.1; // 0.075; // 0.1; + static double EPSACTION = 0.1; // 0.075; // 0.1;Came void AddFromTo(cVector from, cVector to) { @@ -910,6 +1022,8 @@ testvect.set(from); testvect.sub(fromto.from); + testvect.y = 0; // PATCH + int factor = 1; //if (CameraPane.FAST) @@ -951,6 +1065,8 @@ testvect.set(from); testvect.sub(fromto.from); + + testvect.y = 0; // PATCH int factor = 1; @@ -1186,6 +1302,7 @@ void SetPosition(Object3D sourcenode, cVector floor, long floorid, cVector centroid) { + assert(false); //assert(CameraPane.drawMode == CameraPane.SHADOW); Object3D transformnode = new Object3D(); @@ -1389,9 +1506,9 @@ groundid = floorid; // green - CameraPane.debugpoint.toParent[3][0] = groundx; - CameraPane.debugpoint.toParent[3][1] = floor.y; - CameraPane.debugpoint.toParent[3][2] = groundz; + CameraPane.debugpointG.toParent[3][0] = groundx; + CameraPane.debugpointG.toParent[3][1] = floor.y; + CameraPane.debugpointG.toParent[3][2] = groundz; if (true) // slow && stepout && onein) { @@ -1468,9 +1585,9 @@ // System.out.println("Allo " + sourcenode); // purple - CameraPane.debugpoint2.toParent[3][0] = floor.x;// + posx; - CameraPane.debugpoint2.toParent[3][1] = ground; // floor.y;// + sourcenode.parent.toParent[3][1]; - CameraPane.debugpoint2.toParent[3][2] = floor.z;// + posz; + CameraPane.debugpointP.toParent[3][0] = floor.x;// + posx; + CameraPane.debugpointP.toParent[3][1] = ground; // floor.y;// + sourcenode.parent.toParent[3][1]; + CameraPane.debugpointP.toParent[3][2] = floor.z;// + posz; if (false) // dist2 > 0.1) @@ -1536,9 +1653,9 @@ this.get(0).TransformToWorld(v0); // cyan - CameraPane.debugpoint3.toParent[3][0] = v0.x; - CameraPane.debugpoint3.toParent[3][1] = ground; - CameraPane.debugpoint3.toParent[3][2] = v0.z; + CameraPane.debugpointC.toParent[3][0] = v0.x; + CameraPane.debugpointC.toParent[3][1] = ground; + CameraPane.debugpointC.toParent[3][2] = v0.z; LA.matConcat(sourcenode.toParent, transformnode.toParent, sourcenode.toParent); LA.matInvert(sourcenode.toParent, sourcenode.fromParent); @@ -1548,9 +1665,9 @@ this.get(0).TransformToWorld(v0); // red - CameraPane.debugpoint4.toParent[3][0] = v0.x; - CameraPane.debugpoint4.toParent[3][1] = ground; - CameraPane.debugpoint4.toParent[3][2] = v0.z; + CameraPane.debugpointR.toParent[3][0] = v0.x; + CameraPane.debugpointR.toParent[3][1] = ground; + CameraPane.debugpointR.toParent[3][2] = v0.z; } } @@ -1590,11 +1707,11 @@ if (goal != null) { - System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalx + ", " + goalz + ")"); + System.err.println("GOAL change (" + sourcenode + "): " + goal + " (was " + goalposx + ", " + goalposz + ")"); //sourcenode.parent.parent.Dump(); - goalx = goal.x; - goalz = goal.z; - targetx = targetz = 0; + goalposx = goal.x; + goalposz = goal.z; + targetdirx = targetdirz = 0; followpath = true; } @@ -1645,16 +1762,16 @@ // } if (false) // !uselast) { - CameraPane.debugpoint.toParent[3][0] = dst.x; - CameraPane.debugpoint.toParent[3][1] = dst.y; - CameraPane.debugpoint.toParent[3][2] = dst.z; + CameraPane.debugpointG.toParent[3][0] = dst.x; + CameraPane.debugpointG.toParent[3][1] = dst.y; + CameraPane.debugpointG.toParent[3][2] = dst.z; } } - if (goalx != 0 || goalz != 0) // TODO + if (goalposx != 0 || goalposz != 0) // TODO { // overwrite speaker orientation - dst.set(goalx,0,goalz); + dst.set(goalposx,0,goalposz); if (sourcenode.parent != null) // july 2014 sourcenode.parent. TransformToLocal(dst); @@ -1706,26 +1823,26 @@ // mars 2014 if (false) // goalx != 0 || goalz != 0) { - targetx = dst.x - src.x; - targetz = dst.z - src.z; + targetdirx = dst.x - src.x; + targetdirz = dst.z - src.z; - if (Math.abs(targetx) > 0.1 || Math.abs(targetz) > 0.1) + if (Math.abs(targetdirx) > 0.1 || Math.abs(targetdirz) > 0.1) { // far enough from goal. keep the goal position. - targetx = 0; - targetz = 0; + targetdirx = 0; + targetdirz = 0; } else { // too close to goal. switch to target direction instead. - goalx = 0; - goalz = 0; + goalposx = 0; + goalposz = 0; } } //sourcenode.getCentroid(src, true); - if (speakernode == sourcenode && goalx == 0 && goalz == 0) + if (speakernode == sourcenode && goalposx == 0 && goalposz == 0) { if (ScriptNode.lastspeaker != null) new Exception().printStackTrace(); @@ -1734,13 +1851,13 @@ // LA.xformPos(src, fromParent, src); - if ((ScriptNode.speaker != null && CameraPane.SPEAKERMOCAP || goalx != 0 || goalz != 0) && targetx == 0 && targetz == 0) + if ((ScriptNode.speaker != null && CameraPane.SPEAKERMOCAP || goalposx != 0 || goalposz != 0) && targetdirx == 0 && targetdirz == 0) dst.sub(src); else // vector mode { - dst.x = targetx; - dst.z = targetz; + dst.x = targetdirx; + dst.z = targetdirz; // TEST TARGET // dst.x = CameraPane.selectedpoint.toParent[3][0]; @@ -2188,9 +2305,16 @@ toVector.x = LA.cos(to); toVector.y = LA.sin(to); + double fromA = Math.atan2(fromVector.y, fromVector.x); + double toA = Math.atan2(toVector.y, toVector.x); + Vector2d currentVector = Slerp(fromVector, toVector, step); - return Math.atan2(currentVector.y, currentVector.x); + double angle = Math.atan2(currentVector.y, currentVector.x); + + double angle2 = (1-step) * fromA + step * toA; + + return angle; } public static Vector2d Slerp(Vector2d from, Vector2d to, double step) @@ -2242,6 +2366,8 @@ { e.printStackTrace(); } + + SetHipOrientation(); if (true) return; @@ -2670,8 +2796,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") && @@ -3096,8 +3222,8 @@ // LA.matIdentity(rot.fromParent); // july 2014 - goalx = goalz = 0; - targetx = targetz = 0; +// goalx = goalz = 0; + targetdirx = targetdirz = 0; //SetPositionDelta(true, true, true, false); // LoadData(); -- Gitblit v1.6.2