Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lack of temporary object type functions #12

Open
awsdert opened this issue Jun 25, 2021 · 4 comments
Open

Lack of temporary object type functions #12

awsdert opened this issue Jun 25, 2021 · 4 comments

Comments

@awsdert
Copy link

awsdert commented Jun 25, 2021

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.

@awsdert
Copy link
Author

awsdert commented Jun 25, 2021

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

@dagostinelli
Copy link
Owner

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

@dagostinelli
Copy link
Owner

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

@awsdert
Copy link
Author

awsdert commented Jun 26, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants