GithubHelp home page GithubHelp logo

jglm's Introduction

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 involv 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, we have to thanks JOML for the inspiration about this :)

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 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 transform 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() and return the object itself in order to concatenate operations.
  • jOOU, for the unsigned version for the four Java integer types (byte, short, int and long).

jglm's People

Contributors

alicanalbayrak avatar elect86 avatar sunny1337 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.