@@ -202,7 +202,7 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique
202202 geom.passes ().push_back (pass);
203203}
204204
205- void GlyphGeom::addArrow (const Point& p1, const Point& p2, double radius, double ratio, double resolution,
205+ void GlyphGeom::addArrow (const Point& p1, const Point& p2, double radius, double ratio, int resolution,
206206 const ColorRGB& color1, const ColorRGB& color2)
207207{
208208 Point mid ((p1.x () * ratio + p2.x () * (1 - ratio)), (p1.y () * ratio + p2.y () * (1 - ratio)), (p1.z () * ratio + p2.z () * (1 - ratio)));
@@ -211,7 +211,7 @@ void GlyphGeom::addArrow(const Point& p1, const Point& p2, double radius, double
211211 generateCylinder (mid, p2, radius, 0.0 , resolution, color1, color2);
212212}
213213
214- void GlyphGeom::addSphere (const Point& p, double radius, double resolution, const ColorRGB& color)
214+ void GlyphGeom::addSphere (const Point& p, double radius, int resolution, const ColorRGB& color)
215215{
216216 generateSphere (p, radius, resolution, color);
217217}
@@ -221,25 +221,31 @@ void GlyphGeom::addBox(const Point& center, Tensor& t, double scale)
221221 generateBox (center, t, scale);
222222}
223223
224- void GlyphGeom::addEllipsoid (const Point& p, Tensor& t, Vector& scaled_eigenvals, double resolution, const ColorRGB& color)
224+ void GlyphGeom::addEllipsoid (const Point& p, Tensor& t, Vector& scaled_eigenvals, int resolution, const ColorRGB& color)
225225{
226226 generateEllipsoid (p, t, scaled_eigenvals, resolution, color);
227227}
228228
229- void GlyphGeom::addCylinder (const Point& p1, const Point& p2, double radius, double resolution,
229+ void GlyphGeom::addCylinder (const Point& p1, const Point& p2, double radius, int resolution,
230230 const ColorRGB& color1, const ColorRGB& color2)
231231{
232232 generateCylinder (p1, p2, radius, radius, resolution, color1, color2);
233233}
234234
235- void GlyphGeom::addCone (const Point& p1, const Point& p2, double radius, double resolution,
236- const ColorRGB& color1, const ColorRGB& color2)
235+ void GlyphGeom::addDisk (const Point& p1, const Point& p2, double radius, int resolution,
236+ const ColorRGB& color1, const ColorRGB& color2)
237+ {
238+ generateDisk (p1, p2, radius, radius, resolution, color1, color2);
239+ }
240+
241+ void GlyphGeom::addCone (const Point& p1, const Point& p2, double radius, int resolution,
242+ bool renderBase, const ColorRGB& color1, const ColorRGB& color2)
237243{
238- generateCylinder (p1, p2, radius, 0.0 , resolution , color1, color2);
244+ generateCone (p1, p2, radius, resolution, renderBase , color1, color2);
239245}
240246
241247void GlyphGeom::addClippingPlane (const Point& p1, const Point& p2,
242- const Point& p3, const Point& p4, double radius, double resolution,
248+ const Point& p3, const Point& p4, double radius, int resolution,
243249 const ColorRGB& color1, const ColorRGB& color2)
244250{
245251 addSphere (p1, radius, resolution, color1);
@@ -278,7 +284,7 @@ void GlyphGeom::addPoint(const Point& p, const ColorRGB& color)
278284}
279285
280286void GlyphGeom::generateCylinder (const Point& p1, const Point& p2, double radius1,
281- double radius2, double resolution, const ColorRGB& color1,
287+ double radius2, int resolution, const ColorRGB& color1,
282288 const ColorRGB& color2)
283289{
284290 double num_strips = resolution;
@@ -291,58 +297,182 @@ void GlyphGeom::generateCylinder(const Point& p1, const Point& p2, double radius
291297 Vector crx = n.getArbitraryTangent ();
292298 Vector u = Cross (crx, n).normal ();
293299 Vector p;
294- // points_.push_back(Vector(p1.x(), p1.y(), p1.z()));
295- // points_.push_back(Vector(p2.x(), p2.y(), p2.z()));
296- // int p1_index = numVBOElements_;
297- // colors_.push_back(color1);
298- // normals_.push_back(n);
299- // numVBOElements_++;
300- // int p2_index = numVBOElements_;
301- // colors_.push_back(color2);
302- // normals_.push_back(n);
303- // numVBOElements_++;
304- for (double strips = 0 .; strips <= num_strips; strips += 1 .)
300+ for (int strips = 0 ; strips <= num_strips; strips++)
305301 {
306302 uint32_t offset = static_cast <uint32_t >(numVBOElements_);
307303 p = std::cos (2 . * M_PI * strips / num_strips) * u +
308304 std::sin (2 . * M_PI * strips / num_strips) * crx;
309305 p.normalize ();
306+ Vector normals (((p2-p1).length () * p + (r2-r1)*n).normal ());
307+
310308 points_.push_back (r1 * p + Vector (p1));
311309 colors_.push_back (color1);
310+ normals_.push_back (normals);
312311 numVBOElements_++;
313312 points_.push_back (r2 * p + Vector (p2));
314313 colors_.push_back (color2);
315- numVBOElements_++;
316- Vector normals (((p2-p1).length () * p + (r2-r1)*n).normal ());
317- normals_.push_back (normals);
318314 normals_.push_back (normals);
315+ numVBOElements_++;
316+
319317 indices_.push_back (0 + offset);
320318 indices_.push_back (1 + offset);
321319 indices_.push_back (2 + offset);
322320 indices_.push_back (2 + offset);
323321 indices_.push_back (1 + offset);
324322 indices_.push_back (3 + offset);
325-
326- // Sides
327- // points_.push_back(r1 * p + Vector(p1));
328- // colors_.push_back(color1);
329- // normals_.push_back(n);
330- // numVBOElements_++;
331- // points_.push_back(r2 * p + Vector(p2));
332- // colors_.push_back(color2);
333- // normals_.push_back(n);
334- // numVBOElements_++;
335- // indices_.push_back(p1_index);
336- // indices_.push_back(0 + offset);
337- // indices_.push_back(2 + offset);
338- // indices_.push_back(p2_index);
339- // indices_.push_back(1 + offset);
340- // indices_.push_back(3 + offset);
341323 }
342324 for (int jj = 0 ; jj < 6 ; jj++) indices_.pop_back ();
343325}
344326
345- void GlyphGeom::generateSphere (const Point& center, double radius, double resolution, const ColorRGB& color)
327+ void GlyphGeom::generateCone (const Point& p1, const Point& p2, double radius,
328+ int resolution, bool renderBase,
329+ const ColorRGB& color1, const ColorRGB& color2)
330+ {
331+ resolution = resolution < 0 ? 20 : resolution;
332+ radius = radius < 0 ? 1 : radius;
333+
334+ // generate triangles for the cylinders.
335+ Vector n ((p1 - p2).normal ());
336+ Vector crx = n.getArbitraryTangent ();
337+ Vector u = Cross (crx, n).normal ();
338+
339+ // Center of base
340+ uint32_t base_index = numVBOElements_;
341+ int points_per_loop = 2 ;
342+ if (renderBase)
343+ {
344+ points_.push_back (Vector (p1));
345+ colors_.push_back (color1);
346+ normals_.push_back (n);
347+ numVBOElements_++;
348+ points_per_loop = 3 ;
349+ }
350+
351+ // Precalculate
352+ double length = (p2-p1).length ();
353+ double strip_angle = 2 . * M_PI / resolution;
354+
355+ Vector p;
356+ // Add points, normals, and colors
357+ for (int strips = 0 ; strips <= resolution; strips++)
358+ {
359+ p = std::cos (strip_angle * strips) * u +
360+ std::sin (strip_angle * strips) * crx;
361+ p.normalize ();
362+ Vector normals ((length * p - radius * n).normal ());
363+
364+ points_.push_back (radius * p + Vector (p1));
365+ colors_.push_back (color1);
366+ normals_.push_back (normals);
367+ points_.push_back (Vector (p2));
368+ colors_.push_back (color2);
369+ normals_.push_back (normals);
370+
371+ if (renderBase)
372+ {
373+ points_.push_back (radius * p + Vector (p1));
374+ colors_.push_back (color1);
375+ normals_.push_back (n);
376+ }
377+ }
378+
379+ uint32_t offset = static_cast <uint32_t >(numVBOElements_);
380+ numVBOElements_ += resolution * points_per_loop;
381+
382+ // Add indices
383+ for (int strips = offset; strips < resolution * points_per_loop + offset; strips += points_per_loop)
384+ {
385+ indices_.push_back (strips);
386+ indices_.push_back (strips + 1 );
387+ indices_.push_back (strips + points_per_loop);
388+ if (renderBase)
389+ {
390+ indices_.push_back (base_index);
391+ indices_.push_back (strips + 2 );
392+ indices_.push_back (strips + points_per_loop + 2 );
393+ }
394+ }
395+ }
396+
397+ void GlyphGeom::generateDisk (const Point& p1, const Point& p2, double radius1,
398+ double radius2, int resolution, const ColorRGB& color1,
399+ const ColorRGB& color2)
400+ {
401+ resolution = resolution < 0 ? 20 : resolution;
402+ radius1 = radius1 < 0 ? 1.0 : radius1;
403+ radius2 = radius2 < 0 ? 1.0 : radius2;
404+
405+ // generate triangles for the cylinders.
406+ Vector n ((p1 - p2).normal ());
407+ Vector crx = n.getArbitraryTangent ();
408+ Vector u = Cross (crx, n).normal ();
409+
410+ int points_per_loop = 4 ;
411+
412+ // Add center points so flat sides can be drawn
413+ points_.push_back (Vector (p1));
414+ points_.push_back (Vector (p2));
415+ int p1_index = numVBOElements_;
416+ colors_.push_back (color1);
417+ normals_.push_back (n);
418+ numVBOElements_++;
419+ int p2_index = numVBOElements_;
420+ colors_.push_back (color2);
421+ normals_.push_back (n);
422+ numVBOElements_++;
423+
424+ // Precalculate
425+ double length = (p2-p1).length ();
426+ double strip_angle = 2 . * M_PI / resolution;
427+
428+ Vector p;
429+ // Add points, normals, and colors
430+ for (int strips = 0 ; strips <= resolution; strips++)
431+ {
432+ p = std::cos (strip_angle * strips) * u +
433+ std::sin (strip_angle * strips) * crx;
434+ p.normalize ();
435+ Vector normals ((length * p + (radius2-radius1)*n).normal ());
436+ points_.push_back (radius1 * p + Vector (p1));
437+ colors_.push_back (color1);
438+ normals_.push_back (normals);
439+ points_.push_back (radius2 * p + Vector (p2));
440+ colors_.push_back (color2);
441+ normals_.push_back (normals);
442+
443+ // Points for base
444+ points_.push_back (radius1 * p + Vector (p1));
445+ colors_.push_back (color1);
446+ normals_.push_back (n);
447+ points_.push_back (radius2 * p + Vector (p2));
448+ colors_.push_back (color2);
449+ normals_.push_back (n);
450+ }
451+
452+ uint32_t offset = static_cast <uint32_t >(numVBOElements_);
453+ numVBOElements_ += resolution * points_per_loop;
454+
455+ // Add indices
456+ for (int strips = offset; strips < resolution * points_per_loop + offset; strips += points_per_loop)
457+ {
458+ indices_.push_back (strips);
459+ indices_.push_back (strips + 1 );
460+ indices_.push_back (strips + points_per_loop);
461+ indices_.push_back (strips + 1 );
462+ indices_.push_back (strips + points_per_loop);
463+ indices_.push_back (strips + points_per_loop + 1 );
464+
465+ // Render base
466+ indices_.push_back (p1_index);
467+ indices_.push_back (strips + 2 );
468+ indices_.push_back (strips + points_per_loop + 2 );
469+ indices_.push_back (p2_index);
470+ indices_.push_back (strips + 3 );
471+ indices_.push_back (strips + points_per_loop + 3 );
472+ }
473+ }
474+
475+ void GlyphGeom::generateSphere (const Point& center, double radius, int resolution, const ColorRGB& color)
346476{
347477 double num_strips = resolution;
348478 if (num_strips < 0 ) num_strips = 20.0 ;
@@ -512,7 +642,7 @@ void GlyphGeom::generateBox(const Point& center, Tensor& t, double scale)
512642 **/
513643}
514644
515- void GlyphGeom::generateEllipsoid (const Point& center, Tensor& t, Vector &scaled_eigenvals, double resolution, const ColorRGB& color)
645+ void GlyphGeom::generateEllipsoid (const Point& center, Tensor& t, Vector &scaled_eigenvals, int resolution, const ColorRGB& color)
516646{
517647 Vector eig_vec1, eig_vec2, eig_vec3;
518648 t.get_eigenvectors (eig_vec1, eig_vec2, eig_vec3);
0 commit comments