volmetrics
annotate 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 |
rev | line source |
---|---|
elene@8 | 1 #include <GL/gl.h> |
elene@8 | 2 #include "mesh.h" |
elene@8 | 3 |
elene@8 | 4 Mesh::Mesh() |
elene@8 | 5 { |
elene@8 | 6 } |
elene@8 | 7 |
elene@8 | 8 void Mesh::add_vertex(const Vector3 &vertex) |
elene@8 | 9 { |
elene@8 | 10 vertices.push_back(vertex); |
elene@8 | 11 } |
elene@8 | 12 |
elene@8 | 13 void Mesh::add_normal(const Vector3 &normal) |
elene@8 | 14 { |
elene@8 | 15 normals.push_back(normal); |
elene@8 | 16 } |
elene@8 | 17 |
elene@8 | 18 void Mesh::clear() |
elene@8 | 19 { |
elene@8 | 20 vertices.clear(); |
elene@8 | 21 normals.clear(); |
elene@8 | 22 } |
elene@8 | 23 |
elene@8 | 24 void Mesh::draw() const |
elene@8 | 25 { |
elene@8 | 26 size_t sz = vertices.size(); |
elene@8 | 27 |
elene@8 | 28 if(normals.size() != sz) |
elene@8 | 29 return; |
elene@8 | 30 |
elene@8 | 31 glBegin(GL_TRIANGLES); |
elene@8 | 32 for(size_t i=0; i<sz; i++) { |
elene@8 | 33 const Vector3 &n = normals[i]; |
elene@8 | 34 glNormal3f(n.x, n.y, n.z); |
elene@8 | 35 |
elene@8 | 36 const Vector3 &v = vertices[i]; |
elene@8 | 37 glVertex3f(v.x, v.y, v.z); |
elene@8 | 38 } |
elene@8 | 39 glEnd(); |
elene@8 | 40 } |