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