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

functions for vec to ivec conversion #352

Open
duarm opened this issue Oct 20, 2023 · 1 comment
Open

functions for vec to ivec conversion #352

duarm opened this issue Oct 20, 2023 · 1 comment

Comments

@duarm
Copy link
Contributor

duarm commented Oct 20, 2023

I work hexagon maps, and I store everything with ivec3 because most operations are cheaper with integers. It's common for when calculating from hexagon space to world/screen space, convert the ivec3 to vec3, so there's no rounding issues. It would be nice to have ivec types to vec type conversions. Something like:

void vec3_ivec3(vec3 const a, ivec3 dest)
{
	dest[0] = a[0];
	dest[1] = a[1];
	dest[2] = a[2];
}

void vec2_ivec2(vec2 const a, ivec2 dest)
{
	dest[0] = a[0];
	dest[1] = a[1];
}

Maybe a macro?

#define vec3_ivec3(a) ((ivec3) { a[0], a[1], a[2] })

ivec3 dest = vec3_ivec3(a);

any better ideas? feedback welcome.

@duarm duarm changed the title functions for vec conversion/merging functions for vec to ivec conversion Oct 20, 2023
@recp
Copy link
Owner

recp commented Oct 23, 2023

Hi @duarm,

Sorry for the late response,

We can have float <-> int vector conversion as you proposed. I think we can continue with functions for now.

FWIW, in the future we may need additional functions for rounding numbers e.g. vec3_ivec3_round(), vec3_ivec3_rounded(), vec3_round_ivec3()...

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