ld33_umonster
changeset 8:bed39534d471
fell back to the equi-radii capsule which works
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 25 Aug 2015 02:26:01 +0300 |
parents | 92d662deb66e |
children | 4f6168f3ca82 |
files | src/dragon.cc src/geom.cc |
diffstat | 2 files changed, 36 insertions(+), 6 deletions(-) [+] |
line diff
1.1 --- a/src/dragon.cc Tue Aug 25 00:38:00 2015 +0300 1.2 +++ b/src/dragon.cc Tue Aug 25 02:26:01 2015 +0300 1.3 @@ -10,10 +10,11 @@ 1.4 #define DYN_FCOUNT 64 1.5 #define DYN_VCOUNT (DYN_FCOUNT * 3) 1.6 1.7 -#define NUM_NECK_SEG 8 1.8 +#define NUM_NECK_SEG 10 1.9 static const float nseg_sizes[NUM_NECK_SEG][2] = { 1.10 - {1.0, 3.0}, {1.0, 1.5}, {1.5, 2.0}, {2.0, 2.5}, {2.5, 3.0}, {3.0, 3.5} 1.11 + {2.0, 2.0}, {1.0, 1.0}, {1.0, 1.0}, {1.25, 1.25}, {1.3, 1.3}, {1.5, 1.5}, {1.6, 1.6}, {1.75, 1.75}, {2.0, 2.0}, {2.1, 2.1} 1.12 }; 1.13 +#define NSEG_SZ_SCALE 0.5f 1.14 1.15 static Vector3 bezier(const Vector3 &a, const Vector3 &b, const Vector3 &c, const Vector3 &d, float t); 1.16 static float mseval(struct metasurface *ms, float x, float y, float z); 1.17 @@ -36,8 +37,9 @@ 1.18 neck_seg = new Capsule[neck_seg_count]; 1.19 1.20 for(int i=0; i<neck_seg_count; i++) { 1.21 - neck_seg[i].w[0] = nseg_sizes[i][0]; 1.22 - neck_seg[i].w[1] = nseg_sizes[i][1]; 1.23 + int idx = neck_seg_count - i - 1; 1.24 + neck_seg[i].w[0] = nseg_sizes[idx][0] * NSEG_SZ_SCALE; 1.25 + neck_seg[i].w[1] = nseg_sizes[idx][1] * NSEG_SZ_SCALE; 1.26 } 1.27 1.28 msurf = msurf_create(); 1.29 @@ -135,8 +137,8 @@ 1.30 1.31 void Dragon::draw() const 1.32 { 1.33 - static float bmin[] = { head_xlim[0] - VOXEL_PAD * 0.9, head_ylim[0] - VOXEL_PAD, head_pos.z }; 1.34 - static float bmax[] = { head_xlim[1] + VOXEL_PAD * 0.9, head_ylim[1] + VOXEL_PAD * 2.1f, pos.z + VOXEL_PAD }; 1.35 + static float bmin[] = { head_xlim[0] - VOXEL_PAD * 1.2f, head_ylim[0] - VOXEL_PAD, head_pos.z }; 1.36 + static float bmax[] = { head_xlim[1] + VOXEL_PAD * 1.2f, head_ylim[1] + VOXEL_PAD * 2.1f, pos.z + VOXEL_PAD }; 1.37 msurf_set_bounds(msurf, bmin[0], bmin[1], bmin[2], bmax[0], bmax[1], bmax[2]); 1.38 1.39
2.1 --- a/src/geom.cc Tue Aug 25 00:38:00 2015 +0300 2.2 +++ b/src/geom.cc Tue Aug 25 02:26:01 2015 +0300 2.3 @@ -256,6 +256,33 @@ 2.4 return (pt - cent).length() - rad; 2.5 } 2.6 2.7 +// TODO version which takes both radii into account 2.8 +float capsule_distance(const Vector3 &a, float ra, const Vector3 &b, float rb, const Vector3 &pt) 2.9 +{ 2.10 + Vector3 ab_dir = b - a; 2.11 + float ab_len_sq = ab_dir.length_sq(); 2.12 + 2.13 + if(fabs(ab_len_sq) < 1e-5) { 2.14 + // if a == b, the capsule is a sphere with radius the maximum of the capsule radii 2.15 + return sphere_distance(a, std::max(ra, rb), pt); 2.16 + } 2.17 + float ab_len = sqrt(ab_len_sq); 2.18 + 2.19 + Vector3 ap_dir = pt - a; 2.20 + 2.21 + float t = dot_product(ap_dir, ab_dir / ab_len) / ab_len; 2.22 + if(t < 0.0) { 2.23 + return sphere_distance(a, ra, pt); 2.24 + } 2.25 + if(t >= 1.0) { 2.26 + return sphere_distance(b, rb, pt); 2.27 + } 2.28 + 2.29 + Vector3 pproj = a + ab_dir * t; 2.30 + return (pproj - pt).length() - ra; 2.31 +} 2.32 + 2.33 +#if 0 2.34 float capsule_distance(const Vector3 &a, float ra, const Vector3 &b, float rb, const Vector3 &pt) 2.35 { 2.36 Vector3 ab_dir = b - a; 2.37 @@ -304,3 +331,4 @@ 2.38 } 2.39 return dist; 2.40 } 2.41 +#endif