Giter Club home page Giter Club logo

gmlinear2's Introduction

GMLinear v2.3.0

Matrix and vector library for GameMaker Studio 2.3.3+

Introduction

GMLinear is an implementation of matrix and vector operations in pure GML. You can use it to simplify many common calculations in 2D and 3D geometry and implement algorithms/formulas involving linear algebra. Hard-coded optimized functions are available for 2D, 3D and 4D vectors and 2x2, 3x3 and 4x4 matrices.

Requirements

  • GameMaker Studio 2.3.3 or above

If you use GameMaker Studio 2.2 or below, please use v2.0.0.

If you use GameMaker Studio 1.4, please see GMLinear Legacy.

Installation

Download the latest version from the YoYo Marketplace or the Releases page.

Contributing to GMLinear

  • Clone this repository.
  • Open the project in GameMaker Studio and make your additions/changes to the GMLinear extension. Also add corresponding tests to the GMLinear_test script group.
  • Use F5 to run the test suite. A successful run should exit on its own without showing any errors (native platforms) or show a green background (HTML5-based platforms).
  • Open a pull request here.

gmlinear2's People

Contributors

dicksonlaw583 avatar juliandicken avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

juliandicken

gmlinear2's Issues

1D arrays for matrices

As far as I can tell matrices should be implemented as 1D arrays since GameMaker seems to be using 1D arrays for its internal matrix operations.
I guess 2D arrays make these easier to work on but a wrapper method would be an easy workaround for this, i.e :

mat = r22(
    0, 1,
    2, 3,
);
mat.at(0,0)

Bug in r3_unit, v[2] is not checked in the 0 magnitude check

Function r3_unit is missing a check for v[2] == 0, results in the incorrect result for any vectors with non-zero v[2] if v[0] and v[1] are zero.

Current:

///@func r3_unit(v, <vout>)
///@arg {r3} v The 3D vector to operate on.
///@arg {r3} <vout> (Optional) The output 3D vector to overwrite. If unspecified, return a new vector.
///@desc Return the 3D unit vector in the direction of v.
function r3_unit(v, vout=[0, 0, 0]) {
	GMLINEAR_INLINE;
	if (v[0] == 0 && v[1] == 0) {
		vout[@0] = 0;
		vout[@1] = 0;
		vout[@2] = 0;
	} else {
		var mag = point_distance_3d(0, 0, 0, v[0], v[1], v[2]);
		vout[@0] = v[0]/mag;
		vout[@1] = v[1]/mag;
		vout[@2] = v[2]/mag;
	}
	return vout;
}
#macro r3_unit_to r3_unit

Correct:

///@func r3_unit(v, <vout>)
///@arg {r3} v The 3D vector to operate on.
///@arg {r3} <vout> (Optional) The output 3D vector to overwrite. If unspecified, return a new vector.
///@desc Return the 3D unit vector in the direction of v.
function r3_unit(v, vout=[0, 0, 0]) {
	GMLINEAR_INLINE;
	if (v[0] == 0 && v[1] == 0 && v[2] == 0) {
		vout[@0] = 0;
		vout[@1] = 0;
		vout[@2] = 0;
	} else {
		var mag = point_distance_3d(0, 0, 0, v[0], v[1], v[2]);
		vout[@0] = v[0]/mag;
		vout[@1] = v[1]/mag;
		vout[@2] = v[2]/mag;
	}
	return vout;
}
#macro r3_unit_to r3_unit

I double checked r2_unit and r4_unit and they're correct, it's just this one that I came across while porting some code

Thank you for your time!

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.