adbrown85 / gloop

Lightweight C++ wrapper for OpenGL
BSD 2-Clause "Simplified" License
1 stars 0 forks source link

Add 3 and 4 width square matrix implementations #2

Closed adbrown85 closed 12 years ago

adbrown85 commented 12 years ago

Since OpenGL no longer has matrix math built-in, we need to make some matrix implementations. For 3D graphics I think three and four width square matrices are enough.

Like our vectors, it would be nice to have them mirror the GLSL implementations as much as possible. Therefore the names should probably be Mat3 and Mat4. (We'll go with capitals for now to be consistent with other types in the library...) To make things easy for now we'll just stick with floats. If we need doubles later we can tack on a d at the end of the name, similar to what GLSL does, or even go template based.

Besides all the necessary operators, they should have a few extra top-level functions that users will expect.

Also we will want some toArray methods so we can easily send the values to OpenGL shaders, or just for users that want or need to work with arrays. We will assume the single-index forms are in column-major order though. We won't support dumping down to a pointer because there's no way to know the dimensions of that.

adbrown85 commented 12 years ago

Nevermind, let's just go with doubles only.

adbrown85 commented 12 years ago

I think I'm leaning towards packing one-dimensional arrays as row-major now, despite the fact that OpenGL traditionally does so in column-major. That way it actually looks right when you initialize one, and you can always just set the transpose flag to true when you pass them to the shader. Plus, really we are using column vectors prefixed by matrices, so our matrices really should be in row-major anyway.

My only concern is that in GLSL a mat4 can be made from four vec4 instances, so that might be a little bit of a disconnect I'd rather not have.

Although I guess overall ideally we should just have separate named constructors, like fromArrayInRowMajor and fromColumns. Just doesn't seem like C++ for some reason...