@pixi/3d
    Preparing search index...

    Class ObservableVector3

    A Vector3 that tells an observer when it changes

    A node's position, scale, rotation and origin use this class, so a change to one updates the node. It has the same methods as Vector3. Each in-place method notifies the observer at most once, and not at all when no component changed. Given an out target, a method writes there and leaves this point and its observer alone.

    app.ticker.add((ticker) => {
    player.position.addScaledVector(velocity, ticker.deltaMS / 1000);
    });

    Implements

    Index
    • get x(): number

      The x component; assigning a different value notifies the observer

      Returns number

      player.position.x += strafeSpeed * dt;
      
    • set x(value: number): void

      Sets the x component

      Parameters

      • value: number

        The new x

      Returns void

    • get y(): number

      The y component; assigning a different value notifies the observer

      Returns number

      if (player.position.y < killPlaneY) respawn(player);
      
    • set y(value: number): void

      Sets the y component

      Parameters

      • value: number

        The new y

      Returns void

    • get z(): number

      The z component; assigning a different value notifies the observer

      Returns number

      crate.position.z = -10;
      
    • set z(value: number): void

      Sets the z component

      Parameters

      • value: number

        The new z

      Returns void

    • Adds v to this point

      Parameters

      • v: PointData3D

        The point to add

      • out: PointLike3D = ...

        The target to write the result into, defaults to this point

      Returns this

      The point the result was written into

      rider.position.add(platformMovement);
      player.position.add(cameraOffset, cameraTarget);
    • Adds v * s to this point, such as a velocity times the frame time

      Parameters

      • v: PointData3D

        The point to scale and add

      • s: number

        The scalar to multiply v by

      • out: PointLike3D = ...

        The target to write the result into, defaults to this point

      Returns this

      The point the result was written into

      player.position.addScaledVector(velocity, dt);
      
    • Computes the angle between this point and v, both seen from the origin

      Returns π/2 when either has zero length.

      Parameters

      Returns number

      The angle in radians, from 0 to π

      const distanceOverSurface = player.position.angleTo(base.position) * planetRadius;
      
    • Transforms this point by m, translation included, without the divide ObservableVector3#applyMatrix4 does

      Cheaper, and correct for any transform that doesn't project, such as a node's world transform.

      Parameters

      • m: Matrix4

        The matrix to apply

      • out: PointLike3D = ...

        The target to write the result into, defaults to this point

      Returns this

      The point the result was written into

      muzzle.position.applyAffineMatrix4(gun.worldTransform, muzzleWorldPosition);
      
    • Multiplies this point by the 3x3 matrix m

      Parameters

      • m: Matrix3

        The matrix to apply

      • out: PointLike3D = ...

        The target to write the result into, defaults to this point

      Returns this

      The point the result was written into

      satellite.position.applyMatrix3(orbitTilt);
      
    • Transforms this point by m, translation included, then divides by the resulting w

      Vector3#applyMatrix4 explains when the divide matters.

      Parameters

      • m: Matrix4

        The matrix to apply

      • out: PointLike3D = ...

        The target to write the result into, defaults to this point

      Returns this

      The point the result was written into

      enemy.position.applyMatrix4(camera.viewProjection, ndc);
      const onScreen = Math.abs(ndc.x) <= 1 && Math.abs(ndc.y) <= 1 && Math.abs(ndc.z) <= 1;
    • Rotates this point around the origin by the unit Quaternion q

      Parameters

      • q: Quaternion

        The unit quaternion to rotate by

      • out: PointLike3D = ...

        The target to write the result into, defaults to this point

      Returns this

      The point the result was written into

      chaseCamera.position.copyFrom(followOffset).applyQuaternion(car.quaternion).add(car.position);
      
    • Clamps each component of this point between the matching components of min and max

      Assumes min <= max componentwise.

      Parameters

      • min: PointData3D

        The lower bound per component

      • max: PointData3D

        The upper bound per component

      • out: PointLike3D = ...

        The target to write the result into, defaults to this point

      Returns this

      The point the result was written into

      player.position.clamp(arenaMin, arenaMax);
      
    • Creates a copy of this point that notifies observer, or this point's own observer when left out

      A clone of a node's position that keeps the node as its observer marks the node's transform for an update whenever the clone changes, though the node hasn't moved. For a plain copy, use new Vector3().copyFrom(node.position).

      Parameters

      Returns ObservableVector3

    • Copies x, y, z from the given point into this point

      Parameters

      Returns this

      loot.position.copyFrom(enemy.position);
      
    • Copies this point's x, y, z into the given point

      Type Parameters

      Parameters

      • p: T

        The point to copy into

      Returns T

      The given point with values updated

      player.position.copyTo(lastCheckpoint);
      
    • Computes the cross product this × v, a vector at right angles to both

      Parameters

      • v: PointData3D

        The other point

      • out: PointLike3D = ...

        The target to write the result into, defaults to this point

      Returns this

      The point the result was written into

      player.position.cross(planetAxis, travelDirection).normalize();
      
    • Computes the distance from this point to v

      Parameters

      Returns number

      const distanceToExit = player.position.distanceTo(exit.position);
      
    • Computes the squared distance from this point to v

      Cheaper than ObservableVector3#distanceTo and enough to compare distances.

      Parameters

      Returns number

      if (player.position.distanceToSquared(coin.position) < pickupRadius * pickupRadius) collect(coin);
      
    • Divides each component of this point by the matching component of v

      Parameters

      • v: PointData3D

        The point to divide by

      • out: PointLike3D = ...

        The target to write the result into, defaults to this point

      Returns this

      The point the result was written into

      player.position.divide(cellSize, cell);
      const column = Math.floor(cell.x);
    • Divides each component of this point by the scalar s

      Parameters

      • s: number

        The scalar to divide by

      • out: PointLike3D = ...

        The target to write the result into, defaults to this point

      Returns this

      The point the result was written into

      pickup.scale.divideScalar(2);
      
    • Computes the dot product of this point and v

      Parameters

      Returns number

      const distanceAlongTrack = car.position.dot(trackDirection);
      
    • Checks whether x, y and z all match p exactly, with no tolerance

      Parameters

      Returns boolean

      if (!player.position.equals(lastSentPosition)) sendPosition(player.position);
      
    • Reads x, y, z from array starting at offset

      Parameters

      • array: Float32Array<ArrayBufferLike> | number[]

        The array to read from

      • offset: number = 0

        The index of the first component

      Returns this

      crates.forEach((crate: Container3D, i: number) => crate.position.fromArray(savedPositions, i * 3));
      
    • Computes the length of this point, its distance from the origin

      Returns number

      const altitude = player.position.magnitude() - planetRadius;
      
    • Computes the squared length of this point

      Cheaper than ObservableVector3#magnitude, since it skips the square root, and enough to compare lengths.

      Returns number

      if (ball.position.magnitudeSquared() > arenaRadius * arenaRadius) resetBall();
      
    • Sets each component to the larger of this point's and v's

      Parameters

      • v: PointData3D

        The point to compare with

      • out: PointLike3D = ...

        The target to write the result into, defaults to this point

      Returns this

      The point the result was written into

      player.position.max({ x: -Infinity, y: floorHeight, z: -Infinity });
      
    • Sets each component to the smaller of this point's and v's

      Parameters

      • v: PointData3D

        The point to compare with

      • out: PointLike3D = ...

        The target to write the result into, defaults to this point

      Returns this

      The point the result was written into

      player.position.min({ x: Infinity, y: ceilingHeight, z: Infinity });
      
    • Multiplies each component of this point by the matching component of v

      Parameters

      • v: PointData3D

        The point to multiply by

      • out: PointLike3D = ...

        The target to write the result into, defaults to this point

      Returns this

      The point the result was written into

      jelly.scale.multiply({ x: 1.2, y: 0.8, z: 1.2 });
      
    • Multiplies each component of this point by the scalar s

      Parameters

      • s: number

        The scalar to multiply by

      • out: PointLike3D = ...

        The target to write the result into, defaults to this point

      Returns this

      The point the result was written into

      balloon.scale.multiplyScalar(1 + inflateRate * dt);
      
    • Negates each component of this point, mirroring it through the origin

      Parameters

      • out: PointLike3D = ...

        The target to write the result into, defaults to this point

      Returns this

      The point the result was written into

      reflection.position.copyFrom(player.position).negate();
      
    • Scales this point to unit length, keeping its direction from the origin

      A zero point stays zero.

      Parameters

      • out: PointLike3D = ...

        The target to write the result into, defaults to this point

      Returns this

      The point the result was written into

      player.position.normalize(surfaceUp);
      
    • Sets the x, y and z components

      Parameters

      • x: number = 0

        The x component

      • y: number = x

        The y component, defaults to x

      • z: number = x

        The z component, defaults to x

      Returns this

      crate.position.set(0, 1, -5);
      crate.scale.set(2);
    • Sets this point to the position the Cylindrical coordinate c describes

      Vector3#setFromCylindrical describes the angle and height.

      Parameters

      Returns this

      const slot = new Cylindrical(towerRadius, 0, 2);

      torches.forEach((torch: Mesh3D, i: number) => {
      slot.theta = (i / torches.length) * Math.PI * 2;
      torch.position.setFromCylindrical(slot);
      });
    • Reads the first three values of column index of m into this point

      In a transform, column 3 is the translation and columns 0 to 2 are the X, Y and Z axes, scaled.

      Parameters

      • m: Matrix4

        The matrix to read from

      • index: number

        The column index, 0 to 3

      Returns this

      marker.position.setFromMatrixColumn(target.worldTransform, 3);
      
    • Sets this point to the position the Spherical coordinate s describes

      Vector3#setFromSpherical describes the angles.

      Parameters

      • s: Spherical

        The spherical coordinate to convert

      Returns this

      orbit.theta += turnSpeed * dt;
      camera.position.setFromSpherical(orbit).add(target.position);
    • Scales this point so its distance from the origin equals length, keeping its direction

      A zero point stays zero.

      Parameters

      • length: number

        The target length

      • out: PointLike3D = ...

        The target to write the result into, defaults to this point

      Returns this

      The point the result was written into

      satellite.position.setLength(orbitRadius);
      
    • Subtracts v from this point

      Parameters

      • v: PointData3D

        The point to subtract

      • out: PointLike3D = ...

        The target to write the result into, defaults to this point

      Returns this

      The point the result was written into

      target.position.subtract(turret.position, aimDirection);
      
    • Writes this point's values into array starting at offset

      Allocates a new array when one is not supplied.

      Type Parameters

      • T extends Float32Array<ArrayBufferLike> | number[] = number[]

      Parameters

      • array: T = ...

        The array to write into

      • offset: number = 0

        The index to write the first component at

      Returns T

      The array the values were written into

      crates.forEach((crate: Container3D, i: number) => crate.position.toArray(savedPositions, i * 3));
      
    • Returns a readable string representation of this point

      Returns string

      console.log(player.position.toString());
      
    • Turns this point, read as a direction, by the rotation and scale in m, ignoring its translation, then normalizes it

      Parameters

      • m: Matrix4

        The matrix whose rotation to apply

      • out: PointLike3D = ...

        The target to write the result into, defaults to this point

      Returns this

      The point the result was written into