@Override public void mouseMoved( final @Nullable MouseEvent e) { assert e != null; /* * If the camera is enabled, get the rotation coefficients for the mouse * movement. */ if (this.sim.cameraIsEnabled()) { this.rotations.from( this.mouse_region.get().coefficients( (double) e.getX(), (double) e.getY())); this.input.addRotationAroundHorizontal(this.rotations.horizontal()); this.input.addRotationAroundVertical(this.rotations.vertical()); } } }
private double integrateForward( final double time) { double s = this.speed_forward; final boolean forward = this.input.isMovingForward(); if (forward) { s += this.acceleration * time; } final boolean backward = this.input.isMovingBackward(); if (backward) { s -= this.acceleration * time; } s = Clamp.clamp(s, -this.maximum_speed, this.maximum_speed); this.camera.cameraMoveForward(s * time); return this.applyDrag(s, time); }
private float integrateUp( final float time) { float s = this.speed_up; final boolean forward = this.input.isMovingUp(); if (forward) { s += this.acceleration * time; } final boolean backward = this.input.isMovingDown(); if (backward) { s -= this.acceleration * time; } s = Clamp.clamp(s, -this.maximum_speed, this.maximum_speed); this.camera.cameraMoveUp(s * time); return this.applyDrag(s, time); }
this.input.setMovingLeft(true); break; this.input.setMovingForward(true); break; this.input.setMovingBackward(true); break; this.input.setMovingRight(true); break; this.input.setMovingUp(true); break; this.input.setMovingDown(true); break;
private double integrateRight( final double time) { double s = this.speed_right; final boolean forward = this.input.isMovingRight(); if (forward) { s += this.acceleration * time; } final boolean backward = this.input.isMovingLeft(); if (backward) { s -= this.acceleration * time; } s = Clamp.clamp(s, -this.maximum_speed, this.maximum_speed); this.camera.cameraMoveRight(s * time); return this.applyDrag(s, time); }
@Test public final void testMovingDown_0() { final JCameraFPSStyleType c = JCameraFPSStyle.newCamera(); final JCameraFPSStyleInputType i = JCameraFPSStyleInput.newInput(); final JCameraFPSStyleLinearIntegratorType d = this.newIntegrator(c, i); i.setMovingDown(true); d.integratorLinearSetMaximumSpeed(1.0f); d.integratorLinearSetAcceleration(1.0f); d.integrate(10.0f); { final VectorI3F expected = new VectorI3F(0.0f, -10.0f, 0.0f); final VectorReadable3FType actual = c.cameraGetPosition(); JCameraFPSStyleLinearIntegratorContract.dumpVector( "position expected", expected); JCameraFPSStyleLinearIntegratorContract.dumpVector( "position actual", actual); Assert.assertEquals(expected.getXF(), actual.getXF(), 0.00001f); Assert.assertEquals(expected.getYF(), actual.getYF(), 0.00001f); Assert.assertEquals(expected.getZF(), actual.getZF(), 0.00001f); } }
@Test public final void testMovingBackward_1() { final JCameraFPSStyleType c = JCameraFPSStyle.newCamera(); final JCameraFPSStyleInputType i = JCameraFPSStyleInput.newInput(); final JCameraFPSStyleLinearIntegratorType d = this.newIntegrator(c, i); i.setMovingBackward(true); d.integratorLinearSetMaximumSpeed(0.5f); d.integratorLinearSetAcceleration(1.0f); d.integrate(10.0f); { final VectorI3F expected = new VectorI3F(0.0f, 0.0f, 5.0f); final VectorReadable3FType actual = c.cameraGetPosition(); JCameraFPSStyleLinearIntegratorContract.dumpVector( "position expected", expected); JCameraFPSStyleLinearIntegratorContract.dumpVector( "position actual", actual); Assert.assertEquals(expected.getXF(), actual.getXF(), 0.00001f); Assert.assertEquals(expected.getYF(), actual.getYF(), 0.00001f); Assert.assertEquals(expected.getZF(), actual.getZF(), 0.00001f); } }
final JCameraFPSStyleAngularIntegratorType d = this.newIntegrator(c, i); i.addRotationAroundVertical(-1.0f); i.addRotationAroundVertical(-1.0f); d.integrate(1.0f); i.addRotationAroundVertical(-1.0f); d.integrate(1.0f); i.addRotationAroundVertical(-1.0f); d.integrate(1.0f);
final JCameraFPSStyleAngularIntegratorType d = this.newIntegrator(c, i); i.addRotationAroundHorizontal(1.0f);
this.input.setMovingLeft(false); break; this.input.setMovingForward(false); break; this.input.setMovingBackward(false); break; this.input.setMovingRight(false); break; this.input.setMovingUp(false); break; this.input.setMovingDown(false); break;
private float integrateRight( final float time) { float s = this.speed_right; final boolean forward = this.input.isMovingRight(); if (forward) { s += this.acceleration * time; } final boolean backward = this.input.isMovingLeft(); if (backward) { s -= this.acceleration * time; } s = Clamp.clamp(s, -this.maximum_speed, this.maximum_speed); this.camera.cameraMoveRight(s * time); return this.applyDrag(s, time); }
@Test public final void testMovingDown_1() { final JCameraFPSStyleType c = JCameraFPSStyle.newCamera(); final JCameraFPSStyleInputType i = JCameraFPSStyleInput.newInput(); final JCameraFPSStyleLinearIntegratorType d = this.newIntegrator(c, i); i.setMovingDown(true); d.integratorLinearSetMaximumSpeed(0.5f); d.integratorLinearSetAcceleration(1.0f); d.integrate(10.0f); { final VectorI3F expected = new VectorI3F(0.0f, -5.0f, 0.0f); final VectorReadable3FType actual = c.cameraGetPosition(); JCameraFPSStyleLinearIntegratorContract.dumpVector( "position expected", expected); JCameraFPSStyleLinearIntegratorContract.dumpVector( "position actual", actual); Assert.assertEquals(expected.getXF(), actual.getXF(), 0.00001f); Assert.assertEquals(expected.getYF(), actual.getYF(), 0.00001f); Assert.assertEquals(expected.getZF(), actual.getZF(), 0.00001f); } }
@Test public final void testMovingBackward_0() { final JCameraFPSStyleType c = JCameraFPSStyle.newCamera(); final JCameraFPSStyleInputType i = JCameraFPSStyleInput.newInput(); final JCameraFPSStyleLinearIntegratorType d = this.newIntegrator(c, i); i.setMovingBackward(true); d.integratorLinearSetMaximumSpeed(1.0f); d.integratorLinearSetAcceleration(1.0f); d.integratorLinearSetAcceleration(1.0f); d.integrate(10.0f); { final VectorI3F expected = new VectorI3F(0.0f, 0.0f, 10.0f); final VectorReadable3FType actual = c.cameraGetPosition(); JCameraFPSStyleLinearIntegratorContract.dumpVector( "position expected", expected); JCameraFPSStyleLinearIntegratorContract.dumpVector( "position actual", actual); Assert.assertEquals(expected.getXF(), actual.getXF(), 0.00001f); Assert.assertEquals(expected.getYF(), actual.getYF(), 0.00001f); Assert.assertEquals(expected.getZF(), actual.getZF(), 0.00001f); } }
final JCameraFPSStyleAngularIntegratorType d = this.newIntegrator(c, i); i.addRotationAroundVertical(1.0f);
final JCameraFPSStyleAngularIntegratorType d = this.newIntegrator(c, i); i.addRotationAroundHorizontal(1.0f);
private double integrateUp( final double time) { double s = this.speed_up; final boolean forward = this.input.isMovingUp(); if (forward) { s += this.acceleration * time; } final boolean backward = this.input.isMovingDown(); if (backward) { s -= this.acceleration * time; } s = Clamp.clamp(s, -this.maximum_speed, this.maximum_speed); this.camera.cameraMoveUp(s * time); return this.applyDrag(s, time); }
private float integrateForward( final float time) { float s = this.speed_forward; final boolean forward = this.input.isMovingForward(); if (forward) { s += this.acceleration * time; } final boolean backward = this.input.isMovingBackward(); if (backward) { s -= this.acceleration * time; } s = Clamp.clamp(s, -this.maximum_speed, this.maximum_speed); this.camera.cameraMoveForward(s * time); return this.applyDrag(s, time); }