diff options
author | Eric Anholt <eric@anholt.net> | 2009-08-01 15:54:53 -0700 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2009-08-01 15:54:53 -0700 |
commit | 8756e79b2c884c5675dbc686c3d5a8e564e5a08f (patch) | |
tree | 71ecc3f4c51fc428780c0dd440dc6d9d780f7526 | |
parent | aa36ace5a0d14b6666886349a383ec93e770d8bb (diff) |
Calculate a better bounding box for the rings by calculating their radius.
-rw-r--r-- | glass.c | 17 | ||||
-rw-r--r-- | glass.h | 2 |
2 files changed, 18 insertions, 1 deletions
@@ -265,7 +265,7 @@ calc_new_ring_transforms(int instance) * So we're just making a bounding box and doing a bounding sphere * of it, really. */ - ring_bounding_sphere_radius = sqrt((7.5 * 7.5) * 3); + ring_bounding_sphere_radius = sqrt((5 + ring.radius) * (5 + ring.radius) * 3); } static void @@ -396,13 +396,19 @@ revolve(const float *verts, unsigned int num_verts, float unrotated_tangent4[4]; float texcoord_len = 0; + /* calculate the radius of the ring. */ + for (i = 0; i < num_verts; i++) { + } + /* Calculate the 4-component vertex and normalized normal data * that will be rotated around. */ + ring.radius = 0; for (i = 0; i < num_verts; i++) { int v0; /* previous vertex */ int v2; /* next vertex */ float v0_v2[2], v1_v2[2], normal_len; + float position[4], this_radius; /* Expand vertex data out to 4f, so we can use the same * matrix functions. @@ -412,6 +418,15 @@ revolve(const float *verts, unsigned int num_verts, verts4[i * 4 + 2] = 0.0; verts4[i * 4 + 3] = 1.0; + mult_m4_p4(position, + translation_matrix, + &verts4[i * 4]); + this_radius = sqrt(position[0] * position[0] + + position[1] * position[1] + + position[2] * position[2]); + if (this_radius > ring.radius) + ring.radius = this_radius; + if (i == 0) v0 = num_verts - 1; else @@ -34,6 +34,8 @@ struct revolved_object { int pos_offset, norm_offset, tangent_offset, texcoord_offset; int elements_offset, elements_vert_stride; int num_verts, num_steps; + /* Maximum distance from center of revolution to a vertex. */ + float radius; }; enum ground_uniform_list { |