PDA

View Full Version : Need help showing parallel lines during rotation



johnquinn888
10-21-2004, 07:40 AM
I am given two points (x1,y1,z1) and (x2, y2, z2).
I want to draw a parallel line on each side of the line created by connecting the two points.
I want the linesto be an constant, equal distance apart from the original line. I am doing a trackball-type matrix rotation with the mouse. I need the lines to stay parallel with the screen and keep the same distance apart.

Here's how i have it set up:

GLfloat x1, y1, z1, x2, y2, z2;
GLfloat xWidthApart, yWidthApart, zWidthApart;

//WidthApart function needs to be determined
WidthApart(&xWidthApart, &yWidthApart, &zWidthApart);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
//rotate around a vector
trackball_Matrix();
//rotate around x or y axis
glRotatef(xRot, 1.0f,0.0f, 0.0f);
glRotatef(yRot, 0.0f,1.0f, 0.0f);
//main body
glPushMatrix();
glBegin(GL_LINES);
glVertexf(x1-xWidthApart, y1-yWidthApart, z1-zWidthApart);
glVertexf(x2-xWidthApart, y2-yWidthApart, z2-zWidthApart);
glEnd();

glBegin(GL_LINES);
glVertexf(x1+xWidthApart, y1+yWidthApart, z1+zWidthApart);
glVertexf(x2+xWidthApart, y2+yWidthApart, z2+zWidthApart);
glEnd();
glPopMatrix();
glPopMatrix();