volmetrics
diff src/mesh.cc @ 8:928954bfefd7
added mesh (draw: immediate mode - todo: displ. list)
author | Eleni Maria Stea <elene.mst@gmail.com> |
---|---|
date | Sat, 25 Jan 2014 19:25:32 +0200 |
parents | |
children | 40febfed6cff |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/mesh.cc Sat Jan 25 19:25:32 2014 +0200 1.3 @@ -0,0 +1,40 @@ 1.4 +#include <GL/gl.h> 1.5 +#include "mesh.h" 1.6 + 1.7 +Mesh::Mesh() 1.8 +{ 1.9 +} 1.10 + 1.11 +void Mesh::add_vertex(const Vector3 &vertex) 1.12 +{ 1.13 + vertices.push_back(vertex); 1.14 +} 1.15 + 1.16 +void Mesh::add_normal(const Vector3 &normal) 1.17 +{ 1.18 + normals.push_back(normal); 1.19 +} 1.20 + 1.21 +void Mesh::clear() 1.22 +{ 1.23 + vertices.clear(); 1.24 + normals.clear(); 1.25 +} 1.26 + 1.27 +void Mesh::draw() const 1.28 +{ 1.29 + size_t sz = vertices.size(); 1.30 + 1.31 + if(normals.size() != sz) 1.32 + return; 1.33 + 1.34 + glBegin(GL_TRIANGLES); 1.35 + for(size_t i=0; i<sz; i++) { 1.36 + const Vector3 &n = normals[i]; 1.37 + glNormal3f(n.x, n.y, n.z); 1.38 + 1.39 + const Vector3 &v = vertices[i]; 1.40 + glVertex3f(v.x, v.y, v.z); 1.41 + } 1.42 + glEnd(); 1.43 +}