audio&island
[carveJwlIkooP6JGAAIwe30JlM.git] / world.h
diff --git a/world.h b/world.h
index cfa3d6b79f51b4f16e690758c1ccf949b3748b9d..af0507fafc0db0f33b0a4f33e6ba0a10d6b3f9f3 100644 (file)
--- a/world.h
+++ b/world.h
@@ -1,15 +1,17 @@
+#include "common.h"
+
+static int ray_world( v3f pos, v3f dir, ray_hit *hit );
+
 #ifndef WORLD_H
 #define WORLD_H
 
-#define VG_3D
-#include "vg/vg.h"
-
 #include "scene.h"
 #include "terrain.h"
 #include "render.h"
 #include "water.h"
 #include "rigidbody.h"
 #include "gate.h"
+#include "bvh.h"
 
 #include "shaders/standard.h"
 
@@ -21,15 +23,13 @@ static struct gworld
 
    v3f tutorial;
 
-#if 0
-   rigidbody box;
-#endif
-
-   teleport_gate gates[16];
+   teleport_gate gates[64];
    u32 gate_count;
-
-   rigidbody temp_rbs[32];
+   
+   rigidbody temp_rbs[128];
    u32 rb_count;
+
+   bh_tree bhcubes;
 }
 world;
 
@@ -48,6 +48,8 @@ static void render_world( m4x4f projection, m4x3f camera )
    scene_bind( &world.foliage );
    scene_draw( &world.foliage );
    glEnable(GL_CULL_FACE);
+
+   vg_line_boxf( world.geo.bbx, 0xff00ff00 );
 }
 
 static void ray_world_get_tri( ray_hit *hit, v3f tri[3] )
@@ -58,7 +60,7 @@ static void ray_world_get_tri( ray_hit *hit, v3f tri[3] )
 
 static int ray_world( v3f pos, v3f dir, ray_hit *hit )
 {
-   return bvh_raycast( &world.geo, pos, dir, hit );
+   return scene_raycast( &world.geo, pos, dir, hit );
 }
 
 static int ray_hit_is_ramp( ray_hit *hit )
@@ -90,6 +92,10 @@ static void world_load(void)
 
    scene_copy_slice( &world.geo, &world.sm_terrain );
 
+   vg_info( "BBX: %.3f %.3f %.3f -> %.3f %.3f %.3f\n",
+         world.geo.bbx[0][0], world.geo.bbx[0][1], world.geo.bbx[0][2],
+         world.geo.bbx[1][0], world.geo.bbx[1][1], world.geo.bbx[1][2] );
+
    /* 
     * TODO: Parametric marker import
     */
@@ -139,12 +145,14 @@ static void world_load(void)
          water_init();
          water_set_surface( &surf, sm->pivot[1] );
 
+         vg_info( "%.3f\n", sm->pivot[1] );
+
          break;
       }
    }
 
    scene_upload( &world.geo );
-   bvh_create( &world.geo );
+   scene_bh_create( &world.geo );
    
    water_compute_depth( world.geo.bbx );
 
@@ -157,15 +165,6 @@ static void world_load(void)
     *
     *       then compute bvh
     */
-#if 0
-   scene_add_foliage( &world.foliage, mworld, boxtest, world.box.to_world );
-#endif
-   
-
-#if 0
-   submodel *boxtest = submodel_get( mworld, "cubey" );
-
-#endif
    
    for( int i=0; i<mworld->layer_count; i++ )
    {
@@ -189,7 +188,6 @@ static void world_load(void)
       rb_update_transform( rb );
    }
 
-
    free( mworld );
 
    v3f volume;
@@ -205,6 +203,7 @@ static void world_load(void)
    {
       v3f pos;
       v3_mul( volume, (v3f){ vg_randf(), 1000.0f, vg_randf() }, pos );
+      pos[1] = 1000.0f;
       v3_add( pos, world.geo.bbx[0], pos );
       
       ray_hit hit;
@@ -213,7 +212,7 @@ static void world_load(void)
       if( ray_world( pos, (v3f){0.0f,-1.0f,0.0f}, &hit ))
       {
          if( hit.normal[1] > 0.8f && !ray_hit_is_ramp(&hit) &&
-             hit.pos[1] > wrender.height )
+             hit.pos[1] > water_height()+10.0f )
          {
             v4f qsurface, qrandom;
             v3f axis;
@@ -228,7 +227,7 @@ static void world_load(void)
 
             v3_copy( hit.pos, transform[3] );
             
-            if( vg_randf() < 0.00000006f )
+            if( vg_randf() < 0.0006f )
             {
                m3x3_identity( transform );
                scene_add_foliage( &world.foliage, mfoliage, sm_tree, transform);
@@ -241,6 +240,9 @@ static void world_load(void)
 
    free( mfoliage );
    scene_upload( &world.foliage );
+   
+   bh_create( &world.bhcubes, 
+         &bh_system_rigidbodies, world.temp_rbs, world.rb_count );
 }
 
 #endif /* WORLD_H */