/* * MouseScaleModulator * Version 1.0, 19/11/2001 * * Copyright (c) 2001 by Netzministerium.de * Written by Till Nagel and René Sander. * Distributed under the terms of the GNU Lesser General Public. (See licence.txt for details) */ /* * Constructs a MouseScaleModulator. * This modulator returns a scale matrix depending on mouse interactions. * When a mouseUp event occurs the rotation will fade to null (spins the object). * * Parameters: * String name - the name of the variable storing this object * e.g. var myMouseScaleModulator = new MouseScaleModulator("myMouseScaleModulator"); * int mode - the interaction mode of the modulator, use MouseScaleModulator.MODE_xxx * constants here. You can rotate around x and y (MODE_ROTATE), just on of them * (MODE_ROTATE_X and MODE_ROTATE_Y), or move the model (MODE_MOVE). * * Returns: * MouseScaleModulator - a new MouseScaleModulator instance */ function MouseScaleModulator(name, mode) { // the name of the variable storing this object this.name = name; // interaction mode this.mode = mode ? mode : MouseScaleModulator.MODE_NONUNIFORM; // the matrix to transform with this.matrix = new Matrix(); this.scaleValues = MouseScaleModulator.SCALE_VALUES; // flag to show if the mouse is down this.isDown = false; // responsible for scaling this.scalingSteps = 0; return this; } /* * Constants specifying the possible interaction modes. * Use these when setting the modulator's mode, e.g. * myMouseScaleModulator.setMode(MouseScaleModulator.MODE_NONUNIFORM); */ MouseScaleModulator.MODE_NONUNIFORM = 0; MouseScaleModulator.MODE_UNIFORM = 1; MouseScaleModulator.SCALE_VALUES = new Array(1.1, 1.1, 1.1, 1.1, 1.05, 1.03); /* * Returns the (rotation) matrix to transform with. * * Returns: * Matrix - The matrix to transform with. */ MouseScaleModulator.prototype.getMatrix = function () { return this.matrix; } /* * MouseScaleModulator.animate * Does nothing. This MouseModulator has no mouse independent rendering. */ MouseScaleModulator.prototype.animate = function() { if (this.isDown) { if (this.scalingSteps <= 5) { var stretchMatrix = new Matrix(); var sv = this.scaleValues[this.scalingSteps]; //alert(this.scalingSteps + " = " + sv); if (this.mode == MouseScaleModulator.MODE_NONUNIFORM) { stretchMatrix.scale(1, 1, sv); // non uniform } else { stretchMatrix.scale(sv, sv, sv); // uniform } this.matrix = stretchMatrix; this.scalingSteps++; } else { this.matrix = new Matrix(); } } else { if (this.scalingSteps > 0) { this.scalingSteps--; var stretchMatrix = new Matrix(); var sv = this.scaleValues[this.scalingSteps]; //alert(this.scalingSteps + " = " + sv); if (this.mode == MouseScaleModulator.MODE_NONUNIFORM) { stretchMatrix.scale(1, 1, 1/sv); // non uniform } else { stretchMatrix.scale(1/sv, 1/sv, 1/sv); // uniform } this.matrix = stretchMatrix; } else { this.matrix = new Matrix(); } } } /* * MouseScaleModulator.up * The mouseUp eventhandler. Pass the event object e when calling * this method in the page's event handler. * * Parameters * Event e - the event object, just pass this on from your original handler */ MouseScaleModulator.prototype.up = function(e) { // to prohibit animate to render this.isDown = false; } /* * MouseScaleModulator.down * The mouseDown eventhandler. Pass the event object e when calling * this method in the page's event handler. * * Parameters * Event e - the event object, just pass this on from your original handler */ MouseScaleModulator.prototype.down = function(e) { // to allow animate to render this.isDown = true; } /* * MouseScaleModulator.move * Does nothing. This MouseModulator has no mousemove dependent rendering. * * Parameters * Event e - the event object, just pass this on from your original handler */ MouseScaleModulator.prototype.move = function(e) { // does nothing }