Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CrossProduct {
- constructor(ObjA, ObjB)
- {
- this.A = null;
- this.B = null;
- this.vector = 0;
- try {
- this.A = { "x": ObjA.x, "y": ObjA.y, "z": ObjA.z };
- } catch (error)
- {
- this.A = { "x": ObjA.width, "y": ObjA.height, "z": ObjA.depth };
- }
- finally {
- this.A = ObjA;
- }
- try {
- this.B = { "x": ObjB.x, "y": ObjB.y, "z": ObjB.z };
- } catch (error)
- {
- this.B = { "x": ObjB.width, "y": ObjB.height, "z": ObjB.depth };
- }
- finally {
- this.B = ObjB;
- }
- this.answer = 0;
- this.i = 0;
- this.orthovector = [];
- this.trigs = [];
- }
- getSimilarity(trigFunction = 0, degree = 45) {
- this.answer = 0;
- this.i = 0;
- this.trigs = [];
- this.answer += this.A.x * this.B.x;
- this.answer += this.A.y * this.B.y;
- this.answer += this.A.z * this.B.z;
- if (trigFunction == 0) {
- var sine = this.answer * Math.sin(degree);
- var cosine = this.answer * Math.cos(degree);
- var tangent = this.answer * Math.tan(degree);
- this.trigs = { "sin": sine, "cos": cosine, "tan": tangent };
- return this.trigs;
- } else if (trigFunction == 1) {
- var sine = this.answer * Math.sinh(degree);
- var cosine = this.answer * Math.cosh(degree);
- var tangent = this.answer * Math.tanh(degree);
- this.trigs = { "sin": sine, "cos": cosine, "tan": tangent };
- } else {
- console.log("param3: 0 sin, cos, tan, 1 sinh, 2 cosh, 3 tanh");
- }
- console.log(this.answer);
- return this.answer;
- }
- ObjA(oA) {
- try {
- this.A = { "x": oA.x, "y": oA.y, "z": oA.z };
- } catch (error)
- {
- this.A = { "x": oA.width, "y": oA.height, "z": oA.depth };
- }
- finally {
- this.A = oA;
- }
- }
- ObjB(oB) {
- try {
- this.B = { "x": oB.x, "y": oB.y, "z": oB.z };
- } catch (error)
- {
- this.B = { "x": oB.width, "y": oB.height, "z": oB.depth };
- }
- finally {
- this.B = oB;
- }
- }
- OrthogonalVector()
- {
- // a1*b2 - a2*b1, a2*b0 - a0b2, a0b1 - a1b0
- var voteX = ((this.A.y*this.B.z) - (this.A.z*this.B.y));
- var voteY = ((this.A.z*this.B.x) - (this.A.x*this.B.z));
- var voteZ = ((this.A.x*this.B.y) - (this.A.y*this.B.x));
- this.orthovector.push((voteX));
- this.orthovector.push((voteY));
- this.orthovector.push((voteZ));
- if ((voteX) === (voteY))
- {
- console.log(voteX);
- this.vector = voteX;
- return (voteX);
- }
- if ((voteY) === (voteZ))
- {
- console.log(voteY);
- this.vector = voteY;
- return (voteY);
- }
- if ((voteZ) === (voteX))
- {
- console.log(voteZ);
- this.vector = voteZ;
- return (voteZ);
- }
- }
- }
- export {CrossProduct};
- import * as THREE from './three.module.js';
- import HumanInterfaceDevice from './humaninterfacedevice.js';
- import { CrossProduct } from './crossproduct.js';
- class collisionChecker {
- constructor(scene, camera, segments, hid) {
- this.scene = scene;
- this.camera = camera;
- this.segments = segments;
- this.hid = hid;
- this.check();
- this.cameraRotationX;
- this.cameraRotationY;
- this.cameraRotationZ;
- }
- check() {
- this.segments.forEach(element => {
- this.detect(element.position);
- });
- }
- detect(elem) {
- // Speed might jump the distanceThreshold ** CAUTION **
- this.hid.speed = 155;
- var x = Math.round(this.hid.direction.x);
- var y = Math.round(this.hid.direction.y);
- var z = Math.round(this.hid.direction.z);
- var ex = elem.x;
- var ey = elem.y;
- var ez = elem.z;
- var velX = this.hid.velocity.x;
- var velY = this.hid.velocity.y;
- var velZ = this.hid.velocity.z;
- console.log(x + " " + velX + " " + y + " " + velY + " " + velZ + " " + z);
- this.hid.controls.x += velX;
- this.hid.controls.y += velY;
- this.hid.controls.z += velZ;
- var magic = new CrossProduct(elem, this.hid.controls);
- var vector = Math.abs(magic.OrthogonalVector());
- if (vector >= (Math.abs(ex) | Math.abs(ey) | Math.abs(ez))) {
- this.hid.controls.x = (vector >= Math.abs(x)) ? -x : 0;
- this.hid.controls.y = (vector >= Math.abs(y)) ? -y : 0;
- this.hid.controls.z = (vector >= Math.abs(z)) ? -z : 0;
- }
- const delta = this.hid.clock.getDelta();
- this.hid.update(delta);
- }
- }
- export { collisionChecker };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement