Exemple #1
0
void ohmd_calc_default_proj_matrices(ohmd_device_properties* props)
{
	mat4x4f proj_base; // base projection matrix

	// Calculate where the lens is on each screen,
	// and with the given value offset the projection matrix.
	float screen_center = props->hsize / 4.0f;
	float lens_shift = screen_center - props->lens_sep / 2.0f;
	float proj_offset = 4.0f * lens_shift / props->hsize;

	// Setup the base projection matrix. Each eye mostly have the
	// same projection matrix with the exception of the offset.
	omat4x4f_init_perspective(&proj_base, props->fov, props->ratio, props->znear, props->zfar);

	// Setup the two adjusted projection matricies. Each is setup to deal
	// with the fact that the lens is not in the center of the screen.
	// These matrices only change of the hardware changes, so static.
	mat4x4f translate;

	omat4x4f_init_translate(&translate, proj_offset, 0, 0);
	omat4x4f_mult(&translate, &proj_base, &props->proj_left);

	omat4x4f_init_translate(&translate, -proj_offset, 0, 0);
	omat4x4f_mult(&translate, &proj_base, &props->proj_right);
}
Exemple #2
0
static void calc_derived_values(rift_priv *priv)
{
	priv->base.properties.hsize = priv->display_info.h_screen_size;
	priv->base.properties.vsize = priv->display_info.v_screen_size;
	priv->base.properties.hres = priv->display_info.h_resolution;
	priv->base.properties.vres = priv->display_info.v_resolution;
	priv->base.properties.lens_sep = priv->display_info.lens_separation;
	priv->base.properties.lens_vpos = priv->display_info.v_center;

	priv->base.properties.fov = DEG_TO_RAD(125.5144f); // TODO calculate.


	// Calculate the screen ratio of each subscreen.
	float full_ratio = (float)priv->display_info.h_resolution /
	                   (float)priv->display_info.v_resolution;
	float ratio = full_ratio / 2.0f;

	priv->base.properties.ratio = ratio;


	// Calculate where the lens is on each screen,
	// and with the given value offset the projection matrix.
	float screen_center = priv->display_info.h_screen_size / 4.0f;
	float lens_shift = screen_center - priv->display_info.lens_separation / 2.0f;
	float proj_offset = 4.0f * lens_shift / priv->display_info.h_screen_size;

	priv->calc_values.proj_offset = proj_offset;


	// Setup the base projection matrix. Each eye mostly have the
	// same projection matrix with the exception of the offset.
	omat4x4f_init_perspective(&priv->calc_values.proj_base,
	                          priv->base.properties.fov,
	                          priv->base.properties.ratio,
	                          priv->base.properties.znear,
	                          priv->base.properties.zfar);


	// Setup the two adjusted projection matricies. Each is setup to deal
	// with the fact that the lens is not in the center of the screen.
	// These matrices only change of the hardware changes, so static.
	mat4x4f translate;

	omat4x4f_init_translate(&translate, proj_offset, 0, 0);
	omat4x4f_mult(&translate,
	              &priv->calc_values.proj_base,
	              &priv->base.properties.proj_left);

	omat4x4f_init_translate(&translate, -proj_offset, 0, 0);
	omat4x4f_mult(&translate,
	              &priv->calc_values.proj_base,
	              &priv->base.properties.proj_right);
}