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/iit2013082_gvc.cpp

//#include <GL/glut.h>
#include <iostream>
#include <cmath>

using namespace std;

/*void init2D(float r, float g, float b)
{
	glClearColor(r,g,b,0.0);
	glMatrixMode (GL_PROJECTION);
	gluOrtho2D (-800.0, 800.0, -800.0, 800.0);
}*/

void perspective(int x[], int y[], int lx[], int ly[]) {
	int n2 = 10, n1 = 4;
	int eye[] = {0, -100, 10};
	int lookup[] = {0, 0, 0};
	int d = 10;
	float angle = 90 - (180*(atan(0.1)))/3.14;
	angle = angle*3.14/180.0;
	for(int i = 0; i < n1; i++) {
		int temp = x[i];
		x[i] = x[i]*cos(angle) - y[i]*sin(angle);
		y[i] = temp*sin(angle)+y[i]*cos(angle);

	}
	for(int i = 0; i < n2; i++) {
		int temp = lx[i];
		lx[i] = lx[i]*cos(angle) - ly[i]*sin(angle);
		ly[i] = temp*sin(angle)+ly[i]*cos(angle);

	}
	for(int i = 0; i < n1; i++) {
		cout << x[i] << "  " << y[i] << endl;
	}
	for(int i = 0; i < n2; i++) {
		cout << lx[i] << "  " << y[i] << endl;
	}
	for(int i = 0; i < n2; i++) {
                lx[i] = -lx[i];
                ly[i] = ly[i];
        }
	for(int i = 0; i < n2; i++) {
                int temp = lx[i];
                lx[i] = lx[i]*cos(angle) - ly[i]*sin(angle);
                ly[i] = temp*sin(angle)+ly[i]*cos(angle);

        }
	for(int i = 0; i < n1; i++) {
		cout << x[i] << "  " << y[i] << endl;
	}
	for(int i = 0; i < n2; i++) {
		cout << lx[i] << "  " << y[i] << endl;
	}
}

void display1() {
    int samples = 100;
    int x[] = {-100, 100, 100, -100};
    int y[] = {700, 700, 500, 500};
	int n = 4;
	int lx[] = {-50, -50, -150, -500, -500, -100, -50, -400, -400, -100};
	int ly[] = {0, 500, 0, 400, 400, 700, 0, 400, 400, 600};
	n = 10;
	perspective(x, y, lx, ly);
}
/*
void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0, 0.0, 0.0);

    glPointSize(1.0f);
    glBegin(GL_POINTS);
	 //square
    int samples = 100;
    int x[] = {-100, 100, 100, -100};
    int y[] = {700, 700, 500, 500};
	int n = 4;
    for (int i = 0; i < n; i++) {
        float dx = (x[(i+1)%n] - x[i]) / (float)samples;
        float dy = (y[(i+1)%n] - y[i]) / (float)samples;
        for( int j = 0; j < samples; j++ )
        {
            glVertex2i( x[i] + j * dx, y[i] + j * dy );
        }
    }
	// Line
	int lx[] = {-50, -50, -150, -500, -500, -100, -50, -400, -400, -100};
	int ly[] = {0, 500, 0, 400, 400, 700, 0, 400, 400, 600};
	n = 10;
	//int samples = 100;
    for (int i = 0; i < n; i += 2) {
        float dx = (lx[(i+1)%n] - lx[i]) / (float)samples;
        float dy = (ly[(i+1)%n] - ly[i]) / (float)samples;
        for( int j = 0; j < samples; j++ )
        {
            glVertex2i( lx[i] + j * dx, ly[i] + j * dy );
        }
    }
	//int lx1[20], ly1[20];
	for(int i = 0; i < n; i++) {
		lx[i] = -lx[i];
		ly[i] = ly[i];
	}
	
    	for (int i = 0; i < n; i += 2) {

        	float dx = (lx[(i+1)%n] - lx[i]) / (float)samples;
        	float dy = (ly[(i+1)%n] - ly[i]) / (float)samples;
        	for( int j = 0; j < samples; j++ ) {
            		glVertex2i( lx[i] + j * dx, ly[i] + j * dy );
        	}
    	}
	//rotate
/*	float angle = 90 - (180*(atan(0.1)))/3.14;
	angle = angle*3.14/180.0;
	int lx1[] = {-50, -50, -150, -500, -500, -100, -50, -400, -400, -100};
	int ly1[] = {0, 500, 0, 400, 400, 700, 0, 400, 400, 600};
	 for(int i = 0; i < 4; i++) {
                int temp = x[i];
                x[i] = x[i]*cos(angle) - y[i]*sin(angle);
                y[i] = temp*sin(angle)+y[i]*cos(angle);

        }
	for (int i = 0; i < n; i++) {
        float dx = (x[(i+1)%n] - x[i]) / (float)samples;
        float dy = (y[(i+1)%n] - y[i]) / (float)samples;
        for( int j = 0; j < samples; j++ )
        {
            glVertex2i( x[i] + j * dx, y[i] + j * dy );
        }
    }
        for(int i = 0; i < 10; i++) {
                int temp = lx[i];
                lx[i] = lx[i]*cos(angle) - ly[i]*sin(angle);
                ly[i] = temp*sin(angle)+ly[i]*cos(angle);

        }
        for (int i = 0; i < 10; i += 2) {

                float dx = (lx[(i+1)%n] - lx[i]) / (float)samples;
                float dy = (ly[(i+1)%n] - ly[i]) / (float)samples;
                for( int j = 0; j < samples; j++ ) {
                        glVertex2i( lx[i] + j * dx, ly[i] + j * dy );
                }
        }


        for(int i = 0; i < 10; i++) {
                int temp = lx1[i];
                lx1[i] = lx1[i]*cos(angle) - ly1[i]*sin(angle);
                ly1[i] = temp*sin(angle)+ly1[i]*cos(angle);

        }
	for (int i = 0; i < 10; i += 2) {

                float dx = (lx1[(i+1)%n] - lx1[i]) / (float)samples;
                float dy = (ly1[(i+1)%n] - ly1[i]) / (float)samples;
                for( int j = 0; j < samples; j++ ) {
                        glVertex2i( lx1[i] + j * dx, ly1[i] + j * dy );
                }
        }

        for(int i = 0; i < 10; i++) {
                int temp = lx[i];
                lx[i] = lx[i]*cos(angle) - ly[i]*sin(angle);
                ly[i] = temp*sin(angle)+ly[i]*cos(angle);

        }
	for (int i = 0; i < 10; i += 2) {

                float dx = (lx[(i+1)%n] - lx[i]) / (float)samples;
                float dy = (ly[(i+1)%n] - ly[i]) / (float)samples;
                for( int j = 0; j < samples; j++ ) {
                        glVertex2i( lx[i] + j * dx, ly[i] + j * dy );
                }
        }
	//perpective(x, y, lx, ly);

   	glEnd();
	glFlush();
}
*/
int main(int argc,char *argv[])
{
	//glutInit(&argc,argv);
	//glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
	//glutInitWindowSize (500, 500);
	//glutInitWindowPosition (100, 100);
	//glutCreateWindow ("Square");
	//init2D(0.0,0.0,0.0);
	//glutDisplayFunc(display);
	//glutMainLoop();
	display1();
	return 0;
}