Skip to content

1. Getting started

Giuseppe Barbieri edited this page Jul 15, 2017 · 7 revisions

Table of Contents


1. Getting started

1.1. Setup

You can use GLM by manually downloading the a release and include it in your project (together with the unsigned dependency) or including in your Gradle file by adding the following in the dependencies section:

dependencies {
    ...
    compile 'com.github.kotlin-graphics:glm:x'
}

and the jitpack server under the repositories section (it is suggested to append it at the end):

repositories {
    ...
    maven { url "https://jitpack.io" }
}

1.2. Example usage

Kotlin

// Include GLM core features
import glm_.vec2.Vec2
import glm_.vec3.Vec3
import glm_.mat4x4.Mat4
import glm_.glm

fun transform(orientation: Vec2, translate: Vec3, up: Vec3): Mat4 {
    val proj = glm.perspective(glm.radians(45f), 1.33f, 0.1f, 10f)
    val viewTranslate = glm.translate(Mat4(1f), translate)
    val viewRotateX = glm.rotate(viewTranslate, orientation.y, up)
    val view = glm.rotate(viewRotateX, orientation.x, up)
    val model = Mat4(1f)
    return proj * view * model
}

or

fun transform(orientation: Vec2, translate: Vec3, up: Vec3): Mat4 = with(glm) {
    val proj = perspective(45f.rad, 1.33f, 0.1f, 10f)
    val view = Mat4()
            .translate_(translate)
            .rotate_(orientation.y, up)
            .rotate_(orientation.x, up)
    val model = Mat4()
    return proj * view * model
}

Java

import glm_.vec2.Vec2;
import glm_.vec3.Vec3;
import glm_.mat4x4.Mat4;
import glm_.glm;

public class Test {

    final static Glm glm = Glm.INSTANCE;

    public Mat4 transform(Vec2 orientation, Vec3 translate, Vec3 up) {
        Mat4 proj = glm.perspective(glm.radians(45f), 1.33f, 0.1f, 10f);
        Mat4 viewTranslate = glm.translate(new Mat4(1f), translate);
        Mat4 viewRotateX = glm.rotate(viewTranslate, orientation.y, up);
        Mat4 view = glm.rotate(viewRotateX, orientation.x, up);
        Mat4 model = new Mat4(1f);
        return proj.times(view).times(model);
    }
}

1.3. Dependencies

GLM depends only on kotlin-unsigned to get support for unsigned operation and math.

Clone this wiki locally