PDA

View Full Version : Cut an ellipsoid where you need (half, 3/4, y axis,...)



Cisne
01-14-2001, 09:53 AM
Hello everyone!
I make an ellipsoid whit parametric ecuations and I need cut in in several parts. I reached cut it on the x axis, but I can't do it, for example, on the y axis, or 3/4.

In the code, when I stop the curl because the variable y reaches the 0, in the window appears a single quad strip, rounded, as an ellipse, instead of a hlf ellipsoid complete.

Well, here is the code:

void medio_elipsoide(GLfloat rx, GLfloat ry, GLfloat rz)
/* rx, ry, rz: semiradious */
{
int const numc=20;
int const numt= 25;
int i, j, k;
double s, t, x, y, z, pi, twopi;
point3 n;

x=1;
pi = PI;
twopi= 2 * PI;
for (i = 0; (i < numc) && (x>0); i++) {
glBegin(GL_QUAD_STRIP);
for (j = 0; j <= numt; j++) {
for (k = 1; k >= 0; k--) {
s = (i + k) % numc + 0.0;
t = j % numt;

x = (rx*cos(s*pi/numc))*cos(t*twopi/numt);
y = (ry*cos(s*pi/numc))*sin(t*twopi/numt);
z = ry*sin(s * pi / numc);

getvector(n,x,y,z);
normalize(n);
glNormal3fv(n);

glVertex3f(x, y, z);
}
}
glEnd();
}


glBegin(GL_POLYGON);{

glNormal3f(0.0,0.0,-1.0);

for (j = numt; j >= 0; j--) {
t = j % numt;

x = rx*cos(t*twopi/numt);
y =ry*sin(t*twopi/numt);

glVertex3f(x, y, 0.0);
}
}glEnd();

}

Whit this, I make a semiellipsoid on the x axis, but How I can on the y?

This is the code for the complete ellipsoid:

void elipsoide(GLfloat rx, GLfloat ry, GLfloat rz)
{
int const numc=20;
int const numt= 25;
int i, j, k;
double s, t, x, y, z, twopi;
point3 n;

twopi= 2 * PI;
for (i = 0; i < numc; i++) {
glBegin(GL_QUAD_STRIP);
for (j = 0; j <= numt; j++) {
for (k = 1; k >= 0; k--) {
s = (i + k) % numc + 0.0;
t = j % numt;

x = (rx*cos(s*twopi/numc))*cos(t*twopi/numt);
y = (ry*cos(s*twopi/numc))*sin(t*twopi/numt);
z = rz*sin(s * twopi / numc);

getvector(n,x,y,z);
normalize(n);
glNormal3fv(n);

glVertex3f(x, y, z);
}
}
glEnd();
}
}


It's equal than other, except the condition of the first curl, and it doesn't draw the polygon of the base.

Thanks a lot.