kotch curve opengl c 2b 2b

Solutions on MaxInterview for kotch curve opengl c 2b 2b by the best coders in the world

showing results for - "kotch curve opengl c 2b 2b"
Alina
17 Oct 2020
1
2#include <GL/glut.h>
3#include <math.h>
4#include <list>
5#include <iostream>
6#define PI 3.14159/180
7
8typedef struct _point {
9  float x;
10  float y;
11}point;
12
13using namespace std;
14
15/* Deklaracije callback funkcija. */
16static void on_display(void);
17
18int main(int argc, char **argv)
19{
20    /* Inicijalizuje se GLUT. */
21    glutInit(&argc, argv);
22    glutInitDisplayMode(GLUT_RGB | /*GLUT_DEPTH | */ GLUT_DOUBLE);
23
24    /* Kreira se prozor. */
25    glutInitWindowSize(800, 800);
26    glutInitWindowPosition(100, 100);
27    glutCreateWindow(argv[0]);
28    glEnable (GL_LINE_SMOOTH);
29    glEnable (GL_BLEND);
30    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
31    glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
32
33
34    /* Registruju se callback funkcije. */
35    glutDisplayFunc(on_display);
36
37    /* Obavlja se OpenGL inicijalizacija. */
38    glClearColor(0.75, 0.75, 0.75, 0);
39    glEnable(GL_DEPTH_TEST);
40
41    /* Program ulazi u glavnu petlju. */
42    glutMainLoop();
43
44    return 0;
45}
46
47static void on_display(void)
48{
49    /* Brise se prethodni sadrzaj prozora. */
50    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
51  
52    list<point> l;
53    list<point>::iterator i;
54    point niz[3];
55    point p1,p2;
56    
57    p1.x = -0.8;
58    p1.y = 0;
59    p2.x = 0.8;
60    p2.y = 0;
61    
62    l.push_back(p1);
63    l.push_back(p2);
64
65    int br_iteracija = 4;
66
67    while(br_iteracija > 0)
68    {
69        unsigned z = l.size();
70        int p = 1;
71        int j = 0;
72        while(p < z)
73        {
74            if(j==0)
75            {
76              i = l.begin();
77	      point pom1 = *i;
78              i++;
79	      point pom3 = *i;
80              niz[0].x = ((pom3.x-pom1.x)/3) + pom1.x;
81              niz[0].y = ((pom3.y-pom1.y)/3) + pom1.y;
82	      niz[2].x = (2*((pom3.x-pom1.x))/3) + pom1.x;
83	      niz[2].y = (2*((pom3.y-pom1.y))/3) + pom1.y;
84	      
85	      float r = sqrt(pow(niz[0].x-niz[2].x,2)+pow(niz[0].y-niz[2].y,2));
86	      float altitude = (r*sqrt(3.0))/2;
87	      float dx = niz[0].x - niz[2].x;
88	      
89	      point p;
90	      p.x = ((pom3.x-pom1.x)/2) + pom1.x;
91	      p.y = ((pom3.y-pom1.y)/2) + pom1.y;
92	      
93	      float slope = -dx / (niz[0].y-niz[2].y+0.000001);
94	      
95	      niz[1].x = sqrt(fabs(altitude*altitude - dx*dx)) / slope + p.x;
96	      niz[1].y = slope * (niz[1].x - p.x) + p.y;
97	      
98              l.insert(i,niz,niz+3);
99            }
100            else
101            {
102                point pom1 = *i;
103                i++;
104		point pom3 = *i;
105                niz[0].x = ((pom3.x-pom1.x)/3) + pom1.x;
106		niz[0].y = ((pom3.y-pom1.y)/3) + pom1.y;
107		niz[2].x = (2*((pom3.x-pom1.x))/3) + pom1.x;
108		niz[2].y = (2*((pom3.y-pom1.y))/3) + pom1.y;
109		
110		float r = sqrt(pow(niz[0].x-niz[2].x,2)+pow(niz[0].y-niz[2].y,2));
111		float altitude = (r*sqrt(3.0))/2;
112		float dx = niz[0].x - niz[2].x;
113		
114		point p;
115		p.x = ((pom3.x-pom1.x)/2) + pom1.x;
116		p.y = ((pom3.y-pom1.y)/2) + pom1.y;
117		
118		float slope = -dx / (niz[0].y-niz[2].y+0.000001);
119		
120		niz[1].x = sqrt(fabs(altitude*altitude - dx*dx)) / slope + p.x;
121		niz[1].y = slope * (niz[1].x - p.x) + p.y;
122		
123                l.insert(i,niz,niz+3);
124            }
125            p++;
126            j++;
127        }
128        br_iteracija--;
129    }
130
131    glColor3f(0,0,1);
132    //glPointSize(2);
133    list<point>::iterator it;
134    it = l.end();
135    it--;
136    
137      for(i = l.begin();i!=it;i++) {
138	glBegin(GL_LINES);
139	point tmp = *i;
140	i++;
141	point tmp2 = *i;
142	glVertex2f(tmp.x,tmp.y);
143	glVertex2f(tmp2.x,tmp2.y);
144	glEnd();
145	i--;
146      }
147
148    /* Nova slika se salje na ekran. */
149    glutSwapBuffers();
150}
151
152
153
similar questions
queries leading to this page
kotch curve opengl c 2b 2b