Ray Tracer Common Project
Image rendering program based on the ray tracing technique.
mesh.hpp
1 
15 #pragma once
16 
17 #include <string>
18 #include <vector>
19 
20 #include "geometry.hpp"
21 
22 namespace rt{
23 
24 class Mesh : public Geometry{
25 public:
26  enum DataType{
27  Triangles = 3,
28  Quads = 4
29  };
30 
31  Mesh();
32  ~Mesh();
33 
34  void add_faces(double *vertex, unsigned int *index, DataType data_type);
35 
36  static Mesh *from_wavefront(const std::string & filename);
37 
42  virtual vector uv(const element &) const;
43 
49  virtual std::vector<hit> hits(const euclidian &e) const;
50 
51  friend std::ostream & operator<<(std::ostream & stream, const Mesh & mesh);
52 
53 private:
54  void _compute_bounding_sphere();
55 
56  struct vertex_t{
57  union{
58  double c[3];
59  struct{
60  int x, y, z;
61  }data;
62  };
63  };
64 
65  struct face_t{
66  vector vertex[3];
67  vector normal[3];
68 
69  double hit(const euclidian &e) const;
70  void compute_normals();
71  };
72 
73  std::vector<face_t> _faces;
74  double _ray;
75 };
76 
77 std::ostream & operator<<(std::ostream & stream, const Mesh & mesh);
78 
79 }
virtual std::vector< hit > hits(const euclidian &e) const
Compute hits between the mesh and an euclidian.
Definition: mesh.cpp:58
Definition: mesh.hpp:24
Definition: bitmap.cpp:4
3D vector
Definition: vector.hpp:28
Geometric entity.
Definition: geometry.hpp:39
virtual vector uv(const element &) const
UV-map a surface element on the mesh.
Definition: mesh.cpp:86
The result of a collistion between a Geometry and an euclidian.
Definition: hit.hpp:39
Geometric surface element unit.
Definition: element.hpp:43
Localised vector class.
Definition: euclidian.hpp:27