/** * Locally applies the inverse of this transform to the given vector: V' = M^{-1}*V * * @param theVector * @return the transformed theVector. * @throws NullPointerException if vector is null. */ public CCVector3 applyInverseVector(CCVector3 theVector) { if (theVector == null) { throw new NullPointerException(); } theVector = theVector.clone(); if (_myIsIdentity) { // No need to make changes // V' = V return theVector; } if (_myIsRotationMatrix) { // Scale is separate from matrix so... // V' = S^{-1}*R^t*V theVector = _myMatrix.applyPre(theVector); if (_myIsUniformScale) { theVector.divideLocal(_myScale.x); } else { theVector.x = theVector.x / _myScale.x; theVector.y = theVector.y / _myScale.y; theVector.z = theVector.z / _myScale.z; } } else { // V' = M^{-1}*V final CCMatrix3x3 invertedMatrix = _myMatrix.invert(); theVector = invertedMatrix.applyPost(theVector); } return theVector; }
/** * Locally applies the inverse of this transform to the given point: P' = M^{-1}*(P-T) * * @param thePoint * @return the transformed point. * @throws NullPointerException if point is null. */ public CCVector3 applyInverse(final CCVector3 thePoint, CCVector3 theStore) { if (thePoint == null) { throw new NullPointerException(); } if (theStore == null) theStore = new CCVector3(thePoint); if (_myIsIdentity) { // No need to make changes // P' = P return theStore; } // Back track translation theStore.subtractLocal(_myTranslation); if (_myIsRotationMatrix) { // Scale is separate from matrix so... // P' = S^{-1}*R^t*(P - T) theStore = _myMatrix.applyPre(theStore); if (_myIsUniformScale) { theStore.divideLocal(_myScale.x); } else { theStore.x = theStore.x / _myScale.x; theStore.y = theStore.y / _myScale.y; theStore.z = theStore.z / _myScale.z; } } else { // P' = M^{-1}*(P - T) final CCMatrix3x3 invertedMatrix = _myMatrix.invert(); theStore = invertedMatrix.applyPost(theStore); } return theStore; }