Your IP : 216.73.216.40


Current Path : /var/www/html/venkat/check3/file/cg2013/pawan/
Upload File :
Current File : /var/www/html/venkat/check3/file/cg2013/pawan/assign1_2.cpp

//RIT20130021
//1.2
/*
draw a line, line(float x1, float y1, float x2, float y2, int Np)
draw a line using closely placed points. 
If dx is the spacing between 2 points n x, the dx = |x1-x2|/Np. Np is the number points in the line.
Now keep changing N and check the time taken to execute your code(Use large N)
Plot time take with respect to N
*/
#include <GL/glut.h>
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

float round(float f)
{
	return (f+0.5);
}

void line(float x1, float y1, float x2, float y2, int steps)
{
	int k;
	float xincrement, dx, dy;
	float yincrement, x, y;

	dx = x2-x1;
	dy = y2-y1;
	float m = dy/dx;
	xincrement = (dx/float(steps));
	
	glColor3f(1.0,0.0,0.0);
	glPointSize(2.0);
	glBegin(GL_POINTS);
	glVertex3f(x1,y1,0.0);

	x = x1;
	y = y1;
	for (k = 1; k <= steps; k++) {
		x = x + xincrement;
		y = y1 + m*(x-x1);
	//	cout << "x = " << x << "y = " << y << endl;
		glVertex3f(x,y,0.0);
	}
	//	glVertex3f(0.0,0.4,0.0);
	glEnd();
}

void draw()
{
	//background color
	glClearColor(1.0,1.0,1.0,0);
	glClear(GL_COLOR_BUFFER_BIT);

	// draw
	line(0.0,0.4,0.75,0.75, 10000);
	glFlush();
}

int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	// single buffer
	glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
	glutInitWindowSize(500,500);
	glutInitWindowPosition(0, 0);
	glutCreateWindow("line using closely spaced points");
	// call to drawing function
	glutDisplayFunc(draw);
	// to show the window
	glutMainLoop();

	return 0;
}
































/*void line(float x1, float y1, float x2, float y2, int steps)
{
    int k;
    float xincrement, dx, dy;
    float yincrement, x, y;
    
    dx = x2-x1;
    dy = y2-y1;
    float m = dy/dx;
    xincrement = (dx/float(steps));
    
    glColor3f(1.0,0.0,0.0);
    glPointSize(2.0);
    glBegin(GL_POINTS);
    glVertex3f(x1,y1,0.0);
    
    x = x1;
    y = y1;
    for (k = 1; k <= steps; k++) {
        x = x + xincrement;
        y = y1 + m*(x-x1);
        //	cout << "x = " << x << "y = " << y << endl;
        glVertex3f(x,y,0.0);
    }
    //	glVertex3f(0.0,0.4,0.0);
    glEnd();
}

void draw()
{
    //background color
    glClearColor(1.0,1.0,1.0,0);
    glClear(GL_COLOR_BUFFER_BIT);
    
    // draw
    line(0.0,0.4,0.75,0.75, 10000);
    glFlush();
}*/