audio&island
authorhgn <hgodden00@gmail.com>
Mon, 4 Jul 2022 00:54:14 +0000 (01:54 +0100)
committerhgn <hgodden00@gmail.com>
Mon, 4 Jul 2022 00:54:14 +0000 (01:54 +0100)
13 files changed:
audio.h [new file with mode: 0644]
blender_export.py
character.h
gate.h
main.c
player.h
shaders/terrain.fs
shaders/terrain.h
sound/skate.ogg [new file with mode: 0644]
sound/slide.ogg [new file with mode: 0644]
sound/wheel.ogg [new file with mode: 0644]
water.h
world.h

diff --git a/audio.h b/audio.h
new file mode 100644 (file)
index 0000000..498acc3
--- /dev/null
+++ b/audio.h
@@ -0,0 +1,55 @@
+#ifndef AUDIO_H
+#define AUDIO_H
+
+#include "common.h"
+
+sfx_vol_control audio_vol_all = { .val = 1.0f, .name = "All" };
+
+sfx_set audio_board =
+{
+   .sources = "sound/skate.ogg\0"
+              "sound/wheel.ogg\0"
+              "sound/slide.ogg\0"
+};
+
+sfx_system audio_player0 =
+{
+   .vol = 0.0f,
+   .ch = 1,
+   .vol_src = &audio_vol_all,
+   .name = "Player0",
+   .flags = SFX_FLAG_REPEAT | SFX_FLAG_PERSISTENT 
+};
+
+sfx_system audio_player1 =
+{
+   .vol = 0.0f,
+   .ch = 1,
+   .vol_src = &audio_vol_all,
+   .name = "Player1",
+   .flags = SFX_FLAG_REPEAT | SFX_FLAG_PERSISTENT
+};
+
+sfx_system audio_player2 =
+{
+   .vol = 0.0f,
+   .ch = 1,
+   .vol_src = &audio_vol_all,
+   .name = "Player2",
+   .flags = SFX_FLAG_REPEAT | SFX_FLAG_PERSISTENT
+};
+
+static void audio_init(void)
+{
+   sfx_set_init( &audio_board, NULL );
+   sfx_set_play( &audio_board, &audio_player0, 0 );
+   sfx_set_play( &audio_board, &audio_player1, 1 );
+   sfx_set_play( &audio_board, &audio_player2, 2 );
+}
+
+static void audio_free(void)
+{
+   sfx_set_free( &audio_board );
+}
+
+#endif /* AUDIO_H */
index afb0f78c41c3432db71699bcdb87044aa6604ce4..a13e84eb4a95b926018528902d7b26c9aee250b2 100644 (file)
@@ -256,6 +256,11 @@ def write_model(name):
 
                   sm.indice_count += 1
 
+            if sm.vertex_count == 0:
+               for j in range(2):
+                  for i in range(3):
+                     sm.bbx[j][i] = 0
+
             layers += [sm]
             header.layer_count += 1
             header.vertex_count += sm.vertex_count
@@ -266,6 +271,8 @@ def write_model(name):
             mref['vertex_start'] = sm.vertex_start
             mref['vertex_count'] = sm.vertex_count
             mref['bbx'] = sm.bbx
+            print( F"{sm.bbx[0][0]},{sm.bbx[0][1]},{sm.bbx[0][2]}" )
+
             mref['material'] = sm.material
             ref['sm'] += [mref]
 
