/**
	 * @param variable
	 * @param positionComponent1 The first component of the position
	 * @param positionComponent2 The second component of the position
	 * @param positionComponent3 The third component of the position
	 * @return
	 */
	float KameleonInterpolator::compute_beta(const std::string& variable, const float& positionComponent1,
			const float& positionComponent2, const float& positionComponent3)
	{
		float dComponent1, dComponent2, dComponent3;
		return compute_beta(variable, positionComponent1, positionComponent2, positionComponent3, dComponent1,
				dComponent2, dComponent3);
	}
Exemplo n.º 2
0
/**
 * Raster the color triangle to the screen.  Points are in
 * NDC coordinates (converted to screen coordinates).
 *
 * colors correspond to the respective points.
 */
void raster_triangle(point *a, point *b, point *c, color ca,
		color cb, color cc, int xres, int yres, color** grid,
		float** depth_grid) {
	point screen_a = NDC_to_screen(a, xres, yres);
	point screen_b = NDC_to_screen(b, xres, yres);
	point screen_c = NDC_to_screen(c, xres, yres);

	float x_min = min_x(&screen_a, &screen_b, &screen_c);
	float x_max = max_x(&screen_a, &screen_b, &screen_c);
	float y_min = min_y(&screen_a, &screen_b, &screen_c);
	float y_max = max_y(&screen_a, &screen_b, &screen_c);

	x_max = x_max > xres ? xres : x_max;
	y_max = y_max > yres ? yres : y_max;

	for (int x = x_min; x < x_max; x++) {
		for (int y = y_min; y < y_max; y++) {
			point curr_point = create_point(x, y, 0);
			float alpha = compute_alpha(&screen_a, &screen_b, &screen_c, &curr_point);
			float beta = compute_beta(&screen_a, &screen_b, &screen_c, &curr_point);
			float gamma = compute_gamma(&screen_a, &screen_b, &screen_c, &curr_point);
			curr_point.z = alpha * screen_a.z + beta * screen_b.z + gamma * screen_c.z;

			if (valid_parameters(alpha, beta, gamma) && depth_grid[x][y] > curr_point.z) {
				color col = compute_color(ca, cb, cc, alpha, beta, gamma);
				grid[x][y].r = col.r;
				grid[x][y].g = col.g;
				grid[x][y].b = col.b;

				depth_grid[x][y] = curr_point.z;
			}
		}
	}
}
Exemplo n.º 3
0
/**
 * Also has depth buffering and ignores points where normals point away
 *
 * Points a, b, c are in NDC
 */
void raster_triangle_Phong(point *a, point *b, point *c,
		point *world_a, point *world_b, point *world_c,
		point *normal_a, point *normal_b, point *normal_c,
		object_copy *obj, vector<light> *lights, camera *CAM,
		int xres, int yres, color** grid, float** depth_grid,
		MatrixXd *perspective, MatrixXd *inv_cam) {

	point screen_a = NDC_to_screen(a, xres, yres);
	point screen_b = NDC_to_screen(b, xres, yres);
	point screen_c = NDC_to_screen(c, xres, yres);

	float x_min = min_x(&screen_a, &screen_b, &screen_c);
	float x_max = max_x(&screen_a, &screen_b, &screen_c);
	float y_min = min_y(&screen_a, &screen_b, &screen_c);
	float y_max = max_y(&screen_a, &screen_b, &screen_c);

	x_max = x_max > xres ? xres : x_max;
	y_max = y_max > yres ? yres : y_max;
	x_min = x_min < 0 ? 0 : x_min;
	y_min = y_min < 0 ? 0 : y_min;

	// TODO: compute colors by normals

	for (int x = x_min; x < x_max; x++) {
		for (int y = y_min; y < y_max; y++) {
			// get alpha/beta/gamma
			point curr_point = create_point(x, y, 0);
			float alpha = compute_alpha(&screen_a, &screen_b, &screen_c, &curr_point);
			float beta = compute_beta(&screen_a, &screen_b, &screen_c, &curr_point);
			float gamma = compute_gamma(&screen_a, &screen_b, &screen_c, &curr_point);
			curr_point.z = alpha * screen_a.z + beta * screen_b.z + gamma * screen_c.z;

			// compute interpolated point (in world view) and normal for the point
			point normal = (*normal_a) * alpha + (*normal_b) * beta + (*normal_c) * gamma;
			point coordinate = (*world_a) * alpha + (*world_b) * beta + (*world_c) * gamma;
			point ndc_coordinate = to_NDC(&coordinate, perspective, inv_cam);

			if (is_in_box(&ndc_coordinate) && valid_parameters(alpha, beta, gamma)
					&& depth_grid[x][y] > curr_point.z) {
				color col = lighting(&coordinate, &normal, obj, lights, CAM);
				grid[x][y].r = col.r;
				grid[x][y].g = col.g;
				grid[x][y].b = col.b;

				depth_grid[x][y] = curr_point.z;
			}
		}
	}
}
Exemplo n.º 4
0
/* synth_buffer
 * ============
 * synthesizes a buffer of sound using
 * amplitude linear interpolation and
 * phase cubic interpolation
 * a1: strating amplitude 
 * a2: ending amplitude
 * f1: starting frequency in radians per sample
 * f2: ending frequency in radians per sample
 * p1: starting phase in radians
 * p2: ending phase in radians
 * buffer: pointer to synthsis buffer
 * which is filled out by the function
 * NOTE: caller should allocate memory for buffer
 * frame_samps: number of samples in frame (buffer)
 */
void synth_buffer(double a1,double a2, double f1, double f2, double p1, double p2, double *buffer, int frame_samps)
{
  int k, M;
  double aux, alpha, beta, amp, amp_inc, int_pha;
  M = compute_m(p1, f1, p2, f2, frame_samps);
  aux = compute_aux(p1, p2, f1, frame_samps, M);
  alpha = compute_alpha(aux, f1, f2, frame_samps);
  beta = compute_beta(aux, f1, f2, frame_samps);
  amp = a1;
  amp_inc = (a2 - a1) / (double)frame_samps;
  for(k = 0; k < frame_samps; k++) {
    int_pha = interp_phase(p1, f1, alpha, beta, k);
    buffer[k] += amp * cos(int_pha);
    amp += amp_inc;
 }
}