I’ve implemented the 3D volume thingy and it almost works correctly
I’m rotating the model in respect to the X and the Y axis. When rotation about one single axis, everything is fine. However, if I rotate it about x and y axes, the texture and clipping planes rotate about different axes
I can’t seem to find what is causing this. I’m not even using the MODELVIEW matrix, just the texture matrix. Any help will be greatly appreciated.
I’ve closely followed dorbie’s example; here are some main parts of the code:
//-------------------------Texture Creation------------------------
glGenTextures(1,&ThreeDTexture);
glBindTexture(GL_TEXTURE_3D_EXT,ThreeDTexture);
glTexImage3DEXT(GL_TEXTURE_3D_EXT,0,GL_RGBA,64,64,64,0,GL_RGBA,GL_UNSIGNED_BYTE,data);
glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_WRAP_R_EXT, GL_CLAMP);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
glEnable(GL_TEXTURE_3D_EXT);
//----------------------Rotation and Clipping----------------------
double eqnxy1[] = {0.0, 0.0, 1.0, 0};
double eqnxy2[] = {0.0, 0.0, -1.0, 1};
double eqnxz1[] = {0.0, 1.0, 0.0, 0};
double eqnxz2[] = {0.0, -1.0, 0.0, 1};
double eqnzy1[] = {1.0, 0.0, 0.0, 0};
double eqnzy2[] = {-1.0, 0.0, 0.0, 1};
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(.5, .5, .5);
glRotatef(rotateY, 1,0,0);
glRotatef(rotateX, 0,1,0);
float textureRotationMatrix[16];
glGetFloatv(GL_TEXTURE_MATRIX, textureRotationMatrix);
for(i=0; i<4; i++) {
clipEquation[i]=0.0;
for(j=0; j<4; j++)
clipEquation[i]+=textureRotationMatrix[i*4+j]*eqnxy1[j];
}
for(i=0; i<3; i++)
clipEquation[i]/=clipEquation[3];
clipEquation[3] = 1.0;
glClipPlane(GL_CLIP_PLANE0, &clipEquation[0]);
if (clipping) glEnable(GL_CLIP_PLANE0);
//…and so on for all 6 clipping planes
//----------------------Finally, Rendering----------------------------
float planeS[] = {1,0,0,1};
float planeT[] = {0,1,0,1};
float planeR[] = {0,0,1,1};
glBindTexture(GL_TEXTURE_3D_EXT, ThreeDTexture);
glBegin(GL_QUADS);
for (float a = 0.0; a < 1.0; a += .02){
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGenfv(GL_S, GL_EYE_PLANE, planeS);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGenfv(GL_T, GL_EYE_PLANE, planeT);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGenfv(GL_R, GL_EYE_PLANE, planeR);
glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_3D_EXT,GL_TEXTURE_WRAP_R_EXT, GL_CLAMP);
glVertex3f(-1 ,-1 ,a);
glVertex3f(-1 ,1 ,a);
glVertex3f(1 ,1 ,a);
glVertex3f(1 ,-1 ,a);
}
glEnd();
[This message has been edited by PhilY (edited 06-13-2002).]
[This message has been edited by PhilY (edited 06-14-2002).]