Giter Club home page Giter Club logo

vec's Introduction

vec

A Minimal set of vector and color functions and structures. Works standalone or to ease interop within an application between various 3rd party libraries that use their own, incompatible, class-based implementations.

V3.* functions will work for any structure having x, y, z number properties. C3.* functions will work for any structure having r, g, b properties, etc.

Intended to ease type incombatibility issues when using Typescript but also avoids pitfalls of using class methods on objects that may be incompatibile when writing plain JS.

There are advantages to working with arrays instead of structs (in which case you should use gl-matrix) but structs may feel more user-friendly in an application and may interop more easily with 3rd party libs like three.js.

Plain objects may (in some cases) be faster than arrays. Using the *.create functions rather than {...} may also improve performance as objects of the same shape will be constructed from the same call site.

Instances of vector structs (or plain arrays) will likely use less memory than typed arrays and are faster to construct. Typed arrays begin to pay off when used in bulk.

Usage Examples:

import V3 from 'vec/v3'

// Safely copy from one type to another without type errors
const a = new CANNON.Vec3(1,2,3)
const b = new THREE.Vector3()
V3.copy(b, a)

// Create a plain object
const c = V3.create()
V3.copy(c, b)

// Compute distance between different vector instance types
const d = V3.dist(a, b)

// Can use 2D functions on XY components of 3D vectors
import V2 from 'vec/v2'
const dXY = V2.dist(a, b)

Matrix functions are not included since it makes more sense to use those as arrays, which gl-matrix is for.

vec's People

Contributors

spacejack avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.