//*****************************************************************************************
// Disclaimer, Authorship and License
/*
	This code has been written to serve as a learning tool for the course MAE 410-574, 
	Virtual Reality Applications and Research, Spring 2007.
	
	Large parts of the code has been adapted from the examples given in the OpenGL 
	Programming Guide by Woo et. al and also from Computer Graphics Using OpenGL by FS Hill
	Some parts of the code has also been adapted from various resources available through 
	out the internet.I thank all those whose code and resources I have used to write these 
	examples. You may use this code for any non-commerical purpose. Feel free to include 
	and use parts of this code for your own application, but remember that this code is not
	entirely bug free, use it at your own risk..If you plan on using the code for your any 
	academic purpose please drop me an email. I would like to attach a link to your course 
	from my home page.

	The Author of this code is Govindarajan Srimathveeravalli, Dept. of Mech and Aero Eng. ,
	University at Buffalo.
*/
//******************************************************************************************
// This code demonstrates the use of GL_POINTS to draw points on the screen. Please make note
// that we create a new function called drawPoint( float, float ) to do the actual drawing. The
// advantage of this is that instead of having a number of OpenGL codes every time we draw a point
// we simply make a single function call and make the function do the drawing. Notice the second
// piece of commented code that draws a sinusoidal function over 't', uncomment it. Execute it and
// note the curve being plotted. Also, take notice of the use of gluOrtho2D function, it helps set 
// up a coordinate system for a given size (640*480) in this case.
// Try the following
// 1. Why do we use glVertex3f instead of say glVertex3i ?
// 2. Plot and ellipse with center at (0,0) instead of the circle.
// 3. Why does the sinusoid plotted seem skewed ?
// 4. Instead of the sinusoid try plotting e^t*cos(2*pi*t)

#include <math.h>
#include <glut.h>


void drawPoint( float x, float y, float z, float pointsize )
{
	glPointSize( pointsize );
	glBegin( GL_POINTS );
		glVertex3f( x, y, z );
	glEnd();
}
	
void reshape( int w, int h)
{

}

void display( )
{
	// nothing to see here, please move along

	// Clear the background before drawing
	glClear( GL_COLOR_BUFFER_BIT );

	// Coloring
	glColor3f( 1., 1., 1. );

	// Add code to draw points
	glColor3f( 1., 0., 0. );
	for( unsigned int i=0; i<100; i++ )
	{
		float angle = 2*3.14*i/100;
		drawPoint( 200.+50.*cos(angle), 200.+50.*sin(angle), 0., 5. );
	}

	// drawing the sine curve here
	 
	glColor3f( 0., 1., 0. );
	for(unsigned int i=0; i<1000; i++)
	{
		//float yVal = sin(i)
		drawPoint( (float)i/10., 200.+100.*sin(3.14*i/180.), 0., 1. );
	}

	// Ensure all drawing commands are executed
	glutSwapBuffers( );
}

void init ( )
{
	// Set the background 
	glClearColor( 0., 0., 0. , 0. );

	// Setting up a rudimentary camera
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity( );
	gluOrtho2D( 0, 640., 0, 480. );
}

int main(int argc, char* argv[])
{

	// Initialize a window with command line arguments
	glutInit( &argc, argv );
	// Provide window with buffering, coloring information
	//glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );
	glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB );
	// Position and Size the window
	glutInitWindowPosition( 50, 50 );
	glutInitWindowSize( 640, 480 );
	// Create the window with the given features with a 'suitable title'
	glutCreateWindow( "Hello World" );

	// do some initialization like setting up background color, camera, projection type etc.
	init( );

	// Assign a display 'callback function'
	glutDisplayFunc( display );

	// The reshape function is called everytime the window is relocated or resized ! duh
	glutReshapeFunc( reshape );

	// Enter the graphics loop
	glutMainLoop( );

	return 0;
}


