Skip to content

Lack of temporary object type functions #12

Description

@awsdert

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions