Skip to content

Calculating AABB center #10

@kaichsu

Description

@kaichsu

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);

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