X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world.h;h=9d419a6ee5a5f485c039716f5ef536d20639ba77;hb=afa80c76d03f5e983092e9d7be33a9102a7ab25e;hp=cdf2f16f0c85a901293dbc1cc9dc691c77b235a4;hpb=7758c7efec3956c68294bc914e7524045a2b1bd7;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world.h b/world.h index cdf2f16..9d419a6 100644 --- a/world.h +++ b/world.h @@ -28,7 +28,7 @@ static void render_world( m4x4f projection, m4x3f camera ) m4x3f identity_matrix; m4x3_identity( identity_matrix ); - render_terrain( projection ); + render_terrain( projection, camera[3] ); scene_bind( &world.geo ); scene_draw( &world.geo ); @@ -38,6 +38,13 @@ static void render_world( m4x4f projection, m4x3f camera ) glEnable(GL_CULL_FACE); } +static void ray_world_get_tri( ray_hit *hit, v3f tri[3] ) +{ + for( int i=0; i<3; i++ ) + v3_copy( world.geo.verts[ hit->tri[i] ].co, tri[i] ); +} + +__attribute__((always_inline)) static int ray_world( v3f pos, v3f dir, ray_hit *hit ) { return bvh_raycast( &world.geo, pos, dir, hit ); @@ -48,7 +55,7 @@ static int ray_hit_is_ramp( ray_hit *hit ) return hit->tri[0] < world.sm_road.vertex_count; } -static void world_init_default(void) +static void world_load(void) { /* Setup scene */ scene_init( &world.geo ); @@ -99,8 +106,8 @@ static void world_init_default(void) free( mworld ); scene_upload( &world.geo ); bvh_create( &world.geo ); - - + + water_compute_depth( world.geo.bbx ); scene_init( &world.foliage ); model *mfoliage = vg_asset_read("models/rs_foliage.mdl"); @@ -111,6 +118,9 @@ static void world_init_default(void) m4x3f transform; + submodel *sm_blob = submodel_get( mfoliage, "blob" ), + *sm_tree = submodel_get( mfoliage, "tree" ); + for( int i=0;i<100000;i++ ) { v3f pos; @@ -122,7 +132,8 @@ static void world_init_default(void) if( ray_world( pos, (v3f){0.0f,-1.0f,0.0f}, &hit )) { - if( hit.normal[1] > 0.8f && !ray_hit_is_ramp(&hit) ) + if( hit.normal[1] > 0.8f && !ray_hit_is_ramp(&hit) && + hit.pos[1] > wrender.height ) { v4f qsurface, qrandom; v3f axis; @@ -136,9 +147,14 @@ static void world_init_default(void) q_m3x3( qsurface, transform ); v3_copy( hit.pos, transform[3] ); - - scene_add_foliage( &world.foliage, mfoliage, - model_get_submodel( mfoliage, 0 ), transform ); + + if( vg_randf() < 0.00000006f ) + { + m3x3_identity( transform ); + scene_add_foliage( &world.foliage, mfoliage, sm_tree, transform ); + } + else + scene_add_foliage( &world.foliage, mfoliage, sm_blob, transform ); } } }