volmetrics

annotate src/mesh.cc @ 36:1df14c5ffa71

conversion to Qt
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 06 Feb 2015 22:39:51 +0200
parents 40febfed6cff
children
rev   line source
nuclear@35 1 #include "opengl.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 }