wco_models 3.1.0.325 → 3.4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/production_theme.scss +4 -1
  3. data/app/assets/stylesheets/wco/main.scss +4 -0
  4. data/app/assets/stylesheets/wco/studio.scss +12 -4
  5. data/app/controllers/wco/api/newspartials_controller.rb +1 -1
  6. data/app/controllers/wco/api/newsproducer_controller.rb +5 -0
  7. data/app/controllers/wco/newspartials_controller.rb +1 -0
  8. data/app/models/iro/datapoint.rb +1 -1
  9. data/app/models/iro/option.rb +16 -2
  10. data/app/models/iro/position.rb +4 -6
  11. data/app/models/iro/priceitem.rb +42 -4
  12. data/app/models/iro/purse.rb +2 -0
  13. data/app/models/iro/stock.rb +1 -2
  14. data/app/models/tda/option.rb +4 -9
  15. data/app/models/wco/newspartial.rb +12 -4
  16. data/app/views/wco/api/newsproducer/README_newsproducer.txt +12 -0
  17. data/app/views/wco/api/newsproducer/_scenes.js-bk +20 -0
  18. data/app/views/wco/api/newsproducer/_scenes.js.erb +15 -0
  19. data/app/views/wco/api/newsproducer/{_studio_blue.js → _studio_blue1.js} +4 -1
  20. data/app/views/wco/api/newsproducer/_studio_blue2.js +912 -0
  21. data/app/views/wco/api/newsproducer/_studio_coc.js +769 -0
  22. data/app/views/wco/api/newsproducer/_studio_coc.js-bk +389 -0
  23. data/app/views/wco/api/newsproducer/_studio_coc.js-cannon +677 -0
  24. data/app/views/wco/api/newsproducer/_studio_fps.js +1018 -0
  25. data/app/views/wco/api/newsproducer/_studio_ra2.js +255 -0
  26. data/app/views/wco/api/newsproducer/_touch_controls.js +708 -0
  27. data/app/views/wco/api/newsproducer/_touch_pad.css +200 -0
  28. data/app/views/wco/api/newsproducer/games_fps.html +504 -0
  29. data/app/views/wco/api/newsproducer/{studio_green.html.erb → studio_blue0.html.erb} +1 -1
  30. data/app/views/wco/api/newsproducer/{studio_blue.html.erb → studio_blue1.html.erb} +3 -3
  31. data/app/views/wco/api/newsproducer/studio_blue2.html.erb +146 -0
  32. data/app/views/wco/api/newsproducer/studio_coc.html.erb +95 -0
  33. data/app/views/wco/api/newsproducer/studio_fps.html.erb +199 -0
  34. data/app/views/wco/api/newsproducer/studio_ra2.html.erb +95 -0
  35. data/app/views/wco/newspartials/_show_in_newsvideo.haml +6 -7
  36. data/app/views/wco/newspartials/index.haml-trash +6 -0
  37. data/config/initializers/08_integrations.rb +14 -1
  38. data/config/initializers/08_integrations.rb-example +0 -2
  39. data/config/routes.rb +3 -0
  40. data/lib/shortcuts.rb +1 -1
  41. metadata +23 -7
  42. data/app/views/wco/api/newsproducer/README.txt +0 -2
  43. /data/app/views/wco/api/newsproducer/{_studio_green.js → _studio_blue0.js} +0 -0
