Kotlin port of OpenGL Mathematics (GLM), a header only C++ mathematics library for graphics software based on the OpenGL Shading Language (GLSL) specifications.

Overview

glm

Build Status license Release Size Github All Releases Awesome Kotlin Badge

This is the Kotlin port of OpenGL Mathematics (GLM), written by g-truc (repository), a header only C++ 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 and functionality than GLSL so that anyone who knows GLSL, can use GLM as well in Kotlin and Java.

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...

This library works perfectly with OpenGL but it also ensures interoperability with other third party libraries and SDK. It is a good candidate for software rendering (raytracing / rasterisation), image processing, physic simulations and any development context that requires a simple and convenient mathematics library.

GLM is written entirely in Kotlin, but can be also used from Java. It is a platform independent library with no dependences other than kotlin-unsigned for unsigned support and kotlin-test for testing.

For more information about GLM, please have a look at the manual and the original API reference documentation. The source code and the documentation are licensed under both the Happy Bunny License (Modified MIT) or the MIT License.

Don't hesitate to contribute to the project by submitting issues or pull requests for bugs and features. Any feedback is welcome at [email protected].

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

fun camera(translate: Float, rotate: Vec2): Mat4 {

    val projection = glm.perspective(glm.PIf * 0.25f, 4.0f / 3.0f, 0.1f, 100.0f)
    var view = glm.translate(Mat4(1.0f), Vec3(0.0f, 0.0f, -translate))
    view = glm.rotate(view, rotate.y, Vec3(-1.0f, 0.0f, 0.0f))
    view = glm.rotate(view, rotate.x, Vec3(0.0f, 1.0f, 0.0f))
    val model = glm.scale(Mat4(1.0f), Vec3(0.5f))
    return projection * view * model
}

How to retrieve it:

You can find all the instructions by mary

Comments
  • static methods

    static methods

    Hi, I'm not sure if this is a by-product of Kotlin but is there a technical reason why the usual functions like glm::frustum are dependent on an Instance instead of just being a static method of the generated class?

    This makes passing the functions around themselves somewhat tedious/infeasible as they need to be invoked on an instance of the glm class.

    Specifically I am trying to call these methods from clojure where the usability is even more impacted by the methods not being static. I can get around this by writing a few macros, but I would rather not add another layer of indirection.

    opened by rutenkolk 10
  • Rebase jdk8 branch

    Rebase jdk8 branch

    This PR rebases jdk8 onto master and changes the github actions JDK version to 8.

    Please note that the rebase leaves a non-linear commit history: let me know if you'd like a merge instead.

    opened by zeroeightysix 4
  • Incorrect gradle linking example

    Incorrect gradle linking example

    The gradle linking example

    dependencies {
          implementation 'com.github.kotlin-graphics.glm:glm:<version>'
      }
    

    seems to be incorrect. Only such option- com.github.kotlin-graphics:glm:<version> worked for me

    opened by asimaranov 4
  • Docs don't mention it's a JVM-only project

    Docs don't mention it's a JVM-only project

    I was quite excited to give this project a try in my small Kotlin/JS + WebGL side-project and I discovered very late that it depends on java.* APIs.

    I'm aware of issue #6, but an important first step before implementing multiplatform support, in my opinion, could be mentioning current state in the readme clearly.

    opened by cubuspl42 3
  • Build Failed - Could not find kx.platform:source:0.2.0.

    Build Failed - Could not find kx.platform:source:0.2.0.

    Just tried to rebuild my project using the latest glm snapshot. However, it seems to fail:

    implementation 'com.github.kotlin-graphics:glm:-SNAPSHOT'

    Could not resolve all files for configuration ':compileClasspath'.
       > Could not resolve com.github.kotlin-graphics:glm:-SNAPSHOT.
         Required by:
             project :
          > Could not resolve com.github.kotlin-graphics:glm:-SNAPSHOT.
             > Could not parse POM https://jitpack.io/com/github/kotlin-graphics/glm/-SNAPSHOT/glm--8dae70c16a-1.pom
                > Could not find kx.platform:source:0.2.0.
                  Searched in the following locations:
                    - https://oss.sonatype.org/content/repositories/snapshots/kx/platform/source/0.2.0/source-0.2.0.pom
                    - https://oss.sonatype.org/content/repositories/snapshots/kx/platform/source/0.2.0/source-0.2.0.jar
                    - https://repo.maven.apache.org/maven2/kx/platform/source/0.2.0/source-0.2.0.pom
                    - https://repo.maven.apache.org/maven2/kx/platform/source/0.2.0/source-0.2.0.jar
                    - https://jitpack.io/kx/platform/source/0.2.0/source-0.2.0.pom
                    - https://jitpack.io/kx/platform/source/0.2.0/source-0.2.0.jar
    

    reverting to implementation 'com.github.kotlin-graphics:glm:9cb1ce84bf' fixes the issue.

    opened by tobias-dv-lnu 3
  • NoSuchMethodError Vector

    NoSuchMethodError Vector

    When trying to use the get() function of the Vec2i a NoSuchMethodError gets thrown. When calling them directly a NoSuchFieldError appears.

    private val creator=LevelCreator(Game.resolution[0].toFloat(), Game.resolution[1].toFloat(),14,8,0f,0f)

    https://github.com/Mitti30/BreakoutOpenGL

    opened by Mitti30 2
  • Add glm methods to clojure class

    Add glm methods to clojure class

    Hi, i wanted to use your library with clojure and came across this disscusion #5 . It looked reasonably easy so i made a small script to get all functions and place them in the Clojure class you created. I don't know kotlin and did not have the time to setup/learn it, so it must contain some unnecessary functions or typos, but maybe it's a first draft.

    opened by Joeyjoejoe 2
  • update readme - new jitpack path since v0.10

    update readme - new jitpack path since v0.10

    Since v0.10 the gradle implementation for jitpack changed. This PR updates the dependency example in the readme accordingly to prevent confusion during the initial setup process.

    opened by NoEpicLoot 2
  • Wrong Calculation for Vec3 times Quat

    Wrong Calculation for Vec3 times Quat

    glm calculates vec3 * quat as : https://github.com/g-truc/glm/blob/23e0701c0483283440d4d1bcd17eb7070fa8eb75/glm/detail/type_quat.inl#L352-L356

    	template<typename T, qualifier Q>
    	GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec<3, T, Q> operator*(vec<3, T, Q> const& v, qua<T, Q> const& q)
    	{
    		return glm::inverse(q) * v;
    	}
    
            template<typename T, qualifier Q>
    	GLM_FUNC_QUALIFIER qua<T, Q> inverse(qua<T, Q> const& q)
    	{
    		return conjugate(q) / dot(q, q);
    	}
    

    That is glm::inverse(q) * v; which can be expanded as conjugate(q) / dot(q, q) * v; However Vec3 * Quat is implemented in: https://github.com/kotlin-graphics/glm/blob/5b0f3461ebe0c1a3a752b1b9a174c09fb7e4b5f4/src/main/kotlin/glm_/quat/quat_operators.kt#L61-L77

    Where line 62 val dot = dot(a, a) should be val dot = dot(b, b) which calculates the dot product of a quaternion and then is used to calculate the inverse of the quaternion.

    opened by wumo 1
  • Gradle and lwjgl 3.2.2-SNAPSHOT

    Gradle and lwjgl 3.2.2-SNAPSHOT

    I'm using your library in my project. My project's build.gradle originally looked like:

    blahblah...
    
    ext {
        ...
        glmVersion = 'v0.9.9.0-build-13'
    }
    
    repositories {
        jcenter()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
    
    dependencies {
        ...
        implementation "com.github.kotlin-graphics.glm:glm:$glmVersion"
    }
    

    Then when I run gradlew build or gradlew run, gradle fails to download lwjgl and emits an error that it can't find 3.2.2-SNAPSHOT version of lwjgl. After reading your library's build.gradle, I found that you are using oss.sonatype.org for downloading lwjgl. So I added that repository to my project's build.gradle like the following code:

    repositories {
        jcenter()
        mavenCentral()
        maven { url 'https://jitpack.io' }
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
    }
    

    And gradle works well now.

    So I think that you should mention in README.md that the users should try this method if gradle emits lwjgl dependency error.

    Thanks.

    opened by Avantgarde95 1
  • Unfriendly installation docs

    Unfriendly installation docs

    First, I'd like to thank you for creating a port of glm. I'd love to use it in my project and I'm very glad that you've put an effort to create this pure-Kotlin port.

    Would you consider improving the documentation about getting the library? In my experience, picking a library looks like this: first I verify if this is the library I'm looking for, then I copy the Gradle snippet, typically from the top of the readme. In case of kotlin-graphics/glm, there's only a link pointing to kotlin-graphics/mary's readme, which is some kind of an analysis, which is not really helpful for people who look for three magical lines of Gradle script (which is, 95% of people).

    opened by cubuspl42 1
  • Feedbacks to design native memory methods

    Feedbacks to design native memory methods

    So, I'm getting some dilemmas right now and I'd like to hear some feedbacks

    I finally recently implemented inline classes into native pointer management in kool (I was eager to do it, but always postponed because of other priorities)

    Where you basically can do something like:

    val intPtr = IntPtr(x) // x is a valid, already allocated area of memory
    intPtr[1] = 5
    val r = intPtr[0]
    

    all for free, offsets are set accordingly to the pointer type

    Now I already used that in the vkk playground (tmp branch) and I went for expliciteness, so write(adr: Adr) or write(stack: MemoryStack) to write the current struct at the given memory address or in the given MemoryStack. On the other side, constructor(ptr: BytePtr)s and read/native { } methods to read from native memory.

    Here in glm, there was only some raw simple methods

    // Vec2
        infix fun to(ptr: Ptr) {
            memPutFloat(ptr, x)
            memPutFloat(ptr + Float.BYTES, y)
        }
    
    // Vec2 companion object
    fun fromPointer(ptr: Ptr) = Vec2(memGetFloat(ptr), memGetFloat(ptr + Float.BYTES))
    

    I'm planning to expand this area, by providing a constructor

    constructor(ptr: FloatPtr) : this( { i -> ptr[i] } )
    

    calling the corresponding functional programming constructor

    This will work for all the vector and matrices, except the vectors using Longs (Vec1l, Vec2l, Vec3l and Vec4l), because they have the convenience constructor accepting just one Long, whose signature will clash with construct(ptr: LongPtr). In this cases, I'll keep the convenience constructor and renounce to the pointer one.

    I'm incline to accept this small incoherence for these vectors type and provide a static method for those.

    This is my first dilemma.

    Second issue is the naming. At the begin I thought to go with to for writing and from for reading into an existing class (constructor otherwise).

    But a part of me is pushing for explicit read and write methods.

    What do you think, guys?

    opened by elect86 0
  • Multiplatform?

    Multiplatform?

    I want to use this library in a multiplatform application. Since the bulk of this library is written in pure Kotlin, going multiplatform would be fairly trivial. The only possible issue I can think of is that JitPack may not work with it, breaking current users. Would need to setup build for all platforms to publish to Bintray or Maven central.

    opened by Dominaezzz 57
Releases(v0.9.9.1-build-3)
Owner
Friendly community providing JVM counterpart of open source tools for real time 3d graphic. "Take care of your tools and they will take care of you." (cit)
null
An Interpreter/Transpiler for the Folders esoteric programming language, a language with no code and just folders

Folders2kt ?? An Interpreter/Transpiler of the Folders esoteric programming language, a language with no code and just folders, written in Kotlin Show

Jens Klingenberg 18 Jan 4, 2023
Simple authentication provider for Ktor that verifies presence of the API key in the header

Ktor API Key Authentication Provider Simple authentication provider for Ktor that verifies presence of the API key in the header. Useful if you want t

Lukas Forst 6 Oct 28, 2022
Collection of JVM library logic that the Sirloin software development team is currently using

Collection of JVM library logic that the Sirloin software development team is currently using

Sirloin Dev 4 May 10, 2022
Bring together all of the remarkable Computer Graphics Algorithms in one place 🚀

Compose Computer Graphics Playground ?? "There was an idea to bring together all of the remarkable Computer Graphics Algorithms in one place. And keep

Jaseemakhtar 162 Dec 27, 2022
This is an example of a simple application with layered software base on clean-architecture as application architecture and mvvm as presentation architecture

This is an example of a simple application with layered software base on clean-architecture as application architecture and mvvm as presentation archi

null 3 Jul 2, 2021
Go Outside is an augmented reality app designed for our team's Software Engineering UI/UX class

Go Outside Go Outside is an augmented reality app designed for our team's Software Engineering UI/UX class. This app serves as a PROTOTYPE to demonstr

Kris 4 Jul 28, 2022
A multifunctional Android RAT with GUI based Web Panel without port forwarding.

AIRAVAT A multifunctional Android RAT with GUI based Web Panel without port forwarding. Features Read all the files of Internal Storage Download Any M

The One And Only 336 Dec 27, 2022
LittleKt - An OpenGL game framework written in Kotlin

LittleKt - A 2D game framework written in Kotlin Currently in development. Littl

LittleKt 128 Dec 31, 2022
Lambë Language 7 Dec 21, 2022
A toy port scanner to help me (and you!) learn Kotlin + Akka.

kotlin-akka-portscan A toy program to help me (and you!) learn Kotlin + Akka. butwhy.gif When I want to learn a new language, I've found it helpful to

Jeremi M Gosney 4 Jul 23, 2022
StretchKt - a Kotlin port of stretch2

StretchKt StretchKt is a Kotlin port of stretch2, which is an implementation of Flexbox originally written in Rust. The current tracked commit of the

null 2 Jun 4, 2022
Kotlin snippets that you can understand quickly, using only stdlib functionality.

Support this and other projects from Ivan Mwiruki here. 30 seconds of Kotlin Curated collection of useful Kotlin 1.3 snippets that you can understand

Ivan Moto 246 Dec 19, 2022
Remote Administrator Tool [ RAT For Android ] No Port Forwarding

XHUNTER RAT for Android ?? · Telegram · ⚖️ Legal Disclaimer: For Educational Purpose Only Usage of XHUNTER for attacking targets without prior mutual

Anon 79 Dec 31, 2022
Gradle plugin to manage tests which should only run nightly and not every time a CI/CD pipeline builds.

NightlyTestsPlugin Gradle Plugin to configure which (j)Unit tests should only be run nightly and not everytime a CI/CD pipeline is triggered. Usage To

VISUS Health IT GmbH 0 Dec 7, 2021
A media player, currently only for Android, that allows you to play songs in background for free

Just Listen A music player currently only for android. It is using Audius public APIs to display and get the playlists/songs. Available on google play

null 68 Dec 27, 2022
An Android UI clone of ABA Mobile app for education purpose only.

ABAUIClone An Android UI clone of ABA Mobile app for education purpose only. Project Specs Language: Kotlin UI Design system: XML-based Design pattern

UTNGY Pisal 3 Oct 5, 2022
Android Multi Theme Switch Library ,use kotlin language ,coroutine ,and so on ...

Magic Mistletoe Android多主题(换肤)切换框架 背景 时隔四年,在网易换肤之前的思路下,做了几点改进,现在完全通过反射创建View,并且在SkinLoadManager中提供一个configCustomAttrs以支持自定义View的属性插队替换 摈弃了之前的AsyncTask

Mistletoe 18 Jun 17, 2022
It is a project that contains lessons and examples about Kotlin programming language. 🇰

Kotlin Tutorials What is Kotlin? I added the platforms it supports and great resources. You can access the article from the link below: https://medium

Halil Özel 94 Dec 22, 2022
A showcase music app for Android entirely written using Kotlin language

Bandhook Kotlin This project is a small replica of the app I developed some time ago. Bandhook can still be found on Play Store At the moment it will

Antonio Leiva 1.9k Dec 23, 2022