/* * CS5600 University of Utah * Charles McGarvey * mcgarvey@eng.utah.edu */ #ifndef _RAY_HH_ #define _RAY_HH_ #include "vec.hh" /* * A simple ray class. */ struct ray { vec_t o; vec_t d; }; typedef struct ray ray_t; /* * Initialize a ray with an origin point and a direction. */ INLINE_MAYBE void ray_init(ray_t* r, vec_t origin, vec_t direction) { r->o = origin; r->d = direction; } /* * Create a new ray with an origin point and a direction. */ INLINE_MAYBE ray_t ray_new(vec_t origin, vec_t direction) { ray_t r; ray_init(&r, origin, direction); return r; } /* * Normalize the direction of a ray. */ INLINE_MAYBE ray_t ray_normalize(ray_t r) { return ray_new(r.o, vec_normalize(r.d)); } /* * Solve for a point along the array, given a distance. The ray must be * normalized for this to work as expected. */ INLINE_MAYBE vec_t ray_solve(ray_t r, scal_t distance) { return vec_add(r.o, vec_scale(r.d, distance)); } #endif // _RAY_HH_