include stdlib include stdio include ctype include math include glut i

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include "glut.h"
#include <vector>
#include <iostream>
using namespace std;
GLUnurbsObj* nobj;
GLfloat ctlarray[][3] = { { -0.9, -0.8, 0.0 },
{ -0.2, 0.8, 0.0 },
{ 0.2, -0.5, 0.0 },
{ 0.9, 0.8, 0.0 } };
GLfloat knot[60];
int degree = 3;
int pointCount = 4;
int knotSize = 0;
void Init() {
glClearColor(1.0, 1.0, 1.0, 1.0);
nobj = gluNewNurbsRenderer();
gluNurbsProperty(nobj, GLU_SAMPLING_TOLERANCE, 25.0);
}
void generateKnot() {
int k = degree + 1;
int n = pointCount - 1;
for (int i = 0; i < n + k + 1; ++i) {
if (i < k)
knot[i] = 0;
else if (i < n + 1)
knot[i] = i - k + 1;
else
knot[i] = n - k + 2;
}
knotSize = n + k + 1;
}
void Display() {
glClear(GL_COLOR_BUFFER_BIT);
glLineWidth(3.0);
for (int i = 0; i < 4; ++i) {
degree = i;
generateKnot();
glColor3f(3. / (i + 1), 2. / (i + 1), 1. / (i + 1));
gluNurbsCurve(nobj, knotSize, knot, 3, &ctlarray[0][0], degree + 1, GL_MAP1_VERTEX_3);
}
glPointSize(4.0);
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_POINTS);
for (int i = 0; i < 4; ++i) {
glVertex3fv(ctlarray[i]);
}
glEnd();
glFlush();
}
int main(int argc, char **argv)
{
glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
glutInitWindowSize(1024, 720);
glutInitWindowPosition(100, 100);
glutCreateWindow("olol");
Init();
glutDisplayFunc(Display);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}