@@ -260,6 +260,12 @@ void GlyphGeom::addDisk(const Point& p1, const Point& p2, double radius, int res
260260 generateCylinder (p1, p2, radius, radius, resolution, color1, color2, true , true );
261261}
262262
263+ void GlyphGeom::addTorus (const Point& p1, const Point& p2, double major_radius, double minor_radius, int resolution,
264+ const ColorRGB& color1, const ColorRGB& color2)
265+ {
266+ generateTorus (p1, p2, major_radius, minor_radius, resolution, color1);
267+ }
268+
263269void GlyphGeom::addCone (const Point& p1, const Point& p2, double radius, int resolution,
264270 bool render_base, const ColorRGB& color1, const ColorRGB& color2)
265271{
@@ -1121,62 +1127,73 @@ void GlyphGeom::generateSuperEllipsoid(const Point& center, Tensor& t, double sc
11211127 for (int jj = 0 ; jj < 6 ; jj++) indices_.pop_back ();
11221128}
11231129
1124- // template <class T>
1125- // void GeomGlyph::gen_torus(const Point& center, const T& t,
1126- // double major_radius, double minor_radius,
1127- // int nu, int nv,
1128- // std::vector< QuadStrip >& quadstrips )
1129- // {
1130- // nu++; //Bring nu to expected value for shape.
1130+ void GlyphGeom::generateTorus (const Point& p1, const Point& p2, double major_radius, double minor_radius,
1131+ int resolution, const ColorRGB& color)
1132+ {
1133+ std::cout << " minor, major rad: " << minor_radius << " , " << major_radius << std::endl;
1134+ int nv = resolution;
1135+ int nu = nv + 1 ;
11311136
1132- // SinCosTable tab1(nu, 0, 2*M_PI);
1133- // SinCosTable tab2(nv, 0, 2*M_PI, minor_radius);
1137+ SinCosTable tab1 (nu, 0 , 2 *M_PI);
1138+ SinCosTable tab2 (nv, 0 , 2 *M_PI, minor_radius);
11341139
1135- // Transform trans;
1136- // Transform rotate;
1137- // gen_transforms( center, t, trans, rotate );
1140+ Transform trans;
1141+ Transform rotate;
1142+ /* Point center = p1 + (p2-p1) * 0.5; */
1143+ generateTransforms ( p1, (p2-p1), trans, rotate );
11381144
11391145 // Draw the torus
1140- // for (int v=0; v<nv-1; v++)
1141- // {
1142- // double z1 = tab2.cos(v+1);
1143- // double z2 = tab2.cos(v);
1146+ for (int v=0 ; v<nv-1 ; v++)
1147+ {
1148+ double z1 = tab2.cos (v+1 );
1149+ double z2 = tab2.cos (v);
11441150
1145- // double nr1 = tab2.sin(v+1);
1146- // double nr2 = tab2.sin(v);
1151+ double nr1 = tab2.sin (v+1 );
1152+ double nr2 = tab2.sin (v);
11471153
1148- // double r1 = major_radius + nr1;
1149- // double r2 = major_radius + nr2;
1154+ double r1 = major_radius + nr1;
1155+ double r2 = major_radius + nr2;
11501156
1151- // QuadStrip quadstrip;
1157+ for (int u=0 ; u<nu; u++)
1158+ {
1159+ uint32_t offset = static_cast <uint32_t >(numVBOElements_);
11521160
1153- // for (int u=0; u<nu; u++)
1154- // {
1155- // double nx = tab1.sin(u);
1156- // double ny = tab1.cos(u);
1161+ double nx = tab1.sin (u);
1162+ double ny = tab1.cos (u);
11571163
1158- // double x1 = r1 * nx;
1159- // double y1 = r1 * ny;
1164+ double x1 = r1 * nx;
1165+ double y1 = r1 * ny;
11601166
1161- // double x2 = r2 * nx;
1162- // double y2 = r2 * ny;
1167+ double x2 = r2 * nx;
1168+ double y2 = r2 * ny;
11631169
1164- // Point p1 = trans * Point(x1, y1, z1);
1165- // Point p2 = trans * Point(x2, y2, z2);
1170+ Vector p1 = Vector (trans * Point (x1, y1, z1));
1171+ Vector p2 = Vector (trans * Point (x2, y2, z2));
1172+ points_.push_back (p1);
1173+ points_.push_back (p2);
11661174
1167- // Vector v1 = rotate * Vector(nr1*nx, nr1*ny, z1);
1168- // Vector v2 = rotate * Vector(nr2*nx, nr2*ny, z2);
1175+ Vector v1 = rotate * Vector (nr1*nx, nr1*ny, z1);
1176+ Vector v2 = rotate * Vector (nr2*nx, nr2*ny, z2);
1177+ v1.safe_normalize ();
1178+ v2.safe_normalize ();
1179+ normals_.push_back (v1);
1180+ normals_.push_back (v2);
11691181
1170- // v1.safe_normalize( );
1171- // v2.safe_normalize( );
1182+ colors_. push_back (color );
1183+ colors_. push_back (color );
11721184
1173- // quadstrip.push_back( std::make_pair(p1, v1) );
1174- // quadstrip.push_back( std::make_pair(p2, v2) );
1175- // }
1185+ numVBOElements_ += 2 ;
11761186
1177- // quadstrips.push_back( quadstrip );
1178- // }
1179- // }
1187+ indices_.push_back (0 + offset);
1188+ indices_.push_back (1 + offset);
1189+ indices_.push_back (2 + offset);
1190+ indices_.push_back (2 + offset);
1191+ indices_.push_back (1 + offset);
1192+ indices_.push_back (3 + offset);
1193+ }
1194+ }
1195+ for (int jj = 0 ; jj < 6 ; jj++) indices_.pop_back ();
1196+ }
11801197
11811198void GlyphGeom::generateLine (const Point& p1, const Point& p2, const ColorRGB& color1, const ColorRGB& color2)
11821199{
0 commit comments