If Canvas3D instances are correctly displayed and resized with HiDPI screens in Java 3D 1.6.1, mouse event coordinates are not correctly scaled yet
The
xscale and
yscale fields
added to Canvas3D should also be used to scale mouse coordinates, probably in
addMouseListener,
addMouseMotionListener,
addMouseWheelListener overridden methods of
Canvas3D, which would scale these coordinates before calling user listeners. But maybe, it's more tricky than that, because
MouseBehavior class handles mouse events too.
Meanwhile, here's a dirty hack that you can use to convert your coordinates if needed. The following method will return fixed mouse coordinates with Java 3D 1.6.1:
Point getMouseLocation(MouseEvent ev) {
try {
Field xscaleField = Canvas3D.class.getDeclaredField("xscale");
xscaleField.setAccessible(true);
double xscale = (Double)(xscaleField.get(ev.getSource()));
Field yscaleField = Canvas3D.class.getDeclaredField("yscale");
yscaleField.setAccessible(true);
double yscale = (Double)(yscaleField.get(ev.getSource()));
return new Point((int)(ev.getX() * xscale), (int)(ev.getY() * yscale));
} catch (Exception ex) {
return ev.getPoint();
}
}
Emmanuel Puybaret