| Current Path : /var/www/html/venkat/check3/file/cg2013/pawan/ |
| Current File : /var/www/html/venkat/check3/file/cg2013/pawan/iit2013082.cpp |
//#include <GL/glut.h>
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int MAX = 1000;
typedef struct {
double x;
double y;
double z;
} Point;
Point p[100], perP[100];
Point prp;
int n;
double zvp;
void perProFormula(Point purana, Point prp, Point &perTransKarke, double whereViewScreenCutsZAxis);
void showPoint(Point p); //only for x and y coordinates
void draw_point();
/*void drawPoint(double x, double y) {
glPointSize(2);
glBegin(GL_POINTS);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2f(x / MAX, y / MAX);
glEnd();
glFlush();
}
void drawLineDDA(double x1, double y1, double x2, double y2) {
glPointSize(2);
glBegin(GL_POINTS);
glColor3f(0.0f, 1.0f, 0.0f);
double dx = x2 - x1;
double dy = y2 - y1;
int i;
double p;
if (abs(dx) > abs(dy)) {
p = abs(dx);
} else {
p = abs(dy);
}
double incx = dx / p;
double incy = dy / p;
double x = x1, y = y1;
glVertex2f(x / MAX, y / MAX);
for (i = 0; i < p; i++) {
x += incx;
y += incy;
glVertex2f(x / MAX, y / MAX);
}
glEnd();
glFlush();
}*/
/*
void display() {
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glPointSize(5);
int x[4] = {-100, -100, 100, 100};
int y[4] = {700, 500, 500, 700};
int i;
for (i = 0; i < 4; i++) {
drawLineDDA(x[i], y[i], x[(i + 1) % 4], y[(i + 1) % 4]);
}
drawLineDDA(-50, 0, 50, 500);
drawLineDDA(-150, 0, -500, 400);
drawLineDDA(-500, 400, -100, 700);
drawLineDDA(-50, 0, -400, 400);
drawLineDDA(-400, 400, -100, 600);
drawLineDDA(50, 0, -50, 500);
drawLineDDA(150, 0, 500, 400);
drawLineDDA(500, 400, 100, 700);
drawLineDDA(50, 0, 400, 400);
drawLineDDA(400, 400, 100, 600);
for (int i = 0; i < 4; i++) {
drawLineDDA(perP[i].x, perP[i].y, perP[(i + 1) % 4].x, perP[(i + 1) % 4].y);
//cout << perP[i].x << " " << perP[i].y << " " << perP[(i + 1) % 4].x << " " << perP[(i + 1) % 4].y << endl;
}
for (int i = 4; i < 24; i += 2) {
drawLineDDA(perP[i].x, perP[i].y+10, perP[i + 1].x, perP[i + 1].y);
//cout << perP[i].x << " " << perP[i].y << " " << perP[(i + 1)].x << " " << perP[(i + 1)].y << endl;
}
glEnd();
glFlush();
//glutPostRedisplay();
}
*/
int main(int argc, char** argv) {
double theta = atan(0.1);
double xx = 10 - sin(theta) * 10;
cout << xx << endl;
prp.x = 0;
prp.y = -100;
prp.z = 10;
zvp = -5;
n = 24;
int x[] = {-100, -100, 100, 100, -50, 50, -150, -500, -500, -100, -50, -400, -400, -100, 50, -50, 150, 500, 500, 100, 50, 400, 400, 100};
int y[] = {700, 500, 500, 700, 0, 500, 0, 400, 400, 700, 0, 400, 400, 600, 0, 500, 0, 400, 400, 700, 0, 400, 400, 600};
for (int i = 0; i < n; i++) {
float a = atan(0.1);
p[i].x = x[i]/10;
p[i].y = y[i]/10;
p[i].z = 0;
perProFormula(p[i], prp, perP[i], zvp);
}
// glutInit(&argc, argv);
// glutCreateWindow("GVC LAB TEST");
// glutInitWindowSize(1000, 1000);
// glutInitWindowPosition(0, 0);
// glutDisplayFunc(display);
// glutMainLoop();
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(perP);
}
void showPoint(Point p) { //only for x and y coordinates
cout << p.x << "," << p.y << endl;
}