I have assembled somes variations of tunnels versions and use a tunnel_version variable that select the wanted version :
int tunnel_version = 3;
void Tunnel(float x1, float y1, float z1, float width, float height, float x2, float y2, float z2)
{
switch(tunnel_version)
{
case 1 : Tunnel_v1(x1, y1, z1, width, height, x2, y2, z2); break;
case 2 : Tunnel_v2(x1, y1, z1, width, height, x2, y2, z2); break;
case 3 : Tunnel_v3(x1, y1, z1, width, height, x2, y2, z2); break;
default : Tunnel_v0(x1, y1, z1, width, height, x2, y2, z2); break;
}
// return;
}
void Tunnel_v0(float x1, float y1, float z1, float width, float height, float x2, float y2, float z2)
{
float x=x1;
float y=y1;
float dz=z2-z1;
float dx=(x2-x1)/dz;
float dy=(y2-y1)/dz;
float z;
glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_QUADS);
for( z=z1 ; z<z2 ;x+=dx, y+=dy, z++)
{
glVertex3f(x-width/2,y-height/2,z);
glVertex3f(x+width/2,y-height/2,z);
glVertex3f(x+width/2,y+height/2,z);
glVertex3f(x-width/2,y+height/2,z);
}
glEnd();
}
void Tunnel_v1(float x1, float y1, float z1, float width, float height, float x2, float y2, float z2)
{
// draw only quads at curve control points
glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_QUADS);
glVertex3f(x1-width/2,y1-height/2,z1);
glVertex3f(x1+width/2,y1-height/2,z1);
glVertex3f(x1+width/2,y1+height/2,z1);
glVertex3f(x1-width/2,y1+height/2,z1);
glEnd();
}
void Tunnel_v2(float x1, float y1, float z1, float width, float height, float x2, float y2, float z2)
{
// draw walls in wireframe
glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_QUADS);
glVertex3f(x1-width/2,y1-height/2,z1);
glVertex3f(x1+width/2,y1-height/2,z1);
glVertex3f(x2+width/2,y2-height/2,z2);
glVertex3f(x2-width/2,y2-height/2,z2);
glVertex3f(x1-width/2,y1-height/2,z1);
glVertex3f(x2-width/2,y2-height/2,z2);
glVertex3f(x2-width/2,y2+height/2,z2);
glVertex3f(x1-width/2,y1+height/2,z1);
glVertex3f(x1+width/2,y1-height/2,z1);
glVertex3f(x2+width/2,y2-height/2,z2);
glVertex3f(x2+width/2,y2+height/2,z2);
glVertex3f(x1+width/2,y1+height/2,z1);
glVertex3f(x1-width/2,y1+height/2,z1);
glVertex3f(x1+width/2,y1+height/2,z1);
glVertex3f(x2+width/2,y2+height/2,z2);
glVertex3f(x2-width/2,y2+height/2,z2);
glEnd();
}
void Tunnel_v3(float x1, float y1, float z1, float width, float height, float x2, float y2, float z2)
{
// draw the normal
float n[3], invlen;
n[0] = x2 - x1;
n[1] = y2 - y1;
n[2] = z2 - z1;
invlen = NORMALSIZE / sqrt( n[0]*n[0] + n[1]*n[1] + n[2]*n[2]);
n[0] *= invlen;
n[1] *= invlen;
n[2] *= invlen;
glColor3f(0.0f,1.0f,0.0f);
glBegin(GL_LINES);
glVertex3f(x1,y1,z1);
glVertex3f(x1+n[0], y1+n[1], z1+n[2]);
glEnd();
Tunnel_v2(x1, y1, z1, width, height, x2, y2, z2);
}
It’s from the P0(x1,y1,z1) and P1(x2,y2,z2) positions used into the Tunnel() switch function that you want to use for the generation of the “x=y=z mathematical formula” ?
Or alls (x,y,z) positions that satisfy the conditions x=y x=z and y=z ???
(cf. this seem intersection of 3D planes or something like this)