📄 quad.c
字号:
for (i = 0; i < slices; i++) {
angle = 2 * PI * (i-0.5) / slices;
sinCache3a[i] = SIN(angle);
cosCache3a[i] = COS(angle);
}
for (j = 0; j <= stacks; j++) {
angle = PI * (j - 0.5) / stacks;
if (qobj->orientation == GLU_OUTSIDE) {
sinCache3b[j] = SIN(angle);
cosCache3b[j] = COS(angle);
} else {
sinCache3b[j] = -SIN(angle);
cosCache3b[j] = -COS(angle);
}
}
}
sinCache1a[slices] = sinCache1a[0];
cosCache1a[slices] = cosCache1a[0];
if (needCache2) {
sinCache2a[slices] = sinCache2a[0];
cosCache2a[slices] = cosCache2a[0];
}
if (needCache3) {
sinCache3a[slices] = sinCache3a[0];
cosCache3a[slices] = cosCache3a[0];
}
switch (qobj->drawStyle) {
case GLU_FILL:
/* Do ends of sphere as TRIANGLE_FAN's (if not texturing)
** We don't do it when texturing because we need to respecify the
** texture coordinates of the apex for every adjacent vertex (because
** it isn't a constant for that point)
*/
if (!(qobj->textureCoords)) {
start = 1;
finish = stacks - 1;
/* Low end first (j == 0 iteration) */
sintemp2 = sinCache1b[1];
zHigh = cosCache1b[1];
switch(qobj->normals) {
case GLU_FLAT:
sintemp3 = sinCache3b[1];
costemp3 = cosCache3b[1];
break;
case GLU_SMOOTH:
sintemp3 = sinCache2b[1];
costemp3 = cosCache2b[1];
glNormal3f(sinCache2a[0] * sinCache2b[0],
cosCache2a[0] * sinCache2b[0],
cosCache2b[0]);
break;
default:
break;
}
glBegin(GL_TRIANGLE_FAN);
glVertex3f(0.0, 0.0, radius);
if (qobj->orientation == GLU_OUTSIDE) {
for (i = slices; i >= 0; i--) {
switch(qobj->normals) {
case GLU_SMOOTH:
glNormal3f(sinCache2a[i] * sintemp3,
cosCache2a[i] * sintemp3,
costemp3);
break;
case GLU_FLAT:
if (i != slices) {
glNormal3f(sinCache3a[i+1] * sintemp3,
cosCache3a[i+1] * sintemp3,
costemp3);
}
break;
case GLU_NONE:
default:
break;
}
glVertex3f(sintemp2 * sinCache1a[i],
sintemp2 * cosCache1a[i], zHigh);
}
} else {
for (i = 0; i <= slices; i++) {
switch(qobj->normals) {
case GLU_SMOOTH:
glNormal3f(sinCache2a[i] * sintemp3,
cosCache2a[i] * sintemp3,
costemp3);
break;
case GLU_FLAT:
glNormal3f(sinCache3a[i] * sintemp3,
cosCache3a[i] * sintemp3,
costemp3);
break;
case GLU_NONE:
default:
break;
}
glVertex3f(sintemp2 * sinCache1a[i],
sintemp2 * cosCache1a[i], zHigh);
}
}
glEnd();
/* High end next (j == stacks-1 iteration) */
sintemp2 = sinCache1b[stacks-1];
zHigh = cosCache1b[stacks-1];
switch(qobj->normals) {
case GLU_FLAT:
sintemp3 = sinCache3b[stacks];
costemp3 = cosCache3b[stacks];
break;
case GLU_SMOOTH:
sintemp3 = sinCache2b[stacks-1];
costemp3 = cosCache2b[stacks-1];
glNormal3f(sinCache2a[stacks] * sinCache2b[stacks],
cosCache2a[stacks] * sinCache2b[stacks],
cosCache2b[stacks]);
break;
default:
break;
}
glBegin(GL_TRIANGLE_FAN);
glVertex3f(0.0, 0.0, -radius);
if (qobj->orientation == GLU_OUTSIDE) {
for (i = 0; i <= slices; i++) {
switch(qobj->normals) {
case GLU_SMOOTH:
glNormal3f(sinCache2a[i] * sintemp3,
cosCache2a[i] * sintemp3,
costemp3);
break;
case GLU_FLAT:
glNormal3f(sinCache3a[i] * sintemp3,
cosCache3a[i] * sintemp3,
costemp3);
break;
case GLU_NONE:
default:
break;
}
glVertex3f(sintemp2 * sinCache1a[i],
sintemp2 * cosCache1a[i], zHigh);
}
} else {
for (i = slices; i >= 0; i--) {
switch(qobj->normals) {
case GLU_SMOOTH:
glNormal3f(sinCache2a[i] * sintemp3,
cosCache2a[i] * sintemp3,
costemp3);
break;
case GLU_FLAT:
if (i != slices) {
glNormal3f(sinCache3a[i+1] * sintemp3,
cosCache3a[i+1] * sintemp3,
costemp3);
}
break;
case GLU_NONE:
default:
break;
}
glVertex3f(sintemp2 * sinCache1a[i],
sintemp2 * cosCache1a[i], zHigh);
}
}
glEnd();
} else {
start = 0;
finish = stacks;
}
for (j = start; j < finish; j++) {
zLow = cosCache1b[j];
zHigh = cosCache1b[j+1];
sintemp1 = sinCache1b[j];
sintemp2 = sinCache1b[j+1];
switch(qobj->normals) {
case GLU_FLAT:
sintemp4 = sinCache3b[j+1];
costemp4 = cosCache3b[j+1];
break;
case GLU_SMOOTH:
if (qobj->orientation == GLU_OUTSIDE) {
sintemp3 = sinCache2b[j+1];
costemp3 = cosCache2b[j+1];
sintemp4 = sinCache2b[j];
costemp4 = cosCache2b[j];
} else {
sintemp3 = sinCache2b[j];
costemp3 = cosCache2b[j];
sintemp4 = sinCache2b[j+1];
costemp4 = cosCache2b[j+1];
}
break;
default:
break;
}
glBegin(GL_QUAD_STRIP);
for (i = 0; i <= slices; i++) {
switch(qobj->normals) {
case GLU_SMOOTH:
glNormal3f(sinCache2a[i] * sintemp3,
cosCache2a[i] * sintemp3,
costemp3);
break;
case GLU_FLAT:
case GLU_NONE:
default:
break;
}
if (qobj->orientation == GLU_OUTSIDE) {
if (qobj->textureCoords) {
glTexCoord2f(1 - (float) i / slices,
1 - (float) (j+1) / stacks);
}
glVertex3f(sintemp2 * sinCache1a[i],
sintemp2 * cosCache1a[i], zHigh);
} else {
if (qobj->textureCoords) {
glTexCoord2f(1 - (float) i / slices,
1 - (float) j / stacks);
}
glVertex3f(sintemp1 * sinCache1a[i],
sintemp1 * cosCache1a[i], zLow);
}
switch(qobj->normals) {
case GLU_SMOOTH:
glNormal3f(sinCache2a[i] * sintemp4,
cosCache2a[i] * sintemp4,
costemp4);
break;
case GLU_FLAT:
glNormal3f(sinCache3a[i] * sintemp4,
cosCache3a[i] * sintemp4,
costemp4);
break;
case GLU_NONE:
default:
break;
}
if (qobj->orientation == GLU_OUTSIDE) {
if (qobj->textureCoords) {
glTexCoord2f(1 - (float) i / slices,
1 - (float) j / stacks);
}
glVertex3f(sintemp1 * sinCache1a[i],
sintemp1 * cosCache1a[i], zLow);
} else {
if (qobj->textureCoords) {
glTexCoord2f(1 - (float) i / slices,
1 - (float) (j+1) / stacks);
}
glVertex3f(sintemp2 * sinCache1a[i],
sintemp2 * cosCache1a[i], zHigh);
}
}
glEnd();
}
break;
case GLU_POINT:
glBegin(GL_POINTS);
for (j = 0; j <= stacks; j++) {
sintemp1 = sinCache1b[j];
costemp1 = cosCache1b[j];
switch(qobj->normals) {
case GLU_FLAT:
case GLU_SMOOTH:
sintemp2 = sinCache2b[j];
costemp2 = cosCache2b[j];
break;
default:
break;
}
for (i = 0; i < slices; i++) {
switch(qobj->normals) {
case GLU_FLAT:
case GLU_SMOOTH:
glNormal3f(sinCache2a[i] * sintemp2,
cosCache2a[i] * sintemp2,
costemp2);
break;
case GLU_NONE:
default:
break;
}
zLow = j * radius / stacks;
if (qobj->textureCoords) {
glTexCoord2f(1 - (float) i / slices,
1 - (float) j / stacks);
}
glVertex3f(sintemp1 * sinCache1a[i],
sintemp1 * cosCache1a[i], costemp1);
}
}
glEnd();
break;
case GLU_LINE:
case GLU_SILHOUETTE:
for (j = 1; j < stacks; j++) {
sintemp1 = sinCache1b[j];
costemp1 = cosCache1b[j];
switch(qobj->normals) {
case GLU_FLAT:
case GLU_SMOOTH:
sintemp2 = sinCache2b[j];
costemp2 = cosCache2b[j];
break;
default:
break;
}
glBegin(GL_LINE_STRIP);
for (i = 0; i <= slices; i++) {
switch(qobj->normals) {
case GLU_FLAT:
glNormal3f(sinCache3a[i] * sintemp2,
cosCache3a[i] * sintemp2,
costemp2);
break;
case GLU_SMOOTH:
glNormal3f(sinCache2a[i] * sintemp2,
cosCache2a[i] * sintemp2,
costemp2);
break;
case GLU_NONE:
default:
break;
}
if (qobj->textureCoords) {
glTexCoord2f(1 - (float) i / slices,
1 - (float) j / stacks);
}
glVertex3f(sintemp1 * sinCache1a[i],
sintemp1 * cosCache1a[i], costemp1);
}
glEnd();
}
for (i = 0; i < slices; i++) {
sintemp1 = sinCache1a[i];
costemp1 = cosCache1a[i];
switch(qobj->normals) {
case GLU_FLAT:
case GLU_SMOOTH:
sintemp2 = sinCache2a[i];
costemp2 = cosCache2a[i];
break;
default:
break;
}
glBegin(GL_LINE_STRIP);
for (j = 0; j <= stacks; j++) {
switch(qobj->normals) {
case GLU_FLAT:
glNormal3f(sintemp2 * sinCache3b[j],
costemp2 * sinCache3b[j],
cosCache3b[j]);
break;
case GLU_SMOOTH:
glNormal3f(sintemp2 * sinCache2b[j],
costemp2 * sinCache2b[j],
cosCache2b[j]);
break;
case GLU_NONE:
default:
break;
}
if (qobj->textureCoords) {
glTexCoord2f(1 - (float) i / slices,
1 - (float) j / stacks);
}
glVertex3f(sintemp1 * sinCache1b[j],
costemp1 * sinCache1b[j], cosCache1b[j]);
}
glEnd();
}
break;
default:
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -