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

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

using namespace std;

double x1, x2, x3, x4, x5, x6, x7, x8, r;

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

Coordinate p[100], perpss[100];
Coordinate initeye;
int n;
double zvp;

void showCoordinate(Coordinate p)
{
    printf("(%d,%d,0)\n",((p.x+0.5)*10),((p.y+0.5)*10));
}

void persp(Coordinate p, Coordinate initeye, Coordinate &perps, double zvp)
{
	double a = (initeye.z - zvp) / (initeye.z - p.z);
	double b = (zvp - p.z) / (initeye.z - p.z);
	perps.x = p.x * a + initeye.x * b;
	perps.y = p.y * a + initeye.y * b;
	showCoordinate(perps);
}

/*void dda(double x1, double x2, double x3, double x4)
{
    double dx = (x3-x1);
    double dy = (x4-x2);
    double deltax, deltay;
    glBegin(GL_CoordinateS);
    if (dx*dy >= 0) {
        if (x1 > x3 || (x1 == x3 && x2 > x4)) {
            swap(x2, x4);
            swap(x1, x3);
        }
        if (abs(dy) <= abs(dx)) {
            deltax = 1;
            deltay = dy/dx;
        }
        else {
            deltax = dx/dy;
            deltay = 1;
        }
        while (x1 < x3 || x2 < x4) {
            glVertex2f(x1, x2);
            x1 += deltax;
            x2 += deltay;
        }
    }
    else {
        if (x1 > x3 || (x1 == x3 && x2 < x4)) {
            swap(x2, x4);
            swap(x1, x3);
        }
        if (abs(dy) <= abs(dx)) {
            deltax = 1;
            deltay = dy/dx;
        }
        else {
            deltax = -dx/dy;
            deltay = -1;
        }
        while (x1 < x3 || x2 > x4) {
            glVertex2f(x1, x2);
            x1 += deltax;
            x2 += deltay;
        }
    }
    glVertex2f(x3, x4);
    glEnd();

}*/

void rotate(double &x1, double &x2, double x, double y)
{
    x1 -= x;
    x2 -= y;

    double theta = 0.002;
    double tmpx, tmpy;
    tmpx = x1 * cos(theta) - x2 * sin(theta);
    tmpy = x1 * sin(theta) + x2 * cos(theta);

    x1 = tmpx;
    x2 = tmpy;

    x1 += x;
    x2 += y;
}

/*void rectangle()
{
    glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0, 1.0, 1.0);
	dda(x1, x2, x3, x4);
	dda(x3, x4, x5, x6);
	dda(x5, x6, x7, x8);
	dda(x7, x8, x1, x2);
	glFlush();
}*/
//void translate()

void display() {
   /* glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0, 1.0, 1.0);
    rectangle();
    dda(-50, 0,-50,500);
    dda(-150, 0,-500,400);
    dda(-500,400,-100,700);
    dda(-50, 0,-400,400);
    dda(-400, 400,-100,600);

    dda(50, 0,50,500);
    dda(150, 0,500,400);
    dda(500,400,100,700);
    dda(50, 0,400,400);
    dda(400, 400,100,600);
    */

    initeye.x/=10;
    initeye.y/=10;
    initeye.z/=10;

	for (int i = 0; i < n; i++) {
			p[i].x/=10;
    		p[i].y/=10;
    		p[i].z/=10;
    		persp(p[i], initeye, perpss[i], zvp);
	}
	//draw_Coordinate();
    //glEnd();
	//glFlush();
}

int main(int argc,char *argv[])
{
    //cin >> x1 >> x2 >> x3 >> x4 >> x7 >> x8 >> x5 >> x6;
    n = 24;
    initeye.x = 0;
    initeye.y = -100;
    initeye.z = 10;
    zvp = 10;
	p[0].x = -100; p[0].y = 700; p[0].z = 0;
	p[1].x = -100; p[1].y = 500; p[1].z = 0;
	p[2].x = 100; p[2].y = 700; p[2].z = 0;
	p[3].x = 100; p[3].y = 500; p[3].z = 0;
	p[4].x = -50; p[4].y = 0; p[4].z = 0;
	p[5].x = -50; p[5].y = 500; p[5].z = 0;
	p[6].x = -150; p[6].y = 0; p[6].z = 0;
	p[7].x = -500; p[7].y = 400; p[7].z = 0;
	p[8].x = -500; p[8].y = 400; p[8].z = 0;
	p[9].x = -100; p[9].y = 700; p[9].z = 0;
	p[10].x = -50; p[10].y = 0; p[10].z = 0;
	p[11].x = -400; p[11].y = 400; p[11].z = 0;
	p[12].x = -400; p[12].y = 400; p[12].z = 0;
	p[13].x = -100; p[13].y = 600; p[13].z = 0;
	p[14].x = 50; p[14].y = 0; p[14].z = 0;
	p[15].x = 50; p[15].y = 500; p[15].z = 0;
	p[16].x = 150; p[16].y = 0; p[16].z = 0;
	p[17].x = 500; p[17].y = 400; p[17].z = 0;
	p[18].x = 500; p[18].y = 400; p[18].z = 0;
	p[19].x = 100; p[19].y = 700; p[19].z = 0;
	p[20].x = 50; p[20].y = 0; p[20].z = 0;
	p[21].x = 400; p[21].y = 400; p[21].z = 0;
	p[22].x = 400; p[22].y = 400; p[22].z = 0;
	p[23].x = 100; p[23].y = 600; p[23].z = 0;
	x1 = p[0].x;
	x2 = p[0].y;
	x3 = p[1].x;
	x4 = p[1].y;
	x7 = p[2].x;
	x8 = p[2].y;
	x5 = p[3].x;
	x6 = p[3].y;
    //cin>>r;
    /*glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_RGB);
	glutInitWindowSize (1000, 1000);
	glutCreateWindow ("Graphics");
	gluOrtho2D (-800, 800.0, -800, 800.0);
	glutDisplayFunc(display);
	glutMainLoop();*/
    display();
    return 0;
}