MCPcopy Index your code
hub / github.com/processing/processing / sphere

Method sphere

core/src/processing/core/PGraphics.java:3148–3211  ·  view source on GitHub ↗

( begin auto-generated from sphere.xml ) A sphere is a hollow ball made from tessellated triangles. ( end auto-generated ) Advanced Implementation notes: cache all the points of the sphere in a static array top and bottom are just a bunch of triangles that land in the center poin

(float r)

Source from the content-addressed store, hash-verified

3146 * @see PGraphics#sphereDetail(int)
3147 */
3148 public void sphere(float r) {
3149 if ((sphereDetailU < 3) || (sphereDetailV < 2)) {
3150 sphereDetail(30);
3151 }
3152
3153 edge(false);
3154
3155
3156 // 1st ring from south pole
3157 beginShape(TRIANGLE_STRIP);
3158 for (int i = 0; i < sphereDetailU; i++) {
3159 normal(0, -1, 0);
3160 vertex(0, -r, 0);
3161 normal(sphereX[i], sphereY[i], sphereZ[i]);
3162 vertex(r * sphereX[i], r * sphereY[i], r * sphereZ[i]);
3163 }
3164 normal(0, -r, 0);
3165 vertex(0, -r, 0);
3166 normal(sphereX[0], sphereY[0], sphereZ[0]);
3167 vertex(r * sphereX[0], r * sphereY[0], r * sphereZ[0]);
3168 endShape();
3169
3170 int v1,v11,v2;
3171
3172 // middle rings
3173 int voff = 0;
3174 for (int i = 2; i < sphereDetailV; i++) {
3175 v1 = v11 = voff;
3176 voff += sphereDetailU;
3177 v2 = voff;
3178 beginShape(TRIANGLE_STRIP);
3179 for (int j = 0; j < sphereDetailU; j++) {
3180 normal(sphereX[v1], sphereY[v1], sphereZ[v1]);
3181 vertex(r * sphereX[v1], r * sphereY[v1], r * sphereZ[v1++]);
3182 normal(sphereX[v2], sphereY[v2], sphereZ[v2]);
3183 vertex(r * sphereX[v2], r * sphereY[v2], r * sphereZ[v2++]);
3184 }
3185 // close each ring
3186 v1 = v11;
3187 v2 = voff;
3188 normal(sphereX[v1], sphereY[v1], sphereZ[v1]);
3189 vertex(r * sphereX[v1], r * sphereY[v1], r * sphereZ[v1]);
3190 normal(sphereX[v2], sphereY[v2], sphereZ[v2]);
3191 vertex(r * sphereX[v2], r * sphereY[v2], r * sphereZ[v2]);
3192 endShape();
3193 }
3194
3195 // add the northern cap
3196 beginShape(TRIANGLE_STRIP);
3197 for (int i = 0; i < sphereDetailU; i++) {
3198 v2 = voff + i;
3199 normal(sphereX[v2], sphereY[v2], sphereZ[v2]);
3200 vertex(r * sphereX[v2], r * sphereY[v2], r * sphereZ[v2]);
3201 normal(0, 1, 0);
3202 vertex(0, r, 0);
3203 }
3204 normal(sphereX[voff], sphereY[voff], sphereZ[voff]);
3205 vertex(r * sphereX[voff], r * sphereY[voff], r * sphereZ[voff]);

Callers

nothing calls this directly

Calls 6

sphereDetailMethod · 0.95
edgeMethod · 0.95
beginShapeMethod · 0.95
normalMethod · 0.95
vertexMethod · 0.95
endShapeMethod · 0.95

Tested by

no test coverage detected