PDA

View Full Version : CSG demo



xfabio
10-16-2000, 12:08 AM
referring to the CSG demo (boolean operation between glut objects) : someone know how to to modify the original source in order to subtract two or more objects B from the base object A ?

Thanks in advance

Dodger
10-16-2000, 08:02 AM
The demo you talk about uses the stencil buffer to do the CSG?
If I'm not mistaken, to e.g. subtract more than one object (say B and C) from the base object A, you could set different stencil buffer bits for each object you want to subtract from the base, where you draw the back faces of the primitives to subtract.

I hope that made sense http://www.opengl.org/discussion_boards/ubb/wink.gif

xfabio
10-16-2000, 10:02 AM
Hi!

in few word what I want to do is a little emulator of a CNC machine : the solid A is in effect the piece I want to mill ( a rectangular box) and the solid B is the tool ( a cylinder). The solid B must follow a linestring inside the solid A and subtracting material . Ok. I started the project following the csg demo that you can find on this site, and as you say, use the stencil buffer. I modified the function that create the solid B as follow

/* original code * this is the solid B (the tool) in my project */
void sphere(void)
{
glLoadName(2);
glPushMatrix();
glTranslatef(sphere_x, sphere_y, sphere_z);
glColor3f(1.0, 1.0, 0.0);
glutSolidSphere(5.0, 16, 16);

glPopMatrix();
}

/* modified code */
void sphere(void)
{
double step;
glLoadName(2);
glPushMatrix();

for (step = 0 ; step < 10; step+=1)
{
glTranslatef(sphere_x+step, sphere_y, sphere_z);
glColor3f(1.0, 1.0, 0.0);
glutSolidSphere(5.0, 16, 16); /* or a cylinder */
}
glPopMatrix();
}


Ok. compile ang go and select B sub A from the menu and look the result . What's wrong in my modified code ? the result is right when subtract the odd solid but wrong on the even solid

Thanks !

Dodger
10-17-2000, 07:20 AM
What do you mean by odd and even solid?

Ok, if you want to subtract the same object multiple times your code looks like it makes sense to me. The only thing that I can imagine is the stencil function that might increment or decrement the wrong way. I don't have the original code so I can't say too much about it but I assume, that it's not prepared for subtracting multiple objects. If my perception of how it works is right, then the stencil buffer has to be left untouched where bits are already set (where a primitive to subtract from another has been already drawn), so that drawing it another time will not change the previously subtracted primitive.
Does that sound logical? http://www.opengl.org/discussion_boards/ubb/smile.gif