123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412 |
- ---
- extends:
- http://vwf.example.com/node3.vwf
- properties:
-
-
-
-
-
- controlValue:
- set: |
- if(this.controlValue == undefined) {
- this.controlValue = value;
- }
- else if(!this.playing && this.controlValue != value) {
- if(value > this.maxValue) {
- value = this.maxValue - 1;
- this.direction = -1;
- }
- else if(value < this.minValue) {
- value = this.minValue + 1;
- this.direction = 1;
- }
- var incrementBy = (Math.abs(value - this.controlValue) * this.direction);
- this.controlValue = value;
- switch(this.controlType) {
- case "translate":
- this.deltaTranslation(incrementBy);
- break;
- case "rotate":
- this.deltaRotation(incrementBy);
- break;
- case "scale":
- this.deltaScale(incrementBy);
- break;
- }
- }
- else {
- this.controlValue = this.controlValue;
- }
- this.controlValueUpdated(this.controlValue);
- value: 0
-
-
-
-
- controlType:
- set: |
- switch ( value ) {
- case "translate":
- case "rotate":
- case "scale":
- this.editMode = value;
- break;
- }
-
-
-
-
-
-
- controlMode:
- set: |
- switch (value) {
- case "momentary":
- case "positions":
- case "continuous":
- this.controlMode = value;
- break;
- }
-
-
-
-
- transformAxis: [1, 0, 0]
-
-
-
-
-
-
-
- transformIncrement: 1
-
-
-
-
- transformDuration:
- set: |
- if(!this.playing) {
- this.transformDuration = value;
- }
- value: 0
-
-
-
-
- minValue: 0
-
-
-
-
- maxValue: 1
-
-
-
-
-
- direction:
- set: |
- if(!this.playing) {
- switch(value) {
- case 1:
- case -1:
- this.direction = value;
- break;
- }
- }
- value: 1
-
-
-
-
-
-
- dragSpeed: 50
- events:
-
-
-
-
-
-
- controlValueUpdated:
- parameters:
- - updatedValue
- methods:
-
-
-
-
-
-
- init:
-
-
-
-
-
-
-
-
- deltaTranslation:
-
-
-
-
-
-
-
-
- deltaRotation:
-
-
-
-
-
-
-
-
- deltaScale:
-
-
-
-
-
-
-
-
- deltaTransform:
- scripts:
- - |
- // Sets up the mouse pointer information used for dragging.
- this.init = function() {
- this.input = {
- "pointerInfo": undefined,
- "pickInfo": undefined,
- "previous": {
- "pointerInfo": undefined,
- "pickInfo": undefined,
- },
- update: function( pointerInfo, pickInfo ){
- if(!this.previous.pointerInfo) {
- this.previous.pointerInfo = this.pointerInfo;
- this.previous.pickInfo = this.pickInfo;
- }
- this.pointerInfo = pointerInfo;
- this.pickInfo = pickInfo;
- },
- clear: function(){
- this.previous.pointerInfo = undefined;
- this.previous.pickInfo = undefined;
- this.pointerInfo = undefined;
- this.pickInfo = undefined;
- },
- change: function() {
- var ret = [ 0, 0 ]
- if ( this.pointerInfo && this.previous.pointerInfo ) {
- ret[0] = this.pointerInfo.position[0] - this.previous.pointerInfo.position[0];
- ret[1] = this.pointerInfo.position[1] - this.previous.pointerInfo.position[1];
- }
- return ret;
- },
- "originalTransformDuration": this.transformDuration
- };
- }
- // Sets the starting values for the mouse pointer if in positions or continuous mode. Sets controlValue to the maxValue if in momentary mode.
- this.pointerDown = function( pointerInfo, pickInfo ) {
- if ( !this.input ) this.init();
- this.input.clear();
- if(this.controlMode == "momentary") {
- this.direction = 1;
- this.controlValue = this.maxValue;
- }
- else {
- this.input.pointerInfo = pointerInfo;
- this.input.pickInfo = pickInfo;
- }
- }
- // If the mouse has not moved, add the direction to the controlValue if in positions or continuous mode. Sets controlValue to the minValue if in momentary mode.
- this.pointerUp = function( pointerInfo, pickInfo ) {
- if(this.controlMode == "momentary") {
- this.direction = -1;
- this.controlValue = this.minValue;
- }
- else if(!this.playing) {
- if(this.input.previous.pointerInfo == undefined) {
- this.controlValue = this.controlValue + this.direction;
- }
- else if (this.controlMode == "continuous") {
- this.direction = (Math.round(this.controlValue) >= this.controlValue) ? 1 : -1;
- this.controlValue = Math.round(this.controlValue);
- }
- this.input.clear();
- this.transformDuration = this.input.originalTransformDuration;
- }
- }
- this.pointerMove = function( pointerInfo, pickInfo ) {
- if(this.controlMode != "momentary" && !this.playing) {
- this.transformDuration = 0;
- this.input.update( pointerInfo, pickInfo );
- var diff = this.input.change();
- var speed = 1 / this.dragSpeed;
- // If in positions mode, wait until the change in mouse position is greater than 1/dragSpeed, then increment or decrement controlValue based on the direction of mouse movement.
- if(this.controlMode == "positions") {
- if(Math.abs(diff[0]) >= Math.abs(diff[1])) {
- if(diff[0] > speed && this.controlValue < this.maxValue) {
- this.direction = 1;
- this.controlValue = this.controlValue + 1;
- this.input.previous.pointerInfo = pointerInfo;
- this.input.previous.pickInfo = pickInfo;
- }
- else if(diff[0] < (speed * -1) && this.controlValue > this.minValue) {
- this.direction = -1;
- this.controlValue = this.controlValue - 1;
- this.input.previous.pointerInfo = pointerInfo;
- this.input.previous.pickInfo = pickInfo;
- }
- }
- else {
- if(diff[1] > speed && this.controlValue < this.maxValue) {
- this.direction = 1;
- this.controlValue = this.controlValue + 1;
- this.input.previous.pointerInfo = pointerInfo;
- this.input.previous.pickInfo = pickInfo;
- }
- else if(diff[1] < (speed * -1) && this.controlValue > this.minValue) {
- this.direction = -1;
- this.controlValue = this.controlValue - 1;
- this.input.previous.pointerInfo = pointerInfo;
- this.input.previous.pickInfo = pickInfo;
- }
- }
- }
- else if(this.controlMode == "continuous") {
- if(Math.abs(diff[0]) >= Math.abs(diff[1])) {
- var changeBy = diff[0] * this.dragSpeed;
- if(diff[0] > 0 && this.controlValue < this.maxValue) {
- this.direction = 1;
- if((this.controlValue + changeBy) < this.maxValue) {
- this.controlValue = this.controlValue + changeBy;
- }
- }
- else if(diff[0] < 0 && this.controlValue > this.minValue) {
- this.direction = -1;
- if((this.controlValue + changeBy) > this.minValue) {
- this.controlValue = this.controlValue + changeBy;
- }
- }
- }
- else {
- var changeBy = diff[1] * this.dragSpeed;
- if(diff[1] > 0 && this.controlValue < this.maxValue) {
- this.direction = 1;
- if((this.controlValue + changeBy) < this.maxValue) {
- this.controlValue = this.controlValue + changeBy;
- }
- }
- else if(diff[1] < 0 && this.controlValue > this.minValue) {
- this.direction = -1;
- if((this.controlValue + changeBy) > this.minValue) {
- this.controlValue = this.controlValue + changeBy;
- }
- }
- }
- this.input.previous.pointerInfo = pointerInfo;
- this.input.previous.pickInfo = pickInfo;
- }
- }
- }
- this.deltaTranslation = function(incrementBy) {
- this.translateBy([(this.transformAxis[0] * this.transformIncrement * incrementBy),
- (this.transformAxis[1] * this.transformIncrement * incrementBy),
- (this.transformAxis[2] * this.transformIncrement * incrementBy)],
- this.transformDuration);
- }
- this.deltaRotation = function(incrementBy) {
- this.rotateBy([this.transformAxis[0], this.transformAxis[1], this.transformAxis[2], (incrementBy * this.transformIncrement)], this.transformDuration, "rotated");
- }
- this.deltaScale = function(incrementBy) {
- var newScale = [1, 1, 1];
- var scaleFactor = Math.pow(Math.abs(this.transformIncrement), incrementBy);
- if(this.transformAxis[0] > 0) {
- if(this.transformIncrement > 0) {
- newScale[0] = newScale[0] * scaleFactor;
- }
- else {
- newScale[0] = newScale[0] / scaleFactor;
- }
- }
- if(this.transformAxis[1] > 0) {
- if(this.transformIncrement > 0) {
- newScale[1] = newScale[1] * scaleFactor;
- }
- else {
- newScale[1] = newScale[1] / scaleFactor;
- }
- }
- if(this.transformAxis[2] > 0) {
- if(this.transformIncrement > 0) {
- newScale[2] = newScale[2] * scaleFactor;
- }
- else {
- newScale[2] = newScale[2] / scaleFactor;
- }
- }
- this.scaleBy(newScale, this.transformDuration);
- }
|