ld33_umonster
diff src/dragon.cc @ 10:1b30bd381667
sweep curve mesh gen and dragon horns
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 27 Aug 2015 05:25:04 +0300 |
parents | 4f6168f3ca82 |
children |
line diff
1.1 --- a/src/dragon.cc Thu Aug 27 01:58:26 2015 +0300 1.2 +++ b/src/dragon.cc Thu Aug 27 05:25:04 2015 +0300 1.3 @@ -4,7 +4,9 @@ 1.4 #include "metasurf.h" 1.5 #include "geom.h" 1.6 #include "game.h" 1.7 +#include "object.h" 1.8 #include "shadow.h" 1.9 +#include "meshgen.h" 1.10 1.11 #define VOXEL_PAD 1.0f 1.12 #define DYN_FCOUNT 64 1.13 @@ -19,6 +21,9 @@ 1.14 static Vector3 bezier(const Vector3 &a, const Vector3 &b, const Vector3 &c, const Vector3 &d, float t); 1.15 static float mseval(struct metasurface *ms, float x, float y, float z); 1.16 static void msvertex(struct metasurface *ms, float x, float y, float z); 1.17 +static void gen_detail_meshes(); 1.18 + 1.19 +static std::vector<Object*> detail_obj; 1.20 1.21 1.22 Dragon::Dragon() 1.23 @@ -48,6 +53,10 @@ 1.24 msurf_set_threshold(msurf, 1.0); 1.25 msurf_eval_func(msurf, mseval); 1.26 msurf_vertex_func(msurf, msvertex); 1.27 + 1.28 + if(detail_obj.empty()) { 1.29 + gen_detail_meshes(); 1.30 + } 1.31 } 1.32 1.33 Dragon::~Dragon() 1.34 @@ -214,6 +223,17 @@ 1.35 glPopAttrib(); 1.36 if(cur_sdr) glUseProgram(cur_sdr); 1.37 } 1.38 + 1.39 + // draw detail objects 1.40 + for(size_t i=0; i<detail_obj.size(); i++) { 1.41 + detail_obj[i]->xform().set_translation(head_pos); 1.42 + 1.43 + if(dbg_wireframe) { 1.44 + detail_obj[i]->draw_wire(); 1.45 + } else { 1.46 + detail_obj[i]->draw(); 1.47 + } 1.48 + } 1.49 } 1.50 1.51 void Dragon::flush_dynvbo() const 1.52 @@ -290,3 +310,40 @@ 1.53 dragon->flush_dynvbo(); 1.54 } 1.55 } 1.56 + 1.57 + 1.58 +#define HORN_RAD 0.15f 1.59 +static Vector2 horn_sweep(float u, float v, void *cls) 1.60 +{ 1.61 + float t = 1.0f - v; 1.62 + float angle = u * 2.0 * M_PI; 1.63 + float x = sin(angle) * t * HORN_RAD; 1.64 + float y = cos(angle) * t * HORN_RAD; 1.65 + return Vector2(x, y + smoothstep(0.3, 1.0, v) * 0.5); 1.66 +} 1.67 + 1.68 +static void gen_detail_meshes() 1.69 +{ 1.70 + Mesh *mesh; 1.71 + Object *obj; 1.72 + Matrix4x4 xform; 1.73 + 1.74 + for(int i=0; i<2; i++) { 1.75 + float sign = i ? 1.0f : -1.0f; 1.76 + 1.77 + mesh = new Mesh; 1.78 + gen_sweep(mesh, 2, 6, 6, horn_sweep, 0); 1.79 + xform.set_translation(Vector3(0.5 * sign, 1.5, 3)); 1.80 + xform.rotate(Vector3(DEG_TO_RAD(25), 0, 0)); 1.81 + xform.rotate(Vector3(0, 0, DEG_TO_RAD(15) * -sign)); 1.82 + mesh->apply_xform(xform, Matrix4x4::identity); 1.83 + 1.84 + obj = new Object; 1.85 + obj->set_mesh(mesh); 1.86 + obj->mtl.diffuse = Vector3(1.0, 0.85, 0.8); 1.87 + obj->mtl.specular = Vector3(1, 1, 1); 1.88 + obj->mtl.shininess = 60.0; 1.89 + 1.90 + detail_obj.push_back(obj); 1.91 + } 1.92 +}