示例#1
0
void object3d_render(screen_buffer *screen, object3d *obj) {
	vec3 a, b, c;
	int i;
	for (i = 0; i < obj->vertex_cnt; i+=3) {
		a = obj->vertices[i][0];
		b = obj->vertices[i+1][0];
		c = obj->vertices[i+2][0];
		
		vec3_rotate(&a, &obj->rotation);
		vec3_mul(&a, &obj->scale);
		vec3_add(&a, &obj->position);

		vec3_rotate(&b, &obj->rotation);
		vec3_mul(&b, &obj->scale);
		vec3_add(&b, &obj->position);
		
		vec3_rotate(&c, &obj->rotation);
		vec3_mul(&c, &obj->scale);
		vec3_add(&c, &obj->position);

		rasterize_vertex(screen, &a, &b, &c);
		//line(screen, a.x, a.y, b.x, b.y, '+');
		//line(screen, b.x, b.y, c.x, c.y, '+');
		//line(screen, c.x, c.y, a.x, a.y, '+');
	}
}
示例#2
0
void matrix3_mul(struct matrix3 *dst, const struct matrix3 *m1,
		const struct matrix3 *m2)
{
	vec3_rotate(&dst->x, &m1->x, m2);
	vec3_rotate(&dst->y, &m1->y, m2);
	vec3_rotate(&dst->z, &m1->z, m2);
	vec3_transform(&dst->t, &m1->t, m2);
}