control-old.vwf.yaml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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 control behavior
  14. ##
  15. ## @name control.vwf
  16. ## @namespace
  17. ---
  18. extends:
  19. http://vwf.example.com/node3.vwf
  20. properties:
  21. ## The current value of the control. Must be between minValue and maxValue. This property
  22. ## multipled by transformIncrement describes how much the translation/rotation/scale has changed.
  23. ##
  24. ## @name control.vwf#controlValue
  25. ## @property
  26. controlValue:
  27. set: |
  28. if(this.controlValue == undefined) {
  29. this.controlValue = value;
  30. }
  31. else if(!this.playing && this.controlValue != value) {
  32. if(value > this.maxValue) {
  33. value = this.maxValue - 1;
  34. this.direction = -1;
  35. }
  36. else if(value < this.minValue) {
  37. value = this.minValue + 1;
  38. this.direction = 1;
  39. }
  40. var incrementBy = (Math.abs(value - this.controlValue) * this.direction);
  41. this.controlValue = value;
  42. switch(this.controlType) {
  43. case "translate":
  44. this.deltaTranslation(incrementBy);
  45. break;
  46. case "rotate":
  47. this.deltaRotation(incrementBy);
  48. break;
  49. case "scale":
  50. this.deltaScale(incrementBy);
  51. break;
  52. }
  53. }
  54. else {
  55. this.controlValue = this.controlValue;
  56. }
  57. this.controlValueUpdated(this.controlValue);
  58. value: 0
  59. ## What property the control modifies. Possible values are "translate", "rotate", and "scale".
  60. ##
  61. ## @name control.vwf#controlType
  62. ## @property
  63. controlType:
  64. set: |
  65. switch ( value ) {
  66. case "translate":
  67. case "rotate":
  68. case "scale":
  69. this.editMode = value;
  70. break;
  71. }
  72. ## How the control modifies the property. Possible values are "momentary", "positions", and
  73. ## "continuous". If set to momentary, the control value is set to maxValue on mouse down and
  74. ## minValue on mouseUp. # If set to positions, the control value will increment by the direction.
  75. ##
  76. ## @name control.vwf#controlMode
  77. ## @property
  78. controlMode:
  79. set: |
  80. switch (value) {
  81. case "momentary":
  82. case "positions":
  83. case "continuous":
  84. this.controlMode = value;
  85. break;
  86. }
  87. ## Determines which axes the changes will be made to.
  88. ##
  89. ## @name control.vwf#transformAxis
  90. ## @property
  91. transformAxis: [1, 0, 0]
  92. ## How much the translation/rotation/scale will change for each increment of controlValue.
  93. ## For example, if the controlType is rotate, a transformIncrement of 30 will rotate the object
  94. ## 30 degrees at controlValue of 1, 60 at controlValue of 2, etc. This multipled by controlValue
  95. ## describes how much the translation/rotation/scale has changed.
  96. ##
  97. ## @name control.vwf#transformIncrement
  98. ## @property
  99. transformIncrement: 1
  100. ## How long the transformation will take. A value of 0 means the transformation is instant.
  101. ##
  102. ## @name control.vwf#transformDuration
  103. ## @property
  104. transformDuration:
  105. set: |
  106. if(!this.playing) {
  107. this.transformDuration = value;
  108. }
  109. value: 0
  110. ## The minimum controlValue can be set to.
  111. ##
  112. ## @name control.vwf#minValue
  113. ## @property
  114. minValue: 0
  115. ## The maximum controlValue can be set to.
  116. ##
  117. ## @name control.vwf#maxValue
  118. ## @property
  119. maxValue: 1
  120. ## Determines whether the controlValue will increase or decrease on a mouse click and the sign
  121. ## of the value passed into the delta methods. Is either 1 or -1.
  122. ##
  123. ## @name control.vwf#direction
  124. ## @property
  125. direction:
  126. set: |
  127. if(!this.playing) {
  128. switch(value) {
  129. case 1:
  130. case -1:
  131. this.direction = value;
  132. break;
  133. }
  134. }
  135. value: 1
  136. ## How quickly the object will move when the mouse is dragged. Larger values result in faster
  137. ## dragging. A value of 1 would mean that the mouse would have to be dragged from one side of
  138. ## the screen to increment the controlValue.
  139. ##
  140. ## @name control.vwf#dragSpeed
  141. ## @property
  142. dragSpeed: 50
  143. events:
  144. ## Notifies listeners that the control value has been updated.
  145. ##
  146. ## @name contro.vwf#controlValueUpdated
  147. ## @event
  148. ##
  149. ## @param {Number} updatedValue
  150. controlValueUpdated:
  151. parameters:
  152. - updatedValue
  153. methods:
  154. ## Sets up the mouse pointer information used for dragging.
  155. ##
  156. ## @name control.vwf#init
  157. ## @function
  158. ##
  159. ## @returns pointer position deltas
  160. init:
  161. ## Translates by the given delta
  162. ##
  163. ## @name control.vwf#deltaTranslation
  164. ## @function
  165. ##
  166. ## @param {Number} incrementBy
  167. ##
  168. ## @returns undefined
  169. deltaTranslation:
  170. ## Rotates by the given delta
  171. ##
  172. ## @name control.vwf#deltaRotation
  173. ## @function
  174. ##
  175. ## @param {Number} incrementBy
  176. ##
  177. ## @returns undefined
  178. deltaRotation:
  179. ## Scales by the given delta
  180. ##
  181. ## @name control.vwf#deltaScale
  182. ## @function
  183. ##
  184. ## @param {Number} incrementBy
  185. ##
  186. ## @returns undefined
  187. deltaScale:
  188. ## Transforms by the given delta
  189. ##
  190. ## @name control.vwf#deltaTransform
  191. ## @function
  192. ##
  193. ## @param {Number} incrementBy
  194. ##
  195. ## @returns undefined
  196. deltaTransform:
  197. scripts:
  198. - |
  199. // Sets up the mouse pointer information used for dragging.
  200. this.init = function() {
  201. this.input = {
  202. "pointerInfo": undefined,
  203. "pickInfo": undefined,
  204. "previous": {
  205. "pointerInfo": undefined,
  206. "pickInfo": undefined,
  207. },
  208. update: function( pointerInfo, pickInfo ){
  209. if(!this.previous.pointerInfo) {
  210. this.previous.pointerInfo = this.pointerInfo;
  211. this.previous.pickInfo = this.pickInfo;
  212. }
  213. this.pointerInfo = pointerInfo;
  214. this.pickInfo = pickInfo;
  215. },
  216. clear: function(){
  217. this.previous.pointerInfo = undefined;
  218. this.previous.pickInfo = undefined;
  219. this.pointerInfo = undefined;
  220. this.pickInfo = undefined;
  221. },
  222. change: function() {
  223. var ret = [ 0, 0 ]
  224. if ( this.pointerInfo && this.previous.pointerInfo ) {
  225. ret[0] = this.pointerInfo.position[0] - this.previous.pointerInfo.position[0];
  226. ret[1] = this.pointerInfo.position[1] - this.previous.pointerInfo.position[1];
  227. }
  228. return ret;
  229. },
  230. "originalTransformDuration": this.transformDuration
  231. };
  232. }
  233. // Sets the starting values for the mouse pointer if in positions or continuous mode. Sets controlValue to the maxValue if in momentary mode.
  234. this.pointerDown = function( pointerInfo, pickInfo ) {
  235. if ( !this.input ) this.init();
  236. this.input.clear();
  237. if(this.controlMode == "momentary") {
  238. this.direction = 1;
  239. this.controlValue = this.maxValue;
  240. }
  241. else {
  242. this.input.pointerInfo = pointerInfo;
  243. this.input.pickInfo = pickInfo;
  244. }
  245. }
  246. // 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.
  247. this.pointerUp = function( pointerInfo, pickInfo ) {
  248. if(this.controlMode == "momentary") {
  249. this.direction = -1;
  250. this.controlValue = this.minValue;
  251. }
  252. else if(!this.playing) {
  253. if(this.input.previous.pointerInfo == undefined) {
  254. this.controlValue = this.controlValue + this.direction;
  255. }
  256. else if (this.controlMode == "continuous") {
  257. this.direction = (Math.round(this.controlValue) >= this.controlValue) ? 1 : -1;
  258. this.controlValue = Math.round(this.controlValue);
  259. }
  260. this.input.clear();
  261. this.transformDuration = this.input.originalTransformDuration;
  262. }
  263. }
  264. this.pointerMove = function( pointerInfo, pickInfo ) {
  265. if(this.controlMode != "momentary" && !this.playing) {
  266. this.transformDuration = 0;
  267. this.input.update( pointerInfo, pickInfo );
  268. var diff = this.input.change();
  269. var speed = 1 / this.dragSpeed;
  270. // 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.
  271. if(this.controlMode == "positions") {
  272. if(Math.abs(diff[0]) >= Math.abs(diff[1])) {
  273. if(diff[0] > speed && this.controlValue < this.maxValue) {
  274. this.direction = 1;
  275. this.controlValue = this.controlValue + 1;
  276. this.input.previous.pointerInfo = pointerInfo;
  277. this.input.previous.pickInfo = pickInfo;
  278. }
  279. else if(diff[0] < (speed * -1) && this.controlValue > this.minValue) {
  280. this.direction = -1;
  281. this.controlValue = this.controlValue - 1;
  282. this.input.previous.pointerInfo = pointerInfo;
  283. this.input.previous.pickInfo = pickInfo;
  284. }
  285. }
  286. else {
  287. if(diff[1] > speed && this.controlValue < this.maxValue) {
  288. this.direction = 1;
  289. this.controlValue = this.controlValue + 1;
  290. this.input.previous.pointerInfo = pointerInfo;
  291. this.input.previous.pickInfo = pickInfo;
  292. }
  293. else if(diff[1] < (speed * -1) && this.controlValue > this.minValue) {
  294. this.direction = -1;
  295. this.controlValue = this.controlValue - 1;
  296. this.input.previous.pointerInfo = pointerInfo;
  297. this.input.previous.pickInfo = pickInfo;
  298. }
  299. }
  300. }
  301. else if(this.controlMode == "continuous") {
  302. if(Math.abs(diff[0]) >= Math.abs(diff[1])) {
  303. var changeBy = diff[0] * this.dragSpeed;
  304. if(diff[0] > 0 && this.controlValue < this.maxValue) {
  305. this.direction = 1;
  306. if((this.controlValue + changeBy) < this.maxValue) {
  307. this.controlValue = this.controlValue + changeBy;
  308. }
  309. }
  310. else if(diff[0] < 0 && this.controlValue > this.minValue) {
  311. this.direction = -1;
  312. if((this.controlValue + changeBy) > this.minValue) {
  313. this.controlValue = this.controlValue + changeBy;
  314. }
  315. }
  316. }
  317. else {
  318. var changeBy = diff[1] * this.dragSpeed;
  319. if(diff[1] > 0 && this.controlValue < this.maxValue) {
  320. this.direction = 1;
  321. if((this.controlValue + changeBy) < this.maxValue) {
  322. this.controlValue = this.controlValue + changeBy;
  323. }
  324. }
  325. else if(diff[1] < 0 && this.controlValue > this.minValue) {
  326. this.direction = -1;
  327. if((this.controlValue + changeBy) > this.minValue) {
  328. this.controlValue = this.controlValue + changeBy;
  329. }
  330. }
  331. }
  332. this.input.previous.pointerInfo = pointerInfo;
  333. this.input.previous.pickInfo = pickInfo;
  334. }
  335. }
  336. }
  337. this.deltaTranslation = function(incrementBy) {
  338. this.translateBy([(this.transformAxis[0] * this.transformIncrement * incrementBy),
  339. (this.transformAxis[1] * this.transformIncrement * incrementBy),
  340. (this.transformAxis[2] * this.transformIncrement * incrementBy)],
  341. this.transformDuration);
  342. }
  343. this.deltaRotation = function(incrementBy) {
  344. this.rotateBy([this.transformAxis[0], this.transformAxis[1], this.transformAxis[2], (incrementBy * this.transformIncrement)], this.transformDuration, "rotated");
  345. }
  346. this.deltaScale = function(incrementBy) {
  347. var newScale = [1, 1, 1];
  348. var scaleFactor = Math.pow(Math.abs(this.transformIncrement), incrementBy);
  349. if(this.transformAxis[0] > 0) {
  350. if(this.transformIncrement > 0) {
  351. newScale[0] = newScale[0] * scaleFactor;
  352. }
  353. else {
  354. newScale[0] = newScale[0] / scaleFactor;
  355. }
  356. }
  357. if(this.transformAxis[1] > 0) {
  358. if(this.transformIncrement > 0) {
  359. newScale[1] = newScale[1] * scaleFactor;
  360. }
  361. else {
  362. newScale[1] = newScale[1] / scaleFactor;
  363. }
  364. }
  365. if(this.transformAxis[2] > 0) {
  366. if(this.transformIncrement > 0) {
  367. newScale[2] = newScale[2] * scaleFactor;
  368. }
  369. else {
  370. newScale[2] = newScale[2] / scaleFactor;
  371. }
  372. }
  373. this.scaleBy(newScale, this.transformDuration);
  374. }