clray
view src/scene.cc @ 23:51f115e337c2
separated obj loading and vector class
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 13 Aug 2010 18:20:45 +0100 |
parents | 6c44e4b1726d |
children | 13091c00d7ca |
line source
1 #include <math.h>
2 #include "scene.h"
4 #define FEQ(a, b) (fabs((a) - (b)) < 1e-8)
5 bool Face::operator ==(const Face &f) const
6 {
7 for(int i=0; i<3; i++) {
8 for(int j=0; j<3; j++) {
9 if(!FEQ(v[i].pos[j], f.v[i].pos[j])) {
10 return false;
11 }
12 if(!FEQ(v[i].normal[j], f.v[i].normal[j])) {
13 return false;
14 }
15 }
16 if(!FEQ(normal[i], f.normal[i])) {
17 return false;
18 }
19 }
20 return true;
21 }
23 bool Scene::add_mesh(Mesh *m)
24 {
25 // make sure triangles have material ids
26 for(size_t i=0; i<m->faces.size(); i++) {
27 m->faces[i].matid = m->matid;
28 }
29 meshes.push_back(m);
30 return true;
31 }
33 int Scene::get_num_meshes() const
34 {
35 return (int)meshes.size();
36 }
38 int Scene::get_num_faces() const
39 {
40 int num_faces = 0;
41 for(size_t i=0; i<meshes.size(); i++) {
42 num_faces += meshes[i]->faces.size();
43 }
44 return num_faces;
45 }
47 int Scene::get_num_materials() const
48 {
49 return (int)matlib.size();
50 }
52 Material *Scene::get_materials()
53 {
54 if(matlib.empty()) {
55 return 0;
56 }
57 return &matlib[0];
58 }
60 const Material *Scene::get_materials() const
61 {
62 if(matlib.empty()) {
63 return 0;
64 }
65 return &matlib[0];
66 }