@Override public void updatePeriodic() { final JCameraSphericalType c = this.sim.getCamera(); this.camera_pos.setValue(c.cameraGetPosition()); this.target_pos.setValue(c.cameraGetTargetPosition()); this.heading.setValue(c.cameraGetAngleHeading()); this.incline.setValue(c.cameraGetAngleIncline()); this.zoom.setValue(c.cameraGetZoom()); }
@Test public void testSnapshotEquality() { final JCameraSphericalType c0 = JCameraSpherical.newCamera(); c0.cameraOrbitHeading((float) (Math.random() * 100.0f)); c0.cameraOrbitIncline((float) (Math.random() * 100.0f)); c0.cameraMoveTargetRight((float) (Math.random() * 100.0f)); c0.cameraMoveTargetUp((float) (Math.random() * 100.0f)); c0.cameraMoveTargetForwardOnXZ((float) (Math.random() * 100.0f)); c0.cameraZoomOut((float) (Math.random() * 100.0f)); final JCameraSphericalType c1 = JCameraSpherical.newCameraFrom(c0); c1.cameraOrbitHeading((float) (Math.random() * 100.0f)); c1.cameraOrbitIncline((float) (Math.random() * 100.0f)); c1.cameraMoveTargetRight((float) (Math.random() * 100.0f)); c1.cameraMoveTargetUp((float) (Math.random() * 100.0f)); c1.cameraMoveTargetForwardOnXZ((float) (Math.random() * 100.0f)); c1.cameraZoomOut((float) (Math.random() * 100.0f)); System.out.println("c0: " + c0); System.out.println("c1: " + c1); final JCameraSphericalSnapshot snap_0 = c0.cameraMakeSnapshot(); final JCameraSphericalSnapshot snap_1 = c1.cameraMakeSnapshot(); Assert.assertEquals(snap_0, snap_0); Assert.assertNotEquals(snap_0, snap_1); Assert.assertNotEquals(snap_0, null); Assert.assertNotEquals(snap_0, Integer.valueOf(23)); Assert.assertEquals(snap_0.hashCode(), snap_0.hashCode()); Assert.assertNotEquals(snap_0.hashCode(), snap_1.hashCode()); Assert.assertEquals(snap_0.toString(), snap_0.toString()); Assert.assertNotEquals(snap_0.toString(), snap_1.toString()); }
/** * @param c An existing camera * * @return A new camera based on the given camera. */ public static JCameraSphericalType newCameraFrom( final JCameraSphericalReadableType c) { final JCameraSphericalType r = new JCameraSpherical(); r.cameraSetAngleHeading(c.cameraGetAngleHeading()); r.cameraSetAngleIncline(c.cameraGetAngleIncline()); r.cameraSetTargetPosition(c.cameraGetTargetPosition()); r.cameraSetZoom(c.cameraGetZoom()); return r; }
@Test public void testEquality() { final JCameraSphericalType c0 = JCameraSpherical.newCamera(); c0.cameraSetAngleHeading((float) (Math.random() * 100.0f)); c0.cameraSetAngleIncline((float) (Math.random() * 100.0f)); c0.cameraSetTargetPosition3f( (float) (Math.random() * 100.0f), (float) (Math.random() * 100.0f), (float) (Math.random() * 100.0f)); c0.cameraSetZoom((float) (Math.random() * 100.0f)); final JCameraSphericalType c1 = JCameraSpherical.newCameraFrom(c0); System.out.println("c0: " + c0); System.out.println("c1: " + c1); Assert.assertEquals(c0, c1); Assert.assertEquals(c0.hashCode(), c1.hashCode()); Assert.assertEquals(c0.toString(), c1.toString()); this.compareSnapshot(c1); this.compareSnapshot(c0); }
c.cameraOrbitHeading((float) Math.toRadians(90)); cr, (float) Math.toRadians(0.0f), c.cameraGetAngleHeading()); Assert.assertTrue(r); final VectorReadable3FType actual = c.cameraGetForward(); JCameraSphericalTest.dumpVector("forward expected", expected); JCameraSphericalTest.dumpVector("forward actual", actual); final VectorReadable3FType actual = c.cameraGetForwardProjectedOnXZ(); JCameraSphericalTest.dumpVector("forward on x/z expected", expected); JCameraSphericalTest.dumpVector("forward on x/z actual", actual); final VectorReadable3FType actual = c.cameraGetUp(); JCameraSphericalTest.dumpVector("up expected", expected); JCameraSphericalTest.dumpVector("up actual", actual); final VectorReadable3FType actual = c.cameraGetRight(); JCameraSphericalTest.dumpVector("right expected", expected); JCameraSphericalTest.dumpVector("right actual", actual); final VectorReadable3FType actual = c.cameraGetPosition(); JCameraSphericalTest.dumpVector("position expected", expected); JCameraSphericalTest.dumpVector("position actual", actual);
@Test public void testDirectionsInclineDecrease90() c.cameraClampInclineDisable(); c.cameraOrbitIncline((float) Math.toRadians(-89.99999)); cr, (float) Math.toRadians(-89.99999), c.cameraGetAngleIncline()); Assert.assertTrue(r); final VectorReadable3FType actual = c.cameraGetForward(); JCameraSphericalTest.dumpVector("forward expected", expected); JCameraSphericalTest.dumpVector("forward actual", actual); final VectorReadable3FType actual = c.cameraGetForwardProjectedOnXZ(); JCameraSphericalTest.dumpVector("forward on x/z expected", expected); JCameraSphericalTest.dumpVector("forward on x/z actual", actual); final VectorReadable3FType actual = c.cameraGetUp(); JCameraSphericalTest.dumpVector("up expected", expected); JCameraSphericalTest.dumpVector("up actual", actual); final VectorReadable3FType actual = c.cameraGetRight(); JCameraSphericalTest.dumpVector("right expected", expected); JCameraSphericalTest.dumpVector("right actual", actual); final VectorReadable3FType actual = c.cameraGetPosition(); JCameraSphericalTest.dumpVector("position expected", expected); JCameraSphericalTest.dumpVector("position actual", actual);
@Test public void testDirectionsRadiusIncrease90() c.cameraSetZoom(10.0f); cr, (float) Math.toRadians(-90.0f), c.cameraGetAngleHeading()); Assert.assertTrue(r); final VectorReadable3FType actual = c.cameraGetForward(); JCameraSphericalTest.dumpVector("forward expected", expected); JCameraSphericalTest.dumpVector("forward actual", actual); final VectorReadable3FType actual = c.cameraGetForwardProjectedOnXZ(); JCameraSphericalTest.dumpVector("forward on x/z expected", expected); JCameraSphericalTest.dumpVector("forward on x/z actual", actual); final VectorReadable3FType actual = c.cameraGetUp(); JCameraSphericalTest.dumpVector("up expected", expected); JCameraSphericalTest.dumpVector("up actual", actual); final VectorReadable3FType actual = c.cameraGetRight(); JCameraSphericalTest.dumpVector("right expected", expected); JCameraSphericalTest.dumpVector("right actual", actual); final VectorReadable3FType actual = c.cameraGetPosition(); JCameraSphericalTest.dumpVector("position expected", expected); JCameraSphericalTest.dumpVector("position actual", actual);
final JCameraSphericalAngularIntegratorType d = this.newIntegrator(c, i); c.cameraClampInclineDisable(); final VectorReadable3FType actual = c.cameraGetPosition(); JCameraSphericalAngularIntegratorContract.dumpVector( "position expected", final VectorReadable3FType actual = c.cameraGetForward(); JCameraSphericalAngularIntegratorContract.dumpVector( "forward expected", final VectorReadable3FType actual = c.cameraGetRight(); JCameraSphericalAngularIntegratorContract.dumpVector( "right expected", final VectorReadable3FType actual = c.cameraGetUp(); JCameraSphericalAngularIntegratorContract.dumpVector( "up expected",
private double integrateForward( final double time) { double s = this.speed_forward; final boolean forward = this.input.isTargetMovingForward(); if (forward) { s += this.target_acceleration * time; } final boolean backward = this.input.isTargetMovingBackward(); if (backward) { s -= this.target_acceleration * time; } s = Clamp.clamp(s, -this.target_maximum_speed, this.target_maximum_speed); s += this.input.takeTargetMovingForward() * this.target_acceleration * time; this.camera.cameraMoveTargetForwardOnXZ(s * time); return applyDrag(s, this.target_drag, time); }
private double integrateUp( final double time) { double s = this.speed_up; final boolean forward = this.input.isTargetMovingUp(); if (forward) { s += this.target_acceleration * time; } final boolean backward = this.input.isTargetMovingDown(); if (backward) { s -= this.target_acceleration * time; } s = Clamp.clamp(s, -this.target_maximum_speed, this.target_maximum_speed); this.camera.cameraMoveTargetUp(s * time); return applyDrag(s, this.target_drag, time); }
private double integrateRight( final double time) { double s = this.speed_right; final boolean forward = this.input.isTargetMovingRight(); if (forward) { s += this.target_acceleration * time; } final boolean backward = this.input.isTargetMovingLeft(); if (backward) { s -= this.target_acceleration * time; } s = Clamp.clamp(s, -this.target_maximum_speed, this.target_maximum_speed); s += this.input.takeTargetMovingRight() * this.target_acceleration * time; this.camera.cameraMoveTargetRight(s * time); return applyDrag(s, this.target_drag, time); }
@Override public void integrate( final float t) { this.speed_zoom = this.integrateZoom(t); final float linear_zoom_scale = this.linear_scale.evaluate(this.camera.cameraGetZoom()); final float drag_zoom_scale = this.drag_scale.evaluate(this.camera.cameraGetZoom()); this.speed_forward = this.integrateForward(t, linear_zoom_scale, drag_zoom_scale); this.speed_right = this.integrateRight(t, linear_zoom_scale, drag_zoom_scale); this.speed_up = this.integrateUp(t); }
private double integrateHeading( final double time) { double s = this.speed_heading; final boolean positive = this.input.isOrbitingHeadingPositive(); if (positive) { s += this.acceleration_heading * time; } final boolean negative = this.input.isOrbitingHeadingNegative(); if (negative) { s -= this.acceleration_heading * time; } s = Clamp.clamp(s, -this.maximum_speed_heading, this.maximum_speed_heading); this.camera.cameraOrbitHeading(s * time); return JCameraSphericalAngularIntegrator.applyDrag( s, this.drag_heading, time); }
private float integrateIncline( final float time) { float s = this.speed_incline; final boolean positive = this.input.isOrbitingInclinePositive(); if (positive) { s += this.acceleration_incline * time; } final boolean negative = this.input.isOrbitingInclineNegative(); if (negative) { s -= this.acceleration_incline * time; } s = Clamp.clamp(s, -this.maximum_speed_incline, this.maximum_speed_incline); /** * If applying the movement resulted in a value that was clamped, then * remove all speed in that direction by returning zero. Otherwise, the * user has to achieve a greater than or equal speed in the opposite * direction just to get the camera to appear to start moving. */ final boolean clamped = this.camera.cameraOrbitIncline(s * time); if (clamped) { return 0.0f; } return JCameraSphericalAngularIntegrator.applyDrag( s, this.drag_incline, time); }
this.input)); this.camera.cameraClampInclineDisable();
c.cameraOrbitHeading((float) Math.toRadians(-90)); cr, (float) Math.toRadians(-180.0f), c.cameraGetAngleHeading()); Assert.assertTrue(r); final VectorReadable3FType actual = c.cameraGetForward(); JCameraSphericalTest.dumpVector("forward expected", expected); JCameraSphericalTest.dumpVector("forward actual", actual); final VectorReadable3FType actual = c.cameraGetForwardProjectedOnXZ(); JCameraSphericalTest.dumpVector("forward on x/z expected", expected); JCameraSphericalTest.dumpVector("forward on x/z actual", actual); final VectorReadable3FType actual = c.cameraGetUp(); JCameraSphericalTest.dumpVector("up expected", expected); JCameraSphericalTest.dumpVector("up actual", actual); final VectorReadable3FType actual = c.cameraGetRight(); JCameraSphericalTest.dumpVector("right expected", expected); JCameraSphericalTest.dumpVector("right actual", actual); final VectorReadable3FType actual = c.cameraGetPosition(); JCameraSphericalTest.dumpVector("position expected", expected); JCameraSphericalTest.dumpVector("position actual", actual);
@Test public void testDirectionsInclineIncrease90() c.cameraClampInclineDisable(); c.cameraOrbitIncline((float) Math.toRadians(89.99999)); cr, (float) Math.toRadians(89.99999), c.cameraGetAngleIncline()); Assert.assertTrue(r); final VectorReadable3FType actual = c.cameraGetForward(); JCameraSphericalTest.dumpVector("forward expected", expected); JCameraSphericalTest.dumpVector("forward actual", actual); final VectorReadable3FType actual = c.cameraGetForwardProjectedOnXZ(); JCameraSphericalTest.dumpVector("forward on x/z expected", expected); JCameraSphericalTest.dumpVector("forward on x/z actual", actual); final VectorReadable3FType actual = c.cameraGetUp(); JCameraSphericalTest.dumpVector("up expected", expected); JCameraSphericalTest.dumpVector("up actual", actual); final VectorReadable3FType actual = c.cameraGetRight(); JCameraSphericalTest.dumpVector("right expected", expected); JCameraSphericalTest.dumpVector("right actual", actual); final VectorReadable3FType actual = c.cameraGetPosition(); JCameraSphericalTest.dumpVector("position expected", expected); JCameraSphericalTest.dumpVector("position actual", actual);
c.cameraClampInclineDisable(); final VectorReadable3FType actual = c.cameraGetPosition(); JCameraSphericalAngularIntegratorContract.dumpVector( "position expected", final VectorReadable3FType actual = c.cameraGetForward(); JCameraSphericalAngularIntegratorContract.dumpVector( "forward expected", final VectorReadable3FType actual = c.cameraGetRight(); JCameraSphericalAngularIntegratorContract.dumpVector( "right expected", final VectorReadable3FType actual = c.cameraGetUp(); JCameraSphericalAngularIntegratorContract.dumpVector( "up expected",
private float integrateForward( final float time) { float s = this.speed_forward; final boolean forward = this.input.isTargetMovingForward(); if (forward) { s += this.target_acceleration * time; } final boolean backward = this.input.isTargetMovingBackward(); if (backward) { s -= this.target_acceleration * time; } s = Clamp.clamp(s, -this.target_maximum_speed, this.target_maximum_speed); s += this.input.takeTargetMovingForward() * this.target_acceleration * time; this.camera.cameraMoveTargetForwardOnXZ(s * time); return JCameraSphericalLinearIntegrator.applyDrag( s, this.target_drag, time); }
private double integrateUp( final double time) { double s = this.speed_up; final boolean forward = this.input.isTargetMovingUp(); if (forward) { s += this.target_acceleration * time; } final boolean backward = this.input.isTargetMovingDown(); if (backward) { s -= this.target_acceleration * time; } s = Clamp.clamp(s, -this.target_maximum_speed, this.target_maximum_speed); this.camera.cameraMoveTargetUp(s * time); return JCameraSphericalLinearIntegratorZoomScaled.applyDrag( s, this.target_drag, time); }