mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-11-10 20:45:35 +01:00
30 lines
722 B
Plaintext
30 lines
722 B
Plaintext
function __ray(origin, direction) constructor {
|
|
self.origin = origin;
|
|
self.direction = direction.normalize();
|
|
|
|
static sampleDistance = function(t) {
|
|
gml_pragma("forceinline");
|
|
return origin.add(direction.multiply(t));
|
|
}
|
|
}
|
|
|
|
function __plane(origin, normal) constructor {
|
|
self.origin = origin;
|
|
self.normal = normal.normalize();
|
|
}
|
|
|
|
#region functions
|
|
function d3d_intersect_ray_plane(ray, plane) {
|
|
//print($"Intersect {ray}\n\tto {plane}");
|
|
|
|
var det = plane.normal.dot(ray.direction);
|
|
if(det == 0) return new __vec3();
|
|
|
|
var rayToPlane = plane.origin.subtract(ray.origin);
|
|
var t = rayToPlane.dot(plane.normal) / det;
|
|
|
|
if(t < 0) return new __vec3();
|
|
|
|
return ray.sampleDistance(t);
|
|
}
|
|
#endregion |