Ejemplo n.º 1
0
static void compute_uvw_vectors(struct Camera *cam)
{
	double halfu, halfv;
	int i;

	/* assumes dir and up are normalized */
	VEC3_COPY(cam->wvec, cam->dir);
	VEC3_NORMALIZE(cam->wvec);

	VEC3_CROSS(cam->uvec, cam->wvec, cam->up);
	VEC3_NORMALIZE(cam->uvec);

	VEC3_CROSS(cam->vvec, cam->uvec, cam->wvec);
	VEC3_NORMALIZE(cam->vvec);

	halfv = tan(RADIAN(cam->fov/2));
	halfu = halfv * cam->aspect;

	for (i = 0; i < 3; i++) {
		cam->scrn_bottom_left[i] = cam->center[i] +
				cam->wvec[i] -
				halfu * cam->uvec[i] -
				halfv * cam->vvec[i];
	}

	VEC3_MUL_ASGN(cam->uvec, 2 * halfu);
	VEC3_MUL_ASGN(cam->vvec, 2 * halfv);
}
Ejemplo n.º 2
0
void CamGetRay(const struct Camera *cam, const double *screen_uv, struct Ray *ray)
{
	int i;
	for (i = 0; i < 3; i++) {
		ray->dir[i] =
				cam->scrn_bottom_left[i] +
				screen_uv[0] * cam->uvec[i] +
				screen_uv[1] * cam->vvec[i] -
				cam->center[i];
	}
	VEC3_NORMALIZE(ray->dir);
	VEC3_COPY(ray->orig, cam->center);
	ray->tmin = cam->znear;
	ray->tmax = cam->zfar;
}
Ejemplo n.º 3
0
void CamGetRay(const struct Camera *cam, const double *screen_uv,
		double time, struct Ray *ray)
{
	const struct Transform *transform_interp = get_interpolated_transform(cam, time);
	double target[3] = {0, 0, 0};
	double eye[3] = {0, 0, 0};

	compute_ray_target(cam, screen_uv, target);
	XfmTransformPoint(transform_interp, target);
	XfmTransformPoint(transform_interp, eye);

	VEC3_SUB(ray->dir, target, eye);
	VEC3_NORMALIZE(ray->dir);
	VEC3_COPY(ray->orig, eye);

	ray->tmin = cam->znear;
	ray->tmax = cam->zfar;
}