rayzor
diff src/snode.cc @ 14:a9a948809c6f
starting the renderer screen, plus misc stuff
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 13 Apr 2014 08:06:21 +0300 |
parents | 964f8ea5f095 |
children | 79609d482762 |
line diff
1.1 --- a/src/snode.cc Sat Apr 12 23:37:55 2014 +0300 1.2 +++ b/src/snode.cc Sun Apr 13 08:06:21 2014 +0300 1.3 @@ -1,6 +1,7 @@ 1.4 #include <string.h> 1.5 #include <assert.h> 1.6 #include "snode.h" 1.7 +#include "min3d.h" 1.8 1.9 1.10 SceneNode::SceneNode() 1.11 @@ -165,6 +166,8 @@ 1.12 // TODO: hierarchy 1.13 void SceneNode::calc_matrix() const 1.14 { 1.15 + if(xform_valid) return; 1.16 + 1.17 xform.set_identity(); 1.18 xform.translate(pivot.x, pivot.y, pivot.z); 1.19 xform = xform * rot.get_matrix(); 1.20 @@ -177,14 +180,52 @@ 1.21 1.22 void SceneNode::calc_inv_matrix() const 1.23 { 1.24 + if(inv_xform_valid) return; 1.25 + 1.26 calc_matrix(); 1.27 1.28 inv_xform = xform.inverse(); 1.29 inv_xform_valid = true; 1.30 } 1.31 1.32 -void SceneNode::draw() const 1.33 +void SceneNode::pre_draw() const 1.34 { 1.35 + m3d_matrix_mode(M3D_MODELVIEW); 1.36 + m3d_push_matrix(); 1.37 + m3d_mult_matrix(get_matrix()[0]); 1.38 +} 1.39 + 1.40 +void SceneNode::post_draw() const 1.41 +{ 1.42 + m3d_matrix_mode(M3D_MODELVIEW); 1.43 + m3d_pop_matrix(); 1.44 +} 1.45 + 1.46 +void SceneNode::draw(bool emph) const 1.47 +{ 1.48 + if(emph) { 1.49 + float avg_scale = (scale.x + scale.y + scale.z) / 3.0; 1.50 + m3d_push_matrix(); 1.51 + m3d_scale(avg_scale / scale.x, avg_scale / scale.y, avg_scale / scale.z); 1.52 + 1.53 + m3d_begin(M3D_LINES); 1.54 + m3d_color(1, 0, 0); 1.55 + m3d_vertex(0, 0, 0); 1.56 + m3d_vertex(0.5, 0, 0); 1.57 + m3d_color(0, 1, 0); 1.58 + m3d_vertex(0, 0, 0); 1.59 + m3d_vertex(0, 0.5, 0); 1.60 + m3d_color(0, 0, 1); 1.61 + m3d_vertex(0, 0, 0); 1.62 + m3d_vertex(0, 0, 0.5); 1.63 + m3d_end(); 1.64 + 1.65 + m3d_pop_matrix(); 1.66 + 1.67 + m3d_color(1, 0.8, 0.1); 1.68 + } else { 1.69 + m3d_color(0.9, 0.9, 0.9); 1.70 + } 1.71 } 1.72 1.73 bool SceneNode::intersect(const Ray &ray, float *dist) const