0.2.1 • Published 4 years ago

m.js v0.2.1

Weekly downloads
5
License
ISC
Repository
github
Last release
4 years ago

alt M JS

M JS

3D math operations in JavaScript.

Install

In the browser just load the file m.js in a script tag at the bottom of its body.

<body>
    ...
    <script src="m.js">
    <!-- your scripts using m.js here -->
</body>

In node just install the package m.js and require (or import) it in your module.

$ npm i m.js
var M = require('m.js');

// or import it (e.g. in React, Vue... whatever)
import M from 'm.js';

Use

Demo code:

// define a matrix where to locate the vertices of a cube
var cube = [
    [],
    []
];

// define the length of the sides
var side = 100;

// define the vertices from one side
cube[0].push(M.p(0, 0, 0));
cube[0].push(M.p(0, side, 0));
cube[0].push(M.p(side, side, 0));
cube[0].push(M.p(side, 0, 0));

// define the vertices from the opposite side
cube[1].push(M.p(0, 0, side));
cube[1].push(M.p(0, side, side));
cube[1].push(M.p(side, side, side));
cube[1].push(M.p(side, 0, side));

for (var i in cube) {
    // translate the cube to locate its reference point (0, 0, 0) to its center
    M.t(cube[i], -side / 2, -side / 2, -side / 2);

    // rotate the cube a bit in z and x axis
    M.rzd(cube[i], 55);
    M.rxd(cube[i], 60);
}

// next render the geometry ...

alt cube-3d.js

SEE animated demo cube-3d.js by running index.html in the browser.

0.2.1

4 years ago

0.2.0

4 years ago

0.1.12

10 years ago

0.1.11

10 years ago

0.1.10

10 years ago

0.1.9

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago