Class Vec3_EX

Hierarchy

  • Vec3
    • Vec3_EX

Constructors

  • Creates a new Vec3 object.

    Example

    var v = new pc.Vec3(1, 2, 3);
    

    Parameters

    • Optional x: number | number[]

      The x value. Defaults to 0. If x is an array of length 3, the array will be used to populate all components.

    • Optional y: number

      The y value. Defaults to 0.

    • Optional z: number

      The z value. Defaults to 0.

    Returns Vec3_EX

Properties

_rotation: Quat
_shaderData: Float32Array
x: number

The first component of the vector.

y: number

The second component of the vector.

z: number

The third component of the vector.

BACK: Vec3

A constant vector set to [0, 0, 1].

DOWN: Vec3

A constant vector set to [0, -1, 0].

FORWARD: Vec3

A constant vector set to [0, 0, -1].

LEFT: Vec3

A constant vector set to [-1, 0, 0].

ONE: Vec3

A constant vector set to [1, 1, 1].

RIGHT: Vec3

A constant vector set to [1, 0, 0].

UP: Vec3

A constant vector set to [0, 1, 0].

ZERO: Vec3

A constant vector set to [0, 0, 0].

Accessors

Methods

  • Adds a 3-dimensional vector to another in place.

    Returns

    Self for chaining.

    Example

    var a = new pc.Vec3(10, 10, 10);
    var b = new pc.Vec3(20, 20, 20);

    a.add(b);

    // Outputs [30, 30, 30]
    console.log("The result of the addition is: " + a.toString());

    Parameters

    • rhs: Vec3

      The vector to add to the specified vector.

    Returns Vec3

  • Adds two 3-dimensional vectors together and returns the result.

    Returns

    Self for chaining.

    Example

    var a = new pc.Vec3(10, 10, 10);
    var b = new pc.Vec3(20, 20, 20);
    var r = new pc.Vec3();

    r.add2(a, b);
    // Outputs [30, 30, 30]

    console.log("The result of the addition is: " + r.toString());

    Parameters

    • lhs: Vec3

      The first vector operand for the addition.

    • rhs: Vec3

      The second vector operand for the addition.

    Returns Vec3

  • Adds a number to each element of a vector.

    Returns

    Self for chaining.

    Example

    var vec = new pc.Vec3(3, 4, 5);

    vec.addScalar(2);

    // Outputs [5, 6, 7]
    console.log("The result of the addition is: " + vec.toString());

    Parameters

    • scalar: number

      The number to add.

    Returns Vec3

  • Each element is rounded up to the next largest integer.

    Returns

    Self for chaining.

    Returns Vec3

  • Returns an identical copy of the specified 3-dimensional vector.

    Returns

    A 3-dimensional vector containing the result of the cloning.

    Example

    var v = new pc.Vec3(10, 20, 30);
    var vclone = v.clone();
    console.log("The result of the cloning is: " + vclone.toString());

    Returns Vec3_EX

  • Copies the contents of a source 3-dimensional vector to a destination 3-dimensional vector.

    Returns

    Self for chaining.

    Example

    var src = new pc.Vec3(10, 20, 30);
    var dst = new pc.Vec3();

    dst.copy(src);

    console.log("The two vectors are " + (dst.equals(src) ? "equal" : "different"));

    Parameters

    • rhs: Vec3

      A vector to copy to the specified vector.

    Returns Vec3

  • Returns the result of a cross product operation performed on the two specified 3-dimensional vectors.

    Returns

    Self for chaining.

    Example

    var back = new pc.Vec3().cross(pc.Vec3.RIGHT, pc.Vec3.UP);

    // Prints the Z axis (i.e. [0, 0, 1])
    console.log("The result of the cross product is: " + back.toString());

    Parameters

    • lhs: Vec3

      The first 3-dimensional vector operand of the cross product.

    • rhs: Vec3

      The second 3-dimensional vector operand of the cross product.

    Returns Vec3

  • Returns the distance between the two specified 3-dimensional vectors.

    Returns

    The distance between the two vectors.

    Example

    var v1 = new pc.Vec3(5, 10, 20);
    var v2 = new pc.Vec3(10, 20, 40);
    var d = v1.distance(v2);
    console.log("The distance between v1 and v2 is: " + d);

    Parameters

    • rhs: Vec3

      The second 3-dimensional vector to test.

    Returns number

  • Divides a 3-dimensional vector by another in place.

    Returns

    Self for chaining.

    Example

    var a = new pc.Vec3(4, 9, 16);
    var b = new pc.Vec3(2, 3, 4);

    a.div(b);

    // Outputs [2, 3, 4]
    console.log("The result of the division is: " + a.toString());

    Parameters

    • rhs: Vec3

      The vector to divide the specified vector by.

    Returns Vec3

  • Divides one 3-dimensional vector by another and writes the result to the specified vector.

    Returns

    Self for chaining.

    Example

    var a = new pc.Vec3(4, 9, 16);
    var b = new pc.Vec3(2, 3, 4);
    var r = new pc.Vec3();

    r.div2(a, b);
    // Outputs [2, 3, 4]

    console.log("The result of the division is: " + r.toString());

    Parameters

    • lhs: Vec3

      The dividend vector (the vector being divided).

    • rhs: Vec3

      The divisor vector (the vector dividing the dividend).

    Returns Vec3

  • Divides each element of a vector by a number.

    Returns

    Self for chaining.

    Example

    var vec = new pc.Vec3(3, 6, 9);

    vec.divScalar(3);

    // Outputs [1, 2, 3]
    console.log("The result of the division is: " + vec.toString());

    Parameters

    • scalar: number

      The number to divide by.

    Returns Vec3

  • Returns the result of a dot product operation performed on the two specified 3-dimensional vectors.

    Returns

    The result of the dot product operation.

    Example

    var v1 = new pc.Vec3(5, 10, 20);
    var v2 = new pc.Vec3(10, 20, 40);
    var v1dotv2 = v1.dot(v2);
    console.log("The result of the dot product is: " + v1dotv2);

    Parameters

    • rhs: Vec3

      The second 3-dimensional vector operand of the dot product.

    Returns number

  • Reports whether two vectors are equal.

    Returns

    True if the vectors are equal and false otherwise.

    Example

    var a = new pc.Vec3(1, 2, 3);
    var b = new pc.Vec3(4, 5, 6);
    console.log("The two vectors are " + (a.equals(b) ? "equal" : "different"));

    Parameters

    • rhs: Vec3

      The vector to compare to the specified vector.

    Returns boolean

  • Each element is set to the largest integer less than or equal to its value.

    Returns

    Self for chaining.

    Returns Vec3

  • 根据3维世界坐标获得标准化gl坐标

    Returns

    标准化gl坐标(w为1)

    Parameters

    • Optional glPos: Vec4

      标准化gl坐标(不传则创建新的向量)

    • Optional camera: CameraComponent

      当前相机,默认为第一个场景相机

    Returns Vec4

  • Returns the magnitude of the specified 3-dimensional vector.

    Returns

    The magnitude of the specified 3-dimensional vector.

    Example

    var vec = new pc.Vec3(3, 4, 0);
    var len = vec.length();
    // Outputs 5
    console.log("The length of the vector is: " + len);

    Returns number

  • Returns the magnitude squared of the specified 3-dimensional vector.

    Returns

    The magnitude of the specified 3-dimensional vector.

    Example

    var vec = new pc.Vec3(3, 4, 0);
    var len = vec.lengthSq();
    // Outputs 25
    console.log("The length squared of the vector is: " + len);

    Returns number

  • Returns the result of a linear interpolation between two specified 3-dimensional vectors.

    Returns

    Self for chaining.

    Example

    var a = new pc.Vec3(0, 0, 0);
    var b = new pc.Vec3(10, 10, 10);
    var r = new pc.Vec3();

    r.lerp(a, b, 0); // r is equal to a
    r.lerp(a, b, 0.5); // r is 5, 5, 5
    r.lerp(a, b, 1); // r is equal to b

    Parameters

    • lhs: Vec3

      The 3-dimensional to interpolate from.

    • rhs: Vec3

      The 3-dimensional to interpolate to.

    • alpha: number

      The value controlling the point of interpolation. Between 0 and 1, the linear interpolant will occur on a straight line between lhs and rhs. Outside of this range, the linear interpolant will occur on a ray extrapolated from this line.

    Returns Vec3

  • Each element is assigned a value from rhs parameter if it is larger.

    Returns

    Self for chaining.

    Parameters

    • rhs: Vec3

      The 3-dimensional vector used as the source of elements to compare to.

    Returns Vec3

  • Each element is assigned a value from rhs parameter if it is smaller.

    Returns

    Self for chaining.

    Parameters

    • rhs: Vec3

      The 3-dimensional vector used as the source of elements to compare to.

    Returns Vec3

  • Multiplies a 3-dimensional vector to another in place.

    Returns

    Self for chaining.

    Example

    var a = new pc.Vec3(2, 3, 4);
    var b = new pc.Vec3(4, 5, 6);

    a.mul(b);

    // Outputs 8, 15, 24
    console.log("The result of the multiplication is: " + a.toString());

    Parameters

    • rhs: Vec3

      The 3-dimensional vector used as the second multiplicand of the operation.

    Returns Vec3

  • Returns the result of multiplying the specified 3-dimensional vectors together.

    Returns

    Self for chaining.

    Example

    var a = new pc.Vec3(2, 3, 4);
    var b = new pc.Vec3(4, 5, 6);
    var r = new pc.Vec3();

    r.mul2(a, b);

    // Outputs 8, 15, 24
    console.log("The result of the multiplication is: " + r.toString());

    Parameters

    • lhs: Vec3

      The 3-dimensional vector used as the first multiplicand of the operation.

    • rhs: Vec3

      The 3-dimensional vector used as the second multiplicand of the operation.

    Returns Vec3

  • Multiplies each element of a vector by a number.

    Returns

    Self for chaining.

    Example

    var vec = new pc.Vec3(3, 6, 9);

    vec.mulScalar(3);

    // Outputs [9, 18, 27]
    console.log("The result of the multiplication is: " + vec.toString());

    Parameters

    • scalar: number

      The number to multiply by.

    Returns Vec3

  • Returns this 3-dimensional vector converted to a unit vector in place. If the vector has a length of zero, the vector's elements will be set to zero.

    Returns

    Self for chaining.

    Example

    var v = new pc.Vec3(25, 0, 0);

    v.normalize();

    // Outputs 1, 0, 0
    console.log("The result of the vector normalization is: " + v.toString());

    Returns Vec3

  • Projects this 3-dimensional vector onto the specified vector.

    Returns

    Self for chaining.

    Example

    var v = new pc.Vec3(5, 5, 5);
    var normal = new pc.Vec3(1, 0, 0);

    v.project(normal);

    // Outputs 5, 0, 0
    console.log("The result of the vector projection is: " + v.toString());

    Parameters

    • rhs: Vec3

      The vector onto which the original vector will be projected on.

    Returns Vec3

  • Each element is rounded up or down to the nearest integer.

    Returns

    Self for chaining.

    Returns Vec3

  • Sets the specified 3-dimensional vector to the supplied numerical values.

    Returns

    Self for chaining.

    Example

    var v = new pc.Vec3();
    v.set(5, 10, 20);

    // Outputs 5, 10, 20
    console.log("The result of the vector set is: " + v.toString());

    Parameters

    • x: number

      The value to set on the first component of the vector.

    • y: number

      The value to set on the second component of the vector.

    • z: number

      The value to set on the third component of the vector.

    Returns Vec3

  • Subtracts a 3-dimensional vector from another in place.

    Returns

    Self for chaining.

    Example

    var a = new pc.Vec3(10, 10, 10);
    var b = new pc.Vec3(20, 20, 20);

    a.sub(b);

    // Outputs [-10, -10, -10]
    console.log("The result of the subtraction is: " + a.toString());

    Parameters

    • rhs: Vec3

      The vector to add to the specified vector.

    Returns Vec3

  • Subtracts two 3-dimensional vectors from one another and returns the result.

    Returns

    Self for chaining.

    Example

    var a = new pc.Vec3(10, 10, 10);
    var b = new pc.Vec3(20, 20, 20);
    var r = new pc.Vec3();

    r.sub2(a, b);

    // Outputs [-10, -10, -10]
    console.log("The result of the subtraction is: " + r.toString());

    Parameters

    • lhs: Vec3

      The first vector operand for the addition.

    • rhs: Vec3

      The second vector operand for the addition.

    Returns Vec3

  • Subtracts a number from each element of a vector.

    Returns

    Self for chaining.

    Example

    var vec = new pc.Vec3(3, 4, 5);

    vec.subScalar(2);

    // Outputs [1, 2, 3]
    console.log("The result of the subtraction is: " + vec.toString());

    Parameters

    • scalar: number

      The number to subtract.

    Returns Vec3

  • Converts the vector to string form.

    Returns

    The vector in string form.

    Example

    var v = new pc.Vec3(20, 10, 5);
    // Outputs [20, 10, 5]
    console.log(v.toString());

    Returns string