volmetrics

changeset 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 5455c9723d9e
children 40febfed6cff
files src/mesh.cc src/mesh.h src/volume.cc src/volume.h
diffstat 4 files changed, 65 insertions(+), 2 deletions(-) [+]
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 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/mesh.h	Sat Jan 25 19:25:32 2014 +0200
     2.3 @@ -0,0 +1,23 @@
     2.4 +#ifndef MESH_H_
     2.5 +#define MESH_H_
     2.6 +
     2.7 +#include <vector>
     2.8 +#include "vector.h"
     2.9 +
    2.10 +class Mesh {
    2.11 +private:
    2.12 +	std::vector<Vector3> vertices;
    2.13 +	std::vector<Vector3> normals;
    2.14 +
    2.15 +public:
    2.16 +	Mesh();
    2.17 +
    2.18 +	void add_vertex(const Vector3 &vertex);
    2.19 +	void add_normal(const Vector3 &normal);
    2.20 +
    2.21 +	void clear();
    2.22 +
    2.23 +	void draw() const;
    2.24 +};
    2.25 +
    2.26 +#endif // MESH_H_
     3.1 --- a/src/volume.cc	Sat Jan 18 03:46:43 2014 +0200
     3.2 +++ b/src/volume.cc	Sat Jan 25 19:25:32 2014 +0200
     3.3 @@ -163,7 +163,7 @@
     3.4  	return vol_tex;
     3.5  }
     3.6  
     3.7 -void Volume::draw()
     3.8 +void Volume::draw() const
     3.9  {
    3.10  }
    3.11  
     4.1 --- a/src/volume.h	Sat Jan 18 03:46:43 2014 +0200
     4.2 +++ b/src/volume.h	Sat Jan 25 19:25:32 2014 +0200
     4.3 @@ -32,7 +32,7 @@
     4.4  
     4.5  	unsigned int get_texture() const;
     4.6  
     4.7 -	void draw();
     4.8 +	void draw() const;
     4.9  };
    4.10  
    4.11  #endif // VOLUME_H_