-
Notifications
You must be signed in to change notification settings - Fork 0
/
platonic.c
113 lines (106 loc) · 3.82 KB
/
platonic.c
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifdef __APPLE__
# include <OpenGL/gl.h>
# include <OpenGL/glu.h>
# include <GLUT/glut.h>
#else
# include <GL/gl.h>
# include <GL/glu.h>
# include <GL/glut.h>
#endif
#include "platonic.h"
////////////////////////////////////////////////////////
// OpenGL ES functions for platonic.h
// rendering points, lines, faces
// index convention for now:
// 0: tetrahedron
// 1: octahedron
// 2: hexahedron
// 3: icosahedron
// 4: dodecahedron
// 5: tetrahedron dual <- special case (same geometry as 0:tetrahedron, aligned differently)
unsigned int _poly_num_vertices[6] = {
TETRAHEDRON_POINT_COUNT, OCTAHEDRON_POINT_COUNT, HEXAHEDRON_POINT_COUNT, ICOSAHEDRON_POINT_COUNT, DODECAHEDRON_POINT_COUNT, TETRAHEDRON_POINT_COUNT
};
unsigned int _poly_num_lines[6] = {
TETRAHEDRON_LINE_COUNT, OCTAHEDRON_LINE_COUNT, HEXAHEDRON_LINE_COUNT, ICOSAHEDRON_LINE_COUNT, DODECAHEDRON_LINE_COUNT, TETRAHEDRON_LINE_COUNT
};
unsigned int _poly_num_faces[6] = {
TETRAHEDRON_FACE_COUNT, OCTAHEDRON_FACE_COUNT, HEXAHEDRON_TRIANGLE_FACE_COUNT, ICOSAHEDRON_FACE_COUNT, DODECAHEDRON_TRIANGLE_FACE_COUNT, TETRAHEDRON_FACE_COUNT
};
const float* _poly_point_arrays[6] = {
_tetrahedron_points, _octahedron_points, _hexahedron_points, _icosahedron_points, _dodecahedron_points, _tetrahedron_dual_points
};
const unsigned short* _poly_line_array[6] = {
_tetrahedron_lines, _octahedron_lines, _hexahedron_lines, _icosahedron_lines, _dodecahedron_lines, _tetrahedron_dual_lines
};
const unsigned short* _poly_face_array[6] = {
_tetrahedron_faces, _octahedron_faces, _hexahedron_triangle_faces, _icosahedron_faces, _dodecahedron_triangle_faces, _tetrahedron_dual_faces
};
int _poly_dual_index[6] = { 5, 2, 1, 4, 3, 0 };
float platonic_dihedral_angle[6] = {
TETRAHEDRON_DIHEDRAL_ANGLE,
OCTAHEDRON_DIHEDRAL_ANGLE,
HEXAHEDRON_DIHEDRAL_ANGLE,
ICOSAHEDRON_DIHEDRAL_ANGLE,
DODECAHEDRON_DIHEDRAL_ANGLE,
TETRAHEDRON_DIHEDRAL_ANGLE
};
float platonic_inradius[6] = {
TETRAHEDRON_INRADIUS,
OCTAHEDRON_INRADIUS,
HEXAHEDRON_INRADIUS,
ICOSAHEDRON_INRADIUS,
DODECAHEDRON_INRADIUS,
TETRAHEDRON_INRADIUS
};
float platonic_midradius[6] = {
TETRAHEDRON_MIDRADIUS,
OCTAHEDRON_MIDRADIUS,
HEXAHEDRON_MIDRADIUS,
ICOSAHEDRON_MIDRADIUS,
DODECAHEDRON_MIDRADIUS,
TETRAHEDRON_MIDRADIUS
};
float platonic_side_length[6] = {
TETRAHEDRON_SIDE_LENGTH,
OCTAHEDRON_SIDE_LENGTH,
HEXAHEDRON_SIDE_LENGTH,
ICOSAHEDRON_SIDE_LENGTH,
DODECAHEDRON_SIDE_LENGTH,
TETRAHEDRON_SIDE_LENGTH
};
float platonic_volume[6] = {
TETRAHEDRON_VOLUME,
OCTAHEDRON_VOLUME,
HEXAHEDRON_VOLUME,
ICOSAHEDRON_VOLUME,
DODECAHEDRON_VOLUME,
TETRAHEDRON_VOLUME
};
void drawPlatonicSolidFaces(char solidType){
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, _poly_point_arrays[solidType]);
glNormalPointer(GL_FLOAT, 0, _poly_point_arrays[ solidType ]);
glDrawElements(GL_TRIANGLES, 3*_poly_num_faces[solidType], GL_UNSIGNED_SHORT, _poly_face_array[solidType]);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}
void drawPlatonicSolidLines(char solidType){
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, _poly_point_arrays[solidType]);
glNormalPointer(GL_FLOAT, 0, _poly_point_arrays[ solidType ]);
glDrawElements(GL_LINES, 2*_poly_num_lines[solidType], GL_UNSIGNED_SHORT, _poly_line_array[solidType]);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}
void drawPlatonicSolidPoints(char solidType){
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, _poly_point_arrays[solidType]);
glNormalPointer(GL_FLOAT, 0, _poly_point_arrays[ solidType ]);
glDrawArrays(GL_POINTS, 0, _poly_num_vertices[solidType]);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}