| Current Path : /var/www/html/venkat/check3/file/cg2013/pawan/ |
| Current File : /var/www/html/venkat/check3/file/cg2013/pawan/IIT2013015_1.cpp |
#include <iostream>
#include <cmath>
#include <GL/gl.h>
#include <cstdlib>
#include <algorithm>
using namespace std;
int f = 0;
float a[4][2]; float b[3][2], l[5][4], aa[4][2], ll[5][4];
float m, c;
/*typedef struct {
float xx;
float yy;
float zz;
} Point;*/
float px, py, pz;
float zvp;
void perProFormula(float xx, float yy)
{
float a = (pz - zvp+10) / (pz);
double b = zvp / pz ;
//cout << xx << " " << yy << endl;
float nx = xx * a + px * b;
float ny = yy * a + py * b;
cout << nx << " " << ny << " " << 0 << endl;
}
void draw_line(int xa, int ya, int xb, int yb)
{
glPointSize(1.0f);
glBegin(GL_POINTS);
int dx = xb-xa, dy = yb-ya;
int steps, j;
float x = xa, y = ya, x_inc, y_inc;
if (abs(dx) > abs(dy)) {
steps = abs(dx);
} else {
steps = abs(dy);
}
steps *= 5;
x_inc = (float)((float)dx / (float)steps);
y_inc = (float)((float)dy / (float)steps);
glBegin(GL_POINTS);
glVertex2f(x, y);
for (j = 0; j < steps; j++) {
x += x_inc;
y += y_inc;
glVertex2f(x, y);
}
glEnd();
}
void print()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glOrtho(-1000.0, 1000.0, -1000.0, 1000.0, -1000.0, 1000.0);
float x1, x2, y1, y2;
for (int i = 0; i < 4; i++) {
x1 = a[i][0]; y1 = a[i][1];
x2 = a[(i+1)%4][0]; y2 = a[(i+1)%4][1];
draw_line(x1, y1, x2, y2);
}
for (int i = 0; i < 5; i++) {
x1 = l[i][0]; y1 = l[i][1];
x2 = l[i][2]; y2 = l[i][3];
//cout << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
draw_line(x1, y1, x2, y2);
}
//cout << "hi" << endl;
for (int i = 0; i < 4; i++) {
x1 = aa[i][0]; y1 = aa[i][1];
x2 = aa[(i+1)%4][0]; y2 = aa[(i+1)%4][1];
draw_line(x1, y1, x2, y2);
}
for (int i = 0; i < 5; i++) {
x1 = ll[i][0]; y1 = ll[i][1];
x2 = ll[i][2]; y2 = ll[i][3];
//cout << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
draw_line(x1, y1, x2, y2);
}
glFlush();
}
void reflection()
{
aa[0][0] = 100; aa[0][1] = 700;
aa[1][0] = 100; aa[1][1] = 500;
aa[2][0] = -100; aa[2][1] = 500;
aa[3][0] = -100; aa[3][1] = 700;
ll[0][0] = 50; ll[0][1] = 0; ll[0][2] = 50; ll[0][3] = 500;
ll[1][0] = 150; ll[1][1] = 0; ll[1][2] = 500; ll[1][3] = 400;
ll[2][0] = 500; ll[2][1] = 400; ll[2][2] = 100; ll[2][3] = 700;
ll[3][0] = 50; ll[3][1] = 0; ll[3][2] = 400; ll[3][3] = 400;
ll[4][0] = 400; ll[4][1] = 400; ll[4][2] = 100; ll[4][3] = 600;
}
int main(int argc, char** argv)
{
a[0][0] = -100; a[0][1] = 700;
a[1][0] = -100; a[1][1] = 500;
a[2][0] = 100; a[2][1] = 500;
a[3][0] = 100; a[3][1] = 700;
l[0][0] = -50; l[0][1] = 0; l[0][2] = -50; l[0][3] = 500;
l[1][0] = -150; l[1][1] = 0; l[1][2] = -500; l[1][3] = 400;
l[2][0] = -500; l[2][1] = 400; l[2][2] = -100; l[2][3] = 700;
l[3][0] = -50; l[3][1] = 0; l[3][2] = -400; l[3][3] = 400;
l[4][0] = -400; l[4][1] = 400; l[4][2] = -100; l[4][3] = 600;
px = 0; py = -100; pz = 10;
zvp = 10;
for (int i = 0; i < 4; i++) {
perProFormula(a[i][0], a[i][1]);
}
reflection();
for (int i = 0; i < 4; i++) {
perProFormula(a[i][0], a[i][1]);
}
for (int i = 0; i < 5; i++) {
perProFormula(l[i][0], l[i][1]);
perProFormula(l[i][2], l[i][3]);
}
for (int i = 0; i < 5; i++) {
perProFormula(ll[i][0], ll[i][1]);
perProFormula(ll[i][2], ll[i][3]);
}
return 0;
}