Git Product home page Git Product logo

glm's Introduction

This project isn't being worked anymore, use this instead.

If you would like to continue it, let me know

glm

Glm is the java port of the OpenGL Mathematics (GLM) a mathematics library for graphics software based on the OpenGL Shading Language (GLSL) specifications.

Glm provides classes and functions designed and implemented with the same naming conventions (within reasonable terms) and functionalities than GLSL so that anyone, who knows GLSL or GLM, can use the java glm as well.

This project isn't limited to GLSL features. An extension system, based on the GLSL extension conventions, provides extended capabilities: matrix transformations, quaternions, data packing, random numbers, noise, etc...

http://glm.g-truc.net/0.9.4/api/modules.html

Code sample:

import glm.glm;
import glm.mat._4.Mat4;
import glm.vec._2.Vec2;
import glm.vec._3.Vec3;

public class Class {
    
    Mat4 camera(float translate, Vec2 rotate) {
        
        Mat4 projection = glm.perspective_(45.0f, 4.0f/3.0f, 0.1f, 100.0f);
        Mat4 view = new Mat4(1.0f).translate(new Vec3(0.0f, 0.0f, -translate));
        view.rotate(rotate.y, new Vec3(-1.0f, 0.0f, 0.0f));
        view.rotate(rotate.x, new Vec3(0.0f, 1.0f, 0.0f));
        Mat4 model = new Mat4(1.0f).scale(new Vec3(0.5f));
        
        return projection.mul(view).mul(model);
    }
}

About the porting.

###Naming

Since i32vec2 would have been I32vec2 because java requires always first letter capital, it has been decided to move the type part at the right and changing the bit lenght directly with the primitive data type (Vec2i32 would have been confusing), so we simply have Vec2i.

c++ java
bvec* Vec*bool
dvec* Vec*d
vec* Vec*
i8vec* Vec*b
i16vec* Vec*s
i32vec* Vec*i
i64vec* Vec*l
u8vec* Vec*ub
u16vec* Vec*us
u32vec* Vec*ui
u64vec* Vec*ul
dmat* Mat*d
mat* Mat*

* means 1, 2, 3 or 4 for c++, but on java only 2, 3 and 4 because we didn't port any *vec1 for the moment since there is no apparent reason.

###Instantiation

All functions with any underscore _ at the end involve implicitly an internal instantiation. They are useful for case scenario when you want the most readable and compact code.

This means Glm.add_(Vec2 a, float b) does not modify a because it instantiates a new Vec2 internally. On contrary, Glm.add(Vec2 a, float b) saves the result on a, while Glm.add(Vec2 res, Vec2 a, float b) saves the result on res.

All of them return the result object (Vec2 in this case) in order to give you the possibility to concatenate multiple operations in cascade.

The Glm class contains all the possible calls. However to improve usability, each vec/mat class have in its own some additional functions (they will refer always to the Glm ones though).

Therefore, similarly, if we have a Vec2 v and if we want to add 2, we simply call v.add(2). If we want the result to be saved on v, like v+= 2, otherwise Vec2 a = v.add_(2) and we save the result in a.

However, binary operations involving a scalar in the first place can, off course, only be called by Glm, so if you want do 1.0f - v, you shall call Glm.sub(1.0f, v).

Since java transforms byte and short value to int before doing any operation, we provide the same for classes involving those type, signed or unsigned.

Steps:

  • add jars under \lib

Enhances:

  • support for openvr matrices, helpful to avoid all the problems regarding colum or row major order.

Credits:

  • JOML, by Kai Burjack for Mat4/d.inverse(), Mat4/d.invTransp/3(), Mat4.det3(), Mat4.scale()
  • jOOU, for the unsigned version for the four Java integer types (byte, short, int and long).

glm's People

Contributors

alicanalbayrak avatar allwritesri avatar elect86 avatar sunny1337 avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

glm's Issues

Can't use openvr dependency on Android API 14

I tried to add this library on gradle.build to use it on an Android app. It didn't work. Gradle sync fails because openvr requires API 22 runtimes (not sure if it was sync or build that fails.)

So, I looked into the code and found that not much of the code was using openvr. After realising that, I removed a few lines of code to compile without openvr dependency. Gradle synced, the app was built, and obviously, glm worked on the app without any problem.

For anyone having the same problem as I did, refer to my forked repo if you want to see what parts of the code I modified/removed. There are still many Android 4.0 phones out there. My phone is the very example.

Changing arithmetic method names for operator overloading support

There is a nice project here that allows to have operator overloading support.

It is basic but still a huge step for java devs.

There are some drawbacks though at the moment:

    Map<String, String> binary = new HashMap<String, String>() {{
        put("+",    "add");
        put("-",    "subtract");
        put("*",    "multiply");
        put("/",    "divide");
        put("%",    "remainder");
        put("&",    "and");
        put("|",    "or");
        put("^",    "xor");
        put("<<",   "shiftLeft");
        put(">>",   "shiftRight");
        put("<",    compareTo);
        put(">",    compareTo);
        put("<=",   compareTo);
        put(">=",   compareTo);
    }};
    String revSuffix = "Rev";
    Map<String, String> unary = new java.util.HashMap<String, String>() {{
        put("-", "negate");     // jdk7
        put("---", "negate");   // jdk8
        put("~", "not");
    }};
    String   compareTo = "compareTo";
    String   indexGet = "get";
    String[] indexSet = new String[]{"set", "put"};
    String[] valueOf = new String[]{"valueOf", "of"};

Please do not verbatim-copy JOML code

The Mat4d class is almost a verbatim copy of JOML's Matrix4f, including the JavaDocs, whose references do not match anymore, because glm just renamed the class and method names.

Examples:
JOML 1.7.1: https://github.com/JOML-CI/JOML/blob/5b9b0c0aa7e374dba08cfca4fe47bdd9c8cc6d03/src/org/joml/Matrix4f.java#L7283-L7300

glm:

/**
* Compute a normal matrix from the upper left 3x3 submatrix of
* <code>this</code> and store it into the upper left 3x3 submatrix of
* <code>dest</code>. All other values of <code>dest</code> will be set to
* {@link #identity() identity}.
* <p>
* The normal matrix of <tt>m</tt> is the transpose of the inverse of
* <tt>m</tt>.
* <p>
* Please note that, if <code>this</code> is an orthogonal matrix or a
* matrix whose columns are orthogonal vectors, then this method <i>need
* not</i> be invoked, since in that case <code>this</code> itself is its
* normal matrix. In that case, use {@link #set3x3(Matrix4f)} to set a given
* Matrix4f to only the upper left 3x3 submatrix of this matrix.
*
* @see #set3x3(Matrix4f)
*
* @param dest will hold the result
* @return dest
*/
public Mat4d invTransp3(Mat4d dest) {

If you want to copy code and even JavaDoc verbatim, then you should at least give credit or ask for permission.

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.