for my previous post,i have already done this.
OpenGL Programming/Bounding box - Wikibooks, open books for an open world
I am up to the stage of the cube,could it be using the looping function?
what kind of cube do there need?
I still need to translate it to the center of the object,
update::
i didn't use frontface ,back face and line loop method,glutWireCube also can work right?
I want to try the line loop method.
Code:
glColor3f(1.0,1.0,0.0);
GLfloat vertices[] = {
minX,minY,minZ,1.0,
maxX,minY,minZ,1.0,
maxX,maxY,minZ,1.0,
minX,maxY,minZ,1.0,
minX,minY,maxZ,1.0,
maxX,minY,maxZ,1.0,
maxX,maxY,maxZ,1.0,
minX,maxY,maxZ,1.0,
};
float sx,sy,sz;//size of the cube
sx = maxX - minX;
sy = maxY - minY;
sz = maxZ - minY;
float cx,cy,cz;//center of the object
cx = (maxX+minX)/2;
cy = (maxY+minY)/2;
cz = (maxZ+maxZ)/2;
glutSolidCube(1.0);//prepare the cube
OpenGL Programming/Bounding box - Wikibooks, open books for an open world
We analyze the object:
Minimum coordinates in X, Y and Z
Maximum coordinates in X, Y and Z
We compute the size necessary for the object: max-min in X, Y and Z
We compute the center of the object: (min+max)/2 in X, Y and Z
We compute of cube around the object:
We prepare a cube of size 1 (1x1x1), centered on the origin
We scale it by the size of the object
We center it on the object
To draw the cube:
We draw the front face using 1 looping line
We draw the back face using 1 looping line
We draw 4 orthogonal lines to join both faces
I am up to the stage of the cube,could it be using the looping function?
what kind of cube do there need?
I still need to translate it to the center of the object,
update::
Code:
float sx,sy,sz;//size of the cube
sx = maxX - minX;
sy = maxY - minY;
sz = maxZ - minY;
float cx,cy,cz;//center of the object
cx = (maxX+minX)/2;
cy = (maxY+minY)/2;
cz = (maxZ+maxZ)/2;
glScalef(sx,sy,sz);
glTranslatef(cx,cy,cz);
glutWireCube(10.0);//prepare the cube
i didn't use frontface ,back face and line loop method,glutWireCube also can work right?
I want to try the line loop method.
Last edited: