Giter VIP home page Giter VIP logo

haxe-glm's Introduction

haxe-glm

License Build Status Coverage

Native Haxe version of the fantastic GLM library (https://github.com/g-truc/glm). For those unaware of the GLM library, it is basically a toolset for using 2, 3, and 4 dimensional vectors and matrices, as well as quaternions. This tends to be rather useful when working with OpenGL, which is largely all about rasterizing primitives using vectors and matrices.

Contributing

Issues, forks, and pull requests are gladly welcomed! This library is meant for you, so help make it into what you want it to be!

Documentation

API

API documentation is available here: http://hamaluik.com/haxe-glm/

Samples

var translate:glm.Mat4 = GLM.translate(new Vec3(3, 4, -1));
var verts:Array<Vec3> = [
	new Vec3(0, 0, 0),
	new Vec3(1, 0, 0),
	new Vec3(1, 1, 0),
	new Vec3(0, 1, 0)
];

for(i in 0...verts.length) {
	verts[i] = translate * verts[i];
}
var degToRad:Float = Math.PI / 180.0;
var projection:Mat4 = GLM.perspective(
	60 / 1.78 * degToRad, // field of view y
	1.78 // aspect ratio
	0.1, 1000 // near, far
);
projection = GLM.ortho(-960, 960, -540, 540);

Manual

Introduction

This library provides 7 classes (actually, abstracts) which enable vector, matrix, and quaternion mathematical operations (Vec2, Vec3, Vec4, Mat2, Mat3, Mat4, and Quat). The vector and quaternion classes are defined as abstracts over arrays of floats, while the matrices are defined as abstracts over arrays of vectors which makes the library work across every target and platform. The library also includes static utiltiies for generating transformation matrices (GLM) and projection matrices (Projection).

Motivation

I decided to create this library for Haxe after seeing project after project write their own code for dealing with vectors, matrices, and quaternions. This has resulted in a lot of duplicated effort by developers who all seem to write their own classes to deal with this.

Hopefully the creation of this [fully cross-target and cross-platform] library, some of this duplicated effort can be minimized in the future.

In-Place Modifications

In general, operations on vectors and matrices strive not to allocate new resources. For example, transposing a matrix will modify the matrix in place rather than creating a new one. Similary, one can add a vector to another in place using the addVecX functions (where X โˆˆ [2, 3, 4]). This functionality is utilized when using the overloaded operators, which create a clone instead of modifying an existing entity (for example the addition operator between two Vec2s is defined as a.clone().addVec2(b)). In the future, the library will likely use object pooling to nearly eliminate unncessary object allocation altogether.

Vectors

Vectors behave the same as they would in a GLSL program, and can be of length 2, 3, or 4 (with automatic casting in between dimensions). Similarly to OpenGL, Vectors provide .xyzw, .rgba, and .stpq access to their elements (though not in combination like OpenGL. i.e. vec.r is valid while vec.rgb is not [currently]).

Matrices

In matrices, the data is stored in Row-major order, although when flattening matrices they can be flattened into row major or column major order using the functions toArrayRowMajor() and toArrayColMajor respectively.

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.