-
Notifications
You must be signed in to change notification settings - Fork 103
vec3
The vec3
object provides tools for working with 3D Vectors or Points.
Both vectors and points in CubicVR.js use the format [0.0, 0.0, 0.0]
.
Parameters:
-
v1
: First 3D vector to compare, format:[0.0, 0.0, 0.0]
-
v2
: Second 3D vector to compare, format:[0.0, 0.0, 0.0]
Returns:
true
if v1 == v2
, false otherwise.
Parameters:
-
v
: 3D Vector, format:[1.0, 0.0, 0.0]
Returns:
Length of vector v.
Parameters:
-
v
: 3D Vector, format:[1.0, 0.0, 0.0]
Returns:
Normalized v.
Parameters:
-
v1
: First 3D vector, format:[1.0, 0.0, 0.0]
-
v2
: Second 3D vector, format:[0.0, 1.0, 0.0]
Returns:
A single float, dot product v1 ⋅ v2.
Parameters:
-
v1
: First 3D vector, format:[1.0, 0.0, 0.0]
-
v2
: Second 3D vector, format:[0.0, 1.0, 0.0]
Returns:
Angle between v1 and v2 on their common plane in radians.
Return vector perpendicular to v1 and v2 on their common plane.
Parameters:
-
v1
: First 3D vector, format:[1.0, 0.0, 0.0]
-
v2
: Second 3D vector, format:[0.0, 1.0, 0.0]
Returns:
Cross-product v1 ⊗ v2.
Multiply the vector components by a constant.
Parameters:
-
v1
: First 3D vector, format:[1.0, 0.0, 0.0]
-
c
: A constant, format:1.0
Returns:
Vector v1 with each component multiplied by constant c.
Parameters:
-
v1
: First 3D vector, format:[1.0, 0.0, 0.0]
-
v2
: Second 3D vector, format:[0.0, 1.0, 0.0]
Returns:
Vector sum v1 + v2.
Parameters:
-
v1
: First 3D vector, format:[1.0, 0.0, 0.0]
-
v2
: Second 3D vector, format:[0.0, 1.0, 0.0]
Returns:
Vector difference v1 - v2.
Return a new position offset from its existing target or alt_source position, relative to a movement viewed from position→target with xdelta/ydelta movement in that view.
Parameters:
-
position
: Position of view, format:[0.0, 0.0, 0.0]
-
target
: Position of view target, format:[0.0, 0.0, 0.0]
-
xdelta
: Movement left/right amount relative to view -
ydelta
: Movement up/down amount relative to view -
alt_source
(optional) : Alternate target to use for source, otherwise it uses target
Returns:
New position relative to target or, if supplied alt_source.
To move point position towards (or away from) point target at trackingSpeed while maintaining safeDistance units away from target.
Parameters:
-
position
: A position, format:[0.0, 0.0, 0.0]
-
target
: A target, format:[0.0, 0.0, 0.0]
-
trackingSpeed
: Distance (or stepping factor) to move position toward target -
safeDistance
: Distance to keep position away from target
Returns:
New position, format: [0.0, 0.0, 0.0]
Given line segment ptA→ptB, calculate the position on the line segment closest to ptTest. Note that the point returned may be outside the line segment but it will be on it; test min/max between your points to be sure.
Parameters:
-
ptA
: First point on line segment, format:[0.0, 0.0, 0.0]
-
ptB
: Second point on line segment, format:[0.0, 0.0, 0.0]
-
ptTest
: Point to compare to segment, format:[0.0, 0.0, 0.0]
Returns:
The closest point to ptTest on line segment ptA→ptB.