示例#1
0
文件: parse.c 项目: alxerg/stl2pov
int step_text(struct stl_reader *r)
{
	float norm[3], pnt[3];
	int j, vertices[3];
	clock_t begin, end;
	unsigned usec;
	assert(r!=NULL);
	begin = clock();
 step_text_again:
	if (read_text_vector(r, nl, norm)) {
		return 1;
	}
	for (j=0; j<3; j++) {
		if (read_text_vector(r, vt, pnt)) {
			return 1;
		}
		vertices[j] = vertex_add(r, pnt);
	}
	facet_add(r, vertices, norm);
	end = clock();
	usec = end-begin;
	if (usec < WORKSLICE) 
		goto step_text_again;
     	return 0;
}
示例#2
0
文件: parse.c 项目: alxerg/stl2pov
int step_binary(struct stl_reader *r)
{
	float *normal, *vertex1, *vertex2, *vertex3;
	clock_t begin, end;
	unsigned usec;
	int vertices[3];
	assert(r!=NULL);
	begin = clock();
 step_binary_again:
	if ((r->ptr - r->buf + 50) > r->buflen) return 1;
	normal = (float*) r->ptr; vertex1 = normal + 3; 
	vertex2 = vertex1 + 3; vertex3 = vertex2 + 3;
	r->ptr += 50;
	vertices[0] = vertex_add(r, vertex1);
	vertices[1] = vertex_add(r, vertex2);
	vertices[2] = vertex_add(r, vertex3);
	facet_add(r, vertices, normal);
	end = clock();
	usec = end-begin;
	if (usec < WORKSLICE)
		goto step_binary_again;
	return 0;
}
示例#3
0
// 绘制扫描线
void device_draw_scanline(device_t *device, scanline_t *scanline) {
	IUINT32 *framebuffer = device->framebuffer[scanline->y];
	float *zbuffer = device->zbuffer[scanline->y];
	int x = scanline->x;
	int w = scanline->w;
	int width = device->width;
	int render_state = device->render_state;
	for (; w > 0; x++, w--) {
		if (x >= 0 && x < width) {
			float rhw = scanline->v.rhw;
			if (rhw >= zbuffer[x]) {
				float w = 1.0f / rhw;
				zbuffer[x] = rhw;
				if (render_state & RENDER_STATE_COLOR) {
					float r = scanline->v.color.r * w;
					float g = scanline->v.color.g * w;
					float b = scanline->v.color.b * w;
					int R = (int)(r * 255.0f);
					int G = (int)(g * 255.0f);
					int B = (int)(b * 255.0f);
					R = CMID(R, 0, 255);
					G = CMID(G, 0, 255);
					B = CMID(B, 0, 255);
					framebuffer[x] = (R << 16) | (G << 8) | (B);
				}
				if (render_state & RENDER_STATE_TEXTURE) {
					float u = scanline->v.tc.u * w;
					float v = scanline->v.tc.v * w;
					IUINT32 cc = device_texture_read(device, u, v);
					framebuffer[x] = cc;
				}
			}
		}
		vertex_add(&scanline->v, &scanline->step);
		if (x >= width) break;
	}
}