Advertisement
onexiv

Thesis for ADP Jr.

Oct 25th, 2023
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. import * as THREE from './three.module.js';
  2. import HumanInterfaceDevice from './humaninterfacedevice.js';
  3. import { CrossProduct } from './crossproduct.js';
  4.  
  5. class collisionChecker {
  6.  
  7. constructor(scene, camera, segments, hid) {
  8. this.scene = scene;
  9. this.camera = camera;
  10. this.segments = segments;
  11. this.hid = hid;
  12. this.check();
  13. }
  14.  
  15. check() {
  16. this.segments.forEach(element => {
  17. this.detect(element.position);
  18. });
  19. }
  20.  
  21. detect(elem) {
  22. // Speed might jump the distanceThreshold ** CAUTION **
  23. this.hid.speed = 155;
  24. var x = this.hid.direction.x;
  25. var z = this.hid.direction.z;
  26.  
  27. var velX = this.hid.velocity.x;
  28. var velZ = this.hid.velocity.z;
  29.  
  30. var cgX = this.hid.controls.x;
  31. var cgZ = this.hid.controls.z;
  32. const directs = [ this.hid.moveForward, this.hid.moveBackward, this.hid.moveLeft, this.hid.moveRight ];
  33. if ((cgX || cgZ) && directs.indexOf(1) == -1) return;
  34.  
  35. this.hid.controls.x = (Math.round(cgX) >= Math.round(elem.x) && Math.round(cgX) < elem.width) ? 0 : (Math.round(cgZ * cgX) / 2 >= Math.round(elem.x) && Math.round(cgZ * cgX) / 2 < elem.width) ? 0 : (cgX + velX) * (-z);
  36. this.hid.controls.z = (Math.round(cgZ) >= Math.round(elem.z) && Math.round(cgZ) < elem.depth) ? 0 : (Math.round(cgX * cgZ) / 2 >= Math.round(elem.z) && Math.round(cgZ * cgX) / 2 < elem.depth) ? 0 : (cgZ + velZ) * (-x);
  37.  
  38. const delta = this.hid.clock.getDelta();
  39. this.hid.update(delta);
  40. }
  41. }
  42.  
  43. export { collisionChecker };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement