f
[carveJwlIkooP6JGAAIwe30JlM.git] / world.h
diff --git a/world.h b/world.h
index add08b7c30d1180a1125a8a4c9a10dd2c9102c5e..9242023a31d7ffade26696bfecb3ee9eec52b876 100644 (file)
--- a/world.h
+++ b/world.h
@@ -48,17 +48,19 @@ static struct gworld
    /* Physics */
    rigidbody temp_rbs[128];
    u32 rb_count;
-   bh_tree bhcubes;
    
    /* Rendering & geometry */
-   scene geo, foliage, props;
-   mdl_submesh sm_surface, sm_other;
+   scene geo, foliage;
+
+   mdl_submesh sm_geo_std_oob, sm_geo_std, sm_geo_vb;
 
    glmesh skybox, skydome;
    mdl_submesh dome_upper, dome_lower;
 
    glmesh cars;
    mdl_submesh car_holden;
+
+   rigidbody mr_ball;
 }
 world;
 
@@ -81,7 +83,7 @@ static int ray_world( v3f pos, v3f dir, ray_hit *hit )
 
 static int ray_hit_is_ramp( ray_hit *hit )
 {
-   return hit->tri[0] < world.sm_surface.vertex_count;
+   return hit->tri[0] > world.sm_geo_std_oob.vertex_count;
 }
 
 static void world_register(void)
@@ -179,7 +181,6 @@ static void world_load(void)
    world.traffic_count = 0;
 
    scene_init( &world.geo );
-   scene_init( &world.props );
 
    /* 
     * Compile meshes into the world scenes
@@ -203,26 +204,22 @@ static void world_load(void)
          mat_vertex_blend = i;
    }
 
-   if( mat_surf )
-      add_all_if_material( &world.geo, mworld, mat_surf );
-   if( mat_vertex_blend )
-      add_all_if_material( &world.geo, mworld, mat_vertex_blend );
-
-
-   scene_copy_slice( &world.geo, &world.sm_surface );
-
    if( mat_surf_oob )
       add_all_if_material( &world.geo, mworld, mat_surf_oob );
    else
       vg_warn( "No OOB surface\n" );
+   scene_copy_slice( &world.geo, &world.sm_geo_std_oob );
 
-   scene_bh_create( &world.geo );
-   scene_upload( &world.geo );
+   if( mat_surf )
+      add_all_if_material( &world.geo, mworld, mat_surf );
+   scene_copy_slice( &world.geo, &world.sm_geo_std );
 
    if( mat_vertex_blend )
-      add_all_if_material( &world.props, mworld, mat_vertex_blend );
+      add_all_if_material( &world.geo, mworld, mat_vertex_blend );
+   scene_copy_slice( &world.geo, &world.sm_geo_vb );
 
-   /* TODO  bvh? */
+   scene_upload( &world.geo );
+   scene_bh_create( &world.geo );
    
    /*
     * Process entities
@@ -317,11 +314,6 @@ static void world_load(void)
    for( int i=0; i<vg_list_size(world.van_man); i++ )
       world.van_man[i].current =&world.traffic[vg_randint(world.traffic_count)];
 
-   scene_upload( &world.props );
-
-   bh_create( &world.bhcubes, 
-         &bh_system_rigidbodies, world.temp_rbs, world.rb_count );
-
    world_apply_foliage();
    free( mworld );
 
@@ -378,7 +370,14 @@ static void world_load(void)
 
    winfo->g_water_fog = 0.04f;
    render_update_lighting_ub();
+   
+
+   world.mr_ball.type = k_rb_shape_sphere;
+   world.mr_ball.inf.sphere.radius = 2.0f;
+   v3_copy( (v3f){ 0.0f, 110.0f, 0.0f }, world.mr_ball.co );
 
+   q_identity(world.mr_ball.q);
+   rb_init( &world.mr_ball );
 }
 
 static void world_init(void)
@@ -406,6 +405,16 @@ static void world_init(void)
 
 static void world_update(void)
 {
+   rb_solver_reset();
+   rb_build_manifold_terrain_sphere( &world.mr_ball );
+   
+   for( int i=0; i<5; i++ )
+      rb_solve_contacts( rb_contact_buffer, rb_contact_count );
+
+   rb_iter( &world.mr_ball );
+   rb_update_transform( &world.mr_ball );
+   rb_debug( &world.mr_ball, 0 );
+
    for( int i=0; i<vg_list_size(world.van_man); i++ )
    {
       traffic_drive( &world.van_man[i] );
@@ -423,7 +432,7 @@ static void bind_terrain_textures(void)
    vg_tex2d_bind( &tex_terrain_colours, 1 );
 }
 
-static void render_props( m4x4f projection, v3f camera )
+static void render_world_vb( m4x4f projection, v3f camera )
 {
    m4x3f identity_matrix;
    m4x3_identity( identity_matrix );
@@ -438,8 +447,8 @@ static void render_props( m4x4f projection, v3f camera )
    shader_vblend_uMdl( identity_matrix );
    shader_vblend_uCamera( camera );
 
-   scene_bind( &world.props );
-   scene_draw( &world.props );
+   scene_bind( &world.geo );
+   mdl_draw_submesh( &world.sm_geo_vb );
 
    mesh_bind( &world.cars );
 
@@ -466,7 +475,8 @@ static void render_terrain( m4x4f projection, v3f camera )
    shader_terrain_uCamera( camera );
 
    scene_bind( &world.geo );
-   scene_draw( &world.geo );
+   mdl_draw_submesh( &world.sm_geo_std_oob );
+   mdl_draw_submesh( &world.sm_geo_std );
 
    glDisable(GL_CULL_FACE);
    scene_bind( &world.foliage );
@@ -532,7 +542,7 @@ static void render_sky(m4x3f camera)
 static void render_world( m4x4f projection, m4x3f camera )
 {
    render_sky( camera );
-   render_props( projection, camera[3] );
+   render_world_vb( projection, camera[3] );
    render_terrain( projection, camera[3] );
 }
 
@@ -555,9 +565,6 @@ static void render_world_depth( m4x4f projection, m4x3f camera )
    scene_draw( &world.foliage );
    glEnable(GL_CULL_FACE);
 #endif
-
-   scene_bind( &world.props );
-   scene_draw( &world.props );
 }
 
 #endif /* WORLD_H */