How come after running my program, the line never start from the first sphere and end at the second sphere? And what modification should i do to my program to make the drawing of the line connecting the 2 spheres by just pressing a key on my keyboard?
My program is wriiten like this:
#include <windows.h>
#include <gl\gl.h>
#include <gl\glut.h>
#include <iostream.h>
void init(void);
void display(void);
float x1,y1,z1,x2,y2,z2;
int main(int argc, char *argv[])
{
cout << “Enter the x1 coordinate of the 1st sphere(range between -1 to 1) :”;
cin >> x1;
cout << “Enter the y1 coordinate of the 1st sphere(range between -1 to 1) :”;
cin >> y1;
cout << “Enter the z1 coordinate of the 1st sphere(range between -1 to 1) :”;
cin >> z1;
cout << “Enter the x2 coordinate of the 2nd sphere(range between -1 to 1) :”;
cin >> x2;
cout << “Enter the y2 coordinate of the 2nd sphere(range between -1 to 1) :”;
cin >> y2;
cout << “Enter the z2 coordinate of the 2nd sphere(range between -1 to 1) :”;
cin >> z2;
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(700,700);
glutInitWindowPosition(550,300);
glutCreateWindow(“Fastrak Project”);
glutDisplayFunc(display);
init();
glutMainLoop();
return 0;
}
void init(void)
{
glClearColor(0.0f ,0.0f ,0.0f ,0.0f);
glClearDepth(1.0f);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)700/(GLfloat)700,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void display(void)
{
glTranslatef(0,0,-5.0f);
glRotatef(-65,1.0f,1.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3d(1.0,0.5,1.0);
glutWireCube(2.00);
glTranslatef(x1,y1,z1);
glColor3f(0.5,0.5,1.0);
glutSolidSphere(0.02,10,10);
glTranslatef(x2,y2,z2);
glColor3f(0.5,1.0,0.5);
glutSolidSphere(0.02,10,10);
glColor3f(1.0,1.0,0.0);
glBegin(GL_LINES);
glVertex3f(x1,y1,z1);
glVertex3f(x2,y2,z2);
glEnd();
glFlush();
glutSwapBuffers();
}