chrisdickinson/voxel-physical — pull request #11 by deathcap (2014-05-07 05:55:27+00:00)
Title: Use gl-matrix vec3 instead of three.js Vector3

Changes voxel-physical to use [gl-matrix](http://glmatrix.net/) for the matrix operations, removing the [three.js](http://threejs.org/) dependency (which is all that voxel-physical was (directly) using three.js for).

Benefits:

* Helps makes progress towards https://github.com/voxel/issues/issues/4 ndarray/gl-now integration (to replace three.js)
* Avoids the need to pull in the (large) three.js dependency for this module
* Better compatibility/versioning - case in point, voxel-physical uses the deprecated two-argument Vector3 sub method:

```
DIRECTION.sub(LOCAL_ATTRACTOR, this.avatar.position)
```

which three.js [deprecated](https://github.com/mrdoob/three.js/blob/master/src/math/Vector3.js#L133):

console.warn( 'DEPRECATED: Vector3\'s .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );

voxel-physical package.json specifies the dependency as:

```
"dependencies": {
"three": "0.X.X",
```

so it could be any version; might even break in the future - and three.js does not use semver (gl-matrix does)

* gl-matrix vec3's are just (typed, usually) arrays, and it does not add any methods on this object. So literal array notation `[1,2,3]` is acceptable for passing in arguments to the vec3 operations.
* More convenient to refer to axes by number 0,1,2 instead of string .x.,y.,z in some cases; avoids the need to write code like this (from [voxel-engine](https://github.com/maxogden/voxel-engine/blob/73defd0b6bfad9202e97d3b9f193dc187e1169b3/index.js#L410)):

var axes = ['x', 'y', 'z']

other.acceleration[axes[axis]] = 0

* Matches the convention documented in voxel-engine https://github.com/maxogden/voxel-engine

> Positions
> x, z: horizontal plane
> y: vertical plane
> We try to always use arrays to represent vectors (aka positions)
>
> [x, y, z]
> Sometimes you may also see objects used, e.g. {x: 0, y: 0, z: 0}, this is because three.js uses objects for vectors.

However, switching voxel-physical to gl-matrix does have some disadvantages. String axes like `velocity.x` are more descriptive than `velocity[0]`. Other modules passing in or receiving three.js-style Vector3 objects will have to be converted (until they also are themselves converted). I think the benefits outweigh these disadvantages, though.

Also, this change is not backwards-compatible. Wanted to get your feedback first before sending the other PRs but it also requires changes to:

* voxel-control: for accessing the velocity vector. Changes at https://github.com/deathcap/voxel-control/commits/glm
* voxel-engine: for removing the axes key conversion. Changes at https://github.com/deathcap/voxel-engine/commit/66651c6f7fecf4e7e696aab36c7e33ea4733553b

Example of all these changes together deployed in https://github.com/deathcap/voxpopuli/tree/1ab19e946b73e750e8d07feb413320839e68206c