From cb37a129d1adb403019c96e798e86e2da9667f15 Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Sun, 17 Nov 2019 17:56:04 -0500 Subject: [PATCH] Maze --- Mocap.java | 275 ++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 183 insertions(+), 92 deletions(-) diff --git a/Mocap.java b/Mocap.java index 172ab78..4656cc7 100644 --- a/Mocap.java +++ b/Mocap.java @@ -261,9 +261,11 @@ // 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.CreateSelectedPoint(); + + 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); @@ -324,21 +326,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); } @@ -477,29 +479,52 @@ } } + static cVector centroid = new cVector(); + static cVector mocaporigin = new cVector(); + void SetHipOrientation() { Object3D hip = get(0); + if (toParent == null) + { + toParent = LA.newMatrix(); + fromParent = LA.newMatrix(); + } + LA.matConcat(toParent, hip.get(0).toParent, matrix); - cVector centroid = new cVector(); + 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); +// this.getCentroid(centroid, true); + + CameraPane.CreateSelectedPoint(); + 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 " + goalx + ", " + goalz + ")"); + System.err.println("GOAL change (" + this + "): " + goal + " (was " + goalposx + ", " + goalposz + ")"); - goalx = goal.x; - goalz = goal.z; - targetx = targetz = 0; + goalposx = goal.x; + goalposz = goal.z; + targetdirx = targetdirz = 0; } - if (goalx == 0 && goalz == 0) + if (goalposx == 0 && goalposz == 0) { // No target if (ScriptNode.speaker != null) @@ -533,8 +558,8 @@ //sourcenode.parent.TransformToLocal(dst); this.parent.TransformToLocal(dst); - goalx = dst.x; - goalz = dst.z; + goalposx = dst.x; + goalposz = dst.z; } else return; @@ -550,17 +575,25 @@ double angleYhip = Math.atan2(-temp.z, temp.x); - double angleYtarget = Math.atan2(goalx - centroid.x, goalz - centroid.z); + 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, 1); // 0.1f); + 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); } @@ -614,6 +647,24 @@ // transient // aout 2013 Object3D skeleton; + void ExtractBigData(Object3D o) + { + super.ExtractBigData(o); + + o.savebvh = this.bvh; + o.saveskeleton = this.skeleton; + this.bvh = null; + this.skeleton = null; + } + + void RestoreBigData(Object3D o) + { + super.RestoreBigData(o); + + this.bvh = o.savebvh; + this.skeleton = o.saveskeleton; + } + boolean smoothed; //boolean touched; @@ -637,11 +688,11 @@ double pinx; double pinz; - double targetx; - double targetz; + double targetdirx; + double targetdirz; - double goalx = -20; - double goalz = -10; + double goalposx = 0; // -20; + double goalposz = 0; // -10; boolean followpath; @@ -712,7 +763,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) { @@ -897,7 +948,7 @@ // //GetFileRoot(); // sept 2014: // - GrafreeD.RENDERME = 3; // patch for Merge objects + Grafreed.RENDERME = 3; // patch for Merge objects float[] thedata = bvh.animation.getBoneData(0); os.x = (float) (path.get(i).toParent[3][0]); // - thedata[frame*6]); @@ -947,7 +998,7 @@ get(0).link2master = path.size() > 1; // hip orientation - if (get(0).link2master) + if (get(0).Link2Support()) { rotateonce = 2; } @@ -1278,6 +1329,7 @@ void SetPosition(Object3D sourcenode, cVector floor, long floorid, cVector centroid) { + assert(false); //assert(CameraPane.drawMode == CameraPane.SHADOW); Object3D transformnode = new Object3D(); @@ -1375,7 +1427,7 @@ double w = 0.00015; //if (!sourcenode.link2master) // strong pin on floor - if (parent.link2master) // strong pin on floor + if (parent.Link2Support()) // strong pin on floor { w = 0.005; // .001; } @@ -1481,9 +1533,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) { @@ -1494,7 +1546,7 @@ // mywave = currentwave++; // } // sound - cVector eye = CameraPane.theRenderer.eyeCamera.location; + cVector eye = Globals.theRenderer.EyeCamera().location; // if (sourcenode.parent.parent != null) // sourcenode.parent.parent.TransformToWorld(floor, tmp); @@ -1539,9 +1591,9 @@ //GraphreeD. wav.play(volume * usedvolume); //, mywave); - lastsoundtime = CameraPane.framecount; + lastsoundtime = Globals.framecount; - GrafreeD.hassound = true; + Grafreed.hassound = true; } // else // System.out.println("skipped"); @@ -1560,9 +1612,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) @@ -1589,7 +1641,7 @@ // sourcenode.parent.toParent[3][1] = ground - floor.y; // sourcenode.parent.toParent[3][2] += groundz - floor.z; // sourcenode.parent.toParent[3][1] = K * (ground - floor.y) + (1 - K) * oldposy; - if (footcontact && (sourcenode.parent != null && !sourcenode.parent.link2master)) // strong pin on floor + if (footcontact && (sourcenode.parent != null && !sourcenode.parent.Link2Support())) // strong pin on floor { v0.x = groundx - floor.x; v0.y = 0; // groundx - floor.x; @@ -1628,9 +1680,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); @@ -1640,9 +1692,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; } } @@ -1682,11 +1734,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; } @@ -1737,16 +1789,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); @@ -1798,26 +1850,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(); @@ -1826,13 +1878,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]; @@ -1954,7 +2006,7 @@ // if (sourcenode.link2master) // if (goalx != 0 || goalz != 0) // K = 0.02; // .0625; - if (parent.link2master) // strong pin on floor + if (parent.Link2Support()) // strong pin on floor { K = 0.05; // 0.02; } @@ -2242,7 +2294,7 @@ } if (!smoothed) - for (int i=0; --i>=0;) + for (int i=10; --i>=0;) SmoothAnimData(); // much reduces shakiness smoothed = true; @@ -2280,9 +2332,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) @@ -2364,9 +2423,9 @@ // SetBreakPoint(get(0).toParent[0], 0); // } - boolean setrotation = get(0).link2master && !firsttimeafterload && frame > 0; + boolean setrotation = get(0).Link2Support() && !firsttimeafterload && frame > 0; boolean setposition = sourcenode != null && // sourcenode.parent != null && // july 2014 - sourcenode./*parent.*/link2master && !firsttimeafterload && frame > 0; + sourcenode./*parent.*/Link2Support() && !firsttimeafterload && frame > 0; // cVector centroid = new cVector(); // cVector floor = new cVector(); @@ -2765,7 +2824,8 @@ //if (bone._rotationEnabled) if (//frame > 0 && !bone.skipmocap && - !bone.name.contains("head") // && + !bone.name.contains("head") && + !bone.name.contains("Head") // && // !bone.name.contains("rFoot") && // !bone.name.contains("lFoot") && // !bone.name.contains("Pinky") && @@ -2798,7 +2858,7 @@ // set translation // (currently only possible for root bone! see mocapdata.com data) - if (bone._isRoot && link2master) // && !GetFileRoot().link2master) + if (bone._isRoot && Link2Support()) // && !GetFileRoot().link2master) { if (hasTranslation) // && _translationEnabled) { @@ -3191,7 +3251,7 @@ // july 2014 // goalx = goalz = 0; - targetx = targetz = 0; + targetdirx = targetdirz = 0; //SetPositionDelta(true, true, true, false); // LoadData(); @@ -3201,8 +3261,8 @@ // aout 2013 endframe = 0; // june 2013 - //ResetZero(); - setPose(frame); + ResetZero(); + //setPose(frame); } static int mocapsupport = 0; @@ -3220,12 +3280,13 @@ int step = 1; + // patch for running hare if (speedup) // fev 2014 step *= 2; // 4; if (rewind) // mars 2014 step *= 4; - if (CameraPane.FAST) // && !CameraPane.HOLD) + //if (CameraPane.FAST) // && !CameraPane.HOLD) step *= CameraPane.STEP; //System.err.println("Step Mocap frame # " + frame); @@ -3257,7 +3318,7 @@ "; fullname = " + fullname); //int delta = frame - baseframe; - if (CameraPane.CROWD) + if (Globals.CROWD) { baseframe = GetFirstFrame(); // 0 initial point } @@ -3266,23 +3327,40 @@ // SetPositionDelta(false, true, false); // ?? false); { if (support == null) - ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest); + { + if (bvh == null && new File(fullname).exists()) + ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest); + else + { + SetGlobalTransform(); + Rewind(); + Fade(); + } + } else { - try - { +// try +// { bvh = ((Mocap)support.get(mocapsupport++ % support.Size())).bvh; // SetPositionDelta(false, true, true, true); LoadData(); Rewind(); Fade(); - } - catch (Exception e) - { - e.printStackTrace(); - ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest); - } +// } +// catch (Exception e) +// { +// System.err.println("An error occured while loading data. Use fallback by loading the file."); +// //e.printStackTrace(); +// try +// { +// ObjEditor.LoadBVHFile(fullname, this, false, beginframe, lastframetest); +// } +// catch (Exception e2) +// { +// System.err.println("Motion file not found: " + fullname); +// } +// } } } @@ -3464,6 +3542,7 @@ // filters out bad input data void FilterAnimData() { + new Exception().printStackTrace(); System.exit(0); float[] data; // = bvh.animation.getBoneData(0); @@ -3821,7 +3900,7 @@ transient boolean restarted; // CROWD issue? - void drawSelf(CameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked) + void drawSelf(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked) { //System.err.println("drawSelf Mocap frame # " + frame); //System.err.println("drawSelf Mocap baseframe # " + baseframe); @@ -3838,17 +3917,24 @@ // if (firstframe) // return; - if (!restarted && /*display.restartframe &&*/ - display.isLIVE() && live && display.drawMode == display.SHADOW) // FUCK + if (//!restarted && /*display.restartframe &&*/ + Globals.isLIVE() && live && (display.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || !Globals.COMPUTESHADOWWHENLIVE)) { //display.restartframe = false; restarted = true; + //System.err.println("restarted = true"); Step(); + + Globals.lighttouched = true; } else { - if (display.isLIVE() && live && display.drawMode != display.SHADOW) + //System.err.println("restarted"); + if (Globals.isLIVE() && live && display.DrawMode() != iCameraPane.SHADOW) + { restarted = false; + //System.err.println("restarted = false"); + } } super.drawSelf(display, root, selected, blocked); @@ -3908,6 +3994,11 @@ // GetObject().release(i); } + boolean HasBigData() + { + return skeleton != null; + } + public Object3D get(int i) { if (i != 0) -- Gitblit v1.6.2