volmetrics

annotate src/mesh.cc @ 26:5ee081af59b8

volume rendering
author Eleni Maria Stea <elene.mst@gmail.com>
date Sun, 27 Apr 2014 18:25:40 +0300
parents 928954bfefd7
children df4a277adb82
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@9 24 bool Mesh::is_empty() const
elene@9 25 {
elene@9 26 return vertices.empty();
elene@9 27 }
elene@9 28
elene@8 29 void Mesh::draw() const
elene@8 30 {
elene@8 31 size_t sz = vertices.size();
elene@8 32
elene@8 33 if(normals.size() != sz)
elene@8 34 return;
elene@8 35
elene@8 36 glBegin(GL_TRIANGLES);
elene@8 37 for(size_t i=0; i<sz; i++) {
elene@8 38 const Vector3 &n = normals[i];
elene@8 39 glNormal3f(n.x, n.y, n.z);
elene@8 40
elene@8 41 const Vector3 &v = vertices[i];
elene@8 42 glVertex3f(v.x, v.y, v.z);
elene@8 43 }
elene@8 44 glEnd();
elene@8 45 }