private void applyDx(final double dx, final Camera camera) { _workerMatrix.fromAngleNormalAxis(_mouseRotateSpeed * dx, _upAxis); _workerMatrix.applyPost(camera.getLeft(), _workerStoreA); camera.setLeft(_workerStoreA); _workerMatrix.applyPost(camera.getDirection(), _workerStoreA); camera.setDirection(_workerStoreA); _workerMatrix.applyPost(camera.getUp(), _workerStoreA); camera.setUp(_workerStoreA); }
private void applyDx(final double dx, final Camera camera) { _workerMatrix.fromAngleNormalAxis(_mouseRotateSpeed * dx, _upAxis); _workerMatrix.applyPost(camera.getLeft(), _workerStoreA); camera.setLeft(_workerStoreA); _workerMatrix.applyPost(camera.getDirection(), _workerStoreA); camera.setDirection(_workerStoreA); _workerMatrix.applyPost(camera.getUp(), _workerStoreA); camera.setUp(_workerStoreA); }
/** * Locally applies this transform to the given vector: V' = M*V * * @param vector * @return the transformed vector. * @throws NullPointerException * if vector is null. */ @Override public Vector3 applyForwardVector(final Vector3 vector) { if (vector == null) { throw new NullPointerException(); } if (_identity) { // No need to make changes // V' = V return vector; } if (_rotationMatrix) { // Scale is separate from matrix // V' = R*S*V vector.set(vector.getX() * _scale.getX(), vector.getY() * _scale.getY(), vector.getZ() * _scale.getZ()); _matrix.applyPost(vector, vector); return vector; } // scale is part of matrix. // V' = M*V _matrix.applyPost(vector, vector); return vector; }
/** * Locally applies this transform to the given vector: V' = M*V * * @param vector * @return the transformed vector. * @throws NullPointerException * if vector is null. */ @Override public Vector3 applyForwardVector(final Vector3 vector) { if (vector == null) { throw new NullPointerException(); } if (_identity) { // No need to make changes // V' = V return vector; } if (_rotationMatrix) { // Scale is separate from matrix // V' = R*S*V vector.set(vector.getX() * _scale.getX(), vector.getY() * _scale.getY(), vector.getZ() * _scale.getZ()); _matrix.applyPost(vector, vector); return vector; } // scale is part of matrix. // V' = M*V _matrix.applyPost(vector, vector); return vector; }
@Override public boolean intersectsSphere(final BoundingSphere bs) { if (!Vector3.isValid(_center) || !Vector3.isValid(bs._center)) { return false; } _compVect1.set(bs.getCenter()).subtractLocal(_center); final Matrix3 tempMa = Matrix3.fetchTempInstance().fromAxes(_xAxis, _yAxis, _zAxis); tempMa.applyPost(_compVect1, _compVect1); boolean result = false; if (Math.abs(_compVect1.getX()) < bs.getRadius() + _extent.getX() && Math.abs(_compVect1.getY()) < bs.getRadius() + _extent.getY() && Math.abs(_compVect1.getZ()) < bs.getRadius() + _extent.getZ()) { result = true; } Matrix3.releaseTempInstance(tempMa); return result; }
@Override public boolean intersectsSphere(final BoundingSphere bs) { if (!Vector3.isValid(_center) || !Vector3.isValid(bs._center)) { return false; } _compVect1.set(bs.getCenter()).subtractLocal(_center); final Matrix3 tempMa = Matrix3.fetchTempInstance().fromAxes(_xAxis, _yAxis, _zAxis); tempMa.applyPost(_compVect1, _compVect1); boolean result = false; if (Math.abs(_compVect1.getX()) < bs.getRadius() + _extent.getX() && Math.abs(_compVect1.getY()) < bs.getRadius() + _extent.getY() && Math.abs(_compVect1.getZ()) < bs.getRadius() + _extent.getZ()) { result = true; } Matrix3.releaseTempInstance(tempMa); return result; }
private void applyDY(final double dy, final Camera camera) { // apply dy angle change to direction vector _workerMatrix.fromAngleNormalAxis(_mouseRotateSpeed * dy, camera.getLeft()); _workerMatrix.applyPost(camera.getDirection(), _workerStoreA); camera.setDirection(_workerStoreA); // do we want to constrain our vertical angle? if (isClampVerticalAngle()) { // check if we went out of bounds and back up final double angleV = MathUtils.HALF_PI - _workerStoreA.smallestAngleBetween(_upAxis); if (angleV > getMaxVerticalAngle() || angleV < getMinVerticalAngle()) { // clamp the angle to our range final double newAngle = MathUtils.clamp(angleV, getMinVerticalAngle(), getMaxVerticalAngle()); // take the difference in angles and back up the direction vector _workerMatrix.fromAngleNormalAxis(-(newAngle - angleV), camera.getLeft()); _workerMatrix.applyPost(camera.getDirection(), _workerStoreA); camera.setDirection(_workerStoreA); // figure out new up vector by crossing direction and left. camera.getDirection().cross(camera.getLeft(), _workerStoreA); camera.setUp(_workerStoreA); return; } } // just apply to up vector _workerMatrix.applyPost(camera.getUp(), _workerStoreA); camera.setUp(_workerStoreA); }
private void applyDY(final double dy, final Camera camera) { // apply dy angle change to direction vector _workerMatrix.fromAngleNormalAxis(_mouseRotateSpeed * dy, camera.getLeft()); _workerMatrix.applyPost(camera.getDirection(), _workerStoreA); camera.setDirection(_workerStoreA); // do we want to constrain our vertical angle? if (isClampVerticalAngle()) { // check if we went out of bounds and back up final double angleV = MathUtils.HALF_PI - _workerStoreA.smallestAngleBetween(_upAxis); if (angleV > getMaxVerticalAngle() || angleV < getMinVerticalAngle()) { // clamp the angle to our range final double newAngle = MathUtils.clamp(angleV, getMinVerticalAngle(), getMaxVerticalAngle()); // take the difference in angles and back up the direction vector _workerMatrix.fromAngleNormalAxis(-(newAngle - angleV), camera.getLeft()); _workerMatrix.applyPost(camera.getDirection(), _workerStoreA); camera.setDirection(_workerStoreA); // figure out new up vector by crossing direction and left. camera.getDirection().cross(camera.getLeft(), _workerStoreA); camera.setUp(_workerStoreA); return; } } // just apply to up vector _workerMatrix.applyPost(camera.getUp(), _workerStoreA); camera.setUp(_workerStoreA); }
transMatrix.applyPost(_compVect1, _compVect1);
transMatrix.applyPost(_compVect1, _compVect1);
@Test public void testLookAt() { final Vector3 direction = new Vector3(-1, 0, 0); final Matrix3 mat3 = new Matrix3().lookAt(direction, Vector3.UNIT_Y); assertEquals(direction, mat3.applyPost(Vector3.UNIT_Z, null)); direction.set(1, 1, 1).normalizeLocal(); mat3.lookAt(direction, Vector3.UNIT_Y); assertEquals(direction, mat3.applyPost(Vector3.UNIT_Z, null)); direction.set(-1, 2, -1).normalizeLocal(); mat3.lookAt(direction, Vector3.UNIT_Y); assertEquals(direction, mat3.applyPost(Vector3.UNIT_Z, new Vector3())); } }
@Test public void testStartEnd() { final Matrix3 mat3 = new Matrix3(); mat3.fromStartEndLocal(Vector3.UNIT_X, Vector3.UNIT_Y); // should be a 90 degree turn around Z assertEquals(new Vector3(-1, 1, 1), mat3.applyPost(new Vector3(1, 1, 1), null)); // coverage mat3.fromStartEndLocal(new Vector3(1, 0, 0), new Vector3(1 + Double.MIN_VALUE, 0, 0)); assertTrue(mat3.applyPost(Vector3.ONE, null).distance(Vector3.ONE) < MathUtils.ZERO_TOLERANCE); mat3.fromStartEndLocal(new Vector3(0, 1, 0), new Vector3(0, 1 + Double.MIN_VALUE, 0)); assertTrue(mat3.applyPost(Vector3.ONE, null).distance(Vector3.ONE) < MathUtils.ZERO_TOLERANCE); mat3.fromStartEndLocal(new Vector3(0, 0, 1), new Vector3(0, 0, 1 + Double.MIN_VALUE)); assertTrue(mat3.applyPost(Vector3.ONE, null).distance(Vector3.ONE) < MathUtils.ZERO_TOLERANCE); }
@Test public void testApplyVector3() { final Matrix3 mat3 = new Matrix3().applyRotationX(MathUtils.HALF_PI); final Vector3 vec3 = new Vector3(0, 1, 0); final Vector3 result = mat3.applyPost(vec3, null); assertTrue(Math.abs(new Vector3(0, 0, 1).distance(result)) <= MathUtils.EPSILON); vec3.set(0, 1, 1); mat3.applyPost(vec3, result); assertTrue(Math.abs(new Vector3(0, -1, 1).distance(result)) <= MathUtils.EPSILON); vec3.set(0, 1, 1); mat3.applyPre(vec3, result); assertTrue(Math.abs(new Vector3(0, 1, -1).distance(result)) <= MathUtils.EPSILON); vec3.set(1, 1, 1); assertTrue(Math.abs(new Vector3(1, 1, -1).distance(mat3.applyPre(vec3, null))) <= MathUtils.EPSILON); }
invertedMatrix.applyPost(vector, vector); Matrix3.releaseTempInstance(invertedMatrix);
invertedMatrix.applyPost(point, point); Matrix3.releaseTempInstance(invertedMatrix);
invertedMatrix.applyPost(point, point); Matrix3.releaseTempInstance(invertedMatrix);
result._matrix.applyPost(_translation, result._translation).negateLocal(); result.updateFlags(_rotationMatrix);
result._matrix.applyPost(_translation, result._translation).negateLocal(); result.updateFlags(_rotationMatrix);