/* * Modifies the rotation part of the transformation axis for * a Cn symmetric complex, so that the narrower end faces the * viewer, and the wider end faces away from the viewer. Example: 3LSV */ private void calcZDirection() { calcBoundaries(); // if the longer part of the structure faces towards the back (-z direction), // rotate around y-axis so the longer part faces the viewer (+z direction) if (Math.abs(minBoundary.z) > Math.abs(maxBoundary.z)) { Matrix4d rot = flipY(); rot.mul(transformationMatrix); transformationMatrix.set(rot); } }
@Override public void prologue(double t) { beginEqualsEnd = false; done = false; subject = WalkToAnimation.this.subject.getTransformableValue(); m_asSeenBy = asSeenBy.getReferenceFrameValue(); edu.cmu.cs.stage3.math.Matrix44 asSeenByTrans = m_asSeenBy.getTransformation(subject.getWorld()); ((edu.cmu.cs.stage3.alice.core.Transformable) m_asSeenBy).standUpRightNow(subject.getWorld()); m_transformationBegin = subject.getTransformation(m_asSeenBy); if (m_asSeenBy == null) { throw new edu.cmu.cs.stage3.alice.core.SimulationPropertyException( subject.name.getStringValue() + " needs something or someone to walk to.", null, asSeenBy); } if (subject == m_asSeenBy) { throw new edu.cmu.cs.stage3.alice.core.SimulationPropertyException( subject.name.getStringValue() + " can't walk to " + subject.name.getStringValue() + ".", getCurrentStack(), asSeenBy); } if (subject.isAncestorOf(m_asSeenBy)) { throw new edu.cmu.cs.stage3.alice.core.SimulationPropertyException( subject.name.getStringValue() + " can't walk to a part of itself", getCurrentStack(), asSeenBy); } // find end transformation javax.vecmath.Vector3d posAbs = getPositionEnd(); javax.vecmath.Vector3d curPos = subject.getPosition(); subject.setPositionRightNow(posAbs, m_asSeenBy); // javax.vecmath.Matrix3d paMatrix = // subject.calculatePointAt(m_asSeenBy, null, new // javax.vecmath.Vector3d(0,1,0), null, true); javax.vecmath.Matrix3d paMatrix = subject.calculatePointAt( m_asSeenBy, null, new javax.vecmath.Vector3d(0, 1, 0), m_asSeenBy, true); subject.setPositionRightNow(curPos); javax.vecmath.Matrix4d pov = asSeenBy.getReferenceFrameValue().getPointOfView(); pov.set(paMatrix); pov.setRow(3, posAbs.x, posAbs.y, posAbs.z, 1.0); m_transformationEnd = new edu.cmu.cs.stage3.math.Matrix44(pov); double dx = m_transformationBegin.m30 - m_transformationEnd.m30; double dy = m_transformationBegin.m31 - m_transformationEnd.m31; double dz = m_transformationBegin.m32 - m_transformationEnd.m32; double distance = Math.sqrt(dx * dx + dy * dy + dz * dz); double s = distance; m_xHermite = new edu.cmu.cs.stage3.math.HermiteCubic( m_transformationBegin.m30, m_transformationEnd.m30, m_transformationBegin.m20 * s, m_transformationEnd.m20 * s); m_yHermite = new edu.cmu.cs.stage3.math.HermiteCubic( m_transformationBegin.m31, m_transformationEnd.m31, m_transformationBegin.m21 * s, m_transformationEnd.m21 * s); m_zHermite = new edu.cmu.cs.stage3.math.HermiteCubic( m_transformationBegin.m32, m_transformationEnd.m32, m_transformationBegin.m22 * s, m_transformationEnd.m22 * s); super.prologue(t); getActualStepLength(); ((edu.cmu.cs.stage3.alice.core.Transformable) m_asSeenBy) .setTransformationRightNow(asSeenByTrans, subject.getWorld()); }
/** * Returns a transformation matrix that rotates refPoints to match coordPoints * * @param refPoints the points to be aligned * @param referenceVectors * @return */ private Matrix4d alignAxes(Vector3d[] axisVectors, Vector3d[] referenceVectors) { Matrix4d m1 = new Matrix4d(); AxisAngle4d a = new AxisAngle4d(); Vector3d axis = new Vector3d(); // calculate rotation matrix to rotate refPoints[0] into coordPoints[0] Vector3d v1 = new Vector3d(axisVectors[0]); Vector3d v2 = new Vector3d(referenceVectors[0]); double dot = v1.dot(v2); if (Math.abs(dot) < 0.999) { axis.cross(v1, v2); axis.normalize(); a.set(axis, v1.angle(v2)); m1.set(a); // make sure matrix element m33 is 1.0. It's 0 on Linux. m1.setElement(3, 3, 1.0); } else if (dot > 0) { // parallel axis, nothing to do -> identity matrix m1.setIdentity(); } else if (dot < 0) { // anti-parallel axis, flip around x-axis m1.set(flipX()); } // apply transformation matrix to all refPoints m1.transform(axisVectors[0]); m1.transform(axisVectors[1]); // calculate rotation matrix to rotate refPoints[1] into coordPoints[1] v1 = new Vector3d(axisVectors[1]); v2 = new Vector3d(referenceVectors[1]); Matrix4d m2 = new Matrix4d(); dot = v1.dot(v2); if (Math.abs(dot) < 0.999) { axis.cross(v1, v2); axis.normalize(); a.set(axis, v1.angle(v2)); m2.set(a); // make sure matrix element m33 is 1.0. It's 0 on Linux. m2.setElement(3, 3, 1.0); } else if (dot > 0) { // parallel axis, nothing to do -> identity matrix m2.setIdentity(); } else if (dot < 0) { // anti-parallel axis, flip around z-axis m2.set(flipZ()); } // apply transformation matrix to all refPoints m2.transform(axisVectors[0]); m2.transform(axisVectors[1]); // combine the two rotation matrices m2.mul(m1); // the RMSD should be close to zero Point3d[] axes = new Point3d[2]; axes[0] = new Point3d(axisVectors[0]); axes[1] = new Point3d(axisVectors[1]); Point3d[] ref = new Point3d[2]; ref[0] = new Point3d(referenceVectors[0]); ref[1] = new Point3d(referenceVectors[1]); if (SuperPosition.rmsd(axes, ref) > 0.1) { System.out.println( "Warning: AxisTransformation: axes alignment is off. RMSD: " + SuperPosition.rmsd(axes, ref)); } return m2; }
/** * Computes the new transform for this interpolator for a given alpha value. * * @param alphaValue alpha value between 0.0 and 1.0 * @param transform object that receives the computed transform for the specified alpha value * @since Java 3D 1.3 */ public void computeTransform(float alphaValue, Transform3D transform) { // compute the current value of u from alpha and the // determine lower and upper knot points computePathInterpolation(alphaValue); // Determine the segment within which we will be interpolating currentSegmentIndex = this.lowerKnot - 1; // if we are at the start of the curve if (currentSegmentIndex == 0 && currentU == 0f) { iHeading = keyFrames[1].heading; iPitch = keyFrames[1].pitch; iBank = keyFrames[1].bank; iPos.set(keyFrames[1].position); iScale.set(keyFrames[1].scale); // if we are at the end of the curve } else if (currentSegmentIndex == (numSegments - 1) && currentU == 1.0) { iHeading = keyFrames[upperKnot].heading; iPitch = keyFrames[upperKnot].pitch; iBank = keyFrames[upperKnot].bank; iPos.set(keyFrames[upperKnot].position); iScale.set(keyFrames[upperKnot].scale); // if we are somewhere in between the curve } else { // Get a reference to the current spline segment i.e. the // one bounded by lowerKnot and upperKnot currentSegment = cubicSplineCurve.getSegment(currentSegmentIndex); // interpolate quaternions iHeading = currentSegment.getInterpolatedHeading(currentU); iPitch = currentSegment.getInterpolatedPitch(currentU); iBank = currentSegment.getInterpolatedBank(currentU); // interpolate position currentSegment.getInterpolatedPositionVector(currentU, iPos); // interpolate position currentSegment.getInterpolatedScale(currentU, iScale); // System.out.println("Pos :" + iPos); } // Modification by ReubenDB if (colorRampingInterpolate == true) { float[] curPos = new float[3]; iPos.get(curPos); myColorRamp.getColor(curPos[1], histColor); // System.out.println("SETING COLOR:" + histColor + " CurPos: " + curPos[0] + ", " + curPos[1] // + ", " + curPos[2]); objectCA.setColor(histColor); // System.out.println("CurrentAlpha = " + myAlpha.value()); } if (timeDisplayInterpolate == true) { myTimeDisplay.updateDisplayFromAlpha(myAlpha.value()); // System.out.println(myAlpha.value()); } // Generate a transformation matrix in tMat using interpolated // heading, pitch and bank pitchMat.setIdentity(); pitchMat.rotX(-iPitch); bankMat.setIdentity(); bankMat.rotZ(iBank); tMat.setIdentity(); tMat.rotY(-iHeading); tMat.mul(pitchMat); tMat.mul(bankMat); // TODO: Vijay - Handle Non-Uniform scale // Currently this interpolator does not handle non uniform scale // We cheat by just taking the x scale component // Scale the transformation matrix sMat.set((double) iScale.x); tMat.mul(sMat); // Set the translation components. tMat.m03 = iPos.x; tMat.m13 = iPos.y; tMat.m23 = iPos.z; rotation.set(tMat); // construct a Transform3D from: axis * rotation * axisInverse transform.mul(axis, rotation); transform.mul(transform, axisInverse); }