@@ -91,7 +91,7 @@ void GlyphGeom::buildObject(GeometryHandle geom, const std::string uniqueNodeID,
9191 }
9292 else if (colorScheme == GeometryObject::COLOR_IN_SITU)
9393 {
94- attribs.push_back (GeometryObject::SpireVBO::AttributeData (" aColor" , 1 * sizeof (uint32_t ), true ));
94+ attribs.push_back (GeometryObject::SpireVBO::AttributeData (" aColor" , 4 * sizeof (float ) ));
9595 if (useTriangles)
9696 {
9797 shader = " Shaders/DirPhongInSitu" ;
@@ -173,7 +173,8 @@ void GlyphGeom::buildObject(GeometryHandle geom, const std::string uniqueNodeID,
173173 vboBuffer->write (static_cast <float >(colors_.at (i).r ()));
174174 vboBuffer->write (static_cast <float >(colors_.at (i).g ()));
175175 vboBuffer->write (static_cast <float >(colors_.at (i).b ()));
176- vboBuffer->write (static_cast <float >(1 .f ));
176+ vboBuffer->write (static_cast <float >(colors_.at (i).a ()));
177+ // vboBuffer->write(static_cast<float>(1.f));
177178 } // no color writing otherwise
178179 }
179180
@@ -205,20 +206,20 @@ void GlyphGeom::addArrow(const Point& p1, const Point& p2, double radius, double
205206
206207 Point mid (ratio * (p1.x () + p2.x ()), ratio * (p1.y () + p2.y ()), ratio * (p1.z () + p2.z ()));
207208
208- generateCylinder (p1, mid, radius / 3 .0 , radius / 3 .0 , resolution, color1, color2, numVBOElements_, points_, normals_, indices_, colors_);
209+ generateCylinder (p1, mid, radius / 6 .0 , radius / 6 .0 , resolution, color1, color2, numVBOElements_, points_, normals_, indices_, colors_);
209210 generateCylinder (mid, p2, radius, 0.0 , resolution, color1, color2, numVBOElements_, points_, normals_, indices_, colors_);
210211}
211212
212213void GlyphGeom::addSphere (const Point& p, double radius, double resolution, const ColorRGB& color)
213214{
214- generateEllipsoid (p, radius, radius, resolution, color, numVBOElements_, points_, normals_, indices_, colors_);
215+ generateSphere (p, radius, radius, resolution, color, numVBOElements_, points_, normals_, indices_, colors_);
215216}
216- /*
217+
217218void GlyphGeom::addEllipsoid (const Point& p, double radius1, double radius2, double resolution, const ColorRGB& color)
218219{
219220 generateEllipsoid (p, radius1, radius2, resolution, color, numVBOElements_, points_, normals_, indices_, colors_);
220221}
221- */
222+
222223void GlyphGeom::addCylinder (const Point p1, const Point& p2, double radius, double resolution,
223224 const ColorRGB& color1, const ColorRGB& color2)
224225{
@@ -233,7 +234,10 @@ void GlyphGeom::addCone(const Point p1, const Point& p2, double radius, double r
233234
234235void GlyphGeom::addNeedle (Point p1, const Point& p2, const ColorRGB& color1, const ColorRGB& color2)
235236{
236- generateLine (p1, p2, color1, color2, numVBOElements_, points_, indices_, colors_);
237+ Point mid (0.5 * (p1.x () + p2.x ()), 0.5 * (p1.y () + p2.y ()), 0.5 * (p1.z () + p2.z ()));
238+ ColorRGB endColor (color2.r (), color2.g (), color2.b (), 0.5 );
239+ generateLine (p1, mid, color1, endColor, numVBOElements_, points_, indices_, colors_);
240+ generateLine (mid, p2, color1, endColor, numVBOElements_, points_, indices_, colors_);
237241}
238242
239243void GlyphGeom::addPoint (const Point& p, const ColorRGB& color)
@@ -280,7 +284,7 @@ void GlyphGeom::generateCylinder(const Point& p1, const Point& p2, double radius
280284 for (int jj = 0 ; jj < 6 ; jj++) indices.pop_back ();
281285}
282286
283- void GlyphGeom::generateEllipsoid (const Point& center, double radius1, double radius2,
287+ void GlyphGeom::generateSphere (const Point& center, double radius1, double radius2,
284288 double resolution, const ColorRGB& color, int64_t & numVBOElements, std::vector<Vector>& points,
285289 std::vector<Vector>& normals, std::vector<uint32_t >& indices, std::vector<ColorRGB>& colors)
286290{
@@ -318,6 +322,82 @@ void GlyphGeom::generateEllipsoid(const Point& center, double radius1, double ra
318322 }
319323}
320324
325+ void GlyphGeom::generateEllipsoid (const Point& center, double radius1, double radius2,
326+ double resolution, const ColorRGB& color, int64_t & numVBOElements, std::vector<Vector>& points,
327+ std::vector<Vector>& normals, std::vector<uint32_t >& indices, std::vector<ColorRGB>& colors)
328+ {
329+ double num_strips = resolution;
330+ if (num_strips < 0 ) num_strips = 20.0 ;
331+ double r1 = radius1 < 0 ? 1.0 : radius1;
332+ double r2 = radius2 < 0 ? 1.0 : radius2;
333+ Vector pp1, pp2;
334+ double theta_inc = /* 2. */ M_PI / num_strips, phi_inc = 0.5 * M_PI / num_strips;
335+ Vector radius = Vector (radius1, 0 , radius2);
336+
337+ // generate triangles for the spheres
338+ for (double phi = 0 .; phi <= M_PI; phi += phi_inc)
339+ {
340+ for (double theta = 0 .; theta <= /* 2. */ M_PI; theta += theta_inc)
341+ {
342+ uint32_t offset = (uint32_t )numVBOElements;
343+ pp1 = Vector (sin (theta) * cos (phi), sin (theta) * sin (phi), cos (theta));
344+ pp2 = Vector (sin (theta) * cos (phi + phi_inc), sin (theta) * sin (phi + phi_inc), cos (theta));
345+ points.push_back (r1 * pp1 + Vector (center));
346+ colors.push_back (color);
347+ numVBOElements++;
348+ points.push_back (r2 * pp2 + Vector (center + radius));
349+ colors.push_back (color);
350+ numVBOElements++;
351+ normals.push_back (pp1);
352+ normals.push_back (pp2);
353+
354+ indices.push_back (0 + offset);
355+ indices.push_back (1 + offset);
356+ indices.push_back (2 + offset);
357+ indices.push_back (2 + offset);
358+ indices.push_back (1 + offset);
359+ indices.push_back (3 + offset);
360+ /*
361+ indices.push_back(0 + offset);
362+ indices.push_back(1 + offset);
363+ indices.push_back(2 + offset);
364+ indices.push_back(2 + offset);
365+ indices.push_back(1 + offset);
366+ indices.push_back(3 + offset);
367+
368+
369+ //generate triangles for the cylinders.
370+ Vector n((p1 - p2).normal()), u = (10 * n + Vector(10, 10, 10)).normal();
371+ Vector crx = Cross(u, n).normal();
372+ u = Cross(crx, n).normal();
373+ Vector p;
374+ for (double strips = 0.; strips <= num_strips; strips += 1.)
375+ {
376+ uint32_t offset = (uint32_t)numVBOElements;
377+ p = std::cos(2. * M_PI * strips / num_strips) * u +
378+ std::sin(2. * M_PI * strips / num_strips) * crx;
379+ p.normalize();
380+ points.push_back(r1 * p + Vector(p1));
381+ colors.push_back(color1);
382+ numVBOElements++;
383+ points.push_back(r2 * p + Vector(p2));
384+ colors.push_back(color2);
385+ numVBOElements++;
386+ normals.push_back(p);
387+ normals.push_back(p);
388+ indices.push_back(0 + offset);
389+ indices.push_back(1 + offset);
390+ indices.push_back(2 + offset);
391+ indices.push_back(2 + offset);
392+ indices.push_back(1 + offset);
393+ indices.push_back(3 + offset);
394+ }
395+ */
396+ }
397+ for (int jj = 0 ; jj < 6 ; jj++) indices.pop_back ();
398+ }
399+ }
400+
321401void GlyphGeom::generateLine (const Point p1, const Point& p2, const ColorRGB& color1, const ColorRGB& color2,
322402 int64_t & numVBOElements, std::vector<Vector>& points, std::vector<uint32_t >& indices, std::vector<ColorRGB>& colors)
323403{
0 commit comments