Ejemplo n.º 1
0
bool plane_intersection_line(const struct plane *p, const struct vec3 *v1,
		const struct vec3 *v2, float *t)
{
	float p1_dist, p2_dist, p1_abs_dist, dist2;
	bool  p1_over, p2_over;

	p1_dist = vec3_plane_dist(v1, p);
	p2_dist = vec3_plane_dist(v2, p);

	if (close_float(p1_dist, 0.0f, EPSILON)) {
		if (close_float(p2_dist, 0.0f, EPSILON))
			return false;

		*t = 0.0f;
		return true;
	} else if (close_float(p2_dist, 0.0f, EPSILON)) {
		*t = 1.0f;
		return true;
	}

	p1_over = (p1_dist > 0.0f);
	p2_over = (p2_dist > 0.0f);

	if (p1_over == p2_over)
		return false;

	p1_abs_dist = fabsf(p1_dist);
	dist2 = p1_abs_dist + fabsf(p2_dist);
	if (dist2 < EPSILON)
		return false;

	*t = p1_abs_dist / dist2;
	return true;
}
Ejemplo n.º 2
0
float calc_torquef(float val1, float val2, float torque, float min_adjust,
                   float t)
{
    float out = val1;
    float dist;
    bool  over;

    if (close_float(val1, val2, EPSILON))
        return val1;

    dist = (val2-val1)*torque;
    over = dist > 0.0f;

    if (over) {
        if (dist < min_adjust) /* prevents from going too slow */
            dist = min_adjust;
        out += dist*t;         /* add torque */
        if (out > val2)        /* clamp if overshoot */
            out = val2;
    } else {
        if (dist > -min_adjust)
            dist = -min_adjust;
        out += dist*t;
        if (out < val2)
            out = val2;
    }

    return out;
}
Ejemplo n.º 3
0
static void render_item_texture(struct obs_scene_item *item)
{
	gs_texture_t *tex = gs_texrender_get_texture(item->item_render);
	gs_effect_t *effect = obs->video.default_effect;
	enum obs_scale_type type = item->scale_filter;
	uint32_t cx = gs_texture_get_width(tex);
	uint32_t cy = gs_texture_get_height(tex);

	if (type != OBS_SCALE_DISABLE) {
		if (type == OBS_SCALE_POINT) {
			gs_eparam_t *image = gs_effect_get_param_by_name(
					effect, "image");
			gs_effect_set_next_sampler(image,
					obs->video.point_sampler);

		} else if (!close_float(item->output_scale.x, 1.0f, EPSILON) ||
		           !close_float(item->output_scale.y, 1.0f, EPSILON)) {
			gs_eparam_t *scale_param;

			if (item->output_scale.x < 0.5f ||
			    item->output_scale.y < 0.5f) {
				effect = obs->video.bilinear_lowres_effect;
			} else if (type == OBS_SCALE_BICUBIC) {
				effect = obs->video.bicubic_effect;
			} else if (type == OBS_SCALE_LANCZOS) {
				effect = obs->video.lanczos_effect;
			}

			scale_param = gs_effect_get_param_by_name(effect,
					"base_dimension_i");
			if (scale_param) {
				struct vec2 base_res_i = {
					1.0f / (float)cx,
					1.0f / (float)cy
				};

				gs_effect_set_vec2(scale_param, &base_res_i);
			}
		}
	}

	while (gs_effect_loop(effect, "Draw"))
		obs_source_draw(tex, 0, 0, 0, 0, 0);
}
Ejemplo n.º 4
0
void cart_to_polar(struct vec3 *dst, const struct vec3 *v)
{
    struct vec3 polar;
    polar.z = vec3_len(v);

    if (close_float(polar.z, 0.0f, EPSILON)) {
        vec3_zero(&polar);
    } else {
        polar.x = asinf(v->y / polar.z);
        polar.y = atan2f(v->x, v->z);
    }

    vec3_copy(dst, &polar);
}
Ejemplo n.º 5
0
static void on_audio_playback(void *param, obs_source_t *source,
		const struct audio_data *audio_data, bool muted)
{
	struct audio_monitor *monitor = param;
	IAudioRenderClient *render = monitor->render;
	uint8_t *resample_data[MAX_AV_PLANES];
	float vol = source->user_volume;
	uint32_t resample_frames;
	uint64_t ts_offset;
	bool success;
	BYTE *output;

	if (pthread_mutex_trylock(&monitor->playback_mutex) != 0) {
		return;
	}
	if (os_atomic_load_long(&source->activate_refs) == 0) {
		goto unlock;
	}

	success = audio_resampler_resample(monitor->resampler, resample_data,
			&resample_frames, &ts_offset,
			(const uint8_t *const *)audio_data->data,
			(uint32_t)audio_data->frames);
	if (!success) {
		goto unlock;
	}

	UINT32 pad = 0;
	monitor->client->lpVtbl->GetCurrentPadding(monitor->client, &pad);

	bool decouple_audio =
		source->async_unbuffered && source->async_decoupled;

	if (monitor->source_has_video && !decouple_audio) {
		uint64_t ts = audio_data->timestamp - ts_offset;

		if (!process_audio_delay(monitor, (float**)(&resample_data[0]),
					&resample_frames, ts, pad)) {
			goto unlock;
		}
	}

	HRESULT hr = render->lpVtbl->GetBuffer(render, resample_frames,
			&output);
	if (FAILED(hr)) {
		goto unlock;
	}

	if (!muted) {
		/* apply volume */
		if (!close_float(vol, 1.0f, EPSILON)) {
			register float *cur = (float*)resample_data[0];
			register float *end = cur +
				resample_frames * monitor->channels;

			while (cur < end)
				*(cur++) *= vol;
		}
		memcpy(output, resample_data[0],
				resample_frames * monitor->channels *
				sizeof(float));
	}

	render->lpVtbl->ReleaseBuffer(render, resample_frames,
			muted ? AUDCLNT_BUFFERFLAGS_SILENT : 0);

unlock:
	pthread_mutex_unlock(&monitor->playback_mutex);
}
Ejemplo n.º 6
0
bool
TestNUB_1d_s()
{
  double start = -5.0;
  double end = 7.0;
  int N  = 200;
  NUgrid* grid = create_center_grid (start, end, 6.0, N);
  bool passed = true;
  float data[N];
  for (int i=0; i<N; i++) 
    data[i] = -1.0 + 2.0*drand48();
  BCtype_s bc;

  // Create spline with PBC
  fprintf (stderr, "Testing 1D single-precision periodic boundary conditions:\n");
  bc.lCode = PERIODIC; bc.rCode = PERIODIC;
  NUBspline_1d_s *periodic = create_NUBspline_1d_s (grid, bc, data);
  float sval, sgrad, slapl, eval, egrad, elapl;
  eval_NUBspline_1d_s_vgl (periodic, start, &sval, &sgrad, &slapl);
  eval_NUBspline_1d_s_vgl (periodic, end  , &eval, &egrad, &elapl);
  bool v_passed, grad_passed, lapl_passed;
  v_passed    = close_float (sval, eval);
  grad_passed = close_float (sgrad, egrad);
  lapl_passed = close_float (slapl, elapl);
  PrintTest ("Value", v_passed);
  PrintTest ("First derivative", grad_passed);
  PrintTest ("Second derivative", lapl_passed);
  passed = passed && v_passed && grad_passed && lapl_passed;

  double x = grid->points[26];
  float val;
  eval_NUBspline_1d_s (periodic, x, &val);
  bool interp_passed = close_float (val, data[26]);
  PrintTest ("Interpolation", interp_passed);
  passed = passed && interp_passed;

  // Create spline with fixed first derivative:
  bc.lCode = DERIV1; bc.lVal = 1.5;
  bc.rCode = DERIV1; bc.rVal = -0.3;
  NUBspline_1d_s *fixed_first = create_NUBspline_1d_s (grid, bc, data);
  fprintf (stderr, "Testing 1D single-precsion fixed first derivative boundary conditions:  \n");
  eval_NUBspline_1d_s_vg (fixed_first, start, &sval, &sgrad);
  eval_NUBspline_1d_s_vg (fixed_first,   end, &eval, &egrad);
  bool bc_passed = close_float (sgrad, 1.5) && close_float (egrad, -0.3);
  PrintTest ("Boundary conditions", bc_passed);
  x = grid->points[26];
  eval_NUBspline_1d_s (periodic, x, &val);
  interp_passed = close_float (val, data[26]);
  PrintTest ("Interpolation", interp_passed);
  passed = passed && interp_passed && bc_passed;

  // Create spline with fixed second derivative:
  bc.lCode = DERIV2; bc.lVal = 1.5;
  bc.rCode = DERIV2; bc.rVal = -0.3;
  NUBspline_1d_s *fixed_second = create_NUBspline_1d_s (grid, bc, data);
  fprintf (stderr, "Testing 1d_s fixed second derivative boundary conditions:  \n");
  eval_NUBspline_1d_s_vgl (fixed_second, start, &sval, &sgrad, &slapl);
  eval_NUBspline_1d_s_vgl (fixed_second,   end, &eval, &egrad, &elapl);
  bc_passed = close_float (slapl, 1.5) && close_float (elapl, -0.3);
  fprintf (stderr, "slapl = %1.8f  elapl = %1.8f\n", slapl, elapl);
  PrintTest ("Boundary conditions", bc_passed);
  x = grid->points[26];
  eval_NUBspline_1d_s (periodic, x, &val);
  interp_passed = close_float (val, data[26]);
  PrintTest ("Interpolation", interp_passed);
  passed = passed && interp_passed && bc_passed;

  return passed;
}