0
\$\begingroup\$

I am creating a AABB for collision detection. I need to calculate the extents for my model and also update them when my model moves. I calculate my min and max when I create my mesh and I use my position to reference the center.

Could someone please show me how to get the extents either with my min and max vectors or with an array of vertices.

Actually for more clarification I tried this

public Vector3f getMin() {
    return Vector3f.sub(pos, extents, null);
}

public Vector3f getMax() {
    return Vector3f.add(pos, extents, null);
}

The problem is that everything seems to be centered around the origin(0,0,0). The position is the position of the entity the AABB represents.

\$\endgroup\$
4
  • \$\begingroup\$ So just to clarify: You already have the min & max positions, and you're asking how to calculate the size of a bounding box from those? \$\endgroup\$
    – user35344
    Apr 6, 2018 at 16:07
  • \$\begingroup\$ @Tyyppi_77 Yes I am \$\endgroup\$ Apr 6, 2018 at 16:33
  • \$\begingroup\$ How are you calculating extents? Why is the same method twice there? How is this code not working? Have you tried rendering/printing out the AABB? Are you sure that your min & max positions are calculated correctly? \$\endgroup\$
    – user35344
    Apr 6, 2018 at 16:56
  • \$\begingroup\$ @Tyyppi_77 Here is how I caluculate extents this.extents = Vector3f.sub(max,min,null); and everything is centered around the origin. \$\endgroup\$ Apr 6, 2018 at 17:05

1 Answer 1

0
\$\begingroup\$

The size of the box that covers the whole mesh is simply the difference between the max and the min position: vec3 size = max - min;.

Now from that you can get the extents simply by halfing the size: vec3 extents = size * 0.5f;

\$\endgroup\$
4
  • \$\begingroup\$ I tried that. Still doesn't work \$\endgroup\$ Apr 6, 2018 at 16:47
  • 3
    \$\begingroup\$ What doesn't work? How does it not work? What is the expected behaviour? You are giving us nothing to help you debug your issue. \$\endgroup\$
    – user35344
    Apr 6, 2018 at 16:48
  • \$\begingroup\$ I edited my post. \$\endgroup\$ Apr 6, 2018 at 16:54
  • 2
    \$\begingroup\$ @MackybenJonah try including numbers in a concrete example. For instance "I have a cube mesh with these vertices: ... I calculate my min and max values as: ... When I use this size calculation I get the result X, but I expect the result Y instead" - that will help us identify where the problem is. \$\endgroup\$
    – DMGregory
    Apr 6, 2018 at 16:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .