Git Product home page Git Product logo

webgl-matrix's Introduction

webgl-matrix

Build Status codecov

Getting Started

This is a lightweight matrix / vector library meant for usage with WebGL.

At the core this library only consists of the traits Matrix and Vector.

Available features:

  • Matrix4: 4x4 matrix operations (includes Vector4)
  • Matrix3: 3x3 matrix operations (includes Vector3)
  • Vector4: 4-dimensional vector operations
  • Vector3: 3-dimensional vector operations
  • SliceOps: Low level slice operations such as addition, subtraction, scaling etc.

Examples

All the types are simple arrays. You may also just use slices as operands.

use webgl_matrix::{Matrix, Vector, ProjectionMatrix, Mat4, Vec4, Mat3, Vec3};

fn main() {
    // all the default operations available
    let mut B = [1., 2., 3.,
                 4., 5., 6.,
                 7., 8., 9.];
    let b = Vec3::ones();
    // Matrix operations are in-place
    B.inverse();
    B.transpose();
    // ..

    // Some basic vector operations
    let c = B.mul_vector_left(&b);
    let mag = c.mag(); // magnitude
    let d = c.scale(5.);
    let e = c.add(&b);

    // Or fancier transformations
    B.translate(&[1., 2., 3.]);

    let A = Mat4::identity();
    // operate on slices
    let b = [1., 2., 3., 4., 5., 6., 7.];

    // with automatic homogenous coordinate expansion
    let c = A.mul_vector(&b[0..=2]);
    // or using all four coordinates
    let d = A.mul_vector(&b[3..]);

    // create projection matrices (left, right, bot, top, near, far)
    let P = Mat4::create_perspective_from_viewport(0., 1., 0., 1., 0.1, 10.);
}

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.