Neatly Packaged Magic

# npm

## matrixgl

1.0.1 • Public • Published

# MatrixGL

MatrixGL is yet another matrix library for WebGL.

## Install without Node.js

Download the zip file from Releases page on GitHub, and unzip the file.

You will see matrixgl.min.js file in the build directory. Copy the file(matrixgl.min.js) into your directory. You can ignore all other files(These files are for Node.js).

## Install with Node.js

Run the install command.

``````\$ npm install matrixgl --save
``````

Then, import MatrixGL in JavaScript.

## Basic Usage

MatrixGL has Vector, Matrix and Quaternion class.

You can use it simply. For example:

Vector classes also have some operation.

Note: MatrixGL's API does not modify the original vector/matrix unlike ordinary OpenGL matrix libraries. So you should assign the result to variables

There are also Matrix classes.

Matrices' values are stored in "column major order" which is the default order of WebGL. This means `new Matrix(1, 2, 3, 4);` represents the first row is `[1, 3]` and second row is `[2, 4]`.

If you are bored with enumerating numbers 16 times to create a Matrix4, please use a spread operator.

In addition to basic methods, `Matrix4` class has special methods. You can generate a model matrix easily with these methods.

Or you can build a model matrix manually.

If you want a rotation matrix about an arbitrary axis, use `rotateAround(axis, radian)` .

or use `Matrix4.rotationAround(axis, radian)`.

To build a "look at" matrix, use `lookAt` method.

If you need a projection matrix, use `Matrix4.orthographic` or `Matrix4.perspective` method.

And combine all above matrices to build a ModelViewProjection matrix.

## Quaternion

MatrixGL supports quaternions for rotation.

To create a rotation matrix from a quaternion, use `Quaternion.rotationAround(axis, rad)` and `toRotationMatrix4()`.

To interpolate between two quaternions, use `slerp(other, t)`.

## Usage with WebGL

You can get `Float32Array` from `values` property of vectors, matrices or quaternions.

So if you use MatrixGL with WebGL, just pass the vector's(or matrix's) `values`.

## How to Build from Source

Install dependencies.

``````\$ npm install
``````

Build.

``````\$ npm run build
``````

## Keywords

### install

`npm i matrixgl`

35

1.0.1

MIT

github.com

github