use of com.ardor3d.framework.Canvas in project energy3d by concord-consortium.
the class SceneManager method initMouse.
private void initMouse() {
logicalLayer.registerTrigger(new InputTrigger(new MouseButtonPressedCondition(MouseButton.LEFT), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
((Component) canvas).requestFocusInWindow();
if (Config.isMac()) {
// control-click is mouse right-click on the Mac, skip
final KeyboardState ks = inputStates.getCurrent().getKeyboardState();
if (ks.isDown(Key.LCONTROL) || ks.isDown(Key.RCONTROL)) {
return;
}
}
if (firstClickState == null) {
firstClickState = inputStates;
mousePressed(inputStates.getCurrent().getMouseState(), inputStates.getCurrent().getKeyboardState());
} else {
firstClickState = null;
mouseReleased(inputStates.getCurrent().getMouseState());
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new MouseButtonReleasedCondition(MouseButton.LEFT), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (Config.isMac()) {
// control-click is mouse right-click on the Mac, skip
final KeyboardState ks = inputStates.getCurrent().getKeyboardState();
if (ks.isDown(Key.LCONTROL) || ks.isDown(Key.RCONTROL)) {
return;
}
}
// if editing object using select or resize then only mouse drag is allowed
if (operation == Operation.SELECT || operation == Operation.RESIZE) {
firstClickState = null;
mouseReleased(inputStates.getCurrent().getMouseState());
} else if (firstClickState != null) {
final MouseState mouseState = inputStates.getCurrent().getMouseState();
final MouseState prevMouseState = firstClickState.getCurrent().getMouseState();
final ReadOnlyVector2 p1 = new Vector2(prevMouseState.getX(), prevMouseState.getY());
final ReadOnlyVector2 p2 = new Vector2(mouseState.getX(), mouseState.getY());
if (!(selectedPart instanceof Foundation || selectedPart instanceof Wall || selectedPart instanceof Window || selectedPart instanceof Door) || p1.distance(p2) > 10) {
firstClickState = null;
mouseReleased(inputStates.getCurrent().getMouseState());
}
}
}
}));
((Component) canvas).addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(final MouseEvent e) {
if (Util.isRightClick(e)) {
mouseRightClicked(e);
}
}
@Override
public void mouseReleased(final MouseEvent e) {
if (Util.isRightClick(e)) {
if (cameraChanged) {
TimeSeriesLogger.getInstance().logCamera("Pan");
cameraChanged = false;
}
}
}
});
((Component) canvas).addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(final MouseEvent e) {
EnergyPanel.getInstance().update();
cameraChanged = true;
}
});
((Component) canvas).addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(final MouseWheelEvent e) {
TimeSeriesLogger.getInstance().logCamera("Zoom");
}
});
logicalLayer.registerTrigger(new InputTrigger(new MouseMovedCondition(), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
refresh = true;
mouseState = inputStates.getCurrent().getMouseState();
}
}));
logicalLayer.registerTrigger(new InputTrigger(new MouseButtonClickedCondition(MouseButton.LEFT), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (Config.isMac()) {
// control-click is mouse right-click on the Mac, skip
final KeyboardState ks = inputStates.getCurrent().getKeyboardState();
if (ks.isDown(Key.LCONTROL) || ks.isDown(Key.RCONTROL)) {
return;
}
}
if (!isTopView() && inputStates.getCurrent().getMouseState().getClickCount(MouseButton.LEFT) == 2) {
if (PrintController.getInstance().isPrintPreview()) {
final MouseState mouse = inputStates.getCurrent().getMouseState();
final Ray3 pickRay = Camera.getCurrentCamera().getPickRay(new Vector2(mouse.getX(), mouse.getY()), false, null);
final PickResults pickResults = new PrimitivePickResults();
PickingUtil.findPick(PrintController.getInstance().getPagesRoot(), pickRay, pickResults, false);
if (pickResults.getNumber() > 0) {
cameraControl.zoomAtPoint(pickResults.getPickData(0).getIntersectionRecord().getIntersectionPoint(0));
}
} else {
final PickedHousePart pickedHousePart = SelectUtil.pickPart(inputStates.getCurrent().getMouseState().getX(), inputStates.getCurrent().getMouseState().getY());
if (pickedHousePart != null) {
cameraControl.zoomAtPoint(pickedHousePart.getPoint());
}
}
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.LSHIFT), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
// SelectUtil.setPickLayer(0);
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.LSHIFT), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
// SelectUtil.setPickLayer(-1);
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.DELETE), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
deleteCurrentSelection();
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.BACK), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
deleteCurrentSelection();
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyHeldCondition(Key.ESCAPE), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
hideAllEditPoints();
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ZERO), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
final KeyboardState ks = inputStates.getCurrent().getKeyboardState();
if (Config.isMac()) {
if (ks.isDown(Key.LMETA) || ks.isDown(Key.RMETA)) {
resetCamera();
}
} else {
if (ks.isDown(Key.LCONTROL) || ks.isDown(Key.RCONTROL)) {
resetCamera();
}
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.I), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
System.out.println("---- Parts: ------------------------");
System.out.println("size = " + Scene.getInstance().getParts().size());
for (final HousePart part : Scene.getInstance().getParts()) {
System.out.println(part);
}
System.out.println("---- Scene: ------------------------");
System.out.println("size = " + Scene.getOriginalHouseRoot().getNumberOfChildren());
for (final Spatial mesh : Scene.getOriginalHouseRoot().getChildren()) {
System.out.println(mesh);
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.R), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
Scene.getInstance().redrawAll(true);
}
}));
// Run/pause model replay
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.SPACE), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (PlayControl.active) {
PlayControl.replaying = !PlayControl.replaying;
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.LEFT), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (PlayControl.active) {
PlayControl.replaying = false;
PlayControl.backward = true;
}
if (isTopView()) {
if (tooManyPartsToMove()) {
moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(-1, 0, 0));
} else {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(-1, 0, 0));
keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
}
} else {
if (selectedPart instanceof Window) {
final Vector3 v = selectedPart.getNormal().clone();
v.crossLocal(Vector3.UNIT_Z);
moveWithKey(inputStates.getCurrent().getKeyboardState(), v);
Scene.getInstance().redrawAll();
}
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.LEFT), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.UP), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (PlayControl.active) {
PlayControl.replaying = false;
PlayControl.backward = true;
}
if (isTopView()) {
if (tooManyPartsToMove()) {
moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(0, 1, 0));
} else {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(0, 1, 0));
keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
}
} else {
if (selectedPart instanceof Window) {
final Vector3 n = selectedPart.getNormal().clone();
final Vector3 v = n.cross(Vector3.UNIT_Z, null);
moveWithKey(inputStates.getCurrent().getKeyboardState(), v.crossLocal(n));
Scene.getInstance().redrawAll();
}
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.UP), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.RIGHT), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (PlayControl.active) {
PlayControl.replaying = false;
PlayControl.forward = true;
}
if (isTopView()) {
if (tooManyPartsToMove()) {
moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(1, 0, 0));
} else {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(1, 0, 0));
keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
}
} else {
if (selectedPart instanceof Window) {
final Vector3 v = selectedPart.getNormal().clone();
v.crossLocal(Vector3.UNIT_Z).negateLocal();
moveWithKey(inputStates.getCurrent().getKeyboardState(), v);
Scene.getInstance().redrawAll();
}
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.RIGHT), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.DOWN), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (PlayControl.active) {
PlayControl.replaying = false;
PlayControl.forward = true;
}
if (isTopView()) {
if (tooManyPartsToMove()) {
moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(0, -1, 0));
} else {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(0, -1, 0));
keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
}
} else {
if (selectedPart instanceof Window) {
final Vector3 n = selectedPart.getNormal().clone();
final Vector3 v = n.cross(Vector3.UNIT_Z, null).negateLocal();
moveWithKey(inputStates.getCurrent().getKeyboardState(), v.crossLocal(n));
Scene.getInstance().redrawAll();
}
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.DOWN), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.ESCAPE), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
PlayControl.active = false;
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.W), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (tooManyPartsToMove()) {
moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(-1, 0, 0));
} else {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(-1, 0, 0));
keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.W), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.E), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (tooManyPartsToMove()) {
moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(1, 0, 0));
} else {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(1, 0, 0));
keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.E), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.S), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (tooManyPartsToMove()) {
moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(0, -1, 0));
} else {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(0, -1, 0));
keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.S), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.N), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (tooManyPartsToMove()) {
moveWithKey(inputStates.getCurrent().getKeyboardState(), new Vector3(0, 1, 0));
} else {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
arrowKeyHolderTask = new KeyHolderTask(inputStates.getCurrent().getKeyboardState(), new Vector3(0, 1, 0));
keyHolder.scheduleAtFixedRate(arrowKeyHolderTask, 0, keyHolderInterval);
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new KeyReleasedCondition(Key.N), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (arrowKeyHolderTask != null) {
arrowKeyHolderTask.cancel();
}
}
}));
}
use of com.ardor3d.framework.Canvas in project energy3d by concord-consortium.
the class CameraControl method setupMouseTriggers.
public void setupMouseTriggers(final LogicalLayer layer, final boolean dragOnly) {
// Mouse look
final Predicate<TwoInputStates> someMouseDown = Predicates.or(TriggerConditions.leftButtonDown(), Predicates.or(TriggerConditions.rightButtonDown(), TriggerConditions.middleButtonDown()));
final Predicate<TwoInputStates> dragged = Predicates.and(TriggerConditions.mouseMoved(), Predicates.and(someMouseDown, Predicates.not(new KeyHeldCondition(Key.LCONTROL))));
final TriggerAction dragAction = new TriggerAction() {
// Test boolean to allow us to ignore first mouse event. First event can wildly vary based on platform.
private boolean firstPing = true;
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (!enabled || !mouseEnabled) {
return;
}
final MouseState mouse = inputStates.getCurrent().getMouseState();
if (mouse.getDx() != 0 || mouse.getDy() != 0) {
if (!firstPing) {
final boolean left = leftMouseButtonEnabled && mouse.getButtonState(MouseButton.LEFT) == ButtonState.DOWN;
final boolean right = rightMouseButtonEnabled && mouse.getButtonState(MouseButton.RIGHT) == ButtonState.DOWN;
final boolean middle = mouse.getButtonState(MouseButton.MIDDLE) == ButtonState.DOWN;
if (left && leftButtonAction == ButtonAction.MOVE || right && rightButtonAction == ButtonAction.MOVE) {
// increase the factor from 150 to speed up moving in the top view
final double fac = Camera.getCurrentCamera().getLocation().length() * 200;
final double dx = -mouse.getDx() * fac / Camera.getCurrentCamera().getWidth();
final double dy = -mouse.getDy() * fac / Camera.getCurrentCamera().getHeight();
move(source.getCanvasRenderer().getCamera(), dx, dy);
SceneManager.getInstance().getCameraNode().updateFromCamera();
Scene.getInstance().updateEditShapes();
} else if (left && leftButtonAction == ButtonAction.ROTATE || right && rightButtonAction == ButtonAction.ROTATE) {
rotate(source.getCanvasRenderer().getCamera(), -mouse.getDx(), -mouse.getDy());
SceneManager.getInstance().getCameraNode().updateFromCamera();
Scene.getInstance().updateEditShapes();
} else if (middle || left && leftButtonAction == ButtonAction.ZOOM || right && rightButtonAction == ButtonAction.ZOOM) {
zoom(source, tpf, -mouse.getDy() * getCurrentExtent() / 100);
}
} else {
firstPing = false;
}
}
}
};
_mouseTrigger = new InputTrigger(dragOnly ? dragged : TriggerConditions.mouseMoved(), dragAction);
layer.registerTrigger(_mouseTrigger);
layer.registerTrigger(new InputTrigger(new MouseWheelMovedCondition(), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
zoom(source, tpf, inputStates.getCurrent().getMouseState().getDwheel() * getCurrentExtent() / 20);
}
}));
}
use of com.ardor3d.framework.Canvas in project energy3d by concord-consortium.
the class Heliodon method initMouse.
private void initMouse(final LogicalLayer logicalLayer) {
logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.F), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
setSunRegionAlwaysVisible(!forceSunRegionOn);
}
}));
logicalLayer.registerTrigger(new InputTrigger(new MouseButtonPressedCondition(MouseButton.LEFT), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
oldHourAngle = hourAngle;
changeTimeAndDateCommand = new ChangeTimeAndDateWithHeliodonCommand(calendar.getTime());
final int x = inputStates.getCurrent().getMouseState().getX();
final int y = inputStates.getCurrent().getMouseState().getY();
final Ray3 pickRay = SceneManager.getInstance().getCanvas().getCanvasRenderer().getCamera().getPickRay(new Vector2(x, y), false, null);
pickResults.clear();
PickingUtil.findPick(sun, pickRay, pickResults);
if (pickResults.getNumber() != 0) {
sunGrabbed = true;
} else {
sunGrabbed = false;
}
if (forceSunRegionOn) {
selectDifferentDeclinationWithMouse = true;
} else {
selectDifferentDeclinationWithMouse = false;
}
SceneManager.getInstance().setMouseControlEnabled(!sunGrabbed);
}
}));
logicalLayer.registerTrigger(new InputTrigger(new MouseButtonReleasedCondition(MouseButton.LEFT), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
sunGrabbed = false;
if (!forceSunRegionOn) {
sunRegion.getSceneHints().setCullHint(CullHint.Always);
}
SceneManager.getInstance().setMouseControlEnabled(true);
if (!Util.isEqual(oldHourAngle, hourAngle) && changeTimeAndDateCommand != null) {
SceneManager.getInstance().getUndoManager().addEdit(changeTimeAndDateCommand);
}
}
}));
logicalLayer.registerTrigger(new InputTrigger(new MouseMovedCondition(), new TriggerAction() {
@Override
public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) {
if (!sunGrabbed) {
return;
}
final MouseState mouse = inputStates.getCurrent().getMouseState();
final Ray3 pickRay = SceneManager.getInstance().getCamera().getPickRay(new Vector2(mouse.getX(), mouse.getY()), false, null);
pickResults.clear();
PickingUtil.findPick(sunRegion, pickRay, pickResults);
final Vector3 intersectionPoint;
if (pickResults.getNumber() > 0) {
final IntersectionRecord intersectionRecord = pickResults.getPickData(0).getIntersectionRecord();
intersectionPoint = intersectionRecord.getIntersectionPoint(intersectionRecord.getClosestIntersection());
} else {
intersectionPoint = null;
}
double smallestDistance = Double.MAX_VALUE;
int hourVertex = -1;
int totalHourVertices = 0;
final Vector3 newSunLocation = new Vector3();
final Vector3 p = new Vector3();
final Vector3 p_abs = new Vector3();
final ReadOnlyTransform rootTansform = root.getTransform();
if (!selectDifferentDeclinationWithMouse) {
final FloatBuffer buf = sunPath.getMeshData().getVertexBuffer();
buf.rewind();
while (buf.hasRemaining()) {
p.set(buf.get(), buf.get(), buf.get());
rootTansform.applyForward(p, p_abs);
final double d;
d = pickRay.distanceSquared(p_abs, null);
if (d < smallestDistance) {
smallestDistance = d;
hourVertex = buf.position() / 3 - 1;
newSunLocation.set(p);
}
}
totalHourVertices = buf.limit() / 3;
}
if (smallestDistance > 5.0 * root.getTransform().getScale().getX() * root.getTransform().getScale().getX()) {
selectDifferentDeclinationWithMouse = true;
}
boolean declinationChanged = false;
if (selectDifferentDeclinationWithMouse) {
sunRegion.getSceneHints().setCullHint(CullHint.Inherit);
int rowCounter = 0;
int resultRow = -1;
final FloatBuffer buf = sunRegion.getMeshData().getVertexBuffer();
buf.rewind();
final double r = 5.0 / 2.0;
final Vector3 prev = new Vector3();
int quadVertexCounter = 0;
final double maxVertexInRow = HOUR_DIVISIONS * 4.0;
int rowVertexCounter = 0;
boolean foundInThisRow = false;
while (buf.hasRemaining()) {
p.set(buf.get(), buf.get(), buf.get());
rootTansform.applyForward(p, p_abs);
final double d;
if (intersectionPoint != null) {
d = intersectionPoint.distanceSquared(p_abs);
} else {
d = pickRay.distanceSquared(p_abs, null);
}
if (d < smallestDistance && p.getZ() >= -MathUtils.ZERO_TOLERANCE) {
smallestDistance = d;
newSunLocation.set(p);
resultRow = rowCounter + (quadVertexCounter >= 2 ? 1 : 0);
hourVertex = rowVertexCounter / 4 + (quadVertexCounter == 1 || quadVertexCounter == 2 ? 1 : 0);
foundInThisRow = true;
}
if (prev.lengthSquared() != 0 && (prev.distance(p) > r || rowVertexCounter >= maxVertexInRow)) {
rowCounter++;
if (foundInThisRow) {
totalHourVertices = rowVertexCounter / 4;
}
foundInThisRow = false;
rowVertexCounter = 0;
}
prev.set(p);
quadVertexCounter = (quadVertexCounter + 1) % 4;
rowVertexCounter++;
}
rowCounter++;
if (resultRow != -1) {
if (rowCounter < DECLINATION_DIVISIONS && latitude > 0) {
resultRow += DECLINATION_DIVISIONS - rowCounter;
}
final double newDeclinationAngle = -TILT_ANGLE + (2.0 * TILT_ANGLE * resultRow / DECLINATION_DIVISIONS);
declinationChanged = !Util.isEqual(newDeclinationAngle, declinationAngle);
if (declinationChanged) {
setDeclinationAngle(newDeclinationAngle, false, true);
dirtySunPath = true;
}
}
}
final double newHourAngle = (hourVertex - Math.floor(totalHourVertices / 2.0)) * Math.PI / 48.0;
final boolean hourAngleChanged = !Util.isEqual(newHourAngle, hourAngle);
if (hourAngleChanged) {
setHourAngle(newHourAngle, false, true, false);
}
if (declinationChanged || hourAngleChanged) {
setSunLocation(newSunLocation);
drawSunTriangle();
EnergyPanel.getInstance().updateRadiationHeatMap();
}
}
}));
}
Aggregations