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

#include <bits/stdc++.h>
#include <GL/glut.h>
#include <GL/gl.h>

using namespace std;

float square[4][2];
float line[5][4];
//float line2[5][4];

typedef struct {
    float x;
    float y;
    float z;
} Point;

Point p[100], perP[100];
Point prp;
int n;
double zvp,d;

Point ans[200];
int ind = 0;

void perProFormula(Point purana, Point prp, Point &perTransKarke, double whereViewScreenCutsZAxis);
void showPoint(Point jiskoDisplayKarnaHai); //only for x and y coordinates

float x1, y,x2,y2,slope,i,tmp,X3,Y3;
void draw_line(float X1, float Y1,float X2,float Y2){
    if(X1 != X2 && Y1 != Y2){
        slope = (Y2-Y1)/(X2-X1);
        tmp = 0.005;
        for(i = min(Y1,Y2); i <= max(Y1,Y2); i = i+tmp){
            Y3 = i;
            X3 = ((Y3-Y1)/slope) + X1;
            glVertex2f(X3,Y3);
        }
	}
    else if(X1 == X2 && Y1 != Y2){
            tmp = 0.005;
        for (i = min(Y1,Y2); i <= max(Y1,Y2); i = i + tmp){
            glVertex2f(X1,i);
        }
    }
    else if(X1 != X2 && Y1 == Y2){
            tmp = 0.005;
        for (i = min(X1,X2); i <= max(X1,X2); i = i + tmp){
            glVertex2f(i,Y1);
        }
    }
}
void display()
{
    glClearColor(0.0,0.0,0.0,0.0);
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0, 1.0, 1.0);
    glPointSize(1.0f);
	glBegin(GL_POINTS);
	///code starts here
	for (int i = 0; i < 4; i++)    	
	draw_line(square[i%4][0], square[i%4][1], square[(i+1)%4][0], square[(i+1)%4][1]);
	glBegin(GL_POINTS);
	for (int i = 0; i < 5; i++) {    	
	draw_line(line[i][0], line[i][1], line[(i)][2], line[(i)][3]);
        }
        for(int i = 0;i < 5;i++) {
          draw_line(-1*line[i][0],line[i][1],-1* line[i][2], line[i][3]);
        }
	//for(int l = 0;l < ind;l += 2) {
	//	draw_line(ans[l].x,ans[l+1].x,ans[l].y,ans[l+1].y);
	//}
	
    ///code ends here
	glEnd();
	glFlush();
}



void Point1()
{
	glutInitDisplayMode(GLUT_RGB);
	glutInitWindowSize (500, 500);
	glutInitWindowPosition (100, 100);
	glutCreateWindow ("IIT2013122_1");
	gluOrtho2D (-1000.0, 1000.0, -1000.0, 1000.0);
	glutDisplayFunc(display);
	//glutDisplayFunc(displayLine);
	glutMainLoop();
}

int main(int argc, char **args)
{
	glutInit(&argc, args);
  //  cin >> x1 >> y>>x2>>y2;
	square[0][0] = -100;
	square[0][1] = 700;
	
	square[1][0] = -100;
	square[1][1] = 500;

	square[2][0] = 100;
	square[2][1] = 500;
	
	square[3][0] = 100;
	square[3][1] = 700;

	line[0][0] = -50;
	line[0][1] = 0;
	line[0][2] = -50;
	line[0][3] = 500;

	line[1][0] = -150;
	line[1][1] = 0;
	line[1][2] = -500;
	line[1][3] = 400;

	line[2][0] = -500;
	line[2][1] = 400;
	line[2][2] = -100;
	line[2][3] = 700;

	line[3][0] = -50;
	line[3][1] = 0;
	line[3][2] = -400;
	line[3][3] = 400;

	line[4][0] = -400;
	line[4][1] = 400;
	line[4][2] = -100;
	line[4][3] = 600;
	prp.x = 0;
	prp.y = -100;
	prp.z = 10;
	d = 10;
	zvp = prp.z - d;
	n = 24;
	for(int i = 0;i < 5;i++) {
		 p[i].x = line[i][0];
		 p[i].y = line[i][1];p[i].z = 0;
    		perProFormula(p[i], prp, perP[i], zvp);
		p[i].x = line[i][2];
		p[i].y = line[i][3];
		perProFormula(p[i], prp, perP[i], zvp);
	}
	for(int i = 0;i < 4;i++) {
		p[i].x = square[i][0];
		 p[i].y = square[i][1];p[i].z = 0;
    		perProFormula(p[i], prp, perP[i], zvp);
	}
	for(int i = 0;i < 5;i++) {
		p[i].x = -1 * line[i][0];
		p[i].y = line[i][1];p[i].z = 0;
    		perProFormula(p[i], prp, perP[i], zvp);
		p[i].x = -1 * line[i][2];
		p[i].y = line[i][3];
		perProFormula(p[i], prp, perP[i], zvp);
	}
	
	/*glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE);
	glutInitWindowSize(500, 500);
	glutInitWindowPosition(10, 10);
	glutCreateWindow("Per Pro");
	glutDisplayFunc(display);
	glutMainLoop();
*/
	for(int i = 0;i < 4;i++) {
		cout << square[i][0] << " " << square[i][1] << endl;
	}
	for(int i = 0;i < 5;i++) {
		cout << line[i][0] << " " << line[i][1] << endl;
		cout << line[i][2] << " " << line[i][3] << endl;
	}
	for(int i = 0;i < 5;i++) {
		cout << -1 * line[i][0] << " " << line[i][1] << endl;
		cout << -1 * line[i][2] << " " << line[i][3] << endl;
	}
cout<<"new pro\n";
	for(int i = 0;i < ind;i++) {
		cout << ans[i].x << " " << ans[i].y << endl;
	}

    Point1();
    return 0;
}

void perProFormula(Point p, Point prp, Point &perP, double zvp)
{
	double a = (prp.z - zvp) / (prp.z - p.z);
	double b = (zvp - p.z) / (prp.z - p.z);

	perP.x = p.x * a + prp.x * b;
	perP.y = p.y * a + prp.y * b;
	
	//showPoint(p);
	showPoint(perP);
}

void showPoint(Point p) //only for x and y coordinates
{
    ans[ind].x = p.x;
    ans[ind].y = p.y;
    ind++;
} 

Displaying new_iit2013122_2.cpp.