# Oriented Bounding Box (rotating about the central point)

This topic is 2090 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

The problem is: when rotating the OBB, it performs a rotation about the x axis instead of a rotation about the local axis (wich seems that i've already implemented this with quaternion). I think that probably is the drawing method. What i'm doing wrong? How do you guys perfoms render on a cube (GL_POLYGON, GL_CUBE, GL_LINELOOP...) ?

min = 0, 0, 0
max = 2, 2, 2

PS: when i draw a cube/sphere it's rotate normally

Problem: I need to rotate the OBB about the central point.

float angle;
Vector axis;

orientation.angleAxis(angle, axis);
glTranslatef(position.x, position.y, position.z);
glRotatef(angle / Mathematics::pi * 180.0f, axis.x, axis.y, axis.z);

glBegin(GL_LINES);
glColor3f(1.0f, 1.0f, 1.0f);

//8 LINE SEGMENTS;

Vector v0(min[0], min[1], min[2]);
Vector v1(max[0], min[1], min[2]);
Vector v2(max[0], max[1], min[2]);
Vector v3(min[0], max[1], min[2]);
Vector v4(min[0], min[1], max[2]);
Vector v5(max[0], min[1], max[2]);
Vector v6(max[0], max[1], max[2]);
Vector v7(min[0], max[1], max[2]);

glVertex3fv(&v0[0]); glVertex3fv(&v1[0]);
glVertex3fv(&v1[0]); glVertex3fv(&v2[0]);
glVertex3fv(&v2[0]); glVertex3fv(&v3[0]);
glVertex3fv(&v3[0]); glVertex3fv(&v0[0]);
glVertex3fv(&v4[0]); glVertex3fv(&v5[0]);
glVertex3fv(&v5[0]); glVertex3fv(&v6[0]);
glVertex3fv(&v6[0]); glVertex3fv(&v7[0]);
glVertex3fv(&v7[0]); glVertex3fv(&v4[0]);
glVertex3fv(&v0[0]); glVertex3fv(&v4[0]);
glVertex3fv(&v1[0]); glVertex3fv(&v5[0]);
glVertex3fv(&v2[0]); glVertex3fv(&v6[0]);
glVertex3fv(&v3[0]); glVertex3fv(&v7[0]);
glEnd();
glPushMatrix();

Thanks guys!!!

##### Share on other sites
glTranslatef(position.x, position.y, position.z);
glRotatef(angle / Mathematics::pi * 180.0f, axis.x, axis.y, axis.z);

just do it the other way around:
glRotatef(angle / Mathematics::pi * 180.0f, axis.x, axis.y, axis.z);
glTranslatef(position.x, position.y, position.z);

Edit: The idea is, that your objects vertices have positions relative to your objects center. Without transformation, this center will be the same as the worlds center. glTranslate and glRotate always transform relative to the worlds center. This means if you first translate, your object will be placed at a different position in the world, now if you rotate, that new position+your vertex positions will be rotate around the worlds center. If you rotate first, your object is rotated around the worlds center, which is also its own center and then it is moved to its final position. This explanation is probably not mathematically perfect, but should give a basic feeling for correct transformation orders. If you want to understand this in more detail, check out rotation and translation matrices and matrix multiplication, especially homogeneous matrices.
Edited by _Slin_

##### Share on other sites

Now seems to REALLY rotate about the world center  . I think the first try it's more correct. When I draw a cube like this:

glBegin(GL_POLYGON);
glColor3f( 1.0, 1.0, 1.0 );
glVertex3f( 0.5, -0.5, 0.5 );
glVertex3f( 0.5, 0.5, 0.5 );
glVertex3f( -0.5, 0.5, 0.5 );
glVertex3f( -0.5, -0.5, 0.5 );
glEnd();

// Purple side - RIGHT
glBegin(GL_POLYGON);
glColor3f( 1.0, 0.0, 1.0 );
glVertex3f( 0.5, -0.5, -0.5 );
glVertex3f( 0.5, 0.5, -0.5 );
glVertex3f( 0.5, 0.5, 0.5 );
glVertex3f( 0.5, -0.5, 0.5 );
glEnd();

// Green side - LEFT
glBegin(GL_POLYGON);
glColor3f( 0.0, 1.0, 0.0 );
glVertex3f( -0.5, -0.5, 0.5 );
glVertex3f( -0.5, 0.5, 0.5 );
glVertex3f( -0.5, 0.5, -0.5 );
glVertex3f( -0.5, -0.5, -0.5 );
glEnd();

// Blue side - TOP
glBegin(GL_POLYGON);
glColor3f( 0.0, 0.0, 1.0 );
glVertex3f( 0.5, 0.5, 0.5 );
glVertex3f( 0.5, 0.5, -0.5 );
glVertex3f( -0.5, 0.5, -0.5 );
glVertex3f( -0.5, 0.5, 0.5 );
glEnd();

// Red side - BOTTOM
glBegin(GL_POLYGON);
glColor3f( 1.0, 0.0, 0.0 );
glVertex3f( 0.5, -0.5, -0.5 );
glVertex3f( 0.5, -0.5, 0.5 );
glVertex3f( -0.5, -0.5, 0.5 );
glVertex3f( -0.5, -0.5, -0.5 );
glEnd();

Rotates perfectly. Maybe is a problem with max and min and I can't figure out. If someone know how to correctly draw a OBB...

##### Share on other sites

what are possible values for min and max in your case?

min = 0, 0, 0
max = 2, 2, 2

##### Share on other sites

glTranslate(x,y,z);glRotate(angle,x,y,z)  and Set up all your vertices as if your box is axigned aligned. If you are using Quaternion you can always convert your quaternion of your object local rotation to an axis and angle and feed that to glRotate.

##### Share on other sites

Would changing:

min = 0, 0, 0
max = 2, 2, 2

to

min  = -1.0, -1.0, -1.0

max =  1.0,  1.0,  1.0

work?

1. 1
Rutin
27
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633311
• Total Posts
3011312
• ### Who's Online (See full list)

There are no registered users currently online

×