sin[radialCount] = MathUtils.sin(angle);
}
sin[radialSamples] = sin[0];
cos[radialSamples] = cos[0];
final Vector3 tempA = new Vector3();
// top point.
verts.put(0).put((float) (radius + halfHeight)).put(0);
norms.put(0).put(1).put(0);
texs.put(1).put(1);
// generating the top dome.
for (int i = 0; i < sphereSamples; i++) {
final double center = radius * (1 - (i + 1) * (inverseSphere));
final double lengthFraction = (center + height + radius) / (height + 2 * radius);
// compute radius of slice
final double fSliceRadius = Math.sqrt(Math.abs(radius * radius - center * center));
for (int j = 0; j <= radialSamples; j++) {
final Vector3 kRadial = tempA.set(cos[j], 0, sin[j]);
kRadial.multiplyLocal(fSliceRadius);
verts.put(kRadial.getXf()).put((float) (center + halfHeight)).put(kRadial.getZf());
kRadial.setY(center);
kRadial.normalizeLocal();
norms.put(kRadial.getXf()).put(kRadial.getYf()).put(kRadial.getZf());
final double radialFraction = 1 - (j * inverseRadial); // in [0,1)
texs.put((float) radialFraction).put((float) lengthFraction);
}
}
// generate cylinder... but no need to add points for first and last
// samples as they are already part of domes.
for (int i = 1; i < axisSamples; i++) {
final double center = halfHeight - (i * height / axisSamples);
final double lengthFraction = (center + halfHeight + radius) / (height + 2 * radius);
for (int j = 0; j <= radialSamples; j++) {
final Vector3 kRadial = tempA.set(cos[j], 0, sin[j]);
kRadial.multiplyLocal(radius);
verts.put(kRadial.getXf()).put((float) center).put(kRadial.getZf());
kRadial.normalizeLocal();
norms.put(kRadial.getXf()).put(kRadial.getYf()).put(kRadial.getZf());
final double radialFraction = 1 - (j * inverseRadial); // in [0,1)
texs.put((float) radialFraction).put((float) lengthFraction);
}
}
// generating the bottom dome.
for (int i = 0; i < sphereSamples; i++) {
final double center = i * (radius / sphereSamples);
final double lengthFraction = (radius - center) / (height + 2 * radius);
// compute radius of slice
final double fSliceRadius = Math.sqrt(Math.abs(radius * radius - center * center));
for (int j = 0; j <= radialSamples; j++) {
final Vector3 kRadial = tempA.set(cos[j], 0, sin[j]);
kRadial.multiplyLocal(fSliceRadius);
verts.put(kRadial.getXf()).put((float) (-center - halfHeight)).put(kRadial.getZf());
kRadial.setY(-center);
kRadial.normalizeLocal();
norms.put(kRadial.getXf()).put(kRadial.getYf()).put(kRadial.getZf());
final double radialFraction = 1 - (j * inverseRadial); // in [0,1)
texs.put((float) radialFraction).put((float) lengthFraction);
}
}