Advertisement
onexiv

Here's Johnny

Oct 25th, 2023
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. class CrossProduct {
  2.  
  3. constructor(ObjA, ObjB)
  4. {
  5. this.A = null;
  6. this.B = null;
  7. this.vector = 0;
  8. try {
  9. this.A = { "x": ObjA.x, "y": ObjA.y, "z": ObjA.z };
  10. } catch (error)
  11. {
  12. this.A = { "x": ObjA.width, "y": ObjA.height, "z": ObjA.depth };
  13. }
  14. finally {
  15. this.A = ObjA;
  16. }
  17. try {
  18. this.B = { "x": ObjB.x, "y": ObjB.y, "z": ObjB.z };
  19. } catch (error)
  20. {
  21. this.B = { "x": ObjB.width, "y": ObjB.height, "z": ObjB.depth };
  22. }
  23. finally {
  24. this.B = ObjB;
  25. }
  26. this.answer = 0;
  27. this.i = 0;
  28. this.orthovector = [];
  29. this.trigs = [];
  30. }
  31.  
  32. getSimilarity(trigFunction = 0, degree = 45) {
  33. this.answer = 0;
  34. this.i = 0;
  35. this.trigs = [];
  36. this.answer += this.A.x * this.B.x;
  37. this.answer += this.A.y * this.B.y;
  38. this.answer += this.A.z * this.B.z;
  39.  
  40. if (trigFunction == 0) {
  41. var sine = this.answer * Math.sin(degree);
  42. var cosine = this.answer * Math.cos(degree);
  43. var tangent = this.answer * Math.tan(degree);
  44. this.trigs = { "sin": sine, "cos": cosine, "tan": tangent };
  45. return this.trigs;
  46. } else if (trigFunction == 1) {
  47. var sine = this.answer * Math.sinh(degree);
  48. var cosine = this.answer * Math.cosh(degree);
  49. var tangent = this.answer * Math.tanh(degree);
  50. this.trigs = { "sin": sine, "cos": cosine, "tan": tangent };
  51. } else {
  52. console.log("param3: 0 sin, cos, tan, 1 sinh, 2 cosh, 3 tanh");
  53. }
  54. console.log(this.answer);
  55. return this.answer;
  56. }
  57.  
  58. ObjA(oA) {
  59. try {
  60. this.A = { "x": oA.x, "y": oA.y, "z": oA.z };
  61. } catch (error)
  62. {
  63. this.A = { "x": oA.width, "y": oA.height, "z": oA.depth };
  64. }
  65. finally {
  66. this.A = oA;
  67. }
  68. }
  69.  
  70. ObjB(oB) {
  71. try {
  72. this.B = { "x": oB.x, "y": oB.y, "z": oB.z };
  73. } catch (error)
  74. {
  75. this.B = { "x": oB.width, "y": oB.height, "z": oB.depth };
  76. }
  77. finally {
  78. this.B = oB;
  79. }
  80. }
  81.  
  82. OrthogonalVector()
  83. {
  84. // a1*b2 - a2*b1, a2*b0 - a0b2, a0b1 - a1b0
  85. var voteX = ((this.A.y*this.B.z) - (this.A.z*this.B.y));
  86. var voteY = ((this.A.z*this.B.x) - (this.A.x*this.B.z));
  87. var voteZ = ((this.A.x*this.B.y) - (this.A.y*this.B.x));
  88. this.orthovector.push((voteX));
  89. this.orthovector.push((voteY));
  90. this.orthovector.push((voteZ));
  91. if ((voteX) === (voteY))
  92. {
  93. console.log(voteX);
  94. this.vector = voteX;
  95. return (voteX);
  96. }
  97. if ((voteY) === (voteZ))
  98. {
  99. console.log(voteY);
  100. this.vector = voteY;
  101. return (voteY);
  102. }
  103. if ((voteZ) === (voteX))
  104. {
  105. console.log(voteZ);
  106. this.vector = voteZ;
  107. return (voteZ);
  108. }
  109.  
  110. }
  111. }
  112.  
  113. export {CrossProduct};
  114. import * as THREE from './three.module.js';
  115. import HumanInterfaceDevice from './humaninterfacedevice.js';
  116. import { CrossProduct } from './crossproduct.js';
  117.  
  118. class collisionChecker {
  119.  
  120. constructor(scene, camera, segments, hid) {
  121. this.scene = scene;
  122. this.camera = camera;
  123. this.segments = segments;
  124. this.hid = hid;
  125. this.check();
  126. this.cameraRotationX;
  127. this.cameraRotationY;
  128. this.cameraRotationZ;
  129. }
  130.  
  131. check() {
  132. this.segments.forEach(element => {
  133. this.detect(element.position);
  134. });
  135. }
  136.  
  137. detect(elem) {
  138. // Speed might jump the distanceThreshold ** CAUTION **
  139. this.hid.speed = 155;
  140. var x = Math.round(this.hid.direction.x);
  141. var y = Math.round(this.hid.direction.y);
  142. var z = Math.round(this.hid.direction.z);
  143. var ex = elem.x;
  144. var ey = elem.y;
  145. var ez = elem.z;
  146. var velX = this.hid.velocity.x;
  147. var velY = this.hid.velocity.y;
  148. var velZ = this.hid.velocity.z;
  149. console.log(x + " " + velX + " " + y + " " + velY + " " + velZ + " " + z);
  150. this.hid.controls.x += velX;
  151. this.hid.controls.y += velY;
  152. this.hid.controls.z += velZ;
  153. var magic = new CrossProduct(elem, this.hid.controls);
  154. var vector = Math.abs(magic.OrthogonalVector());
  155. if (vector >= (Math.abs(ex) | Math.abs(ey) | Math.abs(ez))) {
  156. this.hid.controls.x = (vector >= Math.abs(x)) ? -x : 0;
  157. this.hid.controls.y = (vector >= Math.abs(y)) ? -y : 0;
  158. this.hid.controls.z = (vector >= Math.abs(z)) ? -z : 0;
  159. }
  160. const delta = this.hid.clock.getDelta();
  161. this.hid.update(delta);
  162. }
  163. }
  164.  
  165. export { collisionChecker };
  166.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement