]>
Dogcows Code - chaz/rasterize/blob - vec.h
3 * CS5600 University of Utah
5 * mcgarvey@eng.utah.edu
15 * A simple vector class.
24 typedef struct vec vec_t
;
27 * Initialize a vector with four components.
30 void vec_init(vec_t
* v
, scal_t x
, scal_t y
, scal_t z
, scal_t w
)
40 * Create a new vector with four components.
43 vec_t
vec_new2(scal_t x
, scal_t y
, scal_t z
, scal_t w
)
46 vec_init(&v
, x
, y
, z
, w
);
51 * Create a new vector with three components. The fourth component is
55 vec_t
vec_new(scal_t x
, scal_t y
, scal_t z
)
57 return vec_new2(x
, y
, z
, S(1.0));
60 #define VEC_ZERO vec_new(S(0.0), S(0.0), S(0.0))
61 #define VEC_ORTHO_X vec_new(S(1.0), S(0.0), S(0.0))
62 #define VEC_ORTHO_Y vec_new(S(0.0), S(1.0), S(0.0))
63 #define VEC_ORTHO_Z vec_new(S(0.0), S(0.0), S(1.0))
67 * Scale the vector with a scalar value.
70 vec_t
vec_scale(vec_t v
, scal_t s
)
79 * Add two vectors together.
82 vec_t
vec_add(vec_t a
, vec_t b
)
91 * Subtract a vector from another vector.
94 vec_t
vec_sub(vec_t a
, vec_t b
)
104 * Get the dot product of two vectors.
107 scal_t
vec_dot(vec_t a
, vec_t b
)
109 return a
.x
* b
.x
+ a
.y
* b
.y
+ a
.z
* b
.z
+ a
.w
* b
.w
;
113 * Get the dot product of two vectors, ignoring the last component.
116 scal_t
vec_dot3(vec_t a
, vec_t b
)
118 return a
.x
* b
.x
+ a
.y
* b
.y
+ a
.z
* b
.z
;
123 * Check whether the values of the first three components could actually be
124 * barycentric coordinates. Note: The necessary condition of each component
125 * adding up to one is assumed and not checked.
128 bool vec_is_barycentric(vec_t v
)
131 * XXX: I'm fudging the bounds a little because horizontal edges (relative
132 * to the screen) are otherwise sometimes really jagged. This probably
133 * isn't the best solution.
135 if (S(-0.000001) <= v
.x
&& v
.x
<= S(1.000001) &&
136 S(-0.000001) <= v
.y
&& v
.y
<= S(1.000001) &&
137 S(-0.000001) <= v
.z
&& v
.z
<= S(1.000001)) {
This page took 0.047448 seconds and 5 git commands to generate.