clray

annotate 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
rev   line source
John@15 1 #include <math.h>
nuclear@22 2 #include "scene.h"
nuclear@6 3
John@15 4 #define FEQ(a, b) (fabs((a) - (b)) < 1e-8)
John@15 5 bool Face::operator ==(const Face &f) const
John@15 6 {
John@15 7 for(int i=0; i<3; i++) {
John@15 8 for(int j=0; j<3; j++) {
John@15 9 if(!FEQ(v[i].pos[j], f.v[i].pos[j])) {
John@15 10 return false;
John@15 11 }
John@15 12 if(!FEQ(v[i].normal[j], f.v[i].normal[j])) {
John@15 13 return false;
John@15 14 }
John@15 15 }
John@15 16 if(!FEQ(normal[i], f.normal[i])) {
John@15 17 return false;
John@15 18 }
John@15 19 }
John@15 20 return true;
John@15 21 }
John@15 22
nuclear@13 23 bool Scene::add_mesh(Mesh *m)
nuclear@13 24 {
nuclear@13 25 // make sure triangles have material ids
nuclear@13 26 for(size_t i=0; i<m->faces.size(); i++) {
nuclear@13 27 m->faces[i].matid = m->matid;
nuclear@13 28 }
nuclear@13 29 meshes.push_back(m);
nuclear@13 30 return true;
nuclear@13 31 }
nuclear@13 32
John@14 33 int Scene::get_num_meshes() const
John@14 34 {
John@14 35 return (int)meshes.size();
John@14 36 }
John@14 37
nuclear@13 38 int Scene::get_num_faces() const
nuclear@13 39 {
nuclear@13 40 int num_faces = 0;
nuclear@13 41 for(size_t i=0; i<meshes.size(); i++) {
nuclear@13 42 num_faces += meshes[i]->faces.size();
nuclear@13 43 }
nuclear@13 44 return num_faces;
nuclear@13 45 }
nuclear@13 46
John@14 47 int Scene::get_num_materials() const
John@14 48 {
John@14 49 return (int)matlib.size();
John@14 50 }
John@14 51
John@14 52 Material *Scene::get_materials()
John@14 53 {
John@14 54 if(matlib.empty()) {
John@14 55 return 0;
John@14 56 }
John@14 57 return &matlib[0];
John@14 58 }
John@14 59
John@14 60 const Material *Scene::get_materials() const
John@14 61 {
John@14 62 if(matlib.empty()) {
John@14 63 return 0;
John@14 64 }
John@14 65 return &matlib[0];
John@14 66 }