stuff
[carveJwlIkooP6JGAAIwe30JlM.git] / world.h
diff --git a/world.h b/world.h
index cfa3d6b79f51b4f16e690758c1ccf949b3748b9d..73b42a4c2bbaf45de4a41f5295bf7789f4e5e028 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];
    u32 gate_count;
-
+   
    rigidbody temp_rbs[32];
    u32 rb_count;
+
+   bh_tree bhcubes;
 }
 world;
 
@@ -58,7 +58,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 )
@@ -144,7 +144,7 @@ static void world_load(void)
    }
 
    scene_upload( &world.geo );
-   bvh_create( &world.geo );
+   scene_bh_create( &world.geo );
    
    water_compute_depth( world.geo.bbx );
 
@@ -157,15 +157,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 +180,6 @@ static void world_load(void)
       rb_update_transform( rb );
    }
 
-
    free( mworld );
 
    v3f volume;
@@ -213,7 +203,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 +218,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 +231,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 */