index 047b714df02f62db79b113299848d467abdc2691..59fbdca1408cbdb44b0b7245c902b72834c02178 100644 (file)
@@ -422,7 +422,7 @@ void character_final_pose( struct character *ch, v3f cog,
       character_pose *pose, float q )
 {
    character_pose npose;
-   float dip = vg_clampf(cog[1], -1.0f, 0.3f) * 0.35f,
+   float dip = vg_clampf(cog[1], -1.0f, 0.3f) * 0.5f,
          tilt = vg_clampf(cog[2], -1.0f, 1.0f) * 0.3f;
 
    v4f rz; m4x3f tr;
@@ -447,6 +447,18 @@ void character_final_pose( struct character *ch, v3f cog,
    character_pose_blend( ch, &npose, q );
 }
 
+static void character_yaw_upper( struct character *ch, float yaw )
+{
+   m3x3f r;
+   v4f q;
+
+   q_axis_angle( q, (v3f){0.0f,1.0f,0.0f}, yaw );
+   q_m3x3( q, r );
+
+   m3x3_mulv( r, ch->ik_body.pole, ch->ik_body.pole );
+   m3x3_mulv( r, ch->ik_body.end, ch->ik_body.end );
+}
+
 static void zero_ik_basic( struct ik_basic *ik )
 {
    v3_zero( ik->base );
diff --git a/gate.h b/gate.h
index 7088c7dc5c236dc03223e5b3948904a6011278d0..3151878f25a4f7625c41bb0fe7d7bbe357effdf4 100644 (file)
--- a/gate.h
+++ b/gate.h
@@ -162,7 +162,7 @@ static void render_gate( teleport_gate *gate, m4x3f camera )
    }
 
    render_world( projection, cam_new );
-   
+
    if( grender.high_qual )
    {
       /*
@@ -202,6 +202,14 @@ static void render_gate( teleport_gate *gate, m4x3f camera )
    }
    else
    {
+      glDisable( GL_STENCIL_TEST );
+
+      render_water_texture( cam_new );
+      fb_use( NULL );
+      glEnable( GL_STENCIL_TEST );
+
+      render_water_surface( projection, cam_new );
+
       glStencilMask( 0xFF );
       glStencilFunc( GL_ALWAYS, 1, 0xFF );
       glDisable( GL_STENCIL_TEST );
diff --git a/main.c b/main.c
index def609d6c915b063db19fba3a135ea68c810261f..4462c0ff8ea14eba22ece198f4495bd008713310 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,3 +1,7 @@
+/*
+ * Copyright (C) Mount0 Software, Harry Godden - All Rights Reserved
+ */
+
 #include "common.h"
 
 /* Resources */
@@ -17,6 +21,7 @@ static int sv_debugcam = 0;
 #include "road.h"
 #include "scene.h"
 #include "ik.h"
+#include "audio.h"
 #include "terrain.h"
 #include "character.h"
 #include "ragdoll.h"
@@ -43,6 +48,15 @@ void vg_register(void)
    gate_register();
 }
 
+static void init_other(void)
+{
+   render_init();
+   gate_init();
+   terrain_init();
+   character_init();
+   audio_init();
+}
+
 vg_tex2d *texture_list[] =
 {
    &tex_norwey,
@@ -119,11 +133,8 @@ void vg_start(void)
        });
 
    vg_tex2d_init( texture_list, vg_list_size( texture_list ) );
-
-   render_init();
-   gate_init();
-   terrain_init();
-   character_init();
+   
+   init_other();
 
    character_load( &player.mdl, "ch_default" );
    character_init_ragdoll( &player.mdl );
@@ -167,10 +178,10 @@ void vg_render(void)
    m4x4f world_4x4;
    m4x3_expand( player.camera_inverse, world_4x4 );
 
-   gpipeline.fov = freecam? 60.0f: 120.0f; /* 120 */
+   gpipeline.fov = freecam? 60.0f: 135.0f; /* 120 */
    m4x4_projection( vg_pv, gpipeline.fov, 
          (float)vg_window_x / (float)vg_window_y, 
-         0.025f, 1000.0f );
+         0.1f, 1500.0f );
 
    m4x4_mul( vg_pv, world_4x4, vg_pv );
 
index 6c819801b01f664310d73f91144bc1be1911ab92..34ed46944337270ec1f571bac991ee02a9d37222 100644 (file)
--- a/player.h
+++ b/player.h
@@ -1,6 +1,7 @@
 #ifndef PLAYER_H
 #define PLAYER_H
 
+#include "audio.h"
 #include "common.h"
 #include "character.h"
 #include "bvh.h"
@@ -63,8 +64,7 @@ static void player_transform_update(void)
 
 static int reset_player( int argc, char const *argv[] )
 {
-   v3_copy( (v3f){ 0.0f, -2.0f, 0.0f }, player.co );
-
+   v3_copy( world.tutorial, player.co );
    if( argc == 1 )
    {
       if( !strcmp( argv[0], "tutorial" ))
@@ -1626,12 +1626,17 @@ static void player_animate(void)
 
    character_final_pose( &player.mdl, (v3f){0.0f,0.0f,0.0f}, 
          &pose_fly, amt_air );
+   
+   static float fupper = 0.0f;
+   fupper = vg_lerpf( fupper, -vg_get_axis("horizontal")*0.2f, 0.1f );
+   character_yaw_upper( &player.mdl, fupper );
 
    /* Camera position */
    v3_lerp( player.smooth_localcam, player.mdl.cam_pos, 0.08f, 
             player.smooth_localcam );
    v3_muladds( player.smooth_localcam, offset, 0.7f, player.camera_pos );
    player.camera_pos[1] = vg_clampf( player.camera_pos[1], 0.3f, kheight );
+
    m4x3_mulv( player.to_world, player.camera_pos, player.camera_pos );
 
    player.air_blend = vg_lerpf( player.air_blend, player.in_air, 0.04f );
@@ -2008,6 +2013,51 @@ static void player_do_collision( rigidbody *rb )
    }
 }
 
+static void player_audio(void)
+{
+   float speed = vg_minf(v3_length( player.v )*0.1f,1.0f),
+         attn = v3_dist( player.co, player.camera[3] )+1.0f;
+   attn = (1.0f/(attn*attn)) * speed;
+
+   static float air = 0.0f;
+   air = vg_lerpf(air, player.in_air? 1.0f: 0.0f, 0.7f);
+   
+   v3f ears = { 1.0f,0.0f,0.0f };
+   v3f delta;
+
+   v3_sub( player.co, player.camera[3], delta );
+   v3_normalize( delta );
+   m3x3_mulv( player.camera, ears, ears );
+
+   float pan = v3_dot( ears, delta );
+   audio_player0.pan = pan;
+   audio_player1.pan = pan;
+   audio_player2.pan = pan;
+
+   if( freecam )
+   {
+      audio_player0.vol = 0.0f;
+      audio_player1.vol = 0.0f;
+      audio_player2.vol = 0.0f;
+   }
+   else
+   {
+      if( player.is_dead )
+      {
+         audio_player0.vol = 0.0f;
+         audio_player1.vol = 0.0f;
+         audio_player2.vol = 0.0f;
+      }
+      else
+      {
+         float slide = vg_clampf( fabsf(player.slip), 0.0f, 1.0f );
+         audio_player0.vol = (1.0f-air)*attn*(1.0f-slide);
+         audio_player1.vol =       air *attn;
+         audio_player2.vol = (1.0f-air)*attn*slide;
+      }
+   }
+}
+
 static void player_update(void)
 {
    for( int i=0; i<player.land_log_count; i++ )
@@ -2083,6 +2133,11 @@ static void player_update(void)
 
             player_do_motion();
             player_animate();
+
+            v3f offs = { -0.35f, 0.0f, 0.0f };
+            m3x3_mulv( player.to_world, offs, offs );
+   m4x3_mulv( player.to_world, player.mdl.ik_body.end, player.camera_pos );
+            v3_add( offs, player.camera_pos, player.camera_pos );
          }
          else
          {
@@ -2091,6 +2146,8 @@ static void player_update(void)
       }
    }
 
+   player_audio();
+
    /* Update camera matrices */
    m4x3_identity( player.camera );
    m4x3_rotate_y( player.camera, -player.angles[0] );
@@ -2109,7 +2166,11 @@ static void draw_player(void)
    else
       character_eval( &player.mdl );
 
-   character_draw( &player.mdl, (player.is_dead|player.in_air)? 0.0f: 1.0f );
+   float opacity = 1.0f-player.air_blend;
+   if( player.is_dead )
+      opacity = 0.0f;
+
+   character_draw( &player.mdl, opacity );
 }
 
 #endif /* PLAYER_H */
index 98895a0d1ddd1c00df5eb3fb403d3911b9767940..7cf4dde38e87ce628229e6cf43d65431ddec4e95 100644 (file)
@@ -33,7 +33,7 @@ void main()
 
    // Colour blending
    float amtgrass = step(qnorm.y,0.6);
-   float amtsand = min(max((aCo.y + 90.0) * -0.08,0.0)*qnorm.y,1.0);
+   float amtsand = min(max((aCo.y - 10.0) * -0.08,0.0)*qnorm.y,1.0);
    vec2 uvgradients = vec2( rgarbage.a, -amtgrass*0.125 ) + aUv;
    vec3 diffuse = texture( uTexGradients, uvgradients ).rgb;
    diffuse = mix( diffuse, vec3(1.0,0.9,0.7), amtsand );
