52 const real X = (real)0.525731112119133606;
53 const real Z = (real)0.850650808352039932;
54 std::vector< vec3 > verts;
55 verts.push_back(
vec3(-X, 0, Z) );
56 verts.push_back(
vec3(X, 0, Z) );
57 verts.push_back(
vec3(-X, 0, -Z) );
58 verts.push_back(
vec3(X, 0, -Z) );
59 verts.push_back(
vec3(0, Z, X) );
60 verts.push_back(
vec3(0, Z, -X) );
61 verts.push_back(
vec3(0, -Z, X) );
62 verts.push_back(
vec3(0, -Z, -X) );
63 verts.push_back(
vec3(Z, X, 0) );
64 verts.push_back(
vec3(-Z, X, 0) );
65 verts.push_back(
vec3(Z, -X, 0) );
66 verts.push_back(
vec3(-Z, -X, 0) );
69 1,4,0, 4,9,0, 4,5,9, 8,5,4, 1,8,4,
70 1,10,8, 10,3,8, 8,3,5, 3,2,5, 3,7,2,
71 3,10,7, 10,6,7, 6,11,7, 6,0,11, 6,1,0,
72 10,1,6, 11,0,9, 2,11,9, 5,2,9, 11,2,7
75 std::vector<int> indices;
76 for(
int i=0; i<4*5*3; ++i)
77 indices.push_back(idxs[i]);
84 for(
int i=0; i<detail; ++i)
86 std::vector<int> indices2;
87 std::vector< vec3 > verts2;
88 for(
int j=0, idx=0; j<(int)indices.size(); j+=3)
90 indices2.push_back(idx++); indices2.push_back(idx++); indices2.push_back(idx++);
91 indices2.push_back(idx++); indices2.push_back(idx++); indices2.push_back(idx++);
92 indices2.push_back(idx++); indices2.push_back(idx++); indices2.push_back(idx++);
93 indices2.push_back(idx++); indices2.push_back(idx++); indices2.push_back(idx++);
101 verts2.push_back(v1); verts2.push_back( a); verts2.push_back(c);
102 verts2.push_back( a); verts2.push_back(v2); verts2.push_back(b);
103 verts2.push_back( a); verts2.push_back( b); verts2.push_back(c);
104 verts2.push_back( c); verts2.push_back( b); verts2.push_back(v3);
112 real radius = diameter / 2;
114 coords->
resize( (
int)verts.size() );
115 norms->
resize( (
int)verts.size() );
116 for(
int i=0; i<(int)verts.size(); ++i )
118 coords->
at(i) = (
fvec3)(verts[i]*radius + pos);
125 for(
int i=0; i<(int)indices.size(); ++i)
141 #if defined(VL_OPENGL_ES1) || defined(VL_OPENGL_ES2) 151 static const int patch_idx[] = {
152 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
153 4, 17, 18, 19, 8, 20, 21, 22, 12, 23, 24, 25, 16, 26, 27, 28,
154 19, 29, 30, 31, 22, 32, 33, 34, 25, 35, 36, 37, 28, 38, 39, 40,
155 31, 41, 42, 1, 34, 43, 44, 5, 37, 45, 46, 9, 40, 47, 48, 13,
156 13, 14, 15, 16, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
157 16, 26, 27, 28, 52, 61, 62, 63, 56, 64, 65, 66, 60, 67, 68, 69,
158 28, 38, 39, 40, 63, 70, 71, 72, 66, 73, 74, 75, 69, 76, 77, 78,
159 40, 47, 48, 13, 72, 79, 80, 49, 75, 81, 82, 53, 78, 83, 84, 57,
160 57, 58, 59, 60, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
161 60, 67, 68, 69, 88, 97, 98, 99, 92, 100, 101, 102, 96, 103, 104, 105,
162 69, 76, 77, 78, 99, 106, 107, 108, 102, 109, 110, 111, 105, 112, 113, 114,
163 78, 83, 84, 57, 108, 115, 116, 85, 111, 117, 118, 89, 114, 119, 120, 93,
164 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
165 124, 137, 138, 121, 128, 139, 140, 125, 132, 141, 142, 129, 136, 143, 144, 133,
166 133, 134, 135, 136, 145, 146, 147, 148, 149, 150, 151, 152, 69, 153, 154, 155,
167 136, 143, 144, 133, 148, 156, 157, 145, 152, 158, 159, 149, 155, 160, 161, 69,
168 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177,
169 165, 178, 179, 162, 169, 180, 181, 166, 173, 182, 183, 170, 177, 184, 185, 174,
170 174, 175, 176, 177, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197,
171 177, 184, 185, 174, 189, 198, 199, 186, 193, 200, 201, 190, 197, 202, 203, 194,
172 204, 204, 204, 204, 207, 208, 209, 210, 211, 211, 211, 211, 212, 213, 214, 215,
173 204, 204, 204, 204, 210, 217, 218, 219, 211, 211, 211, 211, 215, 220, 221, 222,
174 204, 204, 204, 204, 219, 224, 225, 226, 211, 211, 211, 211, 222, 227, 228, 229,
175 204, 204, 204, 204, 226, 230, 231, 207, 211, 211, 211, 211, 229, 232, 233, 212,
176 212, 213, 214, 215, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245,
177 215, 220, 221, 222, 237, 246, 247, 248, 241, 249, 250, 251, 245, 252, 253, 254,
178 222, 227, 228, 229, 248, 255, 256, 257, 251, 258, 259, 260, 254, 261, 262, 263,
179 229, 232, 233, 212, 257, 264, 265, 234, 260, 266, 267, 238, 263, 268, 269, 242,
180 270, 270, 270, 270, 279, 280, 281, 282, 275, 276, 277, 278, 271, 272, 273, 274,
181 270, 270, 270, 270, 282, 289, 290, 291, 278, 286, 287, 288, 274, 283, 284, 285,
182 270, 270, 270, 270, 291, 298, 299, 300, 288, 295, 296, 297, 285, 292, 293, 294,
183 270, 270, 270, 270, 300, 305, 306, 279, 297, 303, 304, 275, 294, 301, 302, 271
187 static const float coords[] = {
188 1.4f, 0.0f, 2.4f, 1.4f, -0.784f, 2.4f, 0.784f, -1.4f, 2.4f, 0.0f, -1.4f, 2.4f, 1.3375f, 0.0f, 2.53125f,
189 1.3375f, -0.749f, 2.53125f, 0.749f, -1.3375f, 2.53125f, 0.0f, -1.3375f, 2.53125f, 1.4375f, 0.0f, 2.53125f,
190 1.4375f, -0.805f, 2.53125f, 0.805f, -1.4375f, 2.53125f, 0.0f, -1.4375f, 2.53125f, 1.5f, 0.0f, 2.4f, 1.5f,
191 -0.84f, 2.4f, 0.84f, -1.5f, 2.4f, 0.0f, -1.5f, 2.4f, -0.784f, -1.4f, 2.4f, -1.4f, -0.784f, 2.4f, -1.4f,
192 0.0f, 2.4f, -0.749f, -1.3375f, 2.53125f, -1.3375f, -0.749f, 2.53125f, -1.3375f, 0.0f, 2.53125f, -0.805f,
193 -1.4375f, 2.53125f, -1.4375f, -0.805f, 2.53125f, -1.4375f, 0.0f, 2.53125f, -0.84f, -1.5f, 2.4f, -1.5f,
194 -0.84f, 2.4f, -1.5f, 0.0f, 2.4f, -1.4f, 0.784f, 2.4f, -0.784f, 1.4f, 2.4f, 0.0f, 1.4f, 2.4f, -1.3375f,
195 0.749f, 2.53125f, -0.749f, 1.3375f, 2.53125f, 0.0f, 1.3375f, 2.53125f, -1.4375f, 0.805f, 2.53125f, -0.805f,
196 1.4375f, 2.53125f, 0.0f, 1.4375f, 2.53125f, -1.5f, 0.84f, 2.4f, -0.84f, 1.5f, 2.4f, 0.0f, 1.5f, 2.4f,
197 0.784f, 1.4f, 2.4f, 1.4f, 0.784f, 2.4f, 0.749f, 1.3375f, 2.53125f, 1.3375f, 0.749f, 2.53125f, 0.805f,
198 1.4375f, 2.53125f, 1.4375f, 0.805f, 2.53125f, 0.84f, 1.5f, 2.4f, 1.5f, 0.84f, 2.4f, 1.75f, 0.0f, 1.875f,
199 1.75f, -0.98f, 1.875f, 0.98f, -1.75f, 1.875f, 0.0f, -1.75f, 1.875f, 2.0f, 0.0f, 1.35f, 2.0f, -1.12f, 1.35f,
200 1.12f, -2.0f, 1.35f, 0.0f, -2.0f, 1.35f, 2.0f, 0.0f, 0.9f, 2.0f, -1.12f, 0.9f, 1.12f, -2.0f, 0.9f, 0.0f,
201 -2.0f, 0.9f, -0.98f, -1.75f, 1.875f, -1.75f, -0.98f, 1.875f, -1.75f, 0.0f, 1.875f, -1.12f, -2.0f, 1.35f,
202 -2.0f, -1.12f, 1.35f, -2.0f, 0.0f, 1.35f, -1.12f, -2.0f, 0.9f, -2.0f, -1.12f, 0.9f, -2.0f, 0.0f, 0.9f,
203 -1.75f, 0.98f, 1.875f, -0.98f, 1.75f, 1.875f, 0.0f, 1.75f, 1.875f, -2.0f, 1.12f, 1.35f, -1.12f, 2.0f,
204 1.35f, 0.0f, 2.0f, 1.35f, -2.0f, 1.12f, 0.9f, -1.12f, 2.0f, 0.9f, 0.0f, 2.0f, 0.9f, 0.98f, 1.75f,
205 1.875f, 1.75f, 0.98f, 1.875f, 1.12f, 2.0f, 1.35f, 2.0f, 1.12f, 1.35f, 1.12f, 2.0f, 0.9f, 2.0f, 1.12f, 0.9f,
206 2.0f, 0.0f, 0.45f, 2.0f, -1.12f, 0.45f, 1.12f, -2.0f, 0.45f, 0.0f, -2.0f, 0.45f, 1.5f, 0.0f, 0.225f, 1.5f,
207 -0.84f, 0.225f, 0.84f, -1.5f, 0.225f, 0.0f, -1.5f, 0.225f, 1.5f, 0.0f, 0.15f, 1.5f, -0.84f, 0.15f, 0.84f,
208 -1.5f, 0.15f, 0.0f, -1.5f, 0.15f, -1.12f, -2.0f, 0.45f, -2.0f, -1.12f, 0.45f, -2.0f, 0.0f, 0.45f, -0.84f,
209 -1.5f, 0.225f, -1.5f, -0.84f, 0.225f, -1.5f, 0.0f, 0.225f, -0.84f, -1.5f, 0.15f, -1.5f, -0.84f, 0.15f,
210 -1.5f, 0.0f, 0.15f, -2.0f, 1.12f, 0.45f, -1.12f, 2.0f, 0.45f, 0.0f, 2.0f, 0.45f, -1.5f, 0.84f, 0.225f,
211 -0.84f, 1.5f, 0.225f, 0.0f, 1.5f, 0.225f, -1.5f, 0.84f, 0.15f, -0.84f, 1.5f, 0.15f, 0.0f, 1.5f, 0.15f,
212 1.12f, 2.0f, 0.45f, 2.0f, 1.12f, 0.45f, 0.84f, 1.5f, 0.225f, 1.5f, 0.84f, 0.225f, 0.84f, 1.5f, 0.15f, 1.5f,
213 0.84f, 0.15f, -1.6f, 0.0f, 2.025f, -1.6f, -0.3f, 2.025f, -1.5f, -0.3f, 2.25f, -1.5f, 0.0f, 2.25f, -2.3f,
214 0.0f, 2.025f, -2.3f, -0.3f, 2.025f, -2.5f, -0.3f, 2.25f, -2.5f, 0.0f, 2.25f, -2.7f, 0.0f, 2.025f, -2.7f,
215 -0.3f, 2.025f, -3.0f, -0.3f, 2.25f, -3.0f, 0.0f, 2.25f, -2.7f, 0.0f, 1.8f, -2.7f, -0.3f, 1.8f, -3.0f, -0.3f,
216 1.8f, -3.0f, 0.0f, 1.8f, -1.5f, 0.3f, 2.25f, -1.6f, 0.3f, 2.025f, -2.5f, 0.3f, 2.25f, -2.3f, 0.3f, 2.025f,
217 -3.0f, 0.3f, 2.25f, -2.7f, 0.3f, 2.025f, -3.0f, 0.3f, 1.8f, -2.7f, 0.3f, 1.8f, -2.7f, 0.0f, 1.575f, -2.7f,
218 -0.3f, 1.575f, -3.0f, -0.3f, 1.35f, -3.0f, 0.0f, 1.35f, -2.5f, 0.0f, 1.125f, -2.5f, -0.3f, 1.125f, -2.65f,
219 -0.3f, 0.9375f, -2.65f, 0.0f, 0.9375f, -2.0f, -0.3f, 0.9f, -1.9f, -0.3f, 0.6f, -1.9f, 0.0f, 0.6f, -3.0f, 0.3f,
220 1.35f, -2.7f, 0.3f, 1.575f, -2.65f, 0.3f, 0.9375f, -2.5f, 0.3f, 1.125f, -1.9f, 0.3f, 0.6f, -2.0f, 0.3f, 0.9f,
221 1.7f, 0.0f, 1.425f, 1.7f, -0.66f, 1.425f, 1.7f, -0.66f, 0.6f, 1.7f, 0.0f, 0.6f, 2.6f, 0.0f, 1.425f, 2.6f,
222 -0.66f, 1.425f, 3.1f, -0.66f, 0.825f, 3.1f, 0.0f, 0.825f, 2.3f, 0.0f, 2.1f, 2.3f, -0.25f, 2.1f, 2.4f, -0.25f,
223 2.025f, 2.4f, 0.0f, 2.025f, 2.7f, 0.0f, 2.4f, 2.7f, -0.25f, 2.4f, 3.3f, -0.25f, 2.4f, 3.3f, 0.0f, 2.4f, 1.7f,
224 0.66f, 0.6f, 1.7f, 0.66f, 1.425f, 3.1f, 0.66f, 0.825f, 2.6f, 0.66f, 1.425f, 2.4f, 0.25f, 2.025f, 2.3f, 0.25f,
225 2.1f, 3.3f, 0.25f, 2.4f, 2.7f, 0.25f, 2.4f, 2.8f, 0.0f, 2.475f, 2.8f, -0.25f, 2.475f, 3.525f, -0.25f, 2.49375f,
226 3.525f, 0.0f, 2.49375f, 2.9f, 0.0f, 2.475f, 2.9f, -0.15f, 2.475f, 3.45f, -0.15f, 2.5125f, 3.45f, 0.0f, 2.5125f,
227 2.8f, 0.0f, 2.4f, 2.8f, -0.15f, 2.4f, 3.2f, -0.15f, 2.4f, 3.2f, 0.0f, 2.4f, 3.525f, 0.25f, 2.49375f, 2.8f,
228 0.25f, 2.475f, 3.45f, 0.15f, 2.5125f, 2.9f, 0.15f, 2.475f, 3.2f, 0.15f, 2.4f, 2.8f, 0.15f, 2.4f, 0.0f, 0.0f,
229 3.15f, 0.0f, -0.002f, 3.15f, 0.002f, 0.0f, 3.15f, 0.8f, 0.0f, 3.15f, 0.8f, -0.45f, 3.15f, 0.45f, -0.8f, 3.15f,
230 0.0f, -0.8f, 3.15f, 0.0f, 0.0f, 2.85f, 0.2f, 0.0f, 2.7f, 0.2f, -0.112f, 2.7f, 0.112f, -0.2f, 2.7f, 0.0f, -0.2f,
231 2.7f, -0.002f, 0.0f, 3.15f, -0.45f, -0.8f, 3.15f, -0.8f, -0.45f, 3.15f, -0.8f, 0.0f, 3.15f, -0.112f, -0.2f, 2.7f,
232 -0.2f, -0.112f, 2.7f, -0.2f, 0.0f, 2.7f, 0.0f, 0.002f, 3.15f, -0.8f, 0.45f, 3.15f, -0.45f, 0.8f, 3.15f, 0.0f,
233 0.8f, 3.15f, -0.2f, 0.112f, 2.7f, -0.112f, 0.2f, 2.7f, 0.0f, 0.2f, 2.7f, 0.45f, 0.8f, 3.15f, 0.8f, 0.45f, 3.15f,
234 0.112f, 0.2f, 2.7f, 0.2f, 0.112f, 2.7f, 0.4f, 0.0f, 2.55f, 0.4f, -0.224f, 2.55f, 0.224f, -0.4f, 2.55f, 0.0f,
235 -0.4f, 2.55f, 1.3f, 0.0f, 2.55f, 1.3f, -0.728f, 2.55f, 0.728f, -1.3f, 2.55f, 0.0f, -1.3f, 2.55f, 1.3f, 0.0f,
236 2.4f, 1.3f, -0.728f, 2.4f, 0.728f, -1.3f, 2.4f, 0.0f, -1.3f, 2.4f, -0.224f, -0.4f, 2.55f, -0.4f, -0.224f, 2.55f,
237 -0.4f, 0.0f, 2.55f, -0.728f, -1.3f, 2.55f, -1.3f, -0.728f, 2.55f, -1.3f, 0.0f, 2.55f, -0.728f, -1.3f, 2.4f, -1.3f,
238 -0.728f, 2.4f, -1.3f, 0.0f, 2.4f, -0.4f, 0.224f, 2.55f, -0.224f, 0.4f, 2.55f, 0.0f, 0.4f, 2.55f, -1.3f, 0.728f,
239 2.55f, -0.728f, 1.3f, 2.55f, 0.0f, 1.3f, 2.55f, -1.3f, 0.728f, 2.4f, -0.728f, 1.3f, 2.4f, 0.0f, 1.3f, 2.4f,
240 0.224f, 0.4f, 2.55f, 0.4f, 0.224f, 2.55f, 0.728f, 1.3f, 2.55f, 1.3f, 0.728f, 2.55f, 0.728f, 1.3f, 2.4f, 1.3f,
241 0.728f, 2.4f, 0.0f, 0.0f, 0.0f, 1.5f, 0.0f, 0.15f, 1.5f, 0.84f, 0.15f, 0.84f, 1.5f, 0.15f, 0.0f, 1.5f, 0.15f,
242 1.5f, 0.0f, 0.075f, 1.5f, 0.84f, 0.075f, 0.84f, 1.5f, 0.075f, 0.0f, 1.5f, 0.075f, 1.425f, 0.0f, 0.0f, 1.425f,
243 0.798f, 0.0f, 0.798f, 1.425f, 0.0f, 0.0f, 1.425f, 0.0f, -0.84f, 1.5f, 0.15f, -1.5f, 0.84f, 0.15f, -1.5f, 0.0f,
244 0.15f, -0.84f, 1.5f, 0.075f, -1.5f, 0.84f, 0.075f, -1.5f, 0.0f, 0.075f, -0.798f, 1.425f, 0.0f, -1.425f, 0.798f,
245 0.0f, -1.425f, 0.0f, 0.0f, -1.5f, -0.84f, 0.15f, -0.84f, -1.5f, 0.15f, 0.0f, -1.5f, 0.15f, -1.5f, -0.84f, 0.075f,
246 -0.84f, -1.5f, 0.075f, 0.0f, -1.5f, 0.075f, -1.425f, -0.798f, 0.0f, -0.798f, -1.425f, 0.0f, 0.0f, -1.425f, 0.0f,
247 0.84f, -1.5f, 0.15f, 1.5f, -0.84f, 0.15f, 0.84f, -1.5f, 0.075f, 1.5f, -0.84f, 0.075f, 0.798f, -1.425f, 0.0f, 1.425f,
254 for(
int i=0; i<32; ++i)
257 for(
int j=0; j<16; ++j)
259 int idx = patch_idx[j+16*i]-1;
260 VL_CHECK(idx <
sizeof(coords) / coords[0])
277 #if defined(VL_OPENGL_ES1) || defined(VL_OPENGL_ES2) 289 diameter = diameter / 2.0f;
294 vert3->
resize( theta * phi + 2 );
296 vert3->
at(vert_idx++) = (
fvec3)(
vec3(0,1*diameter,0) + origin);
297 for(
int i=0; i<theta; ++i)
299 for(
int j=0; j<phi; ++j)
302 vec3 v(0,1*diameter,0);
305 vert3->
at(vert_idx++) = (
fvec3)(v+origin);
308 vert3->
at(vert_idx++) = (
fvec3)(
vec3(0,-1*diameter,0) + origin);
316 for(
int i=0; i<theta-1; ++i)
318 for(
int j=0; j<phi; ++j)
335 for(
int j=0; j<phi; ++j)
342 for(
int j=0; j<phi; ++j)
349 #if defined(VL_OPENGL_ES1) || defined(VL_OPENGL_ES2) 361 diameter = diameter / 2;
367 vert3->
resize( theta * phi + (top?phi+1:0) + (bottom?phi+1:0) );
369 for(
int i=0; i<theta; ++i)
371 for(
int j=0; j<phi; ++j)
373 vec3 v(1*diameter, 1*height - 2*height*((real)i/(theta-1)), 0);
375 vert3->
at(vert_idx++) = (
fvec3)(v + origin);
385 for(
int i=0; i<theta-1; ++i)
387 for(
int j=0; j<phi; ++j)
405 int fan_center = vert_idx;
406 vert3->
at(vert_idx++) = (
fvec3)(
vec3(0, height, 0) + origin);
407 for(
int j=0; j<phi; ++j)
409 vec3 v(1*diameter, height, 0);
411 vert3->
at(vert_idx++) = (
fvec3)(v + origin);
416 for(
int j=0; j<phi+1; ++j)
427 int fan_center = vert_idx;
428 vert3->
at(vert_idx++) = (
fvec3)(
vec3(0, -height, 0) + origin);
429 for(
int j=0; j<phi; ++j)
431 vec3 v(1*diameter, - height, 0);
433 vert3->
at(vert_idx++) = (
fvec3)(v + origin);
438 for(
int j=0; j<phi+1; ++j)
439 tris->
indexBuffer()->
at(idx++) = 1+fan_center+(phi -1 - j%phi);
442 #if defined(VL_OPENGL_ES1) || defined(VL_OPENGL_ES2) 456 const real radius = diameter / 2.0f - thickness;
461 vert3->
resize( (phi+1) * (theta+1) );
466 norm3->
resize( (phi+1) * (theta+1) );
473 texc2->
resize( (phi+1) * (theta+1) );
477 for(
int i=0; i<theta+1; ++i)
479 for(
int j=0; j<phi+1; ++j)
481 vec3 v(thickness, 0, 0);
482 vec3 o(radius, 0, 0);
488 texc2->
at(vect_idx) =
fvec2((
float)i/theta,(
float)j/phi) * tex_coords;
490 vert3->
at(vect_idx) = (
fvec3)(v + o + origin);
503 for(
int i=0; i<theta; ++i)
505 for(
int j=0; j<phi; ++j)
515 #if defined(VL_OPENGL_ES1) || defined(VL_OPENGL_ES2) 529 return makeBox( (min+max)*0.5, max.
x()-min.
x(), max.
y()-min.
y(), max.
z()-min.
z(), tex_coords );
562 #if defined(VL_OPENGL) 576 memcpy(vert3->
ptr(), verts,
sizeof(verts));
591 memcpy(tex_array->
ptr(), texc,
sizeof(texc));
597 a1, a2, a3, a3, a0, a1,
598 a2, a6, a7, a7, a3, a2,
599 a6, a5, a4, a4, a7, a6,
600 a5, a1, a0, a0, a4, a5,
601 a0, a3, a7, a7, a4, a0,
602 a5, a6, a2, a2, a1, a5
608 memcpy(vert3->
ptr(), verts,
sizeof(verts));
613 fvec2(0,1),
fvec2(0,0),
fvec2(1,0),
fvec2(1,0),
fvec2(1,1),
fvec2(0,1),
614 fvec2(0,1),
fvec2(0,0),
fvec2(1,0),
fvec2(1,0),
fvec2(1,1),
fvec2(0,1),
615 fvec2(1,0),
fvec2(1,1),
fvec2(0,1),
fvec2(0,1),
fvec2(0,0),
fvec2(1,0),
616 fvec2(0,1),
fvec2(0,0),
fvec2(1,0),
fvec2(1,0),
fvec2(1,1),
fvec2(0,1),
617 fvec2(0,0),
fvec2(1,0),
fvec2(1,1),
fvec2(1,1),
fvec2(0,1),
fvec2(0,0),
618 fvec2(1,1),
fvec2(0,1),
fvec2(0,0),
fvec2(0,0),
fvec2(1,0),
fvec2(1,1),
623 memcpy(tex_array->
ptr(), texc,
sizeof(texc));
628 #if defined(VL_OPENGL_ES1) || defined(VL_OPENGL_ES2) 643 real x = side / 2.0f;
645 real z = side / 2.0f;
658 vert3->
at(0) = a4; vert3->
at(1) = a2; vert3->
at(2) = a1;
659 vert3->
at(3) = a2; vert3->
at(4) = a4; vert3->
at(5) = a3;
660 vert3->
at(6) = a4; vert3->
at(7) = a1; vert3->
at(8) = a0;
661 vert3->
at(9) = a1; vert3->
at(10) = a2; vert3->
at(11) = a0;
662 vert3->
at(12) = a2; vert3->
at(13) = a3; vert3->
at(14) = a0;
663 vert3->
at(15) = a3; vert3->
at(16) = a4; vert3->
at(17) = a0;
665 #if defined(VL_OPENGL_ES1) || defined(VL_OPENGL_ES2) 680 diameter = diameter / 2;
682 vert3->
resize( phi+1 + (bottom?phi+1:0) );
685 vert3->
at(vert_idx++) = (
fvec3)(
vec3(0, height/2.0f, 0) + origin);
686 for(
int j=0; j<phi; ++j)
688 vec3 v(1*diameter, -height/2.0f, 0);
690 vert3->
at(vert_idx++) = (
fvec3)(v + origin);
699 for(
int j=0; j<phi+1; ++j)
705 int fan_center = vert_idx;
706 vert3->
at(vert_idx++) = (
fvec3)(
vec3(0, -height/2.0f, 0) + origin);
707 for(
int j=0; j<phi; ++j)
709 vec3 v(1*diameter, -height/2.0f, 0);
711 vert3->
at(vert_idx++) = (
fvec3)(v + origin);
719 for(
int j=0; j<phi+1; ++j)
720 bottom_fan->
indexBuffer()->
at(idx++) = fan_center+1+(phi-1-j%phi);
723 #if defined(VL_OPENGL_ES1) || defined(VL_OPENGL_ES2) 742 real dx = xside / (x-1);
743 real dz = zside / (z-1);
758 for(
int i=0; i<z; ++i)
759 for(
int j=0; j<x; ++j, ++vert_idx)
761 vert3->
at(vert_idx) = (
fvec3)(
vec3(-xside+j*dx, 0, -zside+i*dz) + origin);
764 float tu = (float)j/(x-1);
765 float tv = (float)i/(z-1);
766 text2->
at(vert_idx).
s() = (1.0f-tu) * uv0.
s() + tu * uv1.
s();
767 text2->
at(vert_idx).
t() = (1.0f-tv) * uv0.
t() + tv * uv1.
t();
776 for(
int i=0; i<z-1; ++i)
778 for(
int j=0; j<x-1; ++j)
787 #if defined(VL_OPENGL_ES1) || defined(VL_OPENGL_ES2) 803 vert3->
resize( (
int)pos.size() );
804 col4->
resize( (
int)pos.size() );
806 for(
unsigned i=0; i<pos.size(); ++i)
814 #if defined(VL_OPENGL_ES1) || defined(VL_OPENGL_ES2) 831 const real x = 0.525731112119133606f / 1.0f;
832 const real z = 0.850650808352039932f / 1.0f;
833 const real radius = diameter / 2.0f;
837 vert3->
at(0) = (
fvec3)(origin +
vec3(-x, 0.0, +z)*radius);
838 vert3->
at(1) = (
fvec3)(origin +
vec3(+x, 0.0, +z)*radius);
839 vert3->
at(2) = (
fvec3)(origin +
vec3(-x, 0.0, -z)*radius);
840 vert3->
at(3) = (
fvec3)(origin +
vec3(+x, 0.0, -z)*radius);
842 vert3->
at(4) = (
fvec3)(origin +
vec3(0.0, +z, +x)*radius);
843 vert3->
at(5) = (
fvec3)(origin +
vec3(0.0, +z, -x)*radius);
844 vert3->
at(6) = (
fvec3)(origin +
vec3(0.0, -z, +x)*radius);
845 vert3->
at(7) = (
fvec3)(origin +
vec3(0.0, -z, -x)*radius);
847 vert3->
at(8) = (
fvec3)(origin +
vec3(+z, +x, 0.0)*radius);
848 vert3->
at(9) = (
fvec3)(origin +
vec3(-z, +x, 0.0)*radius);
849 vert3->
at(10) = (
fvec3)(origin +
vec3(+z, -x, 0.0)*radius);
850 vert3->
at(11) = (
fvec3)(origin +
vec3(-z, -x, 0.0)*radius);
852 unsigned short faces[20][3] =
854 {1,4,0}, {4,9,0}, {4,5,9}, {8,5,4}, {1,8,4},
855 {1,10,8}, {10,3,8}, {8,3,5}, {3,2,5}, {3,7,2},
856 {3,10,7}, {10,6,7}, {6,11,7}, {6,0,11}, {6,1,0},
857 {10,1,6}, {11,0,9}, {2,11,9}, {5,2,9}, {11,2,7}
865 #if defined(VL_OPENGL_ES1) || defined(VL_OPENGL_ES2) 880 for(
int i=0; i<slices; ++i)
882 real t = 360.0f * i / slices;
888 #if defined(VL_OPENGL_ES1) || defined(VL_OPENGL_ES2) 897 float height2 = height / 2.0f;
906 std::vector<fvec3> verts;
907 std::vector<fvec4> cols;
910 for(
int i=0; i<segments; ++i)
912 float a = (float)i/segments*
fPi*2.0f;
915 cols.push_back(top_col);
917 if (top_col != bottom_col)
920 for(
int i=0; i<segments; ++i)
922 float a = (float)i/segments*
fPi*2.0f;
925 cols.push_back(top_col);
928 for(
int i=0; i<segments; ++i)
930 float a = (float)i/segments*
fPi*2.0f;
933 cols.push_back(bottom_col);
941 int upup = segments*0;
942 int uplo = segments*1;
943 int loup = segments*2;
944 int lolo = segments*3;
945 for(
int i=0; i<segments; ++i)
947 int i1 = (i+1) % segments;
964 int upup = segments*0;
965 int uplo = segments*1;
966 for(
int i=0; i<segments; ++i)
968 int i1 = (i+1) % segments;
976 for(
int i=0; i<segments; ++i)
978 float a = (float)i/segments*
fPi*2.0f;
981 cols.push_back(bottom_col);
986 int start = (int)verts.size();
987 for(
int i=0; i<segments; ++i)
989 float a = (float)i/segments*
fPi*2.0f;
992 cols.push_back(top_col);
997 for(
int i=0,j=segments; j--; ++i)
1002 int start = (int)verts.size();
1003 for(
int i=0; i<segments; ++i)
1005 float a = (float)i/segments*
fPi*2.0f;
1006 fvec3 v(::
cos(a)*radius,-height2,::
sin(a)*radius);
1008 cols.push_back(bottom_col);
1013 for(
int i=0; i<segments; ++i)
1016 int segments2 = segments/3;
if (segments2<2) segments2=2;
1019 int start = (int)verts.size();
1020 for(
int j=0; j<segments2; ++j)
1022 float aj = (float)j/segments2*
fPi/2.0f;
1023 for(
int i=0; i<segments; ++i)
1025 float a = (float)i/segments*360;
1028 cols.push_back(top_col);
1032 verts.push_back(
fvec3(0,+height2+radius,0));
1033 cols.push_back(top_col);
1038 for(
int j=0,idx=0; j<segments2-1; ++j)
1040 int uplo = start+segments*j;
1041 int upup = start+segments*(j+1);
1042 for(
int i=0; i<segments; ++i)
1044 int i1 = (i+1) % segments;
1056 for(
int i=0; i<segments+1; ++i)
1057 de->
indexBuffer()->
at(i+1) = (GLuint)verts.size()-1-segments+i%segments;
1061 int start = (int)verts.size();
1062 for(
int j=0; j<segments2; ++j)
1064 float aj = (float)j/segments2*
fPi/2.0f;
1065 for(
int i=0; i<segments; ++i)
1067 float a = -(float)i/segments*360;
1070 cols.push_back(bottom_col);
1074 verts.push_back(
fvec3(0,-height2-radius,0));
1075 cols.push_back(bottom_col);
1080 for(
int j=0,idx=0; j<segments2-1; ++j)
1082 int uplo = start+segments*j;
1083 int upup = start+segments*(j+1);
1084 for(
int i=0; i<segments; ++i)
1086 int i1 = (i+1) % segments;
1098 for(
int i=0; i<segments+1; ++i)
1099 de->
indexBuffer()->
at(i+1) = (GLuint)verts.size()-1-segments+i%segments;
1105 #if defined(VL_OPENGL_ES1) || defined(VL_OPENGL_ES2)
const T_Scalar & t() const
const Vector3 & normalize(T_Scalar *len=NULL)
Vector3< float > fvec3
A 3 components vector with float precision.
VLGRAPHICS_EXPORT ref< Geometry > makeCylinder(const vec3 &origin, real diameter=1, real height=1, int phi=20, int theta=2, bool top=true, bool bottom=true)
Creates a cylinder.
void setObjectName(const char *name)
The name of the object, by default set to the object's class name in debug builds.
const T_Scalar & s() const
const T_Scalar & z() const
const ArrayAbstract * vertexArray() const
Conventional vertex array.
VLGRAPHICS_EXPORT ref< Geometry > makeCone(const vec3 &origin, real diameter=1, real height=1, int phi=20, bool bottom=true)
Creates a cone.
void setVertexArray(ArrayAbstract *data)
Conventional vertex array.
VLGRAPHICS_EXPORT ref< Geometry > makeTeapot(const vec3 &origin, real diameter=1, int detail=8)
Creates a classic Newell's teapot.
Removes from a Geometry the vertices with the same attributes.
vec3 center() const
Returns the center of the AABB.
void removeDoubles(Geometry *geom)
void setNormalArray(ArrayAbstract *data)
Conventional normal array.
void setColorArray(const fvec4 &color)
Fills the color array with the given color.
size_t size() const
Returns the number of elements of an array.
The Geometry class is a Renderable that implements a polygonal mesh made of polygons, lines and points.
Points & points()
The control points grid defining the bicubic Bézier patch(es).
Visualization Library main namespace.
const float fPi
Greek Pi constant using float precision.
const unsigned char * ptr() const
Returns the pointer to the first element of the local buffer. Equivalent to bufferObject()->ptr() ...
Vector2< float > fvec2
A 2 components vector with float precision.
VLGRAPHICS_EXPORT ref< Geometry > makeBox(const vec3 &origin, real xside=1, real yside=1, real zside=1, bool tex_coords=true)
Creates a box.
The AABB class implements an axis-aligned bounding box using vl::real precision.
VLGRAPHICS_EXPORT ref< Geometry > makeIcosahedron(const vec3 &origin, real diameter)
Creates an icosahedron.
real width() const
Returns the width of the AABB computed as max.x - min.x.
Defines one or more concatenated bicubic Bézier patches to be used with the BezierSurface class...
void initFrom(const std::vector< T_VectorType > &vector)
const vec3 & maxCorner() const
Returns the corner of the AABB with the maximum x y z coordinates.
float max(float a, float b)
The BezierSurface class implements a Geometry that is capable of visualizing multiple bicubic Bézier ...
float min(float a, float b)
VLGRAPHICS_EXPORT ref< Geometry > makeTorus(const vec3 &origin, real diameter=1, real thickness=0.2, int phi=10, int theta=10, float tex_coords=0.0f)
Creates torus. This function generates also appropriate normals.
void setDetail(unsigned i)
The sampling level of the patch, must not be less than 2. The higher the sampling level...
std::vector< ref< BezierPatch > > & patches()
Returns the Bézier patches that are part of this Bézier surface.
VLGRAPHICS_EXPORT ref< Geometry > makeCapsule(float radius, float height, int segments, ECapsuleCap top_cap, ECapsuleCap bottom_cap, const fvec4 &top_col, const fvec4 &bottom_col)
Creates a 3d capsule with rounded, flat or no caps.
const T_Scalar & y() const
VLGRAPHICS_EXPORT ref< Geometry > makePyramid(const vec3 &origin, real side=1, real height=1)
Creates a pyramid.
void setTexCoordArray(int tex_unit, ArrayAbstract *data)
Conventional texture coords arrays.
void transform(const mat4 &matr, bool normalize=true)
Transforms vertices and normals belonging to this geometry.
arr_type * indexBuffer()
The BufferObject containing the indices used to render.
void updateBezierSurface(bool gen_tex_coords=true)
Generates the Bézier surface geometry based on the current patches and detail.
const vec3 & minCorner() const
Returns the corner of the AABB with the minimum x y z coordinates.
static Matrix4 & getRotation(Matrix4 &out, float degrees, float x, float y, float z)
T_VectorType & at(size_t i)
fvec3 vec3
Defined as: 'typedef fvec3 vec3'. See also VL_PIPELINE_PRECISION.
VLGRAPHICS_EXPORT ref< Geometry > makeIcosphere(const vec3 &pos, real diameter=1, int detail=2, bool remove_doubles=true)
Creates a sphere by iteratively subdividing an icosahedron.
virtual size_t size() const =0
Returns the number of elements of an array.
VLGRAPHICS_EXPORT ref< Geometry > makePoints(const std::vector< vec3 > &pos, const fvec4 &color=white)
Creates a set of points.
static Matrix4 & getTranslation(Matrix4 &out, const Vector3< float > &v)
static Matrix4 & getScaling(Matrix4 &out, const Vector3< float > &v)
const T_Scalar & x() const
The ref<> class is used to reference-count an Object.
const AABB & boundingBox() const
Returns the bounding box of a Renderable without recomputing the bounds if dirty. ...
VLGRAPHICS_EXPORT ref< Geometry > makeGrid(const vec3 &origin, real xside, real zside, int x, int z, bool gen_texcoords=false, fvec2 uv0=fvec2(0, 0), fvec2 uv1=fvec2(1, 1), bool center=true)
Creates a 2D grid.
VLGRAPHICS_EXPORT ref< Geometry > makeUVSphere(const vec3 &origin, real diameter=1, int phi=20, int theta=20)
Creates a uv sphere.
void makeGLESFriendly()
Calls triangulateDrawCalls() and shrinkDrawCalls().
Wraps the OpenGL function glDrawArrays().
VLGRAPHICS_EXPORT ref< Geometry > makeCircle(vec3 origin, real radius, int slices=60)
Creates a 2D circle.
Collection< DrawCall > & drawCalls()
Returns the list of DrawCall objects bound to a Geometry.