Beispiel #1
0
void affine_operate(affine_stack_t *transforms, affine_operator_t op, void* data) {
	affine_par_t* par_iter;
	int x, y;
	if(transforms->par_next == NULL) {
		op(data, transforms->cur);
	} else {
		affine_stack_t* j = transforms;
		while(j != NULL && j->par_next != NULL) {
			j->par_cur = j->par_next;
			j->par_cur->x_cur = j->par_cur->x_range_min;
			j->par_cur->y_cur = j->par_cur->y_range_min;
			j = j->prev;
		}
		while(1) {
			affine_t composite = identity;
			j = transforms;
			while(j != NULL && j->par_cur != NULL) {
				composite = affine_compose(j->par_cur->cur, composite);
				composite = affine_compose(affine_translate(j->par_cur->x_cur*j->par_cur->x_offset,j->par_cur->y_cur*j->par_cur->y_offset), composite);
				j = j->prev;
			}
			op(data, composite);
			j = transforms;
			while(j != NULL && j->par_cur != NULL && j->par_cur->par_next == NULL && j->par_cur->x_cur >= j->par_cur->x_range_max && j->par_cur->y_cur >= j->par_cur->y_range_max) {
				j->par_cur = j->par_next;
				j->par_cur->x_cur = j->par_cur->x_range_min;
				j->par_cur->y_cur = j->par_cur->y_range_min;
				j = j->prev;
			}
			if(j == NULL || j->par_next == NULL ) {
				j = transforms;
				while(j != NULL && j->par_cur != NULL) {
					j->par_cur = NULL;
					j = j->prev;
				}
				break;
			}
			if(j->par_cur->x_cur < j->par_cur->x_range_max) {
				j->par_cur->x_cur++;
			} else if (j->par_cur->y_cur < j->par_cur->y_range_max) {
				j->par_cur->x_cur = j->par_cur->x_range_min;
				j->par_cur->y_cur++;
			} else {
				j->par_cur = j->par_cur->par_next;
				j->par_cur->x_cur = j->par_cur->x_range_min;
				j->par_cur->y_cur = j->par_cur->y_range_min;
			}
		}
		j = transforms;
		while(j != NULL && j->par_cur != NULL) {
			j->par_cur = NULL;
			j = j->prev;
		}
	}
}
Beispiel #2
0
void render(SDL_Surface* screen)
{
    SDL_LockSurface(screen);
    unsigned int* pixels = (unsigned int*)screen->pixels;
    int x,y;
    for (y = 0; y < screen->h; y++)
    {
        for (x = 0; x < screen->w; x++)
        {
            pixels[(y * screen->w) + x] = black;
        }
    }

    static float angle = 0.0f; 
    affine_identity(rast->model_affine);
    affine_translate(rast->model_affine, 0.0, 0.0, -4.0, 0.0); 
    affine_rotate(rast->model_affine, angle, 0.0, 1.0, 0.0, 0.0); 
    affine_translate(rast->model_affine, 0.0, 0.0, 4.0, 0.0);
    if (++angle > 360.0f)
    {
        angle = 0.0f;
    }

    //raytrace_scene(screen);
    rasteriser_render_triangle(rast, screen, front, 255, 0, 0);
    rasteriser_render_triangle(rast, screen, back, 0, 255, 0);
    rasteriser_render_triangle(rast, screen, left, 0, 0, 255);
    rasteriser_render_triangle(rast, screen, right, 255, 255, 255);
/*
    affine_apply(transform, front->a, front->a);
    affine_apply(transform, front->b, front->b);
    affine_apply(transform, front->c, front->c);
  */ 
    SDL_UnlockSurface(screen);
    SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
}