use of com.ardor3d.math.Vector2 in project energy3d by concord-consortium.
the class Building method contains.
public boolean contains(final double x, final double y, final boolean init) {
if (!wallComplete)
return false;
final int n = wallVertices.size();
if (n == 0)
return false;
if (init) {
if (wallPath == null)
wallPath = new Path2D.Double();
else
wallPath.reset();
Vector2 v = wallVertices.get(0);
wallPath.moveTo(v.getX(), v.getY());
for (int i = 1; i < n; i++) {
v = wallVertices.get(i);
wallPath.lineTo(v.getX(), v.getY());
}
v = wallVertices.get(0);
wallPath.lineTo(v.getX(), v.getY());
wallPath.closePath();
}
return wallPath != null ? wallPath.contains(x, y) : false;
}
use of com.ardor3d.math.Vector2 in project energy3d by concord-consortium.
the class Building method calculate.
/**
* @return false if the building does not conform
*/
public boolean calculate() {
final double scale = Scene.getInstance().getAnnotationScale();
height = foundation.getBoundingHeight() * scale;
if (!wallComplete)
return false;
final int n = wallVertices.size();
area = 0;
Vector2 v1, v2;
for (int i = 0; i < n - 1; i++) {
v1 = wallVertices.get(i);
v2 = wallVertices.get(i + 1);
area += v1.getX() * v2.getY() - v2.getX() * v1.getY();
}
v1 = wallVertices.get(n - 1);
v2 = wallVertices.get(0);
area += v1.getX() * v2.getY() - v2.getX() * v1.getY();
area *= 0.5;
cx = 0;
cy = 0;
for (int i = 0; i < n - 1; i++) {
v1 = wallVertices.get(i);
v2 = wallVertices.get(i + 1);
cx += (v1.getX() * v2.getY() - v2.getX() * v1.getY()) * (v1.getX() + v2.getX());
cy += (v1.getX() * v2.getY() - v2.getX() * v1.getY()) * (v1.getY() + v2.getY());
}
v1 = wallVertices.get(n - 1);
v2 = wallVertices.get(0);
cx += (v1.getX() * v2.getY() - v2.getX() * v1.getY()) * (v1.getX() + v2.getX());
cy += (v1.getX() * v2.getY() - v2.getX() * v1.getY()) * (v1.getY() + v2.getY());
cx /= 6 * area;
cy /= 6 * area;
cx *= scale;
cy *= scale;
area = Math.abs(area) * scale * scale;
wallArea = 0;
for (Wall w : walls) {
wallArea += w.getArea();
}
windowArea = 0;
for (Window w : windows) {
windowArea += w.getArea();
}
windowToFloorRatio = windowArea / (area * height / STORY_HEIGHT);
return true;
}
use of com.ardor3d.math.Vector2 in project energy3d by concord-consortium.
the class Foundation method pickMesh.
public void pickMesh(final int x, final int y) {
selectedMesh = null;
if (importedNodes != null) {
final PickResults pickResults = new PrimitivePickResults();
pickResults.setCheckDistance(true);
final Ray3 pickRay = SceneManager.getInstance().getCamera().getPickRay(new Vector2(x, y), false, null);
for (final Node node : importedNodes) {
for (final Spatial s : node.getChildren()) {
if (s instanceof Mesh) {
PickingUtil.findPick(s, pickRay, pickResults, false);
}
}
}
if (pickResults.getNumber() > 0) {
final Pickable pickable = pickResults.getPickData(0).getTarget();
if (pickable instanceof Mesh) {
selectedMesh = (Mesh) pickable;
drawMeshSelection(selectedMesh);
}
} else {
setMeshSelectionVisible(false);
}
}
}
use of com.ardor3d.math.Vector2 in project energy3d by concord-consortium.
the class HousePart method toRelative.
public Vector3 toRelative(final ReadOnlyVector3 p) {
final HousePart container = getContainerRelative();
if (container == null) {
return p.clone();
}
final Vector3 p0 = container.getAbsPoint(0);
final Vector3 p1 = container.getAbsPoint(1);
final Vector3 p2 = container.getAbsPoint(2);
final Vector2 p_2d = new Vector2(p.getX(), p.getY());
final Vector2 p0_2d = new Vector2(p0.getX(), p0.getY());
final double uScale = Util.projectPointOnLineScale(p_2d, p0_2d, new Vector2(p2.getX(), p2.getY()));
final double vScale;
final boolean relativeToHorizontal = getContainerRelative().isHorizontal();
if (relativeToHorizontal) {
vScale = Util.projectPointOnLineScale(p_2d, p0_2d, new Vector2(p1.getX(), p1.getY()));
return new Vector3(uScale, vScale, p.getZ());
} else {
vScale = Util.projectPointOnLineScale(new Vector2(0, p.getZ()), new Vector2(0, p0.getZ()), new Vector2(0, p1.getZ()));
return new Vector3(uScale, 0.0, vScale);
}
}
use of com.ardor3d.math.Vector2 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();
}
}
}));
}
Aggregations