请问如何用OpenGL绘制两个球体之间的圆柱?
zhghl 2006-02-12 01:41:22 void COpenGLOcxCtrl::drawChannel( GLfloat x1, GLfloat y1, GLfloat z1, GLfloat x2, GLfloat y2, GLfloat z2 ){
GLfloat dx = abs(x2 - x1);
GLfloat dy = abs(y2 - y1);
GLfloat dz = abs(z2 - z1);
GLfloat distance = sqrt( dx*dx + dy*dy + dz*dz );
GLfloat sinx = dy / sqrt( dy*dy + dz*dz );
GLfloat argx = asin( sinx ) * 180.0f / 3.1415926f;
GLfloat siny = dy / sqrt( dy*dy + dx*dx );
GLfloat argy = asin( siny ) * 180.0f / 3.1415926f;
glPushMatrix();
glTranslatef(x1, y1, z1);
glutSolidSphere(0.001, 12, 12);
GLUquadric * mySphere;
mySphere = gluNewQuadric();
gluQuadricDrawStyle(mySphere, GLU_FILL);
gluQuadricNormals(mySphere, GLU_SMOOTH);
glRotated(argx, 1.0f, 0.0f, 0.0f);
glRotated(argy, 0.0f, 1.0f, 0.0f);
gluCylinder(mySphere, 0.001, 0.001, distance, 6, 1);
glPopMatrix();
glPushMatrix();
glTranslatef(x2, y2, z2);
glutSolidSphere(0.001, 12, 12);
glPopMatrix();
}
上面是我的思路,可是不结果不对,应该怎样实现?谢谢!