void drawScene(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glClear(GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
//glLoadIdentity(); //Reset the drawing perspective
glPushMatrix();
glTranslatef(0.0f, 0.0f, -5.0f); //Move forward 5 units into visible region
if((prevcoord[0]!=coordinates[0])&&(prevcoord[1]!=coordinates[1])){ //this if statement accounts for transmission lag
glPushMatrix(); //Save the current state of transformations
glPushName(1);
glColor3ub(255,255,255); //white
glBegin(GL_LINE_STRIP);
glVertex3f(prevcoord[0],prevcoord[1],prevcoord[2]);//initial line co-ordinate, needs to be updated to init GPSlocation
glVertex3f(coordinates[0],coordinates[1],coordinates[2]);
glEnd();
glPopName();
glPopMatrix();
//draws the red triangle with the current location of the igv
glPushMatrix(); //save previous translate and color
glPushName(2);
//glClear(GL_DEPTH_BUFFER_BIT);
glTranslatef(coordinates[0],coordinates[1],coordinates[2]);
glRotatef((360/(2*PI))*atan2(coordinates[1],coordinates[0]),coordinates[0],coordinates[1],coordinates[2]); //does rotation calc
//glRotatef((360/(2*PI))*atan2(coordinates[1],coordinates[0]),1,1,1); //does rotation calc
glColor3ub(255,0,0); //set to red
glBegin(GL_TRIANGLES);
glVertex2f(0,.05);
glVertex2f(0,-.05);
glVertex2f(.05,0);
glEnd();
glPopName();
glPopMatrix(); //restore previous translate and color
}
//this section erases the old triangle and overwrites it with a green dot
if((prevcoord[0]!=coordinates[0])&&(prevcoord[1]!=coordinates[1])){ //this if statement accounts for transmission lag
glPushMatrix(); //save previous translate and color
glPushName(3);
glTranslatef(prevcoord[0],prevcoord[1],prevcoord[2]);
glRotatef((360/(2*PI))*atan2(prevcoord[1],prevcoord[0]),prevcoord[0],prevcoord[1],prevcoord[2]);
//glRotatef((360/(2*PI))*atan2(prevcoord[1],prevcoord[0]),1,1,1);
glColor3ub(0,0,0); //set black
glBegin(GL_TRIANGLES);
glVertex2f(0,.05);
glVertex2f(0,-.05);
glVertex2f(.05,0);
glEnd();
glColor3ub(0,255,0); //set sphere to green
glutSolidSphere(.02,15,15); //radius, slices,stacks
glPopName();
glPopMatrix(); //restore previous translate and color
}
glPopMatrix();
glutSwapBuffers();
}