Consider the following code:
Matrix4x4 perspective(const ViewFrustum &frustum) { float l = frustum.l; float r = frustum.r; float b = frustum.b; float t = frustum.t; float n = frustum.n; float f = frustum.f; return { { 2 * n / (r - l), 0, (r + l) / (r - l), 0 }, { 0, 2 * n / (t - b), (t + b) / (t - b), 0 }, { 0, 0, -((f + n) / (f - n)), -(2 * n * f / (f - n)) }, { 0, 0, -1, 0 } }; }
To improve the readability of the matrix design, I must either make a copy of the values from the frustum structure, or reference them. However, I also do not need copies or indirect links.
Is it possible to have some kind of "link" that will be resolved at compile time, like a symbolic link. It will have the same effect as:
Matrix4x4 perspective(const ViewFrustum &frustum) { #define l frustum.l; #define r frustum.r; #define b frustum.b; #define t frustum.t; #define n frustum.n; #define f frustum.f; return { { 2 * n / (r - l), 0, (r + l) / (r - l), 0 }, { 0, 2 * n / (t - b), (t + b) / (t - b), 0 }, { 0, 0, -((f + n) / (f - n)), -(2 * n * f / (f - n)) }, { 0, 0, -1, 0 } }; #undef l #undef r #undef b #undef t #undef n #undef f }
Without a preprocessor (or is that acceptable?). I believe that this is really not necessary, or can be avoided in this particular case by making these 6 values arguments to the function directly (although it would be a little annoying to call such a function), but even then I could make a built-in proxy function).
But I was just wondering if this is possible at all? I could not find anything like it. I think this will come in handy for locally shortening descriptive names that will be used a lot, without losing the original names.