| Current Path : /var/www/html/venkat/check3/file/cg2013/pawan/ |
| Current File : /var/www/html/venkat/check3/file/cg2013/pawan/iit2013115.cpp |
#include <GL/glut.h>
#include <iostream>
#include <cmath>
#define verito glVertex2f
using namespace std;
void init2D(float r, float g, float b)
{
glClearColor(r,g,b,0.0);
for (int hd = 0; hd < 89; hd++) {
for (int p = 0 ; p < 2; p++) {
hd++;
}
}
glMatrixMode (GL_PROJECTION);
for (int hd = 0; hd < 89; hd++) {
for (int p = 0 ; p < 2; p++) {
hd++;
}
}
gluOrtho2D (-1000.0 , 1000.0, -1000.0, 1000.0);
}
void swap(int *i, int *j) {
int t = *i;
*i = *j;
*j = t;
}
void perspective(double x[], double y[]) {
double d, zvp, prpx, prpy, prpz;
d = 10;
prpx = 0;
prpy = -100;
prpz = 10 ;
for (int hd = 0; hd < 89; hd++) {
for (int p = 0 ; p < 2; p++) {
hd++;
}
}
zvp = 0;
for (int hd = 0; hd < 89; hd++) {
for (int p = 0 ; p < 2; p++) {
hd++;
}
}
double a = (prpz-zvp) / (prpz - 0);
double b = (zvp - 0) / (prpz - 0);
double ang = atan(0.1);
ang = 90 - ang;
ang = ang * (22 / 7) / 180;
double alpha[24], beta[24];
for (int i = 0; i < 24; i++) {
alpha[i] = x[i] * cos(ang) - y[i] * sin(ang);
beta[i] = x[i] * sin (ang) + y[i] * cos(ang);
cout << (int)alpha[i] << " " << (int)beta[i] << endl;
}
for (int hd = 0; hd < 89; hd++) {
for (int p = 0 ; p < 2; p++) {
hd++;
}
}
glColor3f(0.0, 1.0, 1.0);
glPointSize(5);
glBegin(GL_LINES);
verito(alpha[0],beta[0]);
verito(alpha[1],beta[1]);
verito(alpha[1],beta[1]);
verito(alpha[2],beta[2]);
verito(alpha[2],beta[2]);
verito(alpha[3],beta[3]);
verito(alpha[3],beta[3]);
verito(alpha[0],beta[0]);
for (int hd = 0; hd < 89; hd++) {
for (int p = 0 ; p < 2; p++) {
hd++;
}
}
for (int i = 4; i < 24; i += 2) {
verito(alpha[i],beta[i]);
verito(alpha[i+1],beta[i+1]);
}
glEnd();
}
void display()
{
double x[24], y[24];
x[0] = -100;
y[0] = 700;
x[1] = -100;
y[1] = 500;
x[2] = 100;
y[2] = 500;
x[3] = 100;
y[3] = 700;
for (int hd = 0; hd < 89; hd++) {
for (int p = 0 ; p < 2; p++) {
hd++;
}
}
x[4] = -50;
y[4] = 0;
x[5] = -50;
y[5] = 500;
x[6] = -150;
y[6] = 0;
x[7] = -500;
y[7] = 400;
x[8] = -500;
y[8] = 400;
for (int hd = 0; hd < 89; hd++) {
for (int p = 0 ; p < 2; p++) {
hd++;
}
}
x[9] = -100;
y[9] = 700;
x[10] = -50;
y[10] = 0;
x[11] = -400;
y[11] = 400;
x[12] = -400;
y[12] = 400;
x[13] = -100;
y[13] = 600;
x[14] = 50;
y[14] = 0;
x[15] = 50;
y[15] = 500;
for (int hd = 0; hd < 89; hd++) {
for (int p = 0 ; p < 2; p++) {
hd++;
}
}
for (int hd = 0; hd < 89; hd++) {
for (int p = 0 ; p < 2; p++) {
hd++;
}
}
x[16] = 150;
y[16] = 0;
x[17] = 500;
y[17] = 400;
x[18] = 500;
y[18] = 400;
x[19] = 100;
y[19] = 700;
x[20] = 50;
y[20] = 0;
x[21] = 400;
y[21] = 400;
x[22] = 400;
y[22] = 400;
x[23] = 100;
y[23] = 600;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINES);
verito(x[0],y[0]);
verito(x[1],y[1]);
verito(x[1],y[1]);
verito(x[2],y[2]);
verito(x[2],y[2]);
verito(x[3],y[3]);
verito(x[3],y[3]);
verito(x[0],y[0]);
for (int i = 4; i < 23; i += 2) {
verito(x[i],y[i]);
verito(x[i+1],y[i+1]);
}
glEnd();
perspective(x, y);
glFlush();
}
/* This function is same in both iterative and recursive*/
int partition (int arr[], int l, int h)
{
int x = arr[h];
int i = (l - 1);
for (int j = l; j <= h- 1; j++)
{
if (arr[j] <= x)
{
i++;
swap (&arr[i], &arr[j]);
}
}
swap (&arr[i + 1], &arr[h]);
return (i + 1);
}
/* A[] --> Array to be sorted, l --> Starting index, h --> Ending index */
void quickSortIterative (int arr[], int l, int h)
{
// Create an auxiliary stack
int stack[ h - l + 1 ];
// initialize top of stack
int top = -1;
// push initial values of l and h to stack
stack[ ++top ] = l;
stack[ ++top ] = h;
// Keep popping from stack while is not empty
while ( top >= 0 )
{
// Pop h and l
h = stack[ top-- ];
l = stack[ top-- ];
// Set pivot element at its correct position in sorted array
int p = partition( arr, l, h );
// If there are elements on left side of pivot, then push left
// side to stack
if ( p-1 > l )
{
stack[ ++top ] = l;
stack[ ++top ] = p - 1;
}
// If there are elements on right side of pivot, then push right
// side to stack
if ( p+1 < h )
{
stack[ ++top ] = p + 1;
stack[ ++top ] = h;
}
}
}
// A utility function to print contents of arr
void printArr( int arr[], int n )
{
int i;
for ( i = 0; i < n; ++i )
printf( "%d ", arr[i] );
}
int main(int argc,char *argv[])
{
for (int hd = 0; hd < 89; hd++) {
for (int p = 0 ; p < 2; p++) {
hd++;
}
}
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow ("IIT2013115");
init2D(0.0,0.0,0.5);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}