I donβt know if this is the most efficient method, but I would just calculate the new vertex positions and learn AABB based on this data. For example,
Vertex v0, v1, v2, v3; // in the local coordinates of the rectangle // so for example v0 is always 0,0 and width and height define the others // put some values to v0..v3 glLoadIdentity(); glTranslatef(the position of the rectangle); glTranslatef(center_point); glRotatef(angle, 0,0,1); glTranslatef(-center_point); GLfloat matrix[16]; glGetFloatv(GL_MODELVIEW_MATRIX, matrix); v0 = multiply_matrix_by_vector(matrix, v0); v1 = multiply_matrix_by_vector(matrix, v1); v2 = multiply_matrix_by_vector(matrix, v2); v3 = multiply_matrix_by_vector(matrix, v3); AABB = find_the_minimums_and_maximums(v0, v1, v2, v3);
If you donβt know how to multiply the matrix by vector, try searching on it.
Also note that since the dimensions of the matrix are 4x4, the vectors for the vertices must also be 4-dimensional. You can convert a 2D vector to a 4D vector by adding the third component 0 (zero) and the fourth component 1 (one). After doing the multiplication, you can convert the resulting 4D vector back to 2D by dividing the x and y components into the fourth component and simply ignoring the third component because you don't need the third dimension.
Since matrix multiplications can be quite hard work with the processor, this approach can only be good if you do not need to update a large number of AABBs frequently.
kynnysmatto
source share