public void mousePressed( java.awt.event.MouseEvent ev, edu.cmu.cs.stage3.alice.core.Transformable pickedTransformable, edu.cmu.cs.stage3.alice.scenegraph.renderer.PickInfo pickInfo) { if (isButton1(ev)) { undoRedoStack.startCompound(); if (pickedTransformable != null) { String name = edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getNameForNewChild( pickedTransformable.name.getStringValue(), pickedTransformable.getParent()); int index = pickedTransformable.getParent().getIndexOfChild(pickedTransformable) + 1; // if( undoRedoStack != null ) { // undoRedoStack.setIsListening( true ); // make the copy get automatically picked up by // the undoRedoStack // } pickedTransformable = (edu.cmu.cs.stage3.alice.core.Transformable) pickedTransformable.HACK_createCopy( name, pickedTransformable.getParent(), index, classesToShare, null); edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources .addElementToAppropriateProperty(pickedTransformable, pickedTransformable.getParent()); // undoRedoStack.push( new // edu.cmu.cs.stage3.alice.authoringtool.util.PropertyUndoableRedoable( // pickedTransformable.vehicle, null, pickedTransformable.vehicle.get() ) ); // if( undoRedoStack != null ) { // undoRedoStack.setIsListening( false ); // } } super.mousePressed(ev, pickedTransformable, pickInfo); hasBeenDragged = false; } }
@Override protected Object getValue(Transformable subjectValue, Transformable objectValue) { if (subjectValue.getVolume() > objectValue.getVolume()) { return Boolean.TRUE; } else { return Boolean.FALSE; } }
protected Object getValue(Transformable subjectValue, Transformable objectValue) { double thresholdValue = threshold.doubleValue(); if (subjectValue.getDistanceSquaredTo(objectValue) > thresholdValue * thresholdValue) { return Boolean.TRUE; } else { return Boolean.FALSE; } }
public void released(Point p) { if ((pickedTransformable != null) && (undoRedoStack != null)) { undoRedoStack.push( new PointOfViewUndoableRedoable( pickedTransformable, oldTransformation, pickedTransformable.getLocalTransformation(), scheduler)); } }
public void selected( edu.cmu.cs.stage3.alice.core.Transformable pickedTransformable, edu.cmu.cs.stage3.alice.scenegraph.renderer.PickInfo pickInfo, Point p) { this.pickedTransformable = pickedTransformable; if (pickedTransformable != null) { camera = (edu.cmu.cs.stage3.alice.core.Camera) pickInfo.getSource().getBonus(); world = (edu.cmu.cs.stage3.alice.core.World) camera.getSceneGraphCamera().getRoot().getBonus(); oldTransformation = pickedTransformable.getLocalTransformation(); helper.vehicle.set(world); identity.vehicle.set(world); } }
public void dragged(int dx, int dy, boolean isControlDown, boolean isShiftDown) { if (pickedTransformable != null) { boolean controlDown = isControlDown; boolean shiftDown = isShiftDown; double deltaFactor; if (camera instanceof edu.cmu.cs.stage3.alice.core.camera.OrthographicCamera) { edu.cmu.cs.stage3.alice.core.camera.OrthographicCamera orthoCamera = (edu.cmu.cs.stage3.alice.core.camera.OrthographicCamera) camera; double nearClipHeightInScreen = renderTarget .getAWTComponent() .getHeight(); // TODO: should be viewport, but not working right now double nearClipHeightInWorld = orthoCamera.getSceneGraphOrthographicCamera().getPlane()[3] - orthoCamera.getSceneGraphOrthographicCamera().getPlane()[1]; deltaFactor = nearClipHeightInWorld / nearClipHeightInScreen; if (controlDown) { if (shiftDown) { helper.setTransformationRightNow( edu.cmu.cs.stage3.math.MathUtilities.createIdentityMatrix4d(), camera); helper.setPositionRightNow(zeroVec, pickedTransformable); pickedTransformable.rotateRightNow( edu.cmu.cs.stage3.math.MathUtilities.getXAxis(), -dy * .01, helper); pickedTransformable.rotateRightNow( edu.cmu.cs.stage3.math.MathUtilities.getYAxis(), -dx * .01, pickedTransformable); } else { helper.setTransformationRightNow( edu.cmu.cs.stage3.math.MathUtilities.createIdentityMatrix4d(), camera); helper.setPositionRightNow(zeroVec, pickedTransformable); pickedTransformable.rotateRightNow( edu.cmu.cs.stage3.math.MathUtilities.getZAxis(), -dx * .01, helper); } } else if (shiftDown) { helper.setTransformationRightNow( edu.cmu.cs.stage3.math.MathUtilities.createIdentityMatrix4d(), camera); helper.setPositionRightNow(zeroVec, pickedTransformable); tempVec.x = 0.0; tempVec.y = -dy * deltaFactor; tempVec.z = 0.0; pickedTransformable.moveRightNow(tempVec, helper); } else { helper.setTransformationRightNow( edu.cmu.cs.stage3.math.MathUtilities.createIdentityMatrix4d(), camera); helper.setPositionRightNow(zeroVec, pickedTransformable); tempVec.x = dx * deltaFactor; tempVec.y = -dy * deltaFactor; tempVec.z = 0.0; pickedTransformable.moveRightNow(tempVec, helper); } } else { double projectionMatrix11 = renderTarget.getProjectionMatrix(camera.getSceneGraphCamera()).getElement(1, 1); double nearClipDist = camera.nearClippingPlaneDistance.doubleValue(); double nearClipHeightInWorld = 2 * (nearClipDist / projectionMatrix11); double nearClipHeightInScreen = renderTarget .getAWTComponent() .getHeight(); // TODO: should be viewport, but not working right now double pixelHeight = nearClipHeightInWorld / nearClipHeightInScreen; // double pixelHeight = nearClipHeightInWorld/300; double objectDist = pickedTransformable.getPosition(camera).getLength(); deltaFactor = (objectDist * pixelHeight) / nearClipDist; if (controlDown) { if (shiftDown) { helper.setTransformationRightNow( edu.cmu.cs.stage3.math.MathUtilities.createIdentityMatrix4d(), camera); helper.setPositionRightNow(zeroVec, pickedTransformable); pickedTransformable.rotateRightNow( edu.cmu.cs.stage3.math.MathUtilities.getXAxis(), -dy * .01, helper); pickedTransformable.rotateRightNow( edu.cmu.cs.stage3.math.MathUtilities.getYAxis(), -dx * .01, pickedTransformable); } else { helper.setTransformationRightNow( edu.cmu.cs.stage3.math.MathUtilities.createIdentityMatrix4d(), world); helper.setPositionRightNow(zeroVec, pickedTransformable); pickedTransformable.rotateRightNow( edu.cmu.cs.stage3.math.MathUtilities.getYAxis(), -dx * .01, helper); } } else if (shiftDown) { helper.setTransformationRightNow( edu.cmu.cs.stage3.math.MathUtilities.createIdentityMatrix4d(), world); helper.setPositionRightNow(zeroVec, pickedTransformable); tempVec.x = 0.0; tempVec.y = -dy * deltaFactor; tempVec.z = 0.0; pickedTransformable.moveRightNow(tempVec, helper); } else { javax.vecmath.Matrix4d cameraTransformation = camera.getSceneGraphTransformable().getAbsoluteTransformation(); cameraUp.x = cameraTransformation.m10; cameraUp.y = cameraTransformation.m11; cameraUp.z = cameraTransformation.m12; cameraForward.x = cameraTransformation.m20; cameraForward.y = cameraTransformation.m21; cameraForward.z = cameraTransformation.m22; helper.setPositionRightNow(zeroVec, pickedTransformable); if (Math.abs(cameraForward.y) < Math.abs(cameraUp.y)) { // if we're looking mostly level cameraForward.y = 0.0; helper.setOrientationRightNow(cameraForward, cameraUp, world); } else { // if we're looking mostly up or down cameraUp.y = 0.0; cameraForward.negate(); helper.setOrientationRightNow(cameraUp, cameraForward, world); } tempVec.x = dx * deltaFactor; tempVec.y = 0.0; tempVec.z = -dy * deltaFactor; pickedTransformable.moveRightNow(tempVec, helper); } } } }