@Override public void compute(ProcessorArmingCollection collection) { degrees += increment; quaternion.fromAngles(0.0f, degrees, 0.0f); quaternion.mult(up, upOut); quaternion.mult(position, positionOut); }
protected void handleRotate(Vector3f start, Vector3f end, float direction) { LOGGER.warning( "Handling rotate, start: " + start + "" + "\nlast: " + lastTranslation + "" + "\nend: " + end); Vector3f increment = end.subtract(lastTranslation); increment.y = 0; float length = increment.length(); float magic = 3f; // ~ 180 degrees float percent = length / magic; // if the difference is negative, we need to rotate in the opposite // direction. Caclulate the difference after taking into account // the direction of the camera // CellTransform viewTransform = ViewManager.getViewManager().getCameraTransform(); // Quaternion viewRotation = viewTransform.getRotation(null); // increment = viewRotation.mult(increment); // // LOGGER.warning("viewTransform: " + viewTransform + ", increment: " + // increment); // // if (increment.x < 0 || increment.z < 0) { // percent = -percent; // } // take direction into account percent *= direction; Quaternion rotation = new Quaternion(); rotation.fromAngles(0f, percent * FastMath.PI, 0f); // rotation is the total rotation since we started moving the mouse, // so calculate just the delta to apply Quaternion deltaRotation = rotation.mult(lastRotation.inverse()); LOGGER.warning( "Percent: " + percent + " = " + toAnglesString(rotation) + ". Last = " + toAnglesString(lastRotation) + ". Delta = " + toAnglesString(deltaRotation)); applyDelta(Vector3f.ZERO, deltaRotation); }
public ModulatorThreeNodes( ModulatorRenderer Renderer, String node1Name, String node2Name, String node3Name) { renderer = Renderer; rotFinal.fromAngles(0.0f, 0.0f, 0.0f); node1theSpatial = renderer.getNode(node1Name); System.out.println("node1theSpatial = " + node1theSpatial); al = node1theSpatial.getControllers(); Tco = node1theSpatial.getController(0); // float max = Tco.getMaxTime(); // float min = Tco.getMinTime(); Tac = (AnimationController) Tco; Tani = Tac.getAnimation(0); Tkft = Tani.getKeyFrameTimes(); if (traceLoad) System.out.println("node1Tkft size = " + Tkft.length); // Make storage for the transforms at each keyframe transX = new float[Tkft.length]; transY = new float[Tkft.length]; transZ = new float[Tkft.length]; angleX = new float[Tkft.length]; angleY = new float[Tkft.length]; angleZ = new float[Tkft.length]; // Make storage for the Quats that will hold the rotates at each keyframe node1keyFrames = new Quaternion[Tkft.length]; // and the vectors that will hold the translates node1keyTrans = new Vector3f[Tkft.length]; // There wil be multiple animations for the same node. Each animation will express one (?) of // the // directions of rotation or one of the directions of translation, or combinations. All the // rotations // for a key frame combined together will be the full rotation. All the translations for a key // frame // summed together will be the total translation for the key frame. Scaling should have the same // structure // when I get it added. // The result of all this will be a series of Quaternions, one for each key frame start and one // to finish // that contain the rotations for each keyframe. Also, there will be a set of vectors that // contain // the translations. // Step through the animation controllers to pick up the changes at each key frame for (int k = 0; k < al.size(); k++) { if (traceLoad) System.out.println("Controller = " + al.get(k).toString()); // Get the controller and then cast it to an animation controller Controller co = node1theSpatial.getController(k); AnimationController ac = (AnimationController) co; // Get the animations for this controller ArrayList bans = ac.getAnimations(); // Step through the animations for (int i = 0; i < bans.size(); i++) { // Get this animation BoneAnimation ani = ac.getAnimation(i); // Get the frame times for this animation float kft[] = ani.getKeyFrameTimes(); if (traceLoad) { System.out.println("kft size = " + kft.length); for (int j = 0; j < kft.length; j++) { System.out.println("kft - " + kft[j]); } } ArrayList<BoneTransform> bt = ani.getBoneTransforms(); if (traceLoad) { System.out.println("bt size = " + bt.size()); for (int j = 0; j < bt.size(); j++) { System.out.println("bt = " + bt.get(j).toString()); } } Quaternion qt[] = bt.get(0).getRotations(); if (traceLoad) System.out.println("bt - rotations = " + qt.length); for (int j = 0; j < qt.length; j++) { if (traceLoad) System.out.println("rots = " + qt[j]); float[] fromAngles = qt[j].toAngles(null); if (traceLoad) System.out.println( "Angles - " + fromAngles[0] + " - " + fromAngles[1] + " - " + fromAngles[2]); angleX[j] = angleX[j] + fromAngles[0]; angleY[j] = angleY[j] + fromAngles[1]; angleZ[j] = angleZ[j] + fromAngles[2]; } if (traceLoad) System.out.println( " start frame = " + ani.getStartFrame() + " - end frame = " + ani.getEndFrame()); Vector3f v3f[] = bt.get(0).getTranslations(); if (traceLoad) System.out.println("bt - translations = " + v3f.length); for (int j = 0; j < v3f.length; j++) { if (traceLoad) System.out.println("trans = " + v3f[j]); transX[j] = transX[j] + v3f[j].x; transY[j] = transY[j] + v3f[j].y; transZ[j] = transZ[j] + v3f[j].z; } } } // Build the final key frame Quats from the extracted angles and the Vectors from the extracted // translates for (int j = 0; j < Tkft.length; j++) { Quaternion temp = null; temp = new Quaternion(); temp.fromAngles(angleX[j], angleY[j], angleZ[j]); if (traceLoad) System.out.println( " ********************** final angles " + angleX[j] + "--" + angleY[j] + "--" + angleZ[j]); node1keyFrames[j] = temp; node1keyTrans[j] = new Vector3f(transX[j], transY[j], transZ[j]); if (traceLoad) System.out.println( " *************** final translations " + transX[j] + " - " + transY[j] + " - " + transZ[j]); } // ************************************************************************************************* // ************************************************************************************************* node2theSpatial = renderer.getNode(node2Name); System.out.println("theSpatial = " + node2theSpatial); al = node2theSpatial.getControllers(); Tco = node2theSpatial.getController(0); // float max = Tco.getMaxTime(); // float min = Tco.getMinTime(); Tac = (AnimationController) Tco; Tani = Tac.getAnimation(0); Tkft = Tani.getKeyFrameTimes(); if (traceLoad) System.out.println("node2Tkft size = " + Tkft.length); // Make storage for the transforms at each keyframe transX = new float[Tkft.length]; transY = new float[Tkft.length]; transZ = new float[Tkft.length]; angleX = new float[Tkft.length]; angleY = new float[Tkft.length]; angleZ = new float[Tkft.length]; // Make storage for the Quats that will hold the rotates at each keyframe node2keyFrames = new Quaternion[Tkft.length]; // and the vectors that will hold the translates node2keyTrans = new Vector3f[Tkft.length]; // There wil be multiple animations for the same node. Each animation will express one (?) of // the // directions of rotation or one of the directions of translation, or combinations. All the // rotations // for a key frame combined together will be the full rotation. All the translations for a key // frame // summed together will be the total translation for the key frame. Scaling should have the same // structure // when I get it added. // The result of all this will be a series of Quaternions, one for each key frame start and one // to finish // that contain the rotations for each keyframe. Also, there will be a set of vectors that // contain // the translations. // Step through the animation controllers to pick up the changes at each key frame for (int k = 0; k < al.size(); k++) { if (traceLoad) System.out.println("Controller = " + al.get(k).toString()); // Get the controller and then cast it to an animation controller Controller co = node2theSpatial.getController(k); AnimationController ac = (AnimationController) co; // Get the animations for this controller ArrayList bans = ac.getAnimations(); // Step through the animations for (int i = 0; i < bans.size(); i++) { // Get this animation BoneAnimation ani = ac.getAnimation(i); // Get the frame times for this animation float kft[] = ani.getKeyFrameTimes(); if (traceLoad) { System.out.println("kft size = " + kft.length); for (int j = 0; j < kft.length; j++) { System.out.println("kft - " + kft[j]); } } ArrayList<BoneTransform> bt = ani.getBoneTransforms(); if (traceLoad) { System.out.println("bt size = " + bt.size()); for (int j = 0; j < bt.size(); j++) { System.out.println("bt = " + bt.get(j).toString()); } } Quaternion qt[] = bt.get(0).getRotations(); if (traceLoad) System.out.println("bt - rotations = " + qt.length); for (int j = 0; j < qt.length; j++) { if (traceLoad) System.out.println("rots = " + qt[j]); float[] fromAngles = qt[j].toAngles(null); if (traceLoad) System.out.println( "Angles - " + fromAngles[0] + " - " + fromAngles[1] + " - " + fromAngles[2]); angleX[j] = angleX[j] + fromAngles[0]; angleY[j] = angleY[j] + fromAngles[1]; angleZ[j] = angleZ[j] + fromAngles[2]; } if (traceLoad) System.out.println( " start frame = " + ani.getStartFrame() + " - end frame = " + ani.getEndFrame()); Vector3f v3f[] = bt.get(0).getTranslations(); if (traceLoad) System.out.println("bt - translations = " + v3f.length); for (int j = 0; j < v3f.length; j++) { if (traceLoad) System.out.println("trans = " + v3f[j]); transX[j] = transX[j] + v3f[j].x; transY[j] = transY[j] + v3f[j].y; transZ[j] = transZ[j] + v3f[j].z; } } } // Build the final key frame Quats from the extracted angles and the Vectors from the extracted // translates for (int j = 0; j < Tkft.length; j++) { Quaternion temp = null; temp = new Quaternion(); temp.fromAngles(angleX[j], angleY[j], angleZ[j]); if (traceLoad) System.out.println( " ********************** final angles " + angleX[j] + "--" + angleY[j] + "--" + angleZ[j]); node2keyFrames[j] = temp; node2keyTrans[j] = new Vector3f(transX[j], transY[j], transZ[j]); if (traceLoad) System.out.println( " *************** final translations " + transX[j] + " - " + transY[j] + " - " + transZ[j]); } // ************************************************************************************************* // ************************************************************************************************* node3theSpatial = renderer.getNode(node3Name); System.out.println("node3theSpatial = " + node3theSpatial); al = node3theSpatial.getControllers(); Tco = node3theSpatial.getController(0); // float max = Tco.getMaxTime(); // float min = Tco.getMinTime(); Tac = (AnimationController) Tco; Tani = Tac.getAnimation(0); Tkft = Tani.getKeyFrameTimes(); if (traceLoad) System.out.println("node3Tkft size = " + Tkft.length); // Make storage for the transforms at each keyframe transX = new float[Tkft.length]; transY = new float[Tkft.length]; transZ = new float[Tkft.length]; angleX = new float[Tkft.length]; angleY = new float[Tkft.length]; angleZ = new float[Tkft.length]; // Make storage for the Quats that will hold the rotates at each keyframe node3keyFrames = new Quaternion[Tkft.length]; // and the vectors that will hold the translates node3keyTrans = new Vector3f[Tkft.length]; // There wil be multiple animations for the same node. Each animation will express one (?) of // the // directions of rotation or one of the directions of translation, or combinations. All the // rotations // for a key frame combined together will be the full rotation. All the translations for a key // frame // summed together will be the total translation for the key frame. Scaling should have the same // structure // when I get it added. // The result of all this will be a series of Quaternions, one for each key frame start and one // to finish // that contain the rotations for each keyframe. Also, there will be a set of vectors that // contain // the translations. // Step through the animation controllers to pick up the changes at each key frame for (int k = 0; k < al.size(); k++) { if (traceLoad) System.out.println("Controller = " + al.get(k).toString()); // Get the controller and then cast it to an animation controller Controller co = node3theSpatial.getController(k); AnimationController ac = (AnimationController) co; // Get the animations for this controller ArrayList bans = ac.getAnimations(); // Step through the animations for (int i = 0; i < bans.size(); i++) { // Get this animation BoneAnimation ani = ac.getAnimation(i); // Get the frame times for this animation float kft[] = ani.getKeyFrameTimes(); if (traceLoad) { System.out.println("kft size = " + kft.length); for (int j = 0; j < kft.length; j++) { System.out.println("kft - " + kft[j]); } } ArrayList<BoneTransform> bt = ani.getBoneTransforms(); if (traceLoad) { System.out.println("bt size = " + bt.size()); for (int j = 0; j < bt.size(); j++) { System.out.println("bt = " + bt.get(j).toString()); } } Quaternion qt[] = bt.get(0).getRotations(); if (traceLoad) System.out.println("bt - rotations = " + qt.length); for (int j = 0; j < qt.length; j++) { if (traceLoad) System.out.println("rots = " + qt[j]); float[] fromAngles = qt[j].toAngles(null); if (traceLoad) System.out.println( "Angles - " + fromAngles[0] + " - " + fromAngles[1] + " - " + fromAngles[2]); angleX[j] = angleX[j] + fromAngles[0]; angleY[j] = angleY[j] + fromAngles[1]; angleZ[j] = angleZ[j] + fromAngles[2]; } if (traceLoad) System.out.println( " start frame = " + ani.getStartFrame() + " - end frame = " + ani.getEndFrame()); Vector3f v3f[] = bt.get(0).getTranslations(); if (traceLoad) System.out.println("bt - translations = " + v3f.length); for (int j = 0; j < v3f.length; j++) { if (traceLoad) System.out.println("trans = " + v3f[j]); transX[j] = transX[j] + v3f[j].x; transY[j] = transY[j] + v3f[j].y; transZ[j] = transZ[j] + v3f[j].z; } } } // Build the final key frame Quats from the extracted angles and the Vectors from the extracted // translates for (int j = 0; j < Tkft.length; j++) { Quaternion temp = null; temp = new Quaternion(); temp.fromAngles(angleX[j], angleY[j], angleZ[j]); if (traceLoad) System.out.println( " ********************** final angles " + angleX[j] + "--" + angleY[j] + "--" + angleZ[j]); node3keyFrames[j] = temp; node3keyTrans[j] = new Vector3f(transX[j], transY[j], transZ[j]); if (traceLoad) System.out.println( " *************** final translations " + transX[j] + " - " + transY[j] + " - " + transZ[j]); } }
public void animateNode() { Vector3f v3f; int startFrame = 0; int endFrame = 0; float zRotationInc = 0.0f; float xRotationInc = 0.0f; System.out.println("animateNode"); v3f = node1theSpatial.getLocalTranslation(); System.out.println("Before animation - " + v3f + " - After last run = " + v3fFinal); node1result = new TimelineScenario.Sequence(); // Add each key frame info as an animation and then play the whole if (animationStartKeyframe == 0 && animationEndKeyframe == 0) { startFrame = 0; endFrame = Tkft.length - 1; } else { startFrame = animationStartKeyframe; endFrame = animationEndKeyframe - 1; } for (int j = startFrame; j < endFrame; j++) { t = new Timeline(this); // ******************************************* Node 1 float[] fromAngles = node1keyFrames[j].toAngles(null); float[] fromAnglesNext = node1keyFrames[j + 1].toAngles(null); float[] rotFinalAngles = rotFinal.toAngles(null); Quaternion quat = new Quaternion(); quat.fromAngles( // fromAngles[0] + rotFinalAngles[0] + animationStartRotation[0], // fromAngles[1] + rotFinalAngles[1] + animationStartRotation[1], // fromAngles[2] + rotFinalAngles[2] + animationStartRotation[2]); fromAngles[0] + animationStartRotation[0], fromAngles[1] + rotFinalAngles[1] + animationStartRotation[1], fromAngles[2] + animationStartRotation[2]); Quaternion quatNext = new Quaternion(); quatNext.fromAngles( // fromAnglesNext[0] + rotFinalAngles[0] + animationStartRotation[0], // fromAnglesNext[1] + rotFinalAngles[1] + animationStartRotation[1], // fromAnglesNext[2] + rotFinalAngles[2] + animationStartRotation[2]); fromAnglesNext[0] + animationStartRotation[0], fromAnglesNext[1] + rotFinalAngles[1] + animationStartRotation[1], fromAnglesNext[2] + animationStartRotation[2]); // System.out.println("rots - x = " + // (fromAngles[0] + rotFinalAngles[0] + animationStartRotation[0]) + " - y // = " + // (fromAngles[1] + rotFinalAngles[1] + animationStartRotation[1]) + " - z // = " + // (fromAngles[2] + rotFinalAngles[2] + animationStartRotation[2])); t.addPropertyToInterpolate( "Node1Quat", quat, quatNext, new ModulatorQuaternionInterpolator()); //// t.addPropertyToInterpolate("Node1Quat", node1keyFrames[j], node1keyFrames[j + // 1], new ModulatorQuaternionInterpolator()); zRotationInc = (float) Math.sin(animationStartRotation[1]); xRotationInc = (float) Math.cos(animationStartRotation[1]); if (v3fFinal.x == 0.0f && v3fFinal.y == 0.0 && v3fFinal.z == 0.0) { Vector3f tempVec = new Vector3f( (node1keyTrans[j].x + animationStartTranslate.x), (node1keyTrans[j].y + animationStartTranslate.y), (node1keyTrans[j].z + animationStartTranslate.z)); Vector3f tempVecPlus = new Vector3f( (node1keyTrans[j + 1].x + animationStartTranslate.x), (node1keyTrans[j + 1].y + animationStartTranslate.y), (node1keyTrans[j + 1].z + animationStartTranslate.z)); // System.out.println("x = " + // (node1keyTrans[j].x + animationStartTranslate.x) + " - y = " + // (node1keyTrans[j].y + animationStartTranslate.y) + " - z = " + // (node1keyTrans[j].z + animationStartTranslate.z)); t.addPropertyToInterpolate( "Node1Trans", tempVec, tempVecPlus, new ModulatorVectorInterpolator()); } else { Vector3f tempVec = new Vector3f( node1keyTrans[j].x + v3fFinal.x + (node1keyTrans[j].x * (float) Math.sin(rotFinalAngles[1])), node1keyTrans[j].y + v3fFinal.y, node1keyTrans[j].z + v3fFinal.z + (node1keyTrans[j].z * (float) Math.cos(rotFinalAngles[1]))); Vector3f tempVecPlus = new Vector3f( node1keyTrans[j + 1].x + v3fFinal.x + (node1keyTrans[j + 1].x * (float) Math.sin(rotFinalAngles[1])), node1keyTrans[j + 1].y + v3fFinal.y, node1keyTrans[j + 1].z + v3fFinal.z + (node1keyTrans[j + 1].z * (float) Math.cos(rotFinalAngles[1]))); // System.out.println("final - x = " + // (node1keyTrans[j].x + v3fFinal.x + (node1keyTrans[j].x * // (float)Math.sin(rotFinalAngles[1]))) + " - y = " + // (node1keyTrans[j].y + v3fFinal.y) + " - z = " + // (node1keyTrans[j].z + v3fFinal.z + (node1keyTrans[j].z * // (float)Math.cos(rotFinalAngles[1])))); t.addPropertyToInterpolate( "Node1Trans", tempVec, tempVecPlus, new ModulatorVectorInterpolator()); } if (j == endFrame - 1) { t.addCallback( new TimelineCallback() { public void onTimelineDone() { Vector3f v3f = node1theSpatial.getLocalTranslation(); System.out.println("After animation from timeline done - " + v3f); } public void onTimelineStateChanged( TimelineState oldState, TimelineState newState, float arg2, float arg3) { if (newState == TimelineState.DONE) { if (animationSaveTransform) { v3fFinal = node1theSpatial.getLocalTranslation(); rotFinal = node1theSpatial.getLocalRotation(); } System.out.println("After animation - " + v3fFinal); ClientContext.getInputManager() .postEvent(new IntercellEvent("F", animationIceCode)); } } public void onTimelinePulse(float arg0, float arg1) {} }); } //// t.addPropertyToInterpolate("Node1Trans", node1keyTrans[j], node1keyTrans[j + // 1], new ModulatorVectorInterpolator()); // t.setEase(new Spline(0.4f)); t.setDuration((long) ((Tkft[j + 1] - Tkft[j]) * 1000) * animationTimeMultiplier); node1result.addScenarioActor(t); } node2result = new TimelineScenario.Sequence(); // ***************************************** Node 2 // Add each key frame info as an animation and then play the whole for (int j = startFrame; j < endFrame; j++) { t = new Timeline(this); t.addPropertyToInterpolate( "Node2Quat", node2keyFrames[j], node2keyFrames[j + 1], new ModulatorQuaternionInterpolator()); /// Vector3f tempVec = new Vector3f(node2keyTrans[j].x + animationStartTranslate.x, // node2keyTrans[j].y + animationStartTranslate.y, node2keyTrans[j].z + // animationStartTranslate.z); /// Vector3f tempVecPlus = new Vector3f(node2keyTrans[j + 1].x + // animationStartTranslate.x, node2keyTrans[j + 1].y + animationStartTranslate.y, // node2keyTrans[j + 1].z + animationStartTranslate.z); /// t.addPropertyToInterpolate("Node2Trans", tempVec, tempVecPlus, new // ModulatorVectorInterpolator()); /// System.out.println("node2 - orig y = " + node2keyTrans[j].y + " - shift - " + tempVec.y); t.addPropertyToInterpolate( "Node2Trans", node2keyTrans[j], node2keyTrans[j + 1], new ModulatorVectorInterpolator()); // t.setEase(new Spline(0.4f)); t.setDuration((long) ((Tkft[j + 1] - Tkft[j]) * 1000) * animationTimeMultiplier); node2result.addScenarioActor(t); } node3result = new TimelineScenario.Sequence(); // ******************************************************* Node 3 // Add each key frame info as an animation and then play the whole for (int j = startFrame; j < endFrame; j++) { t = new Timeline(this); t.addPropertyToInterpolate( "Node3Quat", node3keyFrames[j], node3keyFrames[j + 1], new ModulatorQuaternionInterpolator()); /// Vector3f tempVec = new Vector3f(node3keyTrans[j].x + animationStartTranslate.x, // node3keyTrans[j].y + animationStartTranslate.y, node3keyTrans[j].z + // animationStartTranslate.z); /// Vector3f tempVecPlus = new Vector3f(node3keyTrans[j + 1].x + // animationStartTranslate.x, node3keyTrans[j + 1].y + animationStartTranslate.y, // node3keyTrans[j + 1].z + animationStartTranslate.z); /// t.addPropertyToInterpolate("Node3Trans", tempVec, tempVecPlus, new // ModulatorVectorInterpolator()); /// System.out.println("node3 - orig y = " + node3keyTrans[j].y + " - shift - " + tempVec.y); t.addPropertyToInterpolate( "Node3Trans", node3keyTrans[j], node3keyTrans[j + 1], new ModulatorVectorInterpolator()); // t.setEase(new Spline(0.4f)); t.setDuration((long) ((Tkft[j + 1] - Tkft[j]) * 1000) * animationTimeMultiplier); node3result.addScenarioActor(t); } node1result.play(); node2result.play(); node3result.play(); }