MetaScene class
[laserbrain_demo] / src / app.cc
index a1936b2..f92899d 100644 (file)
@@ -49,7 +49,8 @@ static float joy_deadzone = 0.01;
 
 static Mat4 view_matrix, mouse_view_matrix, proj_matrix;
 static TextureSet texman;
-static Scene *scn;
+static SceneSet sceneman;
+static MetaScene *mscn;
 static unsigned int sdr_post_gamma;
 
 static long prev_msec;
@@ -97,20 +98,13 @@ bool app_init(int argc, char **argv)
 
        glClearColor(0.2, 0.2, 0.2, 1.0);
 
-       scn = new Scene(&texman);
-       if(!load_scene(scn, opt.scenefile ? opt.scenefile : "data/museum.scene")) {
+       mscn = new MetaScene(&sceneman, &texman);
+       if(!mscn->load(opt.scenefile ? opt.scenefile : "data/museum.scene")) {
                return false;
        }
 
-       // set initial cam_pos above the center of the walk mesh (if any)
-       if(scn->walk_mesh) {
-               Vec3 bcent;
-               float brad;
-               scn->walk_mesh->get_bsphere(&bcent, &brad);
-
-               floor_y = bcent.y;
-               cam_pos = bcent + Vec3(0, user_eye_height, 0);
-       }
+       cam_pos = mscn->start_pos;
+       // TODO use start_rot
 
        if(!(sdr_ltmap_notex = create_program_load("sdr/lightmap.v.glsl", "sdr/lightmap-notex.p.glsl"))) {
                return false;
@@ -140,12 +134,14 @@ void app_cleanup()
        if(opt.vr) {
                goatvr_shutdown();
        }
+
        texman.clear();
+       sceneman.clear();
 }
 
 static bool constrain_walk_mesh(const Vec3 &v, Vec3 *newv)
 {
-       Mesh *wm = scn->walk_mesh;
+       Mesh *wm = mscn->walk_mesh;
        if(!wm) {
                *newv = v;
                return true;
@@ -153,7 +149,7 @@ static bool constrain_walk_mesh(const Vec3 &v, Vec3 *newv)
 
        Ray downray = Ray(v, Vec3(0, -1, 0));
        HitPoint hit;
-       if(scn->walk_mesh->intersect(downray, &hit)) {
+       if(mscn->walk_mesh->intersect(downray, &hit)) {
                *newv = hit.pos;
                newv->y += user_eye_height;
                return true;
@@ -164,8 +160,9 @@ static bool constrain_walk_mesh(const Vec3 &v, Vec3 *newv)
 static void update(float dt)
 {
        texman.update();
+       sceneman.update();
 
-       scn->update(dt);
+       mscn->update(dt);
 
        float speed = walk_speed * dt;
        Vec3 dir;
@@ -329,9 +326,9 @@ static void draw_scene()
        set_light(1, lpos[1], Vec3(0.6, 0.7, 1.0) * 0.6);
        set_light(2, lpos[2], Vec3(0.8, 1.0, 0.8) * 0.3);
 
-       scn->draw();
+       mscn->draw();
 
-       if(show_walk_mesh && scn->walk_mesh) {
+       if(show_walk_mesh && mscn->walk_mesh) {
                glPushAttrib(GL_ENABLE_BIT);
                glEnable(GL_BLEND);
                glBlendFunc(GL_ONE, GL_ONE);
@@ -344,7 +341,7 @@ static void draw_scene()
                glDepthMask(0);
 
                glColor3f(0.3, 0.08, 0.01);
-               scn->walk_mesh->draw();
+               mscn->walk_mesh->draw();
 
                glDepthMask(1);