use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class SceneManager method createCompass.
private Node createCompass() throws IOException {
final ResourceSource source = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_MODEL, "compass.dae");
final ColladaImporter colladaImporter = new ColladaImporter();
// Load the collada scene
Logger.getLogger(ColladaAnimUtils.class.getName()).setLevel(Level.SEVERE);
Logger.getLogger(ColladaMaterialUtils.class.getName()).setLevel(Level.SEVERE);
final ColladaStorage storage = colladaImporter.load(source);
final Node compass = storage.getScene();
BMText txt;
final double Z = 0.1;
txt = new BMText("N", "N", FontManager.getInstance().getAnnotationFont(), Align.South);
txt.setTextColor(ColorRGBA.BLACK);
txt.setAutoRotate(false);
txt.setTranslation(2, 0.0, Z);
txt.setRotation(new Matrix3().fromAngles(0.0, MathUtils.HALF_PI, -MathUtils.HALF_PI));
compass.attachChild(txt);
txt = new BMText("S", "S", FontManager.getInstance().getAnnotationFont(), Align.South);
txt.setTextColor(ColorRGBA.BLACK);
txt.setAutoRotate(false);
txt.setTranslation(-2, -0.0, Z);
txt.setRotation(new Matrix3().fromAngles(0.0, -MathUtils.HALF_PI, MathUtils.HALF_PI));
compass.attachChild(txt);
txt = new BMText("W", "W", FontManager.getInstance().getAnnotationFont(), Align.South);
txt.setAutoRotate(false);
txt.setTranslation(-0.0, 2, Z);
txt.setRotation(new Matrix3().fromAngles(-MathUtils.HALF_PI, 0.0, 0.0));
compass.attachChild(txt);
txt = new BMText("E", "E", FontManager.getInstance().getAnnotationFont(), Align.South);
txt.setAutoRotate(false);
txt.setTranslation(-0.0, -2, Z);
txt.setRotation(new Matrix3().fromAngles(MathUtils.HALF_PI, MathUtils.PI, 0.0));
compass.attachChild(txt);
final DirectionalLight light = new DirectionalLight();
light.setDirection(new Vector3(0, 0, -1));
light.setEnabled(true);
final LightState lightState = new LightState();
lightState.attach(light);
compass.setRenderState(lightState);
compass.getSceneHints().setLightCombineMode(LightCombineMode.Replace);
compass.updateWorldRenderStates(true);
final Node compassNode = new Node();
compassNode.setRotation(new Matrix3().fromAngles(-MathUtils.HALF_PI, 0.0, 0.0));
compassNode.attachChild(compass);
System.out.println("done");
compass.addController(new SpatialController<Spatial>() {
@Override
public void update(final double time, final Spatial caller) {
final Vector3 direction = getCamera().getDirection().normalize(null);
direction.setZ(0);
direction.normalizeLocal();
double angle = -direction.smallestAngleBetween(Vector3.UNIT_Y);
if (direction.dot(Vector3.UNIT_X) > 0) {
angle = -angle;
}
angle -= MathUtils.HALF_PI;
compass.setRotation(new Matrix3().fromAngles(0.0, 0.0, angle - 0.3));
}
});
return compassNode;
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class SceneManager method mouseMoved.
private void mouseMoved() {
if (!mouseControlEnabled) {
return;
}
final int x = mouseState.getX();
final int y = mouseState.getY();
if (Scene.getInstance().getDisableShadowInAction()) {
if (mouseState.getButtonState(MouseButton.LEFT) == ButtonState.DOWN || mouseState.getButtonState(MouseButton.RIGHT) == ButtonState.DOWN) {
if (MainPanel.getInstance().getShadowButton().isSelected()) {
shadowPass.setEnabled(false);
}
} else {
if (MainPanel.getInstance().getShadowButton().isSelected()) {
shadowPass.setEnabled(true);
}
}
}
try {
if (selectedPart != null) {
if (!selectedPart.isDrawCompleted()) {
selectedPart.setPreviewPoint(x, y);
if (selectedPart instanceof Meshable) {
// don't draw grid if it sits on an imported mesh
selectedPart.setGridsVisible(((Meshable) selectedPart).getMeshLocator() == null);
}
} else if (objectMoveStartPoint != null) {
if ((operation == Operation.RESIZE || selectedPart instanceof Foundation)) {
final PickedHousePart pick = SelectUtil.pickPart(x, y, collisionLand);
if (pick != null) {
if (selectedPart instanceof Foundation) {
final Foundation foundation = (Foundation) selectedPart;
final Vector3 pickPoint = pick.getPoint().clone();
// if (!foundation.insideBuilding(pickPoint.getX(), pickPoint.getY(), true)) { // only move the building when clicking outside
final Vector3 d = pickPoint.multiply(1, 1, 0, null).subtractLocal(objectMoveStartPoint.multiply(1, 1, 0, null));
if (foundation.isGroupMaster()) {
final List<Foundation> g = Scene.getInstance().getFoundationGroup(foundation);
for (final Foundation f : g) {
final ArrayList<Vector3> movePoints = objectGroupMovePoints.get(f);
if (movePoints != null) {
// just in case this foundation's move point hasn't been included yet
f.move(d, movePoints);
}
}
} else {
foundation.move(d, objectMovePoints);
}
}
}
} else if (selectedPart instanceof Tree) {
final PickedHousePart pick = SelectUtil.pickPart(x, y, collisionLand);
if (pick != null) {
final Vector3 d = pick.getPoint().multiply(1, 1, 0, null).subtractLocal(objectMoveStartPoint.multiply(1, 1, 0, null));
((Tree) selectedPart).move(d, objectMovePoints);
}
} else if (selectedPart instanceof Window) {
final PickedHousePart pick = SelectUtil.pickPart(x, y, selectedPart.getContainer());
if (pick != null) {
final Vector3 d = pick.getPoint().subtract(objectMoveStartPoint, null);
((Window) selectedPart).move(d, objectMovePoints);
}
}
}
}
hoveredPart = null;
if ((operation == Operation.SELECT || operation == Operation.RESIZE) && mouseState.getButtonState(MouseButton.LEFT) == ButtonState.UP && mouseState.getButtonState(MouseButton.MIDDLE) == ButtonState.UP && mouseState.getButtonState(MouseButton.RIGHT) == ButtonState.UP) {
final PickedHousePart pickedPart = SelectUtil.selectHousePart(x, y, false);
pick = pickedPart == null ? null : pickedPart.getUserData();
final HousePart housePart = pick == null ? null : pick.getHousePart();
if (pick != null) {
hoveredPart = housePart;
if (pick.getEditPointIndex() != -1) {
lastSelectedEditPointMouseState = mouseState;
}
}
}
mouseState = null;
} catch (final Throwable t) {
t.printStackTrace();
BugReporter.report(t);
}
EventQueue.invokeLater(new // this method is run by the main Energy3D thread, so invoke the Swing code later
Runnable() {
@Override
public void run() {
final Component canvasComponent = (Component) canvas;
canvasComponent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
if (!zoomLock && (operation == Operation.SELECT || operation == Operation.RESIZE) && hoveredPart != null) {
if (hoveredPart instanceof Tree || hoveredPart instanceof Human) {
canvasComponent.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
} else if (hoveredPart instanceof SolarCollector) {
if (pick.getEditPointIndex() >= 0) {
canvasComponent.setCursor(Cursor.getPredefinedCursor(pick.getEditPointIndex() == 0 ? Cursor.MOVE_CURSOR : Cursor.HAND_CURSOR));
}
} else {
if (pick.getEditPointIndex() == -1) {
if (hoveredPart instanceof Window) {
// for windows, there is no apparent move point
canvasComponent.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
}
}
}
}
}
});
}
use of com.ardor3d.math.Vector3 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.math.Vector3 in project energy3d by concord-consortium.
the class AngleAnnotation method draw.
@Override
public void draw() {
final ReadOnlyVector3 a = new Vector3().set(p2).subtractLocal(mainPoint).normalizeLocal();
final ReadOnlyVector3 b = new Vector3().set(p3).subtractLocal(mainPoint).normalizeLocal();
final ReadOnlyVector3 axis = n.cross(Vector3.UNIT_Z, null).normalizeLocal();
final Matrix3 toFlat = new Matrix3().fromAngleAxis(Util.angleBetween(n, Vector3.UNIT_Z, n.cross(Vector3.UNIT_Z, null).normalizeLocal()), axis);
final ReadOnlyVector3 aFlat = toFlat.applyPost(a, null);
final ReadOnlyVector3 bFlat = toFlat.applyPost(b, null);
double start, angle;
if (Util.angleBetween(aFlat, bFlat, Vector3.UNIT_Z) >= 0) {
start = Util.angleBetween(Vector3.UNIT_X, aFlat, Vector3.UNIT_Z);
angle = Util.angleBetween(aFlat, bFlat, Vector3.UNIT_Z);
} else {
start = Util.angleBetween(Vector3.UNIT_X, bFlat, Vector3.UNIT_Z);
angle = Util.angleBetween(bFlat, aFlat, Vector3.UNIT_Z);
}
double end = start + angle;
final long angleDegrees = Math.round(Math.toDegrees(end - start));
final double radius = customRadius > 0 ? customRadius : (end == start ? 0.0 : 3.0 / Math.sqrt(end - start));
if (angleDegrees == 90) {
final ReadOnlyVector3[] p = new ReadOnlyVector3[3];
p[0] = a.normalize(null).multiplyLocal(2.0);
p[1] = a.normalize(null).addLocal(b.normalize(null)).multiplyLocal(2.0);
p[2] = b.normalize(null).multiplyLocal(2.0);
final FloatBuffer buf = mesh.getMeshData().getVertexBuffer();
buf.rewind();
buf.limit(9);
mesh.getMeshData().updateVertexCount();
buf.rewind();
for (final ReadOnlyVector3 v : p) {
buf.put(v.getXf()).put(v.getYf()).put(v.getZf());
}
mesh.setRotation(new Matrix3());
detachChild(label);
} else {
boolean special = false;
if ("A".equals(customText) && Util.isEqual(start, Math.PI / 2)) {
// special case for azimuth
angle = angle - Math.PI * 2;
if (Util.isEqual(Math.abs(angle), 2 * Math.PI)) {
angle = 0;
}
end = start + angle;
label.setText("A=" + (angleDegrees == 0 ? 0 : (360 - angleDegrees)) + "\u00B0");
special = true;
} else {
label.setText((customText != null ? customText + "=" : "") + angleDegrees + "\u00B0");
}
((Arc) mesh).set(radius, start, end);
mesh.setRotation(toFlat.invertLocal());
final double start360 = start < 0 ? MathUtils.TWO_PI + start : start;
final double angle360 = angle < 0 ? MathUtils.TWO_PI + angle : angle;
final double end360 = start360 + angle360;
final Matrix3 rotMatrix = toFlat.multiplyLocal(new Matrix3().fromAngles(-Math.PI / 2, 0, (special ? Math.PI / 2 : -Math.PI / 2) + (start360 + end360) / 2));
label.setRotation(rotMatrix);
final Vector3 trans = new Vector3(0, 0, radius / 1.7);
label.setTranslation(rotMatrix.applyPost(trans, trans));
attachChild(label);
}
mesh.updateModelBound();
this.setTranslation(mainPoint);
}
use of com.ardor3d.math.Vector3 in project energy3d by concord-consortium.
the class Heliodon method drawSunPath.
private void drawSunPath() {
final FloatBuffer buf = sunPath.getMeshData().getVertexBuffer();
buf.limit(buf.capacity());
buf.rewind();
final double step = MathUtils.TWO_PI / HOUR_DIVISIONS;
int limit = 0;
for (double hourAngle = -Math.PI; hourAngle < Math.PI + step / 2.0; hourAngle += step) {
final Vector3 v = computeSunLocation(hourAngle, declinationAngle, latitude);
if (v.getZ() > -0.3) {
buf.put(v.getXf()).put(v.getYf()).put(v.getZf());
limit += 3;
}
}
buf.limit(limit);
sunPath.updateModelBound();
sunPath.getSceneHints().setCullHint(limit == 0 ? CullHint.Always : CullHint.Inherit);
dirtySunPath = false;
}
Aggregations