/** * Construct a new immutable {@code JCameraSphericalMouseRegion} instance. * @param origin The value for the {@code origin} attribute * @param width The value for the {@code width} attribute * @param height The value for the {@code height} attribute * @return An immutable JCameraSphericalMouseRegion instance */ public static JCameraSphericalMouseRegion of(JCameraScreenOrigin origin, double width, double height) { return validate(new JCameraSphericalMouseRegion(origin, width, height)); }
private static JCameraSphericalMouseRegion validate(JCameraSphericalMouseRegion instance) { instance.checkPreconditions(); return instance; }
/** * This instance is equal to all instances of {@code JCameraSphericalMouseRegion} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(Object another) { if (this == another) return true; return another instanceof JCameraSphericalMouseRegion && equalTo((JCameraSphericalMouseRegion) another); }
/** * Construct a new mouse region. * * @param in_origin The screen origin. * @param in_width The region width. * @param in_height The region height. * * @return A new mouse region. */ public static JCameraSphericalMouseRegion newRegion( final JCameraScreenOrigin in_origin, final float in_width, final float in_height) { return new JCameraSphericalMouseRegion(in_origin, in_width, in_height); }
@Test public void testCoefficientsBottomLeft() { final VectorM2F out = new VectorM2F(); final JCameraSphericalMouseRegion r = JCameraSphericalMouseRegion.newRegion( JCameraScreenOrigin.SCREEN_ORIGIN_BOTTOM_LEFT, 640, 480); r.getPosition(0, 0, out); Assert.assertEquals(-1.0f, out.getXF(), 0.0f); Assert.assertEquals(-1.0f, out.getYF(), 0.0f); r.getPosition(640, 480, out); Assert.assertEquals(1.0f, out.getXF(), 0.0f); Assert.assertEquals(1.0f, out.getYF(), 0.0f); r.getPosition(320, 240, out); Assert.assertEquals(0.0f, out.getXF(), 0.0f); Assert.assertEquals(0.0f, out.getYF(), 0.0f); }
@Override public void reshape( final @Nullable GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { this.mouse_region.set(JCameraSphericalMouseRegion.of( JCameraScreenOrigin.SCREEN_ORIGIN_TOP_LEFT, (double) width, (double) height)); this.renderer.reshape(width, height); } }
@Override public void mouseDragged( final @Nullable MouseEvent e) { assert e != null; if (e.isButtonDown(2)) { this.position_normalized = this.mouse_region.get().position((double) e.getX(), (double) e.getY()); final double px = -this.position_normalized.x(); final double py = -this.position_normalized.y(); this.input.addTargetMovingContinuousForward(py); this.input.addTargetMovingContinuousRight(px); this.renderer.sendWantWarpPointer(); } } }
/** * Creates an immutable copy of a {@link JCameraSphericalMouseRegionType} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable JCameraSphericalMouseRegion instance */ public static JCameraSphericalMouseRegion copyOf(JCameraSphericalMouseRegionType instance) { if (instance instanceof JCameraSphericalMouseRegion) { return (JCameraSphericalMouseRegion) instance; } return JCameraSphericalMouseRegion.builder() .from(instance) .build(); }
/** * Builds a new {@link JCameraSphericalMouseRegion JCameraSphericalMouseRegion}. * @return An immutable instance of JCameraSphericalMouseRegion * @throws java.lang.IllegalStateException if any required attributes are missing */ public JCameraSphericalMouseRegion build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return JCameraSphericalMouseRegion.validate(new JCameraSphericalMouseRegion(null, origin, width, height)); }
@Test public void testCoefficientsTopLeft() { final VectorM2F out = new VectorM2F(); final JCameraSphericalMouseRegion r = JCameraSphericalMouseRegion.newRegion( JCameraScreenOrigin.SCREEN_ORIGIN_TOP_LEFT, 640, 480); r.getPosition(0, 0, out); Assert.assertEquals(-1.0f, out.getXF(), 0.0f); Assert.assertEquals(1.0f, out.getYF(), 0.0f); r.getPosition(640, 480, out); Assert.assertEquals(1.0f, out.getXF(), 0.0f); Assert.assertEquals(-1.0f, out.getYF(), 0.0f); r.getPosition(320, 240, out); Assert.assertEquals(0.0f, out.getXF(), 0.0f); Assert.assertEquals(0.0f, out.getYF(), 0.0f); } }
JCameraSphericalMouseRegion.of( JCameraScreenOrigin.SCREEN_ORIGIN_TOP_LEFT, 640.0,
@Override public void mouseMoved( final @Nullable MouseEvent e) { assert e != null; this.position_normalized = this.mouse_region.get().position((double) e.getX(), (double) e.getY()); if (this.position_normalized.x() <= -0.98) { this.input.setTargetMovingLeftCursor(true); } else { this.input.setTargetMovingLeftCursor(false); } if (this.position_normalized.x() >= 0.98) { this.input.setTargetMovingRightCursor(true); } else { this.input.setTargetMovingRightCursor(false); } if (this.position_normalized.y() <= -0.98) { this.input.setTargetMovingBackwardCursor(true); } else { this.input.setTargetMovingBackwardCursor(false); } if (this.position_normalized.y() >= 0.98) { this.input.setTargetMovingForwardCursor(true); } else { this.input.setTargetMovingForwardCursor(false); } }
/** * Copy the current immutable object by setting a value for the {@link JCameraSphericalMouseRegionType#origin() origin} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for origin * @return A modified copy of the {@code this} object */ public final JCameraSphericalMouseRegion withOrigin(JCameraScreenOrigin value) { if (this.origin == value) return this; JCameraScreenOrigin newValue = Objects.requireNonNull(value, "origin"); return validate(new JCameraSphericalMouseRegion(this, newValue, this.width, this.height)); }
JCameraSphericalMouseRegion.of( JCameraScreenOrigin.SCREEN_ORIGIN_BOTTOM_LEFT, (double) in_window.getWidth(),
/** * Copy the current immutable object by setting a value for the {@link JCameraSphericalMouseRegionType#width() width} attribute. * A value strict bits equality used to prevent copying of the same value by returning {@code this}. * @param value A new value for width * @return A modified copy of the {@code this} object */ public final JCameraSphericalMouseRegion withWidth(double value) { if (Double.doubleToLongBits(this.width) == Double.doubleToLongBits(value)) return this; return validate(new JCameraSphericalMouseRegion(this, this.origin, value, this.height)); }
/** * Copy the current immutable object by setting a value for the {@link JCameraSphericalMouseRegionType#height() height} attribute. * A value strict bits equality used to prevent copying of the same value by returning {@code this}. * @param value A new value for height * @return A modified copy of the {@code this} object */ public final JCameraSphericalMouseRegion withHeight(double value) { if (Double.doubleToLongBits(this.height) == Double.doubleToLongBits(value)) return this; return validate(new JCameraSphericalMouseRegion(this, this.origin, this.width, value)); }