How to use gl-mat4 - 10 common examples

To help you get started, we’ve selected a few gl-mat4 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 WhitestormJS / nextgl / src / core / Object3D.js View on Github external
constructor() {
    super();

    // FIXME: replace identity() with create()
    this.matrix = identity([]);
    this.matrixWorld = identity([]);
    this.position = [0, 0, 0];
    this.scale = [1, 1, 1];
    this.quaternion = [0, 0, 0, 1];
    this.children = [];
    this.matrixAutoUpdate = true;
    this.matrixWorldAutoUpdate = true;
  }
github jscad / OpenJSCAD.org / packages / utils / regl-renderer / src / rendering / commands / drawMesh / index.js View on Github external
unormal: (context, props) => {
        const model = props.model || props.transforms.matrix
        // console.log('here', model)
        // const model = mat4.identity([])
        const modelViewMatrix = mat4.multiply(mat4.create(), model, props.camera.view)
        const normalMatrix = mat4.create()
        mat4.invert(normalMatrix, modelViewMatrix)
        mat4.transpose(normalMatrix, normalMatrix)
        return normalMatrix
      }
    },
github jscad / csg-viewer / src / rendering / drawAxis.js View on Github external
return (props) => {
    const defaults = {
      model: mat4.identity([])
    }
    props = Object.assign({}, defaults, props)
    return single([
      { color: xColor, model: mat4.multiply(mat4.create(), props.model, xAxisModel) }, // X
      { color: yColor, model: mat4.multiply(mat4.create(), props.model, yAxisModel) }, // Y
      { color: zColor, model: mat4.multiply(mat4.create(), props.model, zAxisModel) } // Z
    ])
  }
}
github jscad / csg-viewer / src / rendering / drawAxis.js View on Github external
return (props) => {
    const defaults = {
      model: mat4.identity([])
    }
    props = Object.assign({}, defaults, props)
    return single([
      { color: xColor, model: mat4.multiply(mat4.create(), props.model, xAxisModel) }, // X
      { color: yColor, model: mat4.multiply(mat4.create(), props.model, yAxisModel) }, // Y
      { color: zColor, model: mat4.multiply(mat4.create(), props.model, zAxisModel) } // Z
    ])
  }
}
github andyhall / glsl-projectron / index.js View on Github external
function paint( xRot, yRot ) {
	
	if (!initialized) { return }
	if (polyBuffersOutdated) {
		// buffers out of sync w/ arrays since last mutation wasn't kept
		vertBuffer.update( polys.vertArr )
		colBuffer.update( polys.colArr )
	}
	
	// rotation matrix (simple Euler angles)
	camMatrix = mat4.create()
	mat4.rotateY(camMatrix, camMatrix, yRot)
	mat4.rotateX(camMatrix, camMatrix, xRot)
	// paint polygons
	drawData( SCREEN, perspective, camMatrix )
}
github andyhall / glsl-projectron / src / index.js View on Github external
function paint(xRot, yRot) {
		if (polyBuffersOutdated) {
			// buffers out of sync w/ arrays since last mutation wasn't kept
			vertBuffer.update(polys.getVertArray())
			colBuffer.update(polys.getColorArray())
		}
		// rotation matrix (simple Euler angles)
		camMatrix = mat4.create()
		mat4.rotateY(camMatrix, camMatrix, xRot || 0)
		mat4.rotateX(camMatrix, camMatrix, yRot || 0)
		// paint polygons
		drawData(null, perspective, camMatrix)
	}
github Erkaman / pnp-gui / example / index.js View on Github external
function centerGeometry(geo, scale) {

    // Calculate the bounding box.
    var bb = boundingBox(geo.positions);

    // Translate the geometry center to the origin.
    var translate = [-0.5 * (bb[0][0] + bb[1][0]), -0.5 * (bb[0][1] + bb[1][1]), -0.5 * (bb[0][2] + bb[1][2])];
    var m = mat4.create();
    mat4.scale(m, m, [scale, scale, scale]);
    mat4.translate(m, m, translate);

    geo.positions = transform(geo.positions, m)
}
github regl-project / regl / example / cube-fbo.js View on Github external
function setupCube ({center, fbo}, block) {
  mat4.perspective(
    cubeProps.projection,
    Math.PI / 2.0,
    1.0,
    0.25,
    1000.0)

  cubeProps.cubeFBO = fbo
  cubeProps.center = center

  // execute `setupCubeFace` 6 times, where each time will be
  // a different batch, and the batchIds of the 6 batches will be
  // 0, 1, 2, 3, 4, 5
  setupCubeFace.call(cubeProps, 6, block)
}
github gregtatum / sessions / 006 / circles.js View on Github external
model: ({model}, {scale = 1, translate = 0}) => (
        mat4.scale([], mat4.translate([], model, [0, translate, 0]), [scale, scale, scale])
      )
    },
github gregtatum / sessions / 015 / mask.js View on Github external
        return (_, {model, headModel}) => mat4.multiply(out, model, headModel)
      })()

gl-mat4

gl-matrix's mat4, split into smaller pieces

Zlib
Latest version published 7 years ago

Package Health Score

56 / 100
Full package analysis