@Override public ATransformable3D resetToLookAt(Vector3 upAxis) { super.resetToLookAt(upAxis); // We want to rotate the forward axis since that's what Quaternion.lookAt() affects mDirectionVec.setAll(mForwardAxis); // Rotate the vector based on our orientation mDirectionVec.rotateBy(mOrientation); return this; } }
/** * Utility method to move the specified number of units along the current forward axis. This will * also adjust the look at target (if a valid one is currently set). * * @param units {@code double} Number of units to move. If negative, movement will be in the "back" direction. */ public void moveForward(double units) { mTempVec.setAll(WorldParameters.FORWARD_AXIS); mTempVec.rotateBy(mOrientation).normalize(); mTempVec.multiply(units); mPosition.add(mTempVec); if (mLookAtEnabled && mLookAtValid) { mLookAt.add(mTempVec); resetToLookAt(); } markModelMatrixDirty(); }
/** * Utility method to move the specified number of units along the current up axis. This will * also adjust the look at target (if a valid one is currently set). * * @param units {@code double} Number of units to move. If negative, movement will be in the "down" direction. */ public void moveUp(double units) { mTempVec.setAll(WorldParameters.UP_AXIS); mTempVec.rotateBy(mOrientation).normalize(); mTempVec.multiply(units); mPosition.add(mTempVec); if (mLookAtEnabled && mLookAtValid) { mLookAt.add(mTempVec); resetToLookAt(); } markModelMatrixDirty(); }
/** * Utility method to move the specified number of units along the current right axis. This will * also adjust the look at target (if a valid one is currently set). * * @param units {@code double} Number of units to move. If negative, movement will be in the "left" direction. */ public void moveRight(double units) { mTempVec.setAll(WorldParameters.RIGHT_AXIS); mTempVec.rotateBy(mOrientation).normalize(); mTempVec.multiply(units); mPosition.add(mTempVec); if (mLookAtValid) { mLookAt.add(mTempVec); resetToLookAt(); } markModelMatrixDirty(); }
public boolean isLookingAtObject(Object3D target, float maxAngle) { mHeadViewQuaternion.fromMatrix(mHeadViewMatrix); mHeadViewQuaternion.inverse(); mForwardVec.setAll(0, 0, 1); mForwardVec.rotateBy(mHeadViewQuaternion); mHeadTranslation.setAll(mHeadViewMatrix.getTranslation()); mHeadTranslation.subtract(target.getPosition()); mHeadTranslation.normalize(); return mHeadTranslation.angle(mForwardVec) < maxAngle; } }
@Test public void testRotateBy() { { final Quaternion q = Quaternion.getIdentity(); Vector3 v = new Vector3(0, 0, 1); v.rotateBy(q); assertEquals("X", 0, v.x, 1e-14); assertEquals("Y", 0, v.y, 1e-14); assertEquals("Z", 1, v.z, 1e-14); } { final Quaternion q = new Quaternion(0.5, 0.5, 0.5, 0.5); Vector3 v = new Vector3(0, 0, 1); v.rotateBy(q); assertEquals("X", 1, v.x, 1e-14); assertEquals("Y", 0, v.y, 1e-14); assertEquals("Z", 0, v.z, 1e-14); } }
@Override public ATransformable3D resetToLookAt(Vector3 upAxis) { super.resetToLookAt(upAxis); // We want to rotate the forward axis since that's what Quaternion.lookAt() affects mDirectionVec.setAll(mForwardAxis); // Rotate the vector based on our orientation mDirectionVec.rotateBy(mOrientation); return this; } }
/** * Utility method to move the specified number of units along the current up axis. This will * also adjust the look at target (if a valid one is currently set). * * @param units {@code double} Number of units to move. If negative, movement will be in the "down" direction. */ public void moveUp(double units) { mTempVec.setAll(WorldParameters.UP_AXIS); mTempVec.rotateBy(mOrientation).normalize(); mTempVec.multiply(units); mPosition.add(mTempVec); if (mLookAtEnabled && mLookAtValid) { mLookAt.add(mTempVec); resetToLookAt(); } markModelMatrixDirty(); }
/** * Utility method to move the specified number of units along the current right axis. This will * also adjust the look at target (if a valid one is currently set). * * @param units {@code double} Number of units to move. If negative, movement will be in the "left" direction. */ public void moveRight(double units) { mTempVec.setAll(WorldParameters.RIGHT_AXIS); mTempVec.rotateBy(mOrientation).normalize(); mTempVec.multiply(units); mPosition.add(mTempVec); if (mLookAtValid) { mLookAt.add(mTempVec); resetToLookAt(); } markModelMatrixDirty(); }
/** * Utility method to move the specified number of units along the current forward axis. This will * also adjust the look at target (if a valid one is currently set). * * @param units {@code double} Number of units to move. If negative, movement will be in the "back" direction. */ public void moveForward(double units) { mTempVec.setAll(WorldParameters.FORWARD_AXIS); mTempVec.rotateBy(mOrientation).normalize(); mTempVec.multiply(units); mPosition.add(mTempVec); if (mLookAtEnabled && mLookAtValid) { mLookAt.add(mTempVec); resetToLookAt(); } markModelMatrixDirty(); }