index 983e0ba350b100f4b82ebdd68268547639a6d213..1880395cc91a5932cd76ab070b4aa88689b2b13c 100644 (file)
@@ -72,7 +72,7 @@ static struct vg_shader _shader_terrain = {
 "\n"
 "   // Colour blending\n"
 "   float amtgrass = step(qnorm.y,0.6);\n"
-"   float amtsand = min(max((aCo.y + 90.0) * -0.08,0.0)*qnorm.y,1.0);\n"
+"   float amtsand = min(max((aCo.y - 10.0) * -0.08,0.0)*qnorm.y,1.0);\n"
 "   vec2 uvgradients = vec2( rgarbage.a, -amtgrass*0.125 ) + aUv;\n"
 "   vec3 diffuse = texture( uTexGradients, uvgradients ).rgb;\n"
 "   diffuse = mix( diffuse, vec3(1.0,0.9,0.7), amtsand );\n"
diff --git a/sound/skate.ogg b/sound/skate.ogg
new file mode 100644 (file)
index 0000000..06b2144
Binary files /dev/null and b/sound/skate.ogg differ
diff --git a/sound/slide.ogg b/sound/slide.ogg
new file mode 100644 (file)
index 0000000..ccfe4be
Binary files /dev/null and b/sound/slide.ogg differ
diff --git a/sound/wheel.ogg b/sound/wheel.ogg
new file mode 100644 (file)
index 0000000..28e09bc
Binary files /dev/null and b/sound/wheel.ogg differ
diff --git a/water.h b/water.h
index bcd0c6847d44ca840d66b8694840bbe6fbad2351..c2a7122c2244c1774e9f49f428803ad6afb85ec1 100644 (file)
--- a/water.h
+++ b/water.h
@@ -32,8 +32,8 @@ static struct
 }
 wrender =
 {
-   .fbreflect = { .format = GL_RGB,  .div = 2 },
-   .fbdepth   = { .format = GL_RGBA, .div = 2 }
+   .fbreflect = { .format = GL_RGB,  .div = 4 },
+   .fbdepth   = { .format = GL_RGBA, .div = 4 }
 };
 
 static float water_height(void)
@@ -86,7 +86,7 @@ static void water_compute_depth( boxf bounds )
    {
       for( int x=0; x<kres; x++ )
       {
-         v3f pos = { x, 0, y };
+         v3f pos = { x, 0.0f, y };
          v3_divs( pos, kres, pos );
          v3_muladd( bounds[0], pos, volume, pos );
          pos[1] = wrender.height;
@@ -98,7 +98,7 @@ static void water_compute_depth( boxf bounds )
          if( ray_world( pos, (v3f){0.0f,-1.0f,0.0f}, &hit ))
          {
             float h = wrender.height - hit.pos[1];
-            h *= 1.0f/15.0f;
+            h *= 1.0f/25.0f;
             h = vg_clampf( h, 0.0f, 1.0f );
             *dst = (u8)(h*255.0f);
          }
@@ -187,8 +187,6 @@ static void render_water_texture( m4x3f camera )
    v4f clippb = { 0.0f, -1.0f, 0.0f, -(wrender.height) };
    m4x3_mulp( inverse, clippb, clippb );
    clippb[3] *= -1.0f;
-   
-   float depth_loss = camera[3][1]-wrender.height;
 
    m4x4_projection( projection,
          gpipeline.fov,
diff --git a/world.h b/world.h
index 73b42a4c2bbaf45de4a41f5295bf7789f4e5e028..af0507fafc0db0f33b0a4f33e6ba0a10d6b3f9f3 100644 (file)
--- a/world.h
+++ b/world.h
@@ -23,10 +23,10 @@ static struct gworld
 
    v3f tutorial;
 
-   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;
@@ -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] )
@@ -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,6 +145,8 @@ static void world_load(void)
          water_init();
          water_set_surface( &surf, sm->pivot[1] );
 
+         vg_info( "%.3f\n", sm->pivot[1] );
+
          break;
       }
    }
@@ -195,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;