AABB and transformations

Hi All.

I’m so humble that rather using Unity or Unreal, I still spend my spare time on poking my rendering whatever as I still have a Starcraft like RPG idea. Which will never be released if I progress as good as I do right now :smiley:

BUT, I’m at least learning and posting here.

The problem is a common one. I have AABB boxes around my models. If I rotate or scale the models, the AABB boxes rotate and scale as well, which is not good. I removed then the rotation and scaling part from the transformation matrix, hence the AABB boxes only move without scale and rotation, but obviously it’s not perfect as the bounding box will not be accurate if the model is high and thin at the same time.

I found a great solution that I should store the original AABB and when a model is rotated or scaled, I should recalculate the AABB itself from the original AABB using the translation matrix. This is good, but the problem is that I not just use AABBs for calculations like ray tracing, but also for visualizing it with a renderer and I have problem there.

The rendering logic is based on batches and instanced rendering. Of course, I can change to simple draw calls per model when I render AABBs, but then I have to render AABBs per model, which will be slow if I have too much models.

I agree, that if I want a game ASAP out, I must skip this or choose an alternative path. The thing is that currently I’m more interested at solving this math-like problem instead of releasing anything.

So any idea?

And what keeps you from doing it this way with the transformed AABBs as well? Just transform your AABBs, upload all of them into a single VBO and render all of them with a single draw call, if that is what you did with the untransformed AABBs.

Hm, interesting. Don’t know why this idea didn’t pop into my head.
So basically the transformation is done on the Java side, I upload all entities’ AABBs into a single VBO, draw it with a single (not even instanced) draw call, and if any of the entities’ transformation matrix changed, I just use

glBufferSubData

and update the VBO I have.

Correct?

You can use instancing as well, and just use the AABBs’ buffer object as an instanced vertex attribute in the shader. The choice is yours. I mean, how did you render the untransformed AABBs in the first place? Just use the same mechanism for the transformed AABBs.
By the way, I added AABB.transform(Matrix4) to the latest 1.9.20-SNAPSHOT version of JOML, if you’d like to use that to transform the AABBs: https://github.com/JOML-CI/JOML/commit/57e762949d792e71a49f01c59c7e08b8508f69cc

I think you’ve saved some of my spare hours with this comment. Thanks! I’ll get back to you when I tried it out :slight_smile: