fix rendering bugs
authorhgn <hgodden00@gmail.com>
Wed, 19 Jul 2023 01:07:50 +0000 (02:07 +0100)
committerhgn <hgodden00@gmail.com>
Wed, 19 Jul 2023 01:07:50 +0000 (02:07 +0100)
player_skate.c
world_render.c

index f971b18037da760d075f57342cb73ffb152df6f3..ac1423962e8f52113ceaed2bc788219e6fbe2371 100644 (file)
@@ -2781,7 +2781,7 @@ VG_STATIC void player__skate_animate( player_instance *player ){
    if( fabsf(lean1)>fabsf(lean2) ) lean = lean1;
    else                            lean = lean2;
 
-   if( ((int)roundf(animator->board_euler[0])) % 2 ) lean = -lean;
+   if( ((int)roundf(animator->board_euler[0]/VG_PIf)) % 2 ) lean = -lean;
    lean = vg_clampf( lean, -1.0f, 1.0f );
    animator->board_lean = 
       vg_lerpf(animator->board_lean, lean, vg.time_delta*18.0f);
index 950e35fe8855aa08ca12b1e649ecde3bd827a58f..ac0df1a1001754bf04f894c09c558c9dc0ed3dd6 100644 (file)
@@ -154,21 +154,59 @@ struct world_pass{
    void (*fn_set_uPvmPrev)( m4x4f pvm );
 };
 
-/* TODO: high level control pass renders. */
+VG_STATIC
+void world_render_traffic( world_instance *world, u32 material_id,
+                           struct world_pass *pass ){
+   if( !mdl_arrcount( &world->ent_traffic ) ) return;
+
+   /* HACK: use the first material for every traffic entity */
+   ent_traffic *first = mdl_arritm( &world->ent_traffic, 0 );
+   if( !first->submesh_count ) return;
+
+   mdl_submesh *sm = mdl_arritm( &world->meta.submeshs, first->submesh_start );
+   if( sm->material_id != material_id ) return;
+
+   struct world_surface *mat = &world->surfaces[ material_id ];
+   pass->fn_bind_textures( world, mat );
+
+   for( u32 j=0; j<mdl_arrcount( &world->ent_traffic ); j++ ){
+      ent_traffic *traffic = mdl_arritm( &world->ent_traffic, j );
+      
+      for( u32 k=0; k<traffic->submesh_count; k++ ){
+         sm = mdl_arritm( &world->meta.submeshs, 
+                           traffic->submesh_start+k );
+
+         m4x3f mmdl;
+         q_m3x3( traffic->transform.q, mmdl );
+         v3_copy( traffic->transform.co, mmdl[3] );
+
+         m4x4f m4mdl;
+         m4x3_expand( mmdl, m4mdl );
+         m4x4_mul( pass->cam->mtx_prev.pv, m4mdl, m4mdl );
+
+         pass->fn_set_mdl( mmdl );
+         pass->fn_set_uPvmPrev( m4mdl );
+
+         mdl_draw_submesh( sm );
+      }
+   }
+}
 
 VG_STATIC 
-void world_render_if( world_instance *world, struct world_pass *pass )
-{
+void world_render_pass( world_instance *world, struct world_pass *pass ){
    for( int i=0; i<world->surface_count; i++ ){
       struct world_surface *mat = &world->surfaces[i];
 
       if( mat->info.shader == pass->shader ){
          mdl_submesh *sm;
 
-         if( pass->geo_type == k_world_geo_type_solid )
+         if( pass->geo_type == k_world_geo_type_solid ){
             sm = &mat->sm_geo;
-         else
+         }
+         else{
+            world_render_traffic( world, i, pass );
             sm = &mat->sm_no_collide;
+         }
 
          if( !sm->indice_count )
             continue;
@@ -180,27 +218,6 @@ void world_render_if( world_instance *world, struct world_pass *pass )
 
          pass->fn_bind_textures( world, mat );
          mdl_draw_submesh( sm );
-
-         for( u32 j=0; j<mdl_arrcount( &world->ent_traffic ); j++ ){
-            ent_traffic *traffic = mdl_arritm( &world->ent_traffic, j );
-            
-            for( u32 k=0; k<traffic->submesh_count; k++ ){
-               sm = mdl_arritm( &world->meta.submeshs, 
-                                 traffic->submesh_start+k );
-
-               q_m3x3( traffic->transform.q, mmdl );
-               v3_copy( traffic->transform.co, mmdl[3] );
-
-               m4x4f m4mdl;
-               m4x3_expand( mmdl, m4mdl );
-               m4x4_mul( pass->cam->mtx_prev.pv, m4mdl, m4mdl );
-
-               pass->fn_set_mdl( mmdl );
-               pass->fn_set_uPvmPrev( m4mdl );
-
-               mdl_draw_submesh( sm );
-            }
-         }
       }
    }
 }
@@ -224,12 +241,12 @@ void world_render_both_stages( world_instance *world, struct world_pass *pass )
 {
    mesh_bind( &world->mesh_geo );
    pass->geo_type = k_world_geo_type_solid;
-   world_render_if( world, pass );
+   world_render_pass( world, pass );
 
    glDisable( GL_CULL_FACE );
    mesh_bind( &world->mesh_no_collide );
    pass->geo_type = k_world_geo_type_nonsolid;
-   world_render_if( world, pass );
+   world_render_pass( world, pass );
    glEnable( GL_CULL_FACE );
 }