Hi, I’m really struggling to create a bounding box around my object. I’ve read websites but the guidance on implementing it isn’t shown and I’ve tried countless times to do it myself so I will show my current working.
My Shape information:
GLfloat normals[] = {0,0,1, 0,0,1, 0,0,1, 0,0,1, // v0-v1-v2-v3
1,0,0, 1,0,0, 1,0,0, 1,0,0, // v0-v3-v4-v5
0,1,0, 0,1,0, 0,1,0, 0,1,0, // v0-v5-v6-v1
-1,0,0, -1,0,0, -1,0,0, -1,0,0, // v1-v6-v7-v2
0,-1,0, 0,-1,0, 0,-1,0, 0,-1,0, // v7-v4-v3-v2
0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1}; // v4-v7-v6-v5
GLfloat vertices[] = {1,1,1, -4,1,1, -4,-1,1, 1,-1,1, // v0-v1-v2-v3
1,1,1, 1,-1,1, 1,-1,-1, 1,1,-1, // v0-v3-v4-v5
1,1,1, 1,1,-1, -4,1,-1, -4,1,1, // v0-v5-v6-v1
-4,1,1, -4,1,-1, -4,-1,-1, -4,-1,1, // v1-v6-v7-v2
-4,-1,-1, 1,-1,-1, 1,-1,1, -4,-1,1, // v7-v4-v3-v2
1,-1,-1, -4,-1,-1, -4,1,-1, 1,1,-1}; // v4-v7-v6-v5
GLfloat colors[] = {1,1,1, 1,1,0, 1,0,0, 1,0,1, // v0-v1-v2-v3
1,1,1, 1,0,1, 0,0,1, 0,1,1, // v0-v3-v4-v5
1,1,1, 0,1,1, 0,1,0, 1,1,0, // v0-v5-v6-v1
1,1,0, 0,1,0, 0,0,0, 1,0,0, // v1-v6-v7-v2
0,0,0, 0,0,1, 1,0,1, 1,0,0, // v7-v4-v3-v2
0,0,1, 0,0,0, 0,1,0, 0,1,1}; // v4-v7-v6-v5
void OBJECT(int x, int y, int z){
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glNormalPointer(GL_FLOAT, 0, normals);
glColorPointer(3, GL_FLOAT, 0, colors);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glPushMatrix();
glTranslatef(x, y, z); // Position Holder
glDrawArrays(GL_QUADS, 0, 24);
glPopMatrix();
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
}
Ok to use a bounding box around my object I’m understanding that I use a Min/Max value and wrap it around my object(poor understanding I know)
What I’ve tried / Doesn’t work
struct Vector3
{
float x;
float y;
float z;
};
struct BoundingBox
{
Vector3 Max;
Vector3 Min;
}OBJECT;
I've inserted this into the draw function for the OBJECT so I can see myself the box being drawn but none of this works because I'm not really understanding fully.
glBegin(GL_LINES);
glColor3f(255,0,0);
glVertex3f(aabb.m_xMin, aabb.m_yMin, aabb.m_zMin);
glVertex3f(aabb.m_xMin, aabb.m_yMin, aabb.m_zMax);
glVertex3f(aabb.m_xMax, aabb.m_yMin, aabb.m_zMin);
glVertex3f(aabb.m_xMax, aabb.m_yMin, aabb.m_zMax);
glVertex3f(aabb.m_xMin, aabb.m_yMax, aabb.m_zMin);
glVertex3f(aabb.m_xMin, aabb.m_yMax, aabb.m_zMax);
glEnd();
I know this is a complete mess but I’m just reading different bits of how to do it without ever seeing a full solution that will help me define my own bounding box.
Can anyone aid me to understand / or how to implement a bounding box for my object array please ~
Regards.