Dav1dde / gl3n

OpenGL Maths for D (not glm for D).
http://dav1dde.github.com/gl3n/
Other
103 stars 49 forks source link

Transformation call order #46

Closed Vild closed 9 years ago

Vild commented 9 years ago

Hey, I'm just wondering if i'm doing something wrong if i need to write all my transformation calls backwards for example:

mat4.identity.rotatey(roty).rotatex(rotx).translate(x, y, z)

When I read the documentation for gl3n you write it in this order.

mat4.identity.translate(x, y, z).rotatex(rotx).rotatey(roty);

And other example is:

This does not work

mat4.identity.translate(x, y, z);
// Which is the same as
mat4.translation(x, y z) * mat4.identity;

This does work

mat4.identity * mat4.translation(x, y z);

Am I doing something wrong or is this a bug?

I am using ldc (which is the default for dub)

Dav1dde commented 9 years ago

Internally it looks like that:

            Matrix rotate(real alpha, Vector!(mt, 3) axis) {
                this = rotation(alpha, axis) * this;
                return this;
            }

            Matrix rotatex(real alpha) {
                this = xrotation(alpha) * this;
                return this;
            }

So e.g. you would use it like that:

    @property override
    mat4 camera() {
        vec3 pos = -(position + offset);
        return mat4.identity.translate(pos.x, pos.y, pos.z)
                    .rotatey(-rotation.y)
                    .rotatex(rotation.x);
    }

(from https://github.com/Dav1dde/BraLa/blob/master/brala/gfx/camera.d#L122-L123)

Vild commented 9 years ago

Here I got a example of the problem of my problem. Have I done anything wrong? I also added C++ equal code. (Which is what i'm translating from) https://github.com/WildN00b/gl3n-thing/blob/master/source/app.d#L124