cloth
diff src/plane.cc @ 3:28a31079dcdf
disc
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 04 Jan 2016 10:52:15 +0200 |
parents | 2eac424f58b2 |
children |
line diff
1.1 --- a/src/plane.cc Tue Feb 12 00:23:40 2013 +0200 1.2 +++ b/src/plane.cc Mon Jan 04 10:52:15 2016 +0200 1.3 @@ -41,25 +41,33 @@ 1.4 return true; 1.5 } 1.6 1.7 -void Plane::draw(float sz) const 1.8 +Matrix4x4 Plane::calc_rot_matrix() const 1.9 { 1.10 Vector3 up = Vector3(0, 1, 0); 1.11 - if(fabs(dot_product(up, normal)) < 1e-6) { 1.12 + if(fabs(dot_product(up, normal)) - 1.0 <= 1e-5) { 1.13 up = Vector3(0, 0, 1); 1.14 } 1.15 1.16 - Vector3 right = cross_product(up, normal); 1.17 - up = cross_product(normal, right); 1.18 + Vector3 right = cross_product(up, normal).normalized(); 1.19 + up = cross_product(normal, right).normalized(); 1.20 1.21 Matrix4x4 rot_matrix; 1.22 rot_matrix.set_column_vector(right, 0); 1.23 rot_matrix.set_column_vector(up, 1); 1.24 rot_matrix.set_column_vector(normal, 2); 1.25 rot_matrix.set_row_vector(Vector4(0, 0, 0, 1), 3); 1.26 + return rot_matrix; 1.27 +} 1.28 + 1.29 +void Plane::draw() const 1.30 +{ 1.31 + const float sz = 10.0f; 1.32 + 1.33 + Matrix4x4 rot_matrix = calc_rot_matrix(); 1.34 1.35 glMatrixMode(GL_MODELVIEW); 1.36 glPushMatrix(); 1.37 - glMultTransposeMatrixf((float*)rot_matrix.m); 1.38 + glMultTransposeMatrixf(rot_matrix[0]); 1.39 1.40 glBegin(GL_QUADS); 1.41 glNormal3f(normal.x, normal.y, normal.z);