intravenous
diff src/vein.cc @ 3:94d4c60af435
some progress
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 22 Apr 2012 03:35:18 +0300 |
parents | 3ea290d35984 |
children | c6a6a64df6de |
line diff
1.1 --- a/src/vein.cc Sat Apr 21 23:03:36 2012 +0300 1.2 +++ b/src/vein.cc Sun Apr 22 03:35:18 2012 +0300 1.3 @@ -1,3 +1,4 @@ 1.4 +#include <stdio.h> 1.5 #ifndef _MSC_VER 1.6 #include <alloca.h> 1.7 #else 1.8 @@ -5,11 +6,12 @@ 1.9 #endif 1.10 #include "vein.h" 1.11 #include "geom.h" 1.12 +#include "sdr.h" 1.13 1.14 Vein::Vein() 1.15 { 1.16 - gen_dist = 8.0; 1.17 - subdiv = 8; 1.18 + gen_dist = 16.0; 1.19 + subdiv = 16; 1.20 ring_subdiv = 16; 1.21 rad = 1.0; 1.22 1.23 @@ -23,14 +25,16 @@ 1.24 1.25 Vector3 Vein::calc_center(const Vector3 &ppos) const 1.26 { 1.27 - // TODO add variation 1.28 - return Vector3(0.0, 0.0, ppos.z); 1.29 + Vector3 pt{0, 0, ppos.z}; 1.30 + pt.x = sin(ppos.z * 0.75); 1.31 + pt.y = cos(ppos.z * 0.2) * 0.6; 1.32 + return pt; 1.33 } 1.34 1.35 Vector3 Vein::calc_dir(const Vector3 &ppos) const 1.36 { 1.37 - // TODO add variation 1.38 - return Vector3(0, 0, 1); 1.39 + Vector3 dir = calc_center(ppos + Vector3(0, 0, 0.01)) - calc_center(ppos - Vector3(0, 0, 0.01)); 1.40 + return dir.normalized(); 1.41 } 1.42 1.43 void Vein::build_idxbuf() 1.44 @@ -53,6 +57,18 @@ 1.45 } 1.46 } 1.47 1.48 +bool Vein::init() 1.49 +{ 1.50 + if(!(sdr = create_program_load("sdr/vein.v.glsl", "sdr/vein.p.glsl"))) { 1.51 + fprintf(stderr, "failed to load vein shaders\n"); 1.52 + return false; 1.53 + } 1.54 + if((attr_tang_loc = get_attrib_loc(sdr, "attr_tang")) == -1) { 1.55 + fprintf(stderr, "can't find tangent attribute!\n"); 1.56 + } 1.57 + return true; 1.58 +} 1.59 + 1.60 void Vein::draw(const Vector3 &ppos) const 1.61 { 1.62 float start_z = ppos.z - gen_dist / 2.0; 1.63 @@ -75,16 +91,17 @@ 1.64 up = cross_product(dir, right); 1.65 1.66 Matrix3x3 vrot{right, up, dir}; 1.67 - //Quaternion vrot(dri, dtheta); 1.68 + vrot.transpose(); 1.69 1.70 float theta = 0.0, dtheta = 2.0 * M_PI / ring_subdiv; 1.71 for(int j=0; j<ring_subdiv; j++) { 1.72 - Vector3 vec = Vector3{-cos(theta) * rad, sin(theta) * rad, 0.0} + cent; 1.73 + Vector3 vec = Vector3{-cos(theta) * rad, sin(theta) * rad, 0.0}; 1.74 vec.transform(vrot); 1.75 + vec += cent; 1.76 1.77 vptr->pos = vec; 1.78 vptr->norm = cent - vec; 1.79 - vptr->tang = Vector3(); // TODO 1.80 + vptr->tang = dir; 1.81 vptr->tc = Vector2(); // TODO 1.82 vptr++; 1.83 1.84 @@ -100,5 +117,7 @@ 1.85 } 1.86 1.87 // awesome, now draw it 1.88 - draw_mesh(GL_QUADS, nfaces * 4, vbuf, idxbuf); 1.89 + bind_program(sdr); 1.90 + draw_mesh(GL_QUADS, nfaces * 4, vbuf, idxbuf, attr_tang_loc); 1.91 + bind_program(0); 1.92 }