@Test public void testSetRotation() { final Matrix3 mat3A = new Matrix3(); // rotate identity 90 degrees around Y final double a = MathUtils.HALF_PI; final Quaternion quaternion = new Quaternion(); quaternion.fromAngleAxis(a, Vector3.UNIT_Y); mat3A.set(quaternion); assertEquals(new Matrix3( // Math.cos(a), 0, Math.sin(a), // 0, 1, 0, // -Math.sin(a), 0, Math.cos(a)), mat3A); }
public MoveWidget withXAxis(final ReadOnlyColorRGBA color, final double scale, final double width, final double lengthGap, final double tipGap) { if (_xArrow != null) { _xArrow.removeFromParent(); } _xColor.set(color); _xArrow = new InteractArrow("xMoveArrow", scale, width, lengthGap, tipGap); _xArrow.setDefaultColor(color); final Quaternion rotate = new Quaternion().fromAngleAxis(MathUtils.HALF_PI, Vector3.UNIT_Y); _xArrow.setRotation(rotate); _handle.attachChild(_xArrow); return this; }
public MoveWidget withYAxis(final ReadOnlyColorRGBA color, final double scale, final double width, final double lengthGap, final double tipGap) { if (_yArrow != null) { _yArrow.removeFromParent(); } _yColor.set(color); _yArrow = new InteractArrow("yMoveArrow", scale, width, lengthGap, tipGap); _yArrow.setDefaultColor(color); final Quaternion rotate = new Quaternion().fromAngleAxis(MathUtils.HALF_PI, Vector3.NEG_UNIT_X); _yArrow.setRotation(rotate); _handle.attachChild(_yArrow); return this; }
pivotVector.setValue((dominantIndex + 2) % 3, 0f); return fromAngleAxis(theta, pivotVector); } finally { Vector3.releaseTempInstance(pivotVector);
pivotVector.setValue((dominantIndex + 2) % 3, 0f); return fromAngleAxis(theta, pivotVector); } finally { Vector3.releaseTempInstance(pivotVector);
public RotateWidget withXAxis(final ReadOnlyColorRGBA color, final float scale, final float width) { if (_xRing != null) { _xRing.removeFromParent(); } _xRing = new InteractRing("xRotRing", 4, 32, scale, width); _xRing.setDefaultColor(color); final Quaternion rotate = new Quaternion().fromAngleAxis(MathUtils.HALF_PI, Vector3.UNIT_Y); _xRing.getMeshData().rotatePoints(rotate); _xRing.getMeshData().rotateNormals(rotate); _handle.attachChild(_xRing); final BlendState blend = new BlendState(); blend.setBlendEnabled(true); _xRing.setRenderState(blend); return this; }
public RotateWidget withYAxis(final ReadOnlyColorRGBA color, final float scale, final float width) { if (_yRing != null) { _yRing.removeFromParent(); } _yRing = new InteractRing("yRotRing", 4, 32, scale, width); _yRing.setDefaultColor(color); final Quaternion rotate = new Quaternion().fromAngleAxis(MathUtils.HALF_PI, Vector3.NEG_UNIT_X); _yRing.getMeshData().rotatePoints(rotate); _yRing.getMeshData().rotateNormals(rotate); _handle.attachChild(_yRing); final BlendState blend = new BlendState(); blend.setBlendEnabled(true); _yRing.setRenderState(blend); return this; }
@Override public void prepare(final ParticleSystem system) { _line.setOrigin(_axis.getOrigin()); _line.setDirection(_axis.getDirection()); final ReadOnlyMatrix3 mat = system.getEmitterTransform().getMatrix(); if (_transformWithScene && !mat.isIdentity()) { final Vector3 temp = Vector3.fetchTempInstance(); mat.applyPost(_line.getOrigin(), temp); _line.setOrigin(temp); mat.applyPost(_line.getDirection(), temp); _line.setDirection(temp); Vector3.releaseTempInstance(temp); } if (_type == VT_CYLINDER) { _rot.fromAngleAxis(-_divergence, _line.getDirection()); } }
@Override public void prepare(final ParticleSystem system) { _line.setOrigin(_axis.getOrigin()); _line.setDirection(_axis.getDirection()); final ReadOnlyMatrix3 mat = system.getEmitterTransform().getMatrix(); if (_transformWithScene && !mat.isIdentity()) { final Vector3 temp = Vector3.fetchTempInstance(); mat.applyPost(_line.getOrigin(), temp); _line.setOrigin(temp); mat.applyPost(_line.getDirection(), temp); _line.setDirection(temp); Vector3.releaseTempInstance(temp); } if (_type == VT_CYLINDER) { _rot.fromAngleAxis(-_divergence, _line.getDirection()); } }
@Test public void testAngleAxis() { final Quaternion quat = new Quaternion().fromAngleAxis(MathUtils.HALF_PI, new Vector3(2, 0, 0)); final Quaternion quat2 = new Quaternion().fromAngleNormalAxis(MathUtils.HALF_PI, new Vector3(1, 0, 0)); assertEquals(quat2, quat); assertTrue(1 - quat.magnitude() <= MathUtils.EPSILON); assertEquals(quat.apply(Vector3.ONE, null), quat2.apply(Vector3.ONE, null)); assertTrue(Math.abs(new Vector3(0, -1, 0).distance(quat.apply(new Vector3(0, 0, 1), null))) <= MathUtils.EPSILON); assertEquals(Quaternion.IDENTITY, new Quaternion(1, 2, 3, 4).fromAngleAxis(MathUtils.HALF_PI, new Vector3(0, 0, 0))); final Vector3 axisStore = new Vector3(); double angle = quat.toAngleAxis(axisStore); assertEquals(quat, new Quaternion().fromAngleAxis(angle, axisStore)); quat.set(0, 0, 0, 0); angle = quat.toAngleAxis(axisStore); assertTrue(0.0 == angle); assertEquals(Vector3.UNIT_X, axisStore); }
@Test public void testFromVectorToVector() { final Quaternion quat = new Quaternion().fromVectorToVector(Vector3.UNIT_Z, Vector3.UNIT_X); assertEquals(new Quaternion().fromAngleAxis(MathUtils.HALF_PI, Vector3.UNIT_Y), quat); quat.fromVectorToVector(Vector3.UNIT_Z, Vector3.NEG_UNIT_Z); assertTrue(Math.abs(new Vector3(0, 0, -1).distance(quat.apply(new Vector3(0, 0, 1), null))) <= Quaternion.ALLOWED_DEVIANCE); quat.fromVectorToVector(Vector3.UNIT_X, Vector3.NEG_UNIT_X); assertTrue(Math.abs(new Vector3(-1, 0, 0).distance(quat.apply(new Vector3(1, 0, 0), null))) <= Quaternion.ALLOWED_DEVIANCE); quat.fromVectorToVector(Vector3.UNIT_Y, Vector3.NEG_UNIT_Y); assertTrue(Math.abs(new Vector3(0, -1, 0).distance(quat.apply(new Vector3(0, 1, 0), null))) <= Quaternion.ALLOWED_DEVIANCE); quat.fromVectorToVector(Vector3.ONE, Vector3.NEG_ONE); assertTrue(Math.abs(new Vector3(-1, -1, -1).distance(quat.apply(new Vector3(1, 1, 1), null))) <= Quaternion.ALLOWED_DEVIANCE); quat.fromVectorToVector(Vector3.ZERO, Vector3.ZERO); assertEquals(Quaternion.IDENTITY, quat); }
@Override public void apply(final double dt, final Particle p, final int index) { final double dtStr = dt * _strength * (_random ? MathUtils.nextRandomFloat() : 1f); p.getPosition().subtract(_line.getOrigin(), _v1); _line.getDirection().cross(_v1, v2); if (v2.length() == 0) { // particle is on the axis return; } v2.normalizeLocal(); if (_type == VT_CYLINDER) { _rot.apply(v2, v2); v2.scaleAdd(dtStr, p.getVelocity(), p.getVelocity()); return; } v2.cross(_line.getDirection(), _v1); _v1.multiplyLocal(_radius); _line.getDirection().scaleAdd(_height, _v1, _v1); _v1.addLocal(_line.getOrigin()); _v1.subtractLocal(p.getPosition()); if (_v1.length() == 0) { // particle is on the ring return; } _v1.normalizeLocal(); _v1.cross(v2, v3); _rot.fromAngleAxis(-_divergence, v2); _rot.apply(v3, v3); v3.scaleAdd(dtStr, p.getVelocity(), p.getVelocity()); }
@Override public void apply(final double dt, final Particle p, final int index) { final double dtStr = dt * _strength * (_random ? MathUtils.nextRandomFloat() : 1f); p.getPosition().subtract(_line.getOrigin(), _v1); _line.getDirection().cross(_v1, v2); if (v2.length() == 0) { // particle is on the axis return; } v2.normalizeLocal(); if (_type == VT_CYLINDER) { _rot.apply(v2, v2); v2.scaleAdd(dtStr, p.getVelocity(), p.getVelocity()); return; } v2.cross(_line.getDirection(), _v1); _v1.multiplyLocal(_radius); _line.getDirection().scaleAdd(_height, _v1, _v1); _v1.addLocal(_line.getOrigin()); _v1.subtractLocal(p.getPosition()); if (_v1.length() == 0) { // particle is on the ring return; } _v1.normalizeLocal(); _v1.cross(v2, v3); _rot.fromAngleAxis(-_divergence, v2); _rot.apply(v3, v3); v3.scaleAdd(dtStr, p.getVelocity(), p.getVelocity()); }
quaternion.fromAngleAxis(a, Vector3.UNIT_Y); mat4A.set(quaternion);
trans.setRotation(new Quaternion().fromAngleAxis(a, Vector3.UNIT_Y));
@Test public void testInvert() { final Quaternion quat1 = new Quaternion(0, 1, 2, 3); final Quaternion quat2 = quat1.invert(null); assertEquals(Quaternion.IDENTITY, quat1.multiply(quat2, null)); assertEquals(quat1, quat2.invert(new Quaternion())); assertEquals(quat1, quat2.invertLocal()); // normalized version quat1.fromAngleAxis(MathUtils.QUARTER_PI, Vector3.UNIT_Y); quat1.invert(quat2); assertEquals(Quaternion.IDENTITY, quat1.multiply(quat2, null)); assertEquals(quat1, quat2.invert(new Quaternion())); assertEquals(quat1, quat2.invertLocal()); // conjugate check assertEquals(new Quaternion(-1, -2, -3, 4), new Quaternion(1, 2, 3, 4).conjugate(null)); }
@Test public void testRayOBBIntersection() throws Exception { final OrientedBoundingBox obb = new OrientedBoundingBox(); obb.setCenter(Vector3.ZERO); obb.setExtent(Vector3.ONE); Ray3 ray = new Ray3(new Vector3(1.2, -10, 0), Vector3.UNIT_Y); assertFalse(obb.intersects(ray)); IntersectionRecord record = obb.intersectsWhere(ray); assertEquals(null, record); final Quaternion rotation = new Quaternion(); rotation.fromAngleAxis(MathUtils.QUARTER_PI, Vector3.UNIT_Z); final Transform transform = new Transform(); transform.setRotation(rotation); obb.transform(transform, obb); ray = new Ray3(new Vector3(1.2, -10, 0), Vector3.UNIT_Y); assertTrue(obb.intersects(ray)); record = obb.intersectsWhere(ray); assertEquals(2, record.getNumberOfIntersections()); }
@Test public void testRayAABBIntersection() throws Exception { final BoundingBox obb = new BoundingBox(); obb.setCenter(Vector3.ZERO); obb.setXExtent(1); obb.setYExtent(1); obb.setZExtent(1); Ray3 ray = new Ray3(new Vector3(2, -10, 0), Vector3.UNIT_Y); assertFalse(obb.intersects(ray)); IntersectionRecord record = obb.intersectsWhere(ray); assertEquals(null, record); final Quaternion rotation = new Quaternion(); rotation.fromAngleAxis(MathUtils.QUARTER_PI, Vector3.UNIT_Z); final Transform transform = new Transform(); transform.setRotation(rotation); obb.transform(transform, obb); ray = new Ray3(new Vector3(1, -10, 0), Vector3.UNIT_Y); assertTrue(obb.intersects(ray)); record = obb.intersectsWhere(ray); assertEquals(2, record.getNumberOfIntersections()); }