dagostinelli/hypatia

Lack of temporary object type functions

awsdert opened this issue · 4 comments

Here's some code I've been converting, I had hoped to find functions suitable for this sort of code but it does not seem to be available, at the moment I'm gonna have to write wrappers to achieve the below without compile time errors:

void lookat( struct vector3 eye, struct vector3 center, struct vector3 up )
{
	struct vector3 z = vector3_normalize( sub3x3r3( eye, center ) );
	struct vector3 x = vector3_normalize( cross3x3( up, z ) );
	struct vector3 y = vector3_normalize( cross3x3( z, x ) );
	struct matrix4 Minv =
	{
		{
			{{ x.x, x.y, x.z,0 }},
			{{ y.x, y.y, y.z,0 }},
			{{ z.x, z.y, z.z,0 }},
			{{ 0,0,0,1 }}
		}
	};
	struct matrix4 Tr =
	{
		{
			{{ 1, 0, 0, -(center.x) }},
			{{ 0, 1, 0, -(center.y) }},
			{{ 0, 0, 1, -(center.z) }},
			{{ 0, 0, 0, 1 }}
		}
	};
	ModelView = mul4x4x4x4r4x4( Minv, Tr );
}

I believe it is better to rename the current functions adding an extra underscore after the prefix and then add the versions using temporary vectors/matrices using the now free'd up names, for example vector3_normalize() would become something like the below:

struct vector3* vector3__normalize(struct vector *vec) { ... }
struct vector3 vector3_normalize(struct vector3 vec) { return *vector3__normalize(&vec); }

The double underscore makes clear that the single underscore version uses the double underscore internally, this allows both the option of speed and the option of preservation to the developer.

Also please add this struct to the union vec2s: struct { float r; float i; }
r is for the "real" numbers and i is for "imaginary" numbers (in case you are still having trouble understanding what "imaginary" numbers are, I think of them as square root pairs, for example i5 * i5 is -25, in "real" that would be -5 * 5 or 5 * -5, i5 represents that "real" pair)

Edit: Also do similar for any related unions please

This is two issues in one. I'll address issue 1 in this issue and issue 2 in #13

I like this idea. (Having both types of functions) I will think about it. Great suggestion!

as a side note, my suggestion of double underscore makes it easy for devs to do a quick session replace of all their calls to the double underscore when upgrading, then it's only a matter of choosing what should use the more readable function calls or the faster core calls