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

Calculating AABB center #10

Open
kaichsu opened this issue Aug 17, 2024 · 0 comments
Open

Calculating AABB center #10

kaichsu opened this issue Aug 17, 2024 · 0 comments

Comments

@kaichsu
Copy link

kaichsu commented Aug 17, 2024

In the vx__voxelize function, the vx__aabb_center function is used to obtain the center point of an AABB by calculating (saabb.min + saabb.max) / 2. However, this is equivalent to ((xyz - hvs) + (xyz + hvs)) / 2, which simplifies to xyz.

Is there a specific reason for using vx__aabb_center to get the AABB center rather than using xyz directly?

voxelizer/voxelizer.h

Lines 630 to 637 in f6ee9cf

vx_vertex_t vx__aabb_center(vx_aabb_t* a)
{
vx_vertex_t boxcenter = a->min;
vx__vec3_add(&boxcenter, &a->max);
vx__vec3_multiply(&boxcenter, 0.5f);
return boxcenter;
}

voxelizer/voxelizer.h

Lines 756 to 769 in f6ee9cf

for (float x = aabb.min.x; x <= aabb.max.x; x += vs.x) {
for (float y = aabb.min.y; y <= aabb.max.y; y += vs.y) {
for (float z = aabb.min.z; z <= aabb.max.z; z += vs.z) {
vx_aabb_t saabb;
saabb.min.x = x - hvs.x;
saabb.min.y = y - hvs.y;
saabb.min.z = z - hvs.z;
saabb.max.x = x + hvs.x;
saabb.max.y = y + hvs.y;
saabb.max.z = z + hvs.z;
vx_vertex_t boxcenter = vx__aabb_center(&saabb);
vx_vertex_t halfsize = vx__aabb_half_size(&saabb);

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

1 participant