Jump to content
Eternal Lands Official Forums
Sign in to follow this  
Grum

Question about bounding boxes for 2D objects

Recommended Posts

In 2d_objects.c, function add_2d_obj(), the bounding boxes for 2D objects are computed as

<set X and Y ranges for the bbox, depending on the type of object>
bbox.bbmin[Z] = z_pos;
bbox.bbmax[Z] = z_pos;

calc_rotation_and_translation_matrix(our_object->matrix, x_pos, y_pos, 0.0f, x_rot, y_rot, z_rot);
matrix_mul_aabb(&bbox, our_object->matrix);

So the bbox is first raised to height z_pos, then rotated, and finally shifted to the objects (x,y) position. Is this correct, and does this really match what happens with the 2D object itself? E.g., if I'm reading this correctly (maybe I'm not), all vertically aligned 2d objects (maps hanging on a wall for instance), have bounding boxes that are centered around z = 0 (or start at z=0, depending on the type of object)

 

I would've expected the code to set the orientation of the box first, and then translate it to the correct position, like

bbox.bbmin[Z] = 0.0f;
bbox.bbmax[Z] = 0.0f;

calc_rotation_and_translation_matrix(our_object->matrix, x_pos, y_pos, z_pos, x_rot, y_rot, z_rot);
matrix_mul_aabb(&bbox, our_object->matrix);

 

So ehm... is this really a bug, or can anyone tell me where I'm wrong?

Share this post


Link to post
Share on other sites

Just FYI, those maps on the walls are not 2d, but 3d objects.

All 2d objects are only flat on the ground(with the exception of sometimes some 2do's being used on a flooring that is above ground level).

Share this post


Link to post
Share on other sites

Ok, so probably the rotations around the y and x axes are zero for all 2d objects, and the bounding boxes are correct by accident.

 

Still, would be nice if someone could confirm this.

Share this post


Link to post
Share on other sites

Well sometimes the rotations are not 0 for those 2 axes, like putting some leaves on the "ground" of an incline.

But that's probably like 1% of all 2do's in the game.

Share this post


Link to post
Share on other sites

Maybe even less. I've done a bit of testing, and found 93 2d0 on all maps that have x or y rotation greater than 45 degrees. I haven't done ingame testing yet, but if my implementation in the Python script I wrote is correct, then the current EL code leads to interesting bounding boxes like:

x_pos =  16.7668819427
y_pos =  10.0156593323
z_pos =  -2.57899975777
x_rot =  270.0
y_rot =  0.0
z_rot =  -360.0
box =  (15.766882, 7.436660, -1.000000) - (17.766882, 7.436660, 1.000000)

 

EDIT: probably obvious, but the first 6 lines are the position and rotation angles of the object, the last line is the computed bounding box (minx,miny,minz) - (maxx,maxy.maxz). For an object with position (16.7668819427, 10.0156593323, -2.57899975777) I don't expect to have to search for it at y=7.436660 and z between -1 and 1.

Edited by Grum

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×