• Create Account

# Oriented Bounding Box (rotating about the central point)

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

6 replies to this topic

### #1Irlan R.  Members   -  Reputation: 1276

Like
0Likes
Like

Posted 18 February 2013 - 03:10 PM

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!!!

### #2_Slin_  Members   -  Reputation: 202

Like
0Likes
Like

Posted 18 February 2013 - 03:53 PM

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_, 18 February 2013 - 04:09 PM.

### #3Irlan R.  Members   -  Reputation: 1276

Like
0Likes
Like

Posted 19 February 2013 - 08:05 AM

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...

### #4_Slin_  Members   -  Reputation: 202

Like
0Likes
Like

Posted 19 February 2013 - 11:00 AM

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

### #5Irlan R.  Members   -  Reputation: 1276

Like
0Likes
Like

Posted 20 February 2013 - 07:07 AM

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

### #6BornToCode  Members   -  Reputation: 904

Like
0Likes
Like

Posted 22 February 2013 - 02:17 PM

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.

### #7DT....  Members   -  Reputation: 487

Like
0Likes
Like

Posted 23 February 2013 - 11:16 PM

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?

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS