spin-on-move.vwf.yaml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. # Copyright 2012 United States Government, as represented by the Secretary of Defense, Under
  2. # Secretary of Defense (Personnel & Readiness).
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  5. # in compliance with the License. You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software distributed under the License
  10. # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  11. # or implied. See the License for the specific language governing permissions and limitations under
  12. # the License.
  13. ## The component representation of a spin behavior (on move)
  14. ##
  15. ## @name spin-on-click.vwf
  16. ## @namespace
  17. ---
  18. extends:
  19. http://vwf.example.com/node3.vwf
  20. properties:
  21. ## Spin rate
  22. ##
  23. ## @name spin-on-move.vwf#spin-rate
  24. ## @property
  25. spin-rate: 40
  26. ## Spin axis
  27. ##
  28. ## @name spin-on-move.vwf#spin-axis
  29. ## @property
  30. spin-axis: [ 0, 0, 1 ]
  31. ## Spin input dimension
  32. ##
  33. ## @name spin-on-move.vwf#spin-inputDim
  34. ## @property
  35. spin-inputDim: "x"
  36. ## Spin value
  37. ##
  38. ## @name spin-on-move.vwf#spin-value
  39. ## @property
  40. spin-value: 0
  41. events:
  42. valueChanged:
  43. methods:
  44. ## Spin function. Updates component rotations and calls future spin
  45. ##
  46. ## @name spin-on-move.vwf#spin
  47. ## @function
  48. ##
  49. ## @returns undefined
  50. spin:
  51. ## Initialization function
  52. ##
  53. ## @name spin-on-move.vwf#init
  54. ## @function
  55. ##
  56. ## @returns undefined
  57. init:
  58. scripts:
  59. - |
  60. this.init = function() {
  61. this.input = {
  62. "pointerInfo": undefined,
  63. "pickInfo": undefined,
  64. "previous": {
  65. "pointerInfo": undefined,
  66. "pickInfo": undefined,
  67. },
  68. pointerDown: {
  69. "pointerInfo": undefined,
  70. "pickInfo": undefined,
  71. },
  72. update: function( pointerInfo, pickInfo ){
  73. this.previous.pointerInfo = this.pointerInfo;
  74. this.previous.pickInfo = this.pickInfo;
  75. this.pointerInfo = pointerInfo;
  76. this.pickInfo = pickInfo;
  77. },
  78. clear: function(){
  79. this.previous.pointerInfo = undefined;
  80. this.previous.pickInfo = undefined;
  81. this.pointerInfo = undefined;
  82. this.pickInfo = undefined;
  83. },
  84. change: function() {
  85. var ret = [ 0, 0 ]
  86. if ( this.pointerInfo && this.previous.pointerInfo ) {
  87. ret[0] = this.pointerInfo.position[0] - this.previous.pointerInfo.position[0];
  88. ret[1] = this.pointerInfo.position[1] - this.previous.pointerInfo.position[1];
  89. }
  90. return ret;
  91. }
  92. };
  93. }
  94. this.pointerDown = function( pointerInfo, pickInfo ) {
  95. if ( !this.input ) this.init();
  96. this.input.pointerDown.pointerInfo = pointerInfo;
  97. this.input.pointerDown.pickInfo = pickInfo;
  98. this.input.clear();
  99. }
  100. this.pointerUp = function( pointerInfo, pickInfo ) {
  101. if ( !this.input ) this.init();
  102. this.input.clear();
  103. }
  104. this.pointerMove = function( pointerInfo, pickInfo ) {
  105. this.input.update( pointerInfo, pickInfo );
  106. var diff = this.input.change();
  107. switch( this["spin-inputDim"] ) {
  108. case "x":
  109. this.spin( diff[0] );
  110. break;
  111. case "y":
  112. this.spin( -diff[1] );
  113. break;
  114. default:
  115. this.spin( Math.sqrt( ( diff[0] * diff[0] ) + ( diff[1] * diff[1] ) ) );
  116. break;
  117. }
  118. }
  119. this.spin = function( value ){
  120. var rate = this["spin-rate"];
  121. var axis = this["spin-axis"];
  122. //console.info( "this.parent.rotateBy( [ "+axis[0]+", "+axis[1]+", "+axis[2]+", "+(rate * value)+" ], 0 )" );
  123. this.parent.rotateBy( [ axis[0], axis[1], axis[2], rate * value ], 0 );
  124. this.valueChanged( this.rotation );
  125. } //@ sourceURL=spin-on-move.vwf