How to use the math.gl.Matrix4 function in math

To help you get started, we’ve selected a few math examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uber / deck.gl / modules / core / src / views / orthographic-view.js View on Github external
function getProjectionMatrix({width, height, near, far}) {
  // Make sure Matrix4.ortho doesn't crash on 0 width/height
  width = width || 1;
  height = height || 1;

  return new Matrix4().ortho({
    left: -width / 2,
    right: width / 2,
    bottom: height / 2,
    top: -height / 2,
    near,
    far
  });
}
github uber / luma.gl / modules / experimental / src / scenegraph / nodes / scenegraph-node.js View on Github external
constructor(props = {}) {
    const {id} = props;

    this.id = id || uid(this.constructor.name);

    this.display = true; // whether to display the object at all
    this.position = new Vector3();
    this.rotation = new Vector3();
    this.scale = new Vector3(1, 1, 1);
    this.matrix = new Matrix4();
    this.userData = {};

    this.props = {};
    this._setScenegraphNodeProps(props);
  }
github uber-web / math.gl / test / src / matrix4.spec.js View on Github external
test('Matrix4.toFloat32Array', t => {
  t.equals(typeof Matrix4.prototype.toFloat32Array, 'function');
  const m = new Matrix4();
  m.identity();
  t.equals(m.toFloat32Array().BYTES_PER_ELEMENT, 4);
  t.end();
});
github uber-web / math.gl / test / src / matrix4.spec.js View on Github external
test('Matrix4#identity (identity matrix)', t => {
  t.equals(typeof Matrix4.prototype.identity, 'function');
  const m = new Matrix4();
  m.identity();

  const RESULT = IDENTITY_MATRIX;

  tapeEquals(t, m, RESULT);
  t.end();
});
github uber / luma.gl / test / apps / wip / cubemap2 / app.js View on Github external
onRender(animationProps) {
    const {gl, aspect, cube, tick} = animationProps;

    const view = new Matrix4().lookAt({eye: [0, 0, -1]}).translate([0, 0, 4]);
    const projection = new Matrix4().perspective({fov: radians(75), aspect});

    gl.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT);

    cube.draw({
      uniforms: {
        uView: view,
        uProjection: projection,
        uMix: 0.5 + Math.sin(tick * 0.02) / 2.0
      }
    });
  }
}
github uber / luma.gl / test / apps / wip / cubemap2 / app.js View on Github external
onRender(animationProps) {
    const {gl, aspect, cube, tick} = animationProps;

    const view = new Matrix4().lookAt({eye: [0, 0, -1]}).translate([0, 0, 4]);
    const projection = new Matrix4().perspective({fov: radians(75), aspect});

    gl.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT);

    cube.draw({
      uniforms: {
        uView: view,
        uProjection: projection,
        uMix: 0.5 + Math.sin(tick * 0.02) / 2.0
      }
    });
  }
}
github uber / deck.gl / modules / core / src / effects / lighting / lighting-effect.js View on Github external
_createLightMatrix() {
    const lightMatrices = [];
    for (const light of this.directionalLights) {
      const viewMatrix = new Matrix4().lookAt({
        eye: new Vector3(light.direction).negate()
      });

      lightMatrices.push(viewMatrix);
    }
    return lightMatrices;
  }
github uber / luma.gl / examples / lessons / 13 / app.js View on Github external
function animate(appState) {
  const timeNow = new Date().getTime();
  if (appState.lastTime != 0) {
    const elapsed = timeNow - appState.lastTime;
    const newMatrix = new Matrix4()
    .rotateY(radians(elapsed / 20));
    appState.moonRotationMatrix.multiplyLeft(newMatrix);
    appState.cubeRotationMatrix.multiplyLeft(newMatrix);
  }
  appState.lastTime = timeNow;
}
github uber / luma.gl / modules / experimental / src / scenegraph / nodes / group-node.js View on Github external
traverse(visitor, {worldMatrix = new Matrix4()} = {}) {
    const modelMatrix = new Matrix4(worldMatrix).multiplyRight(this.matrix);

    for (const child of this.children) {
      if (child instanceof GroupNode) {
        child.traverse(visitor, {worldMatrix: modelMatrix});
      } else {
        visitor(child, {worldMatrix: modelMatrix});
      }
    }
  }
}
github uber / xviz / modules / builder / src / builders / xviz-metadata-builder.js View on Github external
transformMatrix(matrix) {
    if (matrix instanceof Array) {
      matrix = new Matrix4(matrix);
    }

    this.tmp_matrix_transform = matrix;
    return this;
  }

math

Mathematical Functions

Unknown
Latest version published 13 years ago

Package Health Score

39 / 100
Full package analysis