Package Exports
- @vicimpa/glm
Readme
GLM - Math Library
A modern TypeScript math library providing vector, matrix, and quaternion operations.
Features
- Vectors: Vec2, Vec3, Vec4 with comprehensive operations
- Matrices: Mat2, Mat2d, Mat3, Mat4 for transformations
- Quaternions: Quat for 3D rotations
- TypeScript: Full type safety and IntelliSense support
- Modern: ES modules, optimized for modern JavaScript engines
Installation
# Using npm
npm install glm
# Using yarn
yarn add glm
# Using bun
bun add glmUsage
import { Vec3, Mat4, Quat } from 'glm';
// Create vectors
const position = new Vec3(1, 2, 3);
const direction = new Vec3(0, 1, 0);
// Create matrices
const transform = new Mat4();
transform.translate(position);
// Create quaternions
const rotation = new Quat();
rotation.rotateY(Math.PI / 2);
// Apply transformations
direction.applyQuat(rotation);
position.applyMat4(transform);Development
Prerequisites
- Bun (recommended) or Node.js 18+
- TypeScript 5+
Setup
# Clone the repository
git clone <repository-url>
cd glm
# Install dependencies
bun installBuild
# Build everything (types + bundle)
bun run build:all
# Build only the bundle
bun run build
# Build only type declarations
bun run build:types
# Development build (without minification)
bun run build:dev
# Clean build artifacts
bun run cleanTesting
# Run tests
bun test
# Run tests in watch mode
bun test --watchBuild Output
The build process generates:
dist/index.js- Minified ES module bundledist/index.d.ts- TypeScript declarationsdist/index.d.ts.map- Declaration source mapsdist/index.js.map- Source maps
API Reference
Vectors
Vec2
new Vec2(x?, y?)- Create a 2D vectoradd(v),sub(v),mul(v),div(v)- Arithmetic operationsdot(v),length(),normalize()- Vector operationslerp(a, b, t)- Linear interpolation
Vec3
new Vec3(x?, y?, z?)- Create a 3D vectorcross(v)- Cross productapplyQuat(q)- Apply quaternion rotationrotateX/Y/Z(rad, from?)- Axis rotationsrotateAround(rad, axis, from?)- Rotation around axis
Vec4
new Vec4(x?, y?, z?, w?)- Create a 4D vectorapplyQuat(q)- Apply quaternion rotationapplyMat4(m)- Apply 4x4 matrix transformation
Matrices
Mat4
new Mat4()- Create identity matrixtranslate(v),scale(v),rotate(rad, axis)- Transformationsperspective(fov, aspect, near, far)- Perspective projectionortho(left, right, bottom, top, near, far)- Orthographic projection
Quaternions
Quat
new Quat(x?, y?, z?, w?)- Create quaternionrotateX/Y/Z(rad)- Axis rotationsslerp(a, b, t)- Spherical linear interpolationfromEuler(x, y, z, order?)- From Euler angles
License
MIT License