# HG changeset patch # User Eleni Maria Stea <elene.mst@gmail.com> # Date 1390670732 -7200 # Node ID 928954bfefd7092d2722051d14eba076b555cb95 # Parent 5455c9723d9ebd8573baa70850ecfde7aefa2412 added mesh (draw: immediate mode - todo: displ. list) diff -r 5455c9723d9e -r 928954bfefd7 src/mesh.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/mesh.cc Sat Jan 25 19:25:32 2014 +0200 @@ -0,0 +1,40 @@ +#include <GL/gl.h> +#include "mesh.h" + +Mesh::Mesh() +{ +} + +void Mesh::add_vertex(const Vector3 &vertex) +{ + vertices.push_back(vertex); +} + +void Mesh::add_normal(const Vector3 &normal) +{ + normals.push_back(normal); +} + +void Mesh::clear() +{ + vertices.clear(); + normals.clear(); +} + +void Mesh::draw() const +{ + size_t sz = vertices.size(); + + if(normals.size() != sz) + return; + + glBegin(GL_TRIANGLES); + for(size_t i=0; i<sz; i++) { + const Vector3 &n = normals[i]; + glNormal3f(n.x, n.y, n.z); + + const Vector3 &v = vertices[i]; + glVertex3f(v.x, v.y, v.z); + } + glEnd(); +} diff -r 5455c9723d9e -r 928954bfefd7 src/mesh.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/mesh.h Sat Jan 25 19:25:32 2014 +0200 @@ -0,0 +1,23 @@ +#ifndef MESH_H_ +#define MESH_H_ + +#include <vector> +#include "vector.h" + +class Mesh { +private: + std::vector<Vector3> vertices; + std::vector<Vector3> normals; + +public: + Mesh(); + + void add_vertex(const Vector3 &vertex); + void add_normal(const Vector3 &normal); + + void clear(); + + void draw() const; +}; + +#endif // MESH_H_ diff -r 5455c9723d9e -r 928954bfefd7 src/volume.cc --- a/src/volume.cc Sat Jan 18 03:46:43 2014 +0200 +++ b/src/volume.cc Sat Jan 25 19:25:32 2014 +0200 @@ -163,7 +163,7 @@ return vol_tex; } -void Volume::draw() +void Volume::draw() const { } diff -r 5455c9723d9e -r 928954bfefd7 src/volume.h --- a/src/volume.h Sat Jan 18 03:46:43 2014 +0200 +++ b/src/volume.h Sat Jan 25 19:25:32 2014 +0200 @@ -32,7 +32,7 @@ unsigned int get_texture() const; - void draw(); + void draw() const; }; #endif // VOLUME_H_