Types
The basis of the engine will depend on the types that we use. Any 3D program needs 3 and 4 component vectors and matrices. I choose to mimic the GLSL types: vec2, vec3, vec4, bvec2, bvec3, bvec4, mat2, mat3, mat4. We could also add ivec2, ivec3, and ivec4, but they don’t come up very often. So the above will be a good start.
vec2, vec3, vec4
vec2, vec3, and vec4 and 2, 3, and 4 component floating point vectors. Because they will be used as points / vectors, colors and texture coordinates, we will adopt the same convention as GLSL and have the components x, y, z, w, r, g, b, a, s, t, p, and q. Where x = r = s, y = g = t, z = b = p, and w = a = q. This can be taken care of using the following for members of the classes.
union
{
struct { float x; float y; float z; float w; };
struct { float r; float g; float b; float a; };
struct { float s; float t; float p; float q; };
};
Where vec2 has the first two components and so on.
Be sure to add all the nice operators (+, -, *, /, []) to vecs and mats. Plus dot products and cross products. bvecs have methods all() and any() to do logical ||s and &&s.