eqemu
annotate src/scene.cc @ 6:977bc1cb055b
almost done
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 18 Jul 2014 02:35:06 +0300 |
parents | 3d3656360a82 |
children | 2656099aff12 |
rev | line source |
---|---|
nuclear@3 | 1 #include <stdio.h> |
nuclear@3 | 2 #include <stdlib.h> |
nuclear@4 | 3 #include <string.h> |
nuclear@3 | 4 #include "scene.h" |
nuclear@3 | 5 |
nuclear@3 | 6 Scene::~Scene() |
nuclear@3 | 7 { |
nuclear@3 | 8 for(size_t i=0; i<objects.size(); i++) { |
nuclear@3 | 9 delete objects[i]; |
nuclear@3 | 10 } |
nuclear@3 | 11 for(size_t i=0; i<meshes.size(); i++) { |
nuclear@3 | 12 delete meshes[i]; |
nuclear@3 | 13 } |
nuclear@3 | 14 } |
nuclear@3 | 15 |
nuclear@3 | 16 bool Scene::load(const char *fname) |
nuclear@3 | 17 { |
nuclear@3 | 18 FILE *fp = fopen(fname, "rb"); |
nuclear@3 | 19 if(!fp) { |
nuclear@3 | 20 fprintf(stderr, "failed to open scene file: %s\n", fname); |
nuclear@3 | 21 return false; |
nuclear@3 | 22 } |
nuclear@3 | 23 |
nuclear@3 | 24 bool res = load_obj(fp); |
nuclear@3 | 25 fclose(fp); |
nuclear@3 | 26 return res; |
nuclear@3 | 27 } |
nuclear@3 | 28 |
nuclear@3 | 29 void Scene::add_object(Object *obj) |
nuclear@3 | 30 { |
nuclear@3 | 31 objects.push_back(obj); |
nuclear@3 | 32 } |
nuclear@3 | 33 |
nuclear@3 | 34 void Scene::add_mesh(Mesh *mesh) |
nuclear@3 | 35 { |
nuclear@3 | 36 meshes.push_back(mesh); |
nuclear@3 | 37 } |
nuclear@3 | 38 |
nuclear@3 | 39 int Scene::get_num_objects() const |
nuclear@3 | 40 { |
nuclear@3 | 41 return (int)objects.size(); |
nuclear@3 | 42 } |
nuclear@3 | 43 |
nuclear@3 | 44 int Scene::get_num_meshes() const |
nuclear@3 | 45 { |
nuclear@3 | 46 return (int)meshes.size(); |
nuclear@3 | 47 } |
nuclear@3 | 48 |
nuclear@3 | 49 Object *Scene::get_object(int idx) const |
nuclear@3 | 50 { |
nuclear@3 | 51 return objects[idx]; |
nuclear@3 | 52 } |
nuclear@3 | 53 |
nuclear@4 | 54 Object *Scene::get_object(const char *name) const |
nuclear@4 | 55 { |
nuclear@4 | 56 for(size_t i=0; i<objects.size(); i++) { |
nuclear@4 | 57 if(strcmp(objects[i]->get_name(), name) == 0) { |
nuclear@4 | 58 return objects[i]; |
nuclear@4 | 59 } |
nuclear@4 | 60 } |
nuclear@4 | 61 return 0; |
nuclear@4 | 62 } |
nuclear@4 | 63 |
nuclear@6 | 64 bool Scene::remove_object(Object *obj) |
nuclear@6 | 65 { |
nuclear@6 | 66 for(size_t i=0; i<objects.size(); i++) { |
nuclear@6 | 67 if(objects[i] == obj) { |
nuclear@6 | 68 objects.erase(objects.begin() + i); |
nuclear@6 | 69 return true; |
nuclear@6 | 70 } |
nuclear@6 | 71 } |
nuclear@6 | 72 return false; |
nuclear@6 | 73 } |
nuclear@6 | 74 |
nuclear@3 | 75 Mesh *Scene::get_mesh(int idx) const |
nuclear@3 | 76 { |
nuclear@3 | 77 return meshes[idx]; |
nuclear@3 | 78 } |
nuclear@3 | 79 |
nuclear@3 | 80 void Scene::update(long msec) |
nuclear@3 | 81 { |
nuclear@3 | 82 } |
nuclear@3 | 83 |
nuclear@3 | 84 void Scene::render() const |
nuclear@3 | 85 { |
nuclear@3 | 86 for(size_t i=0; i<objects.size(); i++) { |
nuclear@3 | 87 objects[i]->render(); |
nuclear@3 | 88 } |
nuclear@3 | 89 } |