0.1.0 • Published 5 years ago
gl-matrix-extension v0.1.0
glMatrix Extension
A set of utilities for interactive web content creation, following gl-matrix idioms,
The feature set includes 2D rects, sphere utils, 3D volumes utils, and some math functions.
In addition we packed a id generation module and a polyfill for performance.now() and requestionAnimationFrame()
Contribution
Here is some suggestions for contributions
- Help with the documentation / docs generation.
- Suggest or setup testing.
- Discuss future development of the library.
Developer guide & Naming convention
- Extending built-ins: we create a new namespace with
Extas suffix, like forvec2it will bevec2Ext; - New data structures: we will use the same convention as
gl-matrix, lowercase the name, if it can have dimension size we append it as suffix, (examples:rect,aabb2,aabb3,orect,oaabb3,sphere,circle,octree); - Intersections: in some situations the user might just need to know
if two things intersect, in that case she should use the
intersect${Thing}functions, and when they are ready to get more details she should callintersection${Thing}, thegetIntersection${Thing}should not do any checking, it is assumed that the user already did the intersection test, and if the intersection fails, the result is undefined (I mean an undefined result not literalundefined). We might consider atryGetIntersection${Thing}(out, ...): boolean)
Features / Roadmap
- Misc
cuida lazy loadedcuidmodule.nowa lazy loadedperformance.now()polyfill.rafa lazy loadedrequestAnimationFrame()polyfill.cafa lazy loadedcancelAnimationFrame()polyfill.
- 2D Bounding Volumes
vec2Extrect(coords and size)- Basic
create(): rectfromValues(x: number, y: number, width: number, height: number): rectfromVectors(out: rect, coords: vec2, size: vec2): rectclone(rect: rect): rectcopy(out: rect, rect: rect): rectset(out: rect, x: number, y: number, width: number, height: number): rectequals(a: rect, b: rect): rectexactEquals(a: rect, b: rect): rectcontains(rect: rect, point: vec2): rectgetCenter(out: vec2, rect: rect): vec2normalize(out: rect, rect: rect): rectfromBox(out: rect, aabb: box2): rect
- Edges
getLeft(rect: rect): numbergetTop(rect: rect): numbergetRight(rect: rect): numbergetBottom(rect: rect): numbersetLeft(out: rect, value: number): rectsetTop(out: rect, value: number): rectsetRight(out: rect, value: number): rectsetBottom(out: rect, value: number): rect
- Corners
getTopLeft(out: vec2, rect: rect): vec2getTopRight(out: vec2, rect: rect): vec2getBottomLeft(out: vec2, rect: rect): vec2getBottomRight(out: vec2, rect: rect): vec2
- Basic
circle(coords and radius)box2(min, max)obb2(center, extent and rotation)ray2(origin and direction)line2(origin and normal)segment2(from point to point)
- 3D Bounding Volumes
vec3Extintersection3(point and normal)sphere(coords and radius)- Basic
create(): spherefromValues(x: number, y: number, radius: number): spherefromVectors(coords: vec3, radius: number): sphereset(out: sphere, x: number, y: number, radius: number): spheresetCoordsValues(out: sphere, x: number, y: number): spheresetCoords(out: sphere, coords: vec3): spheregetRadius(sphere: sphere): numbergetCoords(out: vec3, sphere: sphere): vec3setRadius(out: sphere, radius: number): sphereclone(sphere: sphere): spherecopy(out: sphere, sphere: sphere): sphereequals(a: sphere, b: sphere): sphereexactEquals(a: sphere, b: sphere): spherecontains(sphere: sphere, point: vec3): sphere
- Intersections
intersectSphere(sphere: sphere, other: sphere): booleanintersectBOX3(sphere: sphere, aabb: box3): booleanintersectOBX3(sphere: sphere, obb: obx3): booleanintersectRay3(sphere: sphere, ray: ray3): booleanintersectPlane(sphere: sphere, plane: plane): booleanintersectLine3(sphere: sphere, line: line3): booleanintersectSeg3(sphere: sphere, segment: seg3): boolean
- Intersection details
getIntersectionSphere(out: intersection3, sphere: sphere, other: sphere): intersection3getIntersectionBOX3(out: intersection3, sphere: sphere, aabb: box3): intersection3getIntersectionOBB3(out: intersection3, sphere: sphere, obb: obb3): intersection3getIntersectionRay3(out: intersection3, sphere: sphere, ray: ray3): intersection3getIntersectionPlane(out: intersection3, sphere: sphere, plane: plane): intersection3getIntersectionLine3(out: intersection3, sphere: sphere, line: line3): intersection3getIntersectionSeg3(out: intersection3, sphere: sphere, segment: seg3): intersection3
- Basic
box3(min, max)obb3(center, extent and quaternion)ray3(origin and direction)plane(origin and normal)line3(from point to point)seg3(from point to point)frustum(considering)transform(considering)
- Space partitioning (considering)
- Geometry utilities
calculateNormal(out: vec3, a: vec3, b: vec3, c: vec3): vec3
- Math functions and utilities
clamp(x: number, min: number, max: number): numberclampAB(x: number, a: number, b: number): numberit's justclamp(x, Math.min(a, b), Math.max(a, b))clamp01(x: number): numberit's justclamp(x, 0, 1)lerp(a: number, b: number, t: number): numbertoDegrees(r: number): numberMath.hypotoptional patch, that uses multiple implementations instead of single loop implementation, for argument counts of0,1,2,3, and4, might be faster, but I use it in my code 🤷♂️