forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathray.js
More file actions
40 lines (37 loc) · 1.42 KB
/
ray.js
File metadata and controls
40 lines (37 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Vec3 } from '../math/vec3.js';
/**
* @class
* @name Ray
* @classdesc An infinite ray.
* @description Creates a new infinite ray starting at a given origin and pointing in a given direction.
* @example
* // Create a new ray starting at the position of this entity and pointing down
* // the entity's negative Z axis
* var ray = new pc.Ray(this.entity.getPosition(), this.entity.forward);
* @param {Vec3} [origin] - The starting point of the ray. The constructor takes a reference of this parameter.
* Defaults to the origin (0, 0, 0).
* @param {Vec3} [direction] - The direction of the ray. The constructor takes a reference of this parameter.
* Defaults to a direction down the world negative Z axis (0, 0, -1).
* @property {Vec3} origin The starting point of the ray.
* @property {Vec3} direction The direction of the ray.
*/
class Ray {
constructor(origin = new Vec3(), direction = new Vec3(0, 0, -1)) {
this.origin = origin;
this.direction = direction;
}
/**
* @function
* @name Ray#set
* @description Sets origin and direction to the supplied vector values.
* @param {Vec3} origin - The starting point of the ray.
* @param {Vec3} direction - The direction of the ray.
* @returns {Ray} Self for chaining.
*/
set(origin, direction) {
this.origin.copy(origin);
this.direction.copy(direction);
return this;
}
}
export { Ray };