playcanvas
Version:
PlayCanvas WebGL game engine
81 lines (80 loc) • 2.59 kB
TypeScript
/**
* A triangle defined by three {@link Vec3} vectors.
*
* @category Math
*/
export class Tri {
/**
* Creates a new Tri object.
*
* @param {Vec3} [v0] - The first 3-dimensional vector.
* @param {Vec3} [v1] - The second 3-dimensional vector.
* @param {Vec3} [v2] - The third 3-dimensional vector.
* @example
* const v0 = new pc.Vec3(1, 0, 0);
* const v1 = new pc.Vec3(0, 1, 0);
* const v2 = new pc.Vec3(2, 2, 1);
* const t = new pc.Tri(v0, v1, v2);
*/
constructor(v0?: Vec3, v1?: Vec3, v2?: Vec3);
/**
* The first 3-dimensional vector of the triangle.
*
* @readonly
* @type {Vec3}
*/
readonly v0: Vec3;
/**
* The second 3-dimensional vector of the triangle.
*
* @type {Vec3}
* @readonly
*/
readonly v1: Vec3;
/**
* The third 3-dimensional vector of the triangle.
*
* @type {Vec3}
* @readonly
*/
readonly v2: Vec3;
/**
* Sets the specified triangle to the supplied 3-dimensional vectors.
*
* @param {Vec3} v0 - The value set on the first 3-dimensional vector of the triangle.
* @param {Vec3} v1 - The value set on the second 3-dimensional vector of the triangle.
* @param {Vec3} v2 - The value set on the third 3-dimensional vector of the triangle.
* @returns {Tri} Self for chaining
* @example
* const t = new pc.Tri(pc.Vec3.UP, pc.Vec3.RIGHT, pc.Vec3.BACK);
* const v0 = new pc.Vec3(1, 0, 0);
* const v1 = new pc.Vec3(0, 1, 0);
* const v2 = new pc.Vec3(2, 2, 1);
* t.set(v0, v1, v2);
*
* // Outputs [[1, 0, 0], [0, 1, 0], [2, 2, 1]]
* console.log("The result of the triangle set is: " + t.toString());
*/
set(v0: Vec3, v1: Vec3, v2: Vec3): Tri;
/**
* Test if a ray intersects with the triangle.
*
* @param {Ray} ray - Ray to test against (direction must be normalized).
* @param {Vec3} [point] - If there is an intersection, the intersection point will be copied
* into here.
* @returns {boolean} True if there is an intersection.
*/
intersectsRay(ray: Ray, point?: Vec3): boolean;
/**
* Converts the specified triangle to string form.
*
* @returns {string} The triangle in string form.
* @example
* const t = new pc.Tri(pc.Vec3.UP, pc.Vec3.RIGHT, pc.Vec3.BACK);
* // Outputs [[0, 1, 0], [1, 0, 0], [0, 0, 1]]
* console.log(t.toString());
*/
toString(): string;
}
import { Vec3 } from '../math/vec3.js';
import type { Ray } from './ray.js';