JSFiddle - React, Tailwind, and code Playground
by Michael Prosser
JavaScript
var box1 = {
width: 2,
height: 1,
depth: 1,
position: { x: 0, y: 0, z: 0 },
rotation: { x: 0, y: 0, z: 0 },
scaling: { x: 0, y: 0, z: 0 }
}
var box2 = {
width: 2,
height: 1,
depth: 1,
position: { x: 0, y: 0, z: 0 },
rotation: { x: 0, y: 0, z: 0 },
scaling: { x: 0, y: 0, z: 0 }
}
var findPoint = function(position,orientation,d){
var z = position.z + Math.cos(orientation.y) * (d*-1);
var x = position.x + Math.sin(orientation.y) * (d*-1);
var y = position.y + Math.tan(orientation.x) * (d*-1);
return {
position: { x: x, y: y, z: z },
orientation: { x: orientation.x, y: orientation.y, z: orientation.z }
};
}
var collided = function(object1,object2){
var hit = false;
var distance = 1;
var point = findPoint(object1.position, object1.rotation, distance);
alert(hit);
}
collided(box1,box2);