@@ -0,0 +1,708 @@
1
+ "use strict";
2
+
3
+ function find_touch(touch_list, id) {
4
+ if (!touch_list) return null
5
+ for (var i = 0; i < touch_list.length; i++) {
6
+ if (touch_list[i].identifier === id) return touch_list[i]
7
+ }
8
+ return null
9
+ }
10
+
11
+ function RotationPad(container) {
12
+
13
+ var mouseDown = false
14
+ var last_x = 0
15
+ var last_y = 0
16
+ var self = this
17
+
18
+ self.container = container
19
+ self.rotationPad = $('<div class="rotation-pad"></div>')
20
+ self.region = $('<div class="region"></div>')
21
+ self.handle = $('<div class="handle"></div>')
22
+
23
+ self.rotationPad.append(self.region).append(self.handle)
24
+ self.container.append(self.rotationPad)
25
+
26
+ var touch_id = null
27
+ var ignore_mouse_until = 0
28
+
29
+ function container_rect() {
30
+ return self.container[0].getBoundingClientRect()
31
+ }
32
+
33
+ function in_look_zone(clientX, clientY) {
34
+ var rect = container_rect()
35
+ var x = clientX - rect.left
36
+ var y = clientY - rect.top
37
+ return x >= rect.width / 2 && x <= rect.width && y >= rect.height / 2 && y <= rect.height
38
+ }
39
+
40
+ function place_pad(clientX, clientY) {
41
+ var rect = container_rect()
42
+ var w = self.rotationPad.outerWidth()
43
+ var h = self.rotationPad.outerHeight()
44
+ self.rotationPad.css({
45
+ left: clientX - rect.left - w / 2,
46
+ top: clientY - rect.top - h / 2
47
+ })
48
+ }
49
+
50
+ function begin_input(clientX, clientY) {
51
+ mouseDown = true
52
+ last_x = clientX
53
+ last_y = clientY
54
+ self.rotationPad.addClass('is-active')
55
+ place_pad(clientX, clientY)
56
+ }
57
+
58
+ function end_input() {
59
+ if (!mouseDown && touch_id === null) return
60
+ mouseDown = false
61
+ touch_id = null
62
+ self.rotationPad.removeClass('is-active')
63
+ }
64
+
65
+ function move_input(clientX, clientY) {
66
+ var dx = clientX - last_x
67
+ var dy = clientY - last_y
68
+ last_x = clientX
69
+ last_y = clientY
70
+ place_pad(clientX, clientY)
71
+ if (dx === 0 && dy === 0) return
72
+ var moveEvent = $.Event("YawPitch", {
73
+ detail: {
74
+ "deltaX": dx,
75
+ "deltaY": dy
76
+ },
77
+ bubbles: false
78
+ })
79
+ $(self).trigger(moveEvent)
80
+ }
81
+
82
+ self.container.on("mousedown", function (event) {
83
+ if (touch_id !== null || Date.now() < ignore_mouse_until) return
84
+ if ($(event.target).closest('.movement-pad').length) return
85
+ if (!in_look_zone(event.clientX, event.clientY)) return
86
+ event.preventDefault()
87
+ begin_input(event.clientX, event.clientY)
88
+ })
89
+
90
+ $(document).on("mouseup", function () {
91
+ if (touch_id !== null) return
92
+ end_input()
93
+ })
94
+
95
+ $(document).on("mousemove", function(event) {
96
+ if (touch_id !== null || !mouseDown) return
97
+ move_input(event.clientX, event.clientY)
98
+ })
99
+
100
+ self.container.on("touchstart", function (event) {
101
+ if (touch_id !== null) return
102
+ if ($(event.target).closest('.movement-pad').length) return
103
+ var touch = event.originalEvent.changedTouches[0]
104
+ if (!touch) return
105
+ if (!in_look_zone(touch.clientX, touch.clientY)) return
106
+ event.preventDefault()
107
+ touch_id = touch.identifier
108
+ ignore_mouse_until = Date.now() + 700
109
+ begin_input(touch.clientX, touch.clientY)
110
+ })
111
+
112
+ $(document).on("touchmove", function(event) {
113
+ if (touch_id === null) return
114
+ var touch = find_touch(event.originalEvent.touches, touch_id)
115
+ if (!touch) return
116
+ move_input(touch.clientX, touch.clientY)
117
+ })
118
+
119
+ $(document).on("touchend touchcancel", function (event) {
120
+ if (touch_id === null) return
121
+ if (!find_touch(event.originalEvent.changedTouches, touch_id)) return
122
+ ignore_mouse_until = Date.now() + 700
123
+ end_input()
124
+ })
125
+
126
+ }
127
+
128
+ RotationPad.prototype = {
129
+ resetHandlePosition: function () {}
130
+ }
131
+
132
+ function MovementPad(container) {
133
+
134
+ var mouseDown = false;
135
+ var mouseStopped = false;
136
+ var mouseStopTimeout, eventRepeatTimeout;
137
+ var newLeft, newTop, distance, angle;
138
+ var self = this;
139
+
140
+ self.container = container;
141
+ self.regionData = {};
142
+ self.handleData = {};
143
+ self.movementPad = $('<div class="movement-pad"></div>');
144
+ self.region = $('<div class="region"></div>');
145
+ self.handle = $('<div class="handle"></div>');
146
+
147
+ self.movementPad.append(self.region).append(self.handle);
148
+ self.container.append(self.movementPad);
149
+
150
+ self.regionData.width = self.region.outerWidth();
151
+ self.regionData.height = self.region.outerHeight();
152
+ self.regionData.position = self.region.position();
153
+ self.regionData.offset = self.region.offset();
154
+ self.regionData.radius = self.regionData.width / 2;
155
+ self.regionData.centerX = self.regionData.position.left + self.regionData.radius;
156
+ self.regionData.centerY = self.regionData.position.top + self.regionData.radius;
157
+
158
+ self.handleData.width = self.handle.outerWidth();
159
+ self.handleData.height = self.handle.outerHeight();
160
+ self.handleData.radius = self.handleData.width / 2;
161
+
162
+ self.regionData.radius = self.regionData.width / 2 - self.handleData.radius;
163
+
164
+ var touch_id = null
165
+ var ignore_mouse_until = 0
166
+
167
+ function begin_input(pageX, pageY) {
168
+ self.regionData.offset = self.region.offset();
169
+ mouseDown = true;
170
+ self.handle.css("opacity", "1.0");
171
+ update(pageX, pageY);
172
+ }
173
+
174
+ function end_input() {
175
+ if (!mouseDown && touch_id === null) return
176
+ mouseDown = false
177
+ touch_id = null
178
+ self.resetHandlePosition()
179
+ }
180
+
181
+ // Mouse events:
182
+ self.region.on("mousedown", function (event) {
183
+ if (touch_id !== null || Date.now() < ignore_mouse_until) return
184
+ event.preventDefault();
185
+ begin_input(event.pageX, event.pageY);
186
+ });
187
+
188
+ $(document).on("mouseup", function () {
189
+ if (touch_id !== null) return
190
+ end_input()
191
+ });
192
+
193
+ $(document).on("mousemove", function(event) {
194
+ if (touch_id !== null || !mouseDown) return;
195
+ update(event.pageX, event.pageY);
196
+ });
197
+
198
+ //Touch events:
199
+ self.region.on("touchstart", function (event) {
200
+ event.preventDefault();
201
+ if (touch_id !== null) return
202
+ var touch = event.originalEvent.changedTouches[0]
203
+ if (!touch) return
204
+ touch_id = touch.identifier
205
+ ignore_mouse_until = Date.now() + 700
206
+ begin_input(touch.pageX, touch.pageY);
207
+ });
208
+
209
+ $(document).on("touchmove", function(event) {
210
+ if (touch_id === null) return
211
+ var touch = find_touch(event.originalEvent.touches, touch_id)
212
+ if (!touch) return
213
+ update(touch.pageX, touch.pageY)
214
+ });
215
+
216
+ $(document).on("touchend touchcancel", function (event) {
217
+ if (touch_id === null) return
218
+ if (!find_touch(event.originalEvent.changedTouches, touch_id)) return
219
+ ignore_mouse_until = Date.now() + 700
220
+ end_input()
221
+ });
222
+
223
+
224
+ function update(pageX, pageY) {
225
+ newLeft = (pageX - self.regionData.offset.left);
226
+ newTop = (pageY - self.regionData.offset.top);
227
+
228
+ // If handle reaches the pad boundaries.
229
+ distance = Math.pow(self.regionData.centerX - newLeft, 2) + Math.pow(self.regionData.centerY - newTop, 2);
230
+ if (distance > Math.pow(self.regionData.radius, 2)) {
231
+ angle = Math.atan2((newTop - self.regionData.centerY), (newLeft - self.regionData.centerX));
232
+ newLeft = (Math.cos(angle) * self.regionData.radius) + self.regionData.centerX;
233
+ newTop = (Math.sin(angle) * self.regionData.radius) + self.regionData.centerY;
234
+ }
235
+ newTop = Math.round(newTop * 10) / 10;
236
+ newLeft = Math.round(newLeft * 10) / 10;
237
+
238
+ self.handle.css({
239
+ top: newTop - self.handleData.radius,
240
+ left: newLeft - self.handleData.radius
241
+ });
242
+ // console.log(newTop , newLeft);
243
+
244
+ // Providing event and data for handling camera movement.
245
+ var deltaX = self.regionData.centerX - parseInt(newLeft);
246
+ var deltaY = self.regionData.centerY - parseInt(newTop);
247
+ // Normalize x,y between -2 to 2 range.
248
+ deltaX = -2 + (2+2) * (deltaX - (-self.regionData.radius)) / (self.regionData.radius - (-self.regionData.radius));
249
+ deltaY = -2 + (2+2) * (deltaY - (-self.regionData.radius)) / (self.regionData.radius - (-self.regionData.radius));
250
+ deltaX = Math.round(deltaX * 10) / 10;
251
+ deltaY = Math.round(deltaY * 10) / 10;
252
+ // console.log(deltaX, deltaY);
253
+
254
+ sendEvent(deltaX, deltaY, 0);
255
+ }
256
+
257
+ function sendEvent(dx, dy, middle) {
258
+ if (!mouseDown) {
259
+ clearTimeout(eventRepeatTimeout);
260
+ var stopEvent = $.Event("stopMove", {
261
+ bubbles: false
262
+ });
263
+ $(self).trigger(stopEvent);
264
+
265
+ return;
266
+ }
267
+
268
+ clearTimeout(eventRepeatTimeout);
269
+ eventRepeatTimeout = setTimeout(function() {
270
+ sendEvent(dx, dy, middle);
271
+ }, 5);
272
+
273
+ var moveEvent = $.Event("move", {
274
+ detail: {
275
+ "deltaX": dx,
276
+ "deltaY": dy,
277
+ "middle": middle
278
+ },
279
+ bubbles: false
280
+ });
281
+ $(self).trigger(moveEvent);
282
+ }
283
+
284
+ self.resetHandlePosition();
285
+ };
286
+
287
+ MovementPad.prototype = {
288
+ resetHandlePosition: function () {
289
+ this.handle.animate({
290
+ top: this.regionData.centerY - this.handleData.radius,
291
+ left: this.regionData.centerX - this.handleData.radius,
292
+ opacity: 0.1
293
+ }, "fast");
294
+ }
295
+ };
296
+
297
+
298
+ function TouchControls(container, camera, options) {
299
+
300
+ var self = this;
301
+ self.config = $.extend({
302
+ speedFactor: 0.5,
303
+ delta: 1,
304
+ rotationFactor: 0.002,
305
+ maxPitch: 55,
306
+ hitTest: true,
307
+ hitTestDistance: 40
308
+ }, options);
309
+
310
+ var container = container;
311
+ var isRightMouseDown = false;
312
+ var rotationMatrices = [];
313
+ var hitObjects = [];
314
+
315
+ var moveForward = false;
316
+ var moveBackward = false;
317
+ var moveLeft = false;
318
+ var moveRight = false;
319
+ var lockMoveForward = false;
320
+ var lockMoveBackward = false;
321
+ var lockMoveLeft = false;
322
+ var lockMoveRight = false;
323
+
324
+ var ztouch = 1, xtouch = 1;
325
+ var PI_2 = Math.PI / 2;
326
+ var maxPitch = self.config.maxPitch * Math.PI / 180;
327
+ var velocity = new THREE.Vector3(0, 0, 0);
328
+
329
+ var cameraHolder = new THREE.Object3D();
330
+ cameraHolder.name = "cameraHolder";
331
+ cameraHolder.add(camera);
332
+
333
+ self.scene = null;
334
+ self.fpsBody = new THREE.Object3D();
335
+ self.fpsBody.add(cameraHolder);
336
+ self.enabled = true
337
+ self.stick_x = 0
338
+ self.stick_y = 0;
339
+
340
+ self.mouse = new THREE.Vector2();
341
+
342
+ // Creating rotation pad:
343
+ self.rotationPad = new RotationPad(container);
344
+ $(self.rotationPad).on("YawPitch", function(event) {
345
+ var rotation = calculateCameraRotation(event.detail.deltaX, event.detail.deltaY);
346
+ self.setRotation(rotation.rx, rotation.ry);
347
+ });
348
+
349
+ // Creating movement pad:
350
+ self.movementPad = new MovementPad(container);
351
+ $(self.movementPad).on("move", function(event) {
352
+ self.stick_x = -event.detail.deltaX / 2
353
+ self.stick_y = event.detail.deltaY / 2
354
+ ztouch = Math.abs(event.detail.deltaY);
355
+ xtouch = Math.abs(event.detail.deltaX);
356
+
357
+ if (event.detail.deltaY == event.detail.middle) {
358
+ ztouch = 1;
359
+ moveForward = moveBackward = false;
360
+ } else {
361
+ if (event.detail.deltaY > event.detail.middle) {
362
+ moveForward = true;
363
+ moveBackward = false;
364
+ }
365
+ else if (event.detail.deltaY < event.detail.middle) {
366
+ moveForward = false;
367
+ moveBackward = true;
368
+ }
369
+ }
370
+
371
+ if (event.detail.deltaX == event.detail.middle) {
372
+ xtouch = 1;
373
+ moveRight = moveLeft = false;
374
+ } else {
375
+ if (event.detail.deltaX < event.detail.middle) {
376
+ moveRight = true;
377
+ moveLeft = false;
378
+ }
379
+ else if (event.detail.deltaX > event.detail.middle) {
380
+ moveRight = false;
381
+ moveLeft = true;
382
+ }
383
+ }
384
+ });
385
+ $(self.movementPad).on("stopMove", function(event) {
386
+ ztouch = xtouch = 1;
387
+ self.stick_x = 0
388
+ self.stick_y = 0
389
+ moveForward = moveBackward = moveLeft = moveRight = false;
390
+ });
391
+
392
+ container.on("contextmenu", onContextMenu);
393
+ container.on("mousedown", onMouseDown);
394
+ container.on("mouseup", onMouseUp);
395
+
396
+ $(document).on("keydown", onKeyDown);
397
+ $(document).on("keyup", onKeyUp);
398
+ $(document).on("mousemove", onMouseMove);
399
+ $(document).on("mouseout", onMouseOut);
400
+
401
+ prepareRotationMatrices();
402
+
403
+ //
404
+ // Events:
405
+ //
406
+ function onContextMenu(event) {
407
+ event.preventDefault();
408
+ };
409
+
410
+ function onMouseDown(event) {
411
+
412
+ if (self.enabled && event.button === 2) {
413
+ isRightMouseDown = true;
414
+ event.preventDefault();
415
+ event.stopPropagation();
416
+ }
417
+ };
418
+
419
+ function onMouseUp(event) {
420
+
421
+ if (self.enabled && event.button === 2) {
422
+ isRightMouseDown = false;
423
+ }
424
+ };
425
+
426
+ function onMouseMove(event) {
427
+
428
+ self.mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
429
+ self.mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
430
+
431
+ if (!self.enabled || !isRightMouseDown) return;
432
+
433
+ var movementX = event.originalEvent.movementX || event.originalEvent.mozMovementX || event.originalEvent.webkitMovementX || 0;
434
+ var movementY = event.originalEvent.movementY || event.originalEvent.mozMovementY || event.originalEvent.webkitMovementY || 0;
435
+ var rotation = calculateCameraRotation(-1 * movementX, -1 * movementY);
436
+
437
+ // console.log(self.mouse, "\n", movementX, rotation);
438
+
439
+ self.setRotation(rotation.rx, rotation.ry);
440
+
441
+ // updateNavPad();
442
+ };
443
+
444
+ function onMouseOut(e) {
445
+ isRightMouseDown = false;
446
+ // self.stopMouseMoving();
447
+ };
448
+
449
+ function onKeyDown(e) {
450
+
451
+ if (!self.enabled) return;
452
+
453
+ switch (e.keyCode) {
454
+
455
+ case 38: // up
456
+ case 87: // w
457
+ moveForward = true;
458
+ break;
459
+
460
+ case 37: // left
461
+ case 65: // a
462
+ moveLeft = true;
463
+ break;
464
+
465
+ case 40: // down
466
+ case 83: // s
467
+ moveBackward = true;
468
+ break;
469
+
470
+ case 39: // right
471
+ case 68: // d
472
+ moveRight = true;
473
+ break;
474
+ }
475
+ };
476
+
477
+ function onKeyUp(e) {
478
+
479
+ switch (e.keyCode) {
480
+
481
+ case 38: // up
482
+ case 87: // w
483
+ moveForward = false;
484
+ break;
485
+
486
+ case 37: // left
487
+ case 65: // a
488
+ moveLeft = false;
489
+ break;
490
+
491
+ case 40: // down
492
+ case 83: // a
493
+ moveBackward = false;
494
+ break;
495
+
496
+ case 39: // right
497
+ case 68: // d
498
+ moveRight = false;
499
+ break;
500
+
501
+ }
502
+ };
503
+
504
+ //
505
+ // Private functions:
506
+ //
507
+ function prepareRotationMatrices() {
508
+
509
+ var rotationMatrixF = new THREE.Matrix4();
510
+ rotationMatrixF.makeRotationY(0);
511
+ rotationMatrices.push(rotationMatrixF); // forward direction.
512
+
513
+ var rotationMatrixB = new THREE.Matrix4();
514
+ rotationMatrixB.makeRotationY(180 * Math.PI / 180);
515
+ rotationMatrices.push(rotationMatrixB);
516
+
517
+ var rotationMatrixL = new THREE.Matrix4();
518
+ rotationMatrixL.makeRotationY(90 * Math.PI / 180);
519
+ rotationMatrices.push(rotationMatrixL);
520
+
521
+ var rotationMatrixR = new THREE.Matrix4();
522
+ rotationMatrixR.makeRotationY((360 - 90) * Math.PI / 180);
523
+ rotationMatrices.push(rotationMatrixR);
524
+ };
525
+
526
+ function calculateCameraRotation(dx, dy, factor) {
527
+ var factor = factor ? factor : self.config.rotationFactor;
528
+ var ry = self.fpsBody.rotation.y - (dx * factor);
529
+ var rx = cameraHolder.rotation.x - (dy * factor);
530
+ rx = Math.max(-maxPitch, Math.min(maxPitch, rx));
531
+
532
+ return {
533
+ rx: rx,
534
+ ry: ry
535
+ };
536
+ };
537
+
538
+ function lockDirectionByIndex(index) {
539
+ if (index == 0)
540
+ self.lockMoveForward(true);
541
+ else if (index == 1)
542
+ self.lockMoveBackward(true);
543
+ else if (index == 2)
544
+ self.lockMoveLeft(true);
545
+ else if (index == 3)
546
+ self.lockMoveRight(true);
547
+ }
548
+
549
+ //
550
+ // Public functions:
551
+ //
552
+ self.update = function() {
553
+ if (!self.enabled) return;
554
+ if (self.config.hitTest)
555
+ self.hitTest();
556
+
557
+ velocity.x += (-1 * velocity.x) * 0.75 * self.config.delta;
558
+ velocity.z += (-1 * velocity.z) * 0.75 * self.config.delta;
559
+
560
+ if (moveForward && !lockMoveForward) velocity.z -= ztouch * self.config.speedFactor * self.config.delta;
561
+ if (moveBackward && !lockMoveBackward) velocity.z += ztouch * self.config.speedFactor * self.config.delta;
562
+
563
+ if (moveLeft && !lockMoveLeft) velocity.x -= xtouch * self.config.speedFactor * self.config.delta;
564
+ if (moveRight && !lockMoveRight) velocity.x += xtouch * self.config.speedFactor * self.config.delta;
565
+
566
+ self.fpsBody.translateX(velocity.x);
567
+ self.fpsBody.translateY(velocity.y);
568
+ self.fpsBody.translateZ(velocity.z);
569
+ };
570
+
571
+ self.hitTest = function() {
572
+ self.unlockAllDirections();
573
+ hitObjects = [];
574
+ var cameraDirection = self.getDirection2(new THREE.Vector3(0, 0, 0)).clone();
575
+
576
+ for (var i = 0; i < 4; i++) {
577
+ // Applying rotation for each direction:
578
+ var direction = cameraDirection.clone();
579
+ direction.applyMatrix4(rotationMatrices[i]);
580
+
581
+ var rayCaster = new THREE.Raycaster(self.fpsBody.position, direction);
582
+ var intersects = rayCaster.intersectObject(self.scene, true);
583
+ if ((intersects.length > 0 && intersects[0].distance < self.config.hitTestDistance)) {
584
+ lockDirectionByIndex(i);
585
+ hitObjects.push(intersects[0]);
586
+ // console.log(intersects[0].object.name, i);
587
+ }
588
+ }
589
+
590
+ return hitObjects;
591
+ };
592
+
593
+ self.getDirection2 = function(v) {
594
+ var self = this;
595
+ var direction = new THREE.Vector3(0, 0, -1);
596
+ var rotation = new THREE.Euler(0, 0, 0, "YXZ");
597
+ var rx = self.fpsBody.getObjectByName("cameraHolder").rotation.x;;
598
+ var ry = self.fpsBody.rotation.y;
599
+
600
+ // console.log("DIRECTION:", this);
601
+ rotation.set(rx, ry, 0);
602
+ v.copy(direction).applyEuler(rotation);
603
+ // console.log(v);
604
+ return v;
605
+ };
606
+
607
+ self.getDirection = function() {
608
+ var self = this;
609
+ var rx = 0;
610
+ var ry = 0;
611
+ var direction = new THREE.Vector3(0, 0, -1);
612
+ var rotation = new THREE.Euler(0, 0, 0, "YXZ");
613
+
614
+ // console.log("DIRECTION:", this);
615
+ if (self != undefined) {
616
+ rx = self.fpsBody.getObjectByName("cameraHolder").rotation.x;
617
+ ry = self.fpsBody.rotation.y;
618
+ console.log(rx, ry);
619
+ }
620
+ // var camHolder = self.fpsBody.getObjectByName("cameraHolder");
621
+
622
+ return function(v) {
623
+ rotation.set(rx, ry, 0);
624
+ v.copy(direction).applyEuler(rotation);
625
+ // console.log(v);
626
+ return v;
627
+ }
628
+ }();
629
+
630
+ self.moveLeft = function() {
631
+ return moveLeft;
632
+ };
633
+
634
+ self.moveRight = function() {
635
+ return moveRight;
636
+ };
637
+
638
+ self.moveForward = function() {
639
+ return moveForward;
640
+ };
641
+
642
+ self.moveBackward = function() {
643
+ return moveBackward;
644
+ };
645
+
646
+ self.lockMoveForward = function(boolean) {
647
+ lockMoveForward = boolean;
648
+ };
649
+
650
+ self.lockMoveBackward = function(boolean) {
651
+ lockMoveBackward = boolean;
652
+ };
653
+
654
+ self.lockMoveLeft = function(boolean) {
655
+ lockMoveLeft = boolean;
656
+ };
657
+
658
+ self.lockMoveRight = function(boolean) {
659
+ lockMoveRight = boolean;
660
+ };
661
+
662
+ self.unlockAllDirections = function() {
663
+ self.lockMoveForward(false);
664
+ self.lockMoveBackward(false);
665
+ self.lockMoveLeft(false);
666
+ self.lockMoveRight(false);
667
+ };
668
+ };
669
+
670
+ TouchControls.prototype = {
671
+ addToScene: function(scene) {
672
+ this.scene = scene;
673
+ scene.add(this.fpsBody);
674
+ },
675
+
676
+ setPosition: function(x, y, z) {
677
+ this.fpsBody.position.set(x, y, z);
678
+ },
679
+
680
+ stopMouseMoving: function() {
681
+ isRightMouseDown = false;
682
+ },
683
+
684
+ setRotation: function(x, y) {
685
+ var camHolder = this.fpsBody.getObjectByName("cameraHolder");
686
+
687
+ if (x !== null)
688
+ camHolder.rotation.x = x;
689
+
690
+ if (y !== null)
691
+ this.fpsBody.rotation.y = y;
692
+ },
693
+
694
+ getHitObjects: function() {
695
+ return hitObjects;
696
+ }
697
+
698
+ };
699
+
700
+ export default {
701
+ TouchControls,
702
+ MovementPad,
703
+ RotationPad,
704
+ }
705
+
706
+ window.TouchControls = TouchControls
707
+ window.MovementPad = MovementPad
708
+ window.RotationPad = RotationPad