All pastes #626950 Raw Edit

Mine

public text v1 · immutable
·published 2007-07-20 00:08 UTC
rendered paste body
BME_Mesh *BME_make_new_uvsphere(BME_Mesh *bm, float radius, int rings, int seg) {
	BME_Vert *v1, *v2;
	BME_Edge *e, *e_arr[2];
	BME_Loop *l;
	BME_Poly *f;
	int i, j;
	float vec[3], rpos, rinc, rrad, spos, sinc;

	rpos = 0; /* ring position */
	rinc = (float)M_PI/rings; /* ring increment */
	sinc = (float)(2*M_PI/seg); /* segment increment */
	vec[0] = 0.0;
	vec[1] = 0.0;
	vec[2] = radius;

	/* make pole verts */
	v1 = BME_MV(bm,vec); /* top */
	vec[2] = -vec[2];
	v2 = BME_MV(bm,vec); /* bottom */

	/* make segment edges */
	for (i=0; i<seg; i++) {
		BME_ME(bm,v1,v2); /* make segment edges */
	}

	/* make segment faces (2-edged for now) */
	for (i=0,e=v1->edge; i<seg; i++,e=BME_disk_nextedge(e,v1)) {
		e_arr[0] = e;
		e_arr[1] = BME_disk_nextedge(e,v1);
		f = BME_MF(bm,v1,v2,e_arr,2); /* counter-clockwise */
	}

	/* start at the "top," and work our way down, building rings */
	l = v1->edge->loop;
	if (l->v != v2) { /* v2 (the "bottom") will be the "hub" */
		l = l->next; /* make sure l->v is v2 */
	}
	for (i=1/*we have one less ring edge than "rings"*/,l=v1->edge->loop; i<rings; i++) {
		rpos += rinc;
		vec[0] = (float)(radius*sin(rpos));
		vec[1] = 0.0;
		vec[2] = (float)(radius*cos(rpos));
		v1 = BME_SEMV(bm,v2,l->prev->e,NULL);
		VECCOPY(v1->co,vec);	
		rrad = vec[0]; /* this ring's radius */
		spos = 0; /* segment position */
		for (j=1; j<seg; j++) {
			spos += sinc;
			vec[0] = (float)(rrad*cos(spos));
			vec[1] = (float)(rrad*sin(spos));
			v1 = BME_SEMV(bm,v2,l->e,NULL);
			VECCOPY(v1->co,vec);
			f = BME_SFME(bm,l->f,l->next->v,l->prev->v,NULL);
			l = ((BME_Loop*)l->radial.next->data)->next;
		}
		f = BME_SFME(bm,l->f,l->next->v,l->prev->v,NULL);
	}
	return bm;
}