goat3dgfx

annotate src/scene.cc @ 12:1868c5975f31

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 24 Nov 2013 18:18:38 +0200
parents 1873dfd13f2d
children 25bf39105c82
rev   line source
nuclear@0 1 #include "scene.h"
nuclear@0 2 #include "opengl.h"
nuclear@12 3 #include "goat3d.h"
nuclear@0 4
nuclear@0 5 Scene::~Scene()
nuclear@0 6 {
nuclear@0 7 destroy();
nuclear@0 8 }
nuclear@0 9
nuclear@0 10 void Scene::destroy()
nuclear@0 11 {
nuclear@0 12 for(size_t i=0; i<objects.size(); i++) {
nuclear@0 13 delete objects[i];
nuclear@0 14 }
nuclear@0 15 objects.clear();
nuclear@0 16
nuclear@0 17 for(size_t i=0; i<meshes.size(); i++) {
nuclear@0 18 delete meshes[i];
nuclear@0 19 }
nuclear@0 20 meshes.clear();
nuclear@0 21
nuclear@0 22 for(size_t i=0; i<curves.size(); i++) {
nuclear@0 23 delete curves[i];
nuclear@0 24 }
nuclear@0 25 curves.clear();
nuclear@0 26 }
nuclear@0 27
nuclear@12 28 bool Scene::load(const char *fname)
nuclear@12 29 {
nuclear@12 30 goat3d *goat = goat3d_create();
nuclear@12 31 if(!goat) {
nuclear@12 32 return false;
nuclear@12 33 }
nuclear@12 34 if(goat3d_load(goat, fname) == -1) {
nuclear@12 35 return false;
nuclear@12 36 }
nuclear@12 37
nuclear@12 38 int num_meshes = goat3d_get_mesh_count(goat);
nuclear@12 39 for(int i=0; i<num_meshes; i++) {
nuclear@12 40 goat3d_mesh *gmesh = goat3d_get_mesh(goat, i);
nuclear@12 41 // TODO cont...
nuclear@12 42 }
nuclear@12 43
nuclear@12 44 goat3d_free(goat);
nuclear@12 45 return true;
nuclear@12 46 }
nuclear@12 47
nuclear@12 48 bool Scene::save(const char *fname) const
nuclear@12 49 {
nuclear@12 50 return false; // TODO
nuclear@12 51 }
nuclear@12 52
nuclear@0 53 void Scene::draw(long msec) const
nuclear@0 54 {
nuclear@0 55 for(size_t i=0; i<objects.size(); i++) {
nuclear@0 56 objects[i]->draw(msec);
nuclear@0 57 }
nuclear@0 58
nuclear@0 59 if(objects.empty()) {
nuclear@0 60 printf("rendering meshes directly\n");
nuclear@0 61 for(size_t i=0; i<meshes.size(); i++) {
nuclear@0 62 meshes[i]->draw();
nuclear@0 63 }
nuclear@0 64 }
nuclear@0 65 }