new animations
authorhgn <hgodden00@gmail.com>
Thu, 2 Jun 2022 15:27:56 +0000 (16:27 +0100)
committerhgn <hgodden00@gmail.com>
Thu, 2 Jun 2022 15:27:56 +0000 (16:27 +0100)
main.c
scene.h
scope.h [new file with mode: 0644]

diff --git a/main.c b/main.c
index 0b368990bd907ed5a278f3a0e121a030b43017d7..c3e75104403cf7c8609a76f8eb5342982246e646 100644 (file)
--- a/main.c
+++ b/main.c
@@ -23,6 +23,8 @@ static int freecam = 0;
 static int debugview = 0;
 static int debugsdf = 0;
 static int sv_debugcam = 0;
+static int sv_phys = 0;
+static int thirdperson = 0;
 
 /* Components */
 #include "road.h"
@@ -41,7 +43,7 @@ static struct gplayer
    /* Physics */
    v3f co, v, a;
    v4f rot;
-   float vswitch, slip_last;
+   float vswitch, slip, slip_last;
 
    float iY;   /* Yaw inertia */
    int in_air;
@@ -51,20 +53,35 @@ static struct gplayer
 
    v3f view;
    v2f look_dir;  /* TEMP */
+   v2f board_xy;
+   float grab;
    float pitch;
 
    m4x3f to_world, to_local;
    
-   v3f handl_target, handr_target,
-       handl, handr;
-
+   /* Opengl */
    glmesh mesh;
    submodel legl,
             legu,
             board,
             torso,
             wheels,
-            feet;
+            foot,
+            
+            /* NEW MODEL */
+            leg_r0, leg_r1, foot_r,
+            leg_l0, leg_l1, foot_l,
+            arm_r0, arm_r1, hand_r,
+            arm_l0, arm_l1, hand_l,
+            body, head;
+
+   /* Rendering */
+   m4x3f mleg_l, mknee_l, mleg_r, mknee_r, mboard;
+   m4x3f marm_l, melbow_l, marm_r, melbow_r, mbutt,
+         mfoot_l, mfoot_r;
+
+   v3f handl_target, handr_target,
+       handl, handr;
 }
 player;
 
@@ -88,10 +105,7 @@ static void player_transform_update(void)
    q_m3x3( player.rot, player.to_world );
    v3_copy( player.co, player.to_world[3] );
 
-   v4f inv;
-   q_inv( player.rot, inv );
-   q_m3x3( inv, player.to_local );
-   v3_negate( player.co, player.to_local[3] );
+   m4x3_invert_affine( player.to_world, player.to_local );
 }
 
 static int reset_player( int argc, char const *argv[] )
@@ -147,6 +161,22 @@ void vg_start(void)
       .persistent = 1
    });
 
+   vg_convar_push( (struct vg_convar){
+      .name = "phys",
+      .data = &sv_phys,
+      .data_type = k_convar_dtype_i32,
+      .opt_i32 = { .min=0, .max=1, .clamp=1 },
+      .persistent = 1
+   });
+
+   vg_convar_push( (struct vg_convar){
+      .name = "thirdperson",
+      .data = &thirdperson,
+      .data_type = k_convar_dtype_i32,
+      .opt_i32 = { .min=0, .max=1, .clamp=1 },
+      .persistent = 1
+   });
+
        vg_function_push( (struct vg_cmd){
                .name = "reset",
                .function = reset_player
@@ -163,7 +193,23 @@ void vg_start(void)
    player.board = *submodel_get( char_dev, "skateboard" );
    player.torso = *submodel_get( char_dev, "torso" );
    player.wheels = *submodel_get( char_dev, "wheels" );
-   player.feet = *submodel_get( char_dev, "feet" );
+   player.foot = *submodel_get( char_dev, "foot" );
+   
+   /* new model */
+   player.leg_r0 = *submodel_get( char_dev, "leg_r0" );
+   player.leg_r1 = *submodel_get( char_dev, "leg_r1" );
+   player.foot_r = *submodel_get( char_dev, "foot_r" );
+   player.leg_l0 = *submodel_get( char_dev, "leg_l0" );
+   player.leg_l1 = *submodel_get( char_dev, "leg_l1" );
+   player.foot_l = *submodel_get( char_dev, "foot_l" );
+   player.arm_r0 = *submodel_get( char_dev, "arm_r0" );
+   player.arm_r1 = *submodel_get( char_dev, "arm_r1" );
+   player.hand_r = *submodel_get( char_dev, "hand_r" );
+   player.arm_l0 = *submodel_get( char_dev, "arm_l0" );
+   player.arm_l1 = *submodel_get( char_dev, "arm_l1" );
+   player.hand_l = *submodel_get( char_dev, "hand_l" );
+   player.body = *submodel_get( char_dev, "body" );
+   player.head = *submodel_get( char_dev, "head" );
    free(char_dev);
 
    /* temp */
@@ -314,6 +360,7 @@ static void player_freecam(void)
 
    v3_muls( move_vel, 0.75f, move_vel );
    v3_add( move_vel, player.view, player.view );
+
 }
 
 static void apply_gravity( v3f vel, float const timestep )
@@ -396,8 +443,9 @@ static void player_physics_ground(void)
    slip = (-vel[0] / vel[2]) * player.vswitch;
    if( fabsf( slip ) > 1.2f )
       slip = vg_signf( slip ) * 1.2f;
+   player.slip = slip;
 
-   
+#if 0
    if( player.slip_last*slip < 0.0f && fabsf(slip) > 0.7f )
    {
       vg_warn( "SWITCH\n" );
@@ -406,6 +454,7 @@ static void player_physics_ground(void)
    }
 
    player.slip_last = slip;
+#endif
 
    float substep = ktimestep * 0.2f;
    
@@ -425,7 +474,7 @@ static void player_physics_ground(void)
       player.iY -=  3.6f * ktimestep;
    
    float steer = vg_get_axis( "horizontal" );
-   player.iY -= vg_signf(steer)*powf(steer,2.0f) * 3.5f * ktimestep;
+   player.iY -= vg_signf(steer)*powf(steer,2.0f) * 1.5f * ktimestep;
 }
 
 static void player_physics_air(void)
@@ -488,9 +537,16 @@ static void player_physics_air(void)
    player.iY -= vg_get_axis( "horizontal" ) * 3.6f * ktimestep;
 }
 
+static void player_animate(void);
 static void player_update(void)
 {
    /* temp */
+   if( freecam )
+   {
+      player_freecam();
+      return;
+   }
+   
    if( vg_get_axis("grabl")>0.0f)
       reset_player(0,NULL);
    if( vg_get_button( "forward" ) )
@@ -500,7 +556,6 @@ static void player_update(void)
       m3x3_mulv( player.to_world, dir, dir );
       v3_muladds( player.v, dir, 5.0f * ktimestep, player.v );
    }
-   
 
    float horizontal = vg_get_axis("horizontal"),
          vertical = vg_get_axis("vertical");
@@ -508,15 +563,12 @@ static void player_update(void)
    player.joy_l[0] = vg_signf(horizontal) * powf( horizontal, 2.0f );
    player.joy_l[1] = vg_signf(vertical) * powf( vertical, 2.0f );
 
-   if( freecam )
+   /* Integrate velocity */
+   if( sv_phys )
    {
-      player_freecam();
-      return;
+      apply_gravity( player.v, ktimestep );
+      v3_muladds( player.co, player.v, ktimestep, player.co );
    }
-   
-   /* Integrate velocity */
-   apply_gravity( player.v, ktimestep );
-   v3_muladds( player.co, player.v, ktimestep, player.co );
 
    /* Integrate inertia */
    v4f rotate; v3f vup = {0.0f,1.0f,0.0f};
@@ -538,19 +590,10 @@ static void player_update(void)
       player_physics_ground();
    
    /* Camera and character */
-   float kheight = 1.8f,
-         kleg = 0.6f;
-
-   v3f head;
-   head[0] =  0.0f;
-   head[1] =  kheight;
-   head[2] =  0.0f;
-
-   m4x3_mulv( player.to_world, head, head );
-   v3_copy( head, player.view );
 
    player_transform_update();
    q_normalize(player.rot);
+   player_animate();
 }
 
 void vg_update(void)
@@ -559,8 +602,45 @@ void vg_update(void)
 
    /* Creating a skeleton of the player dynamically */
 
-   v2f ac;
 
+   #if 0
+   player.handl_target[0] = head[0] + 0.2f;
+   player.handl_target[1] = head[1] - 0.8f*(1.0f-fabsf(slip));
+   player.handl_target[2] = head[2] + 0.2f + 0.7f*fabsf(slip);
+
+   player.handr_target[0] = head[0] + 0.2f;
+   player.handr_target[1] = head[1] - 0.8f*(1.0f-fabsf(slip));
+   player.handr_target[2] = head[2] - (0.2f + 0.7f*fabsf(slip));
+
+   if( vg_maxf(lslip,grab) > 0.5f )
+   {
+      if( player.slip < 0.0f && player.in_air )
+      {
+         player.handl_target[0] = 0.15f;
+         player.handl_target[1] = 0.1f;
+         player.handl_target[2] = 0.4f;
+      }
+      else
+      {
+         player.handr_target[0] =  0.15f;
+         player.handr_target[1] =  0.1f;
+         player.handr_target[2] = -0.4f;
+      }
+
+      if( grab > 0.5f )
+      {
+         player.handr_target[0] =  -0.15f;
+         player.handr_target[1] =  0.1f;
+         player.handr_target[2] =  0.4f;
+      }
+   }
+
+   #endif
+}
+
+static void player_animate(void)
+{
+   /* Camera position */
    static v3f last_vel = { 0.0f, 0.0f, 0.0f };
    static v3f momentum, bob;
 
@@ -568,7 +648,6 @@ void vg_update(void)
    v3_copy( player.v, last_vel );
 
    v3_add( momentum, player.a, momentum );
-   
    v3_lerp( momentum, (v3f){0.0f,0.0f,0.0f}, 0.1f, momentum );
    v3f target;
    
@@ -576,87 +655,108 @@ void vg_update(void)
    momentum[1] = vg_clampf( momentum[1], -0.2f, 5.0f );
    momentum[2] = vg_clampf( momentum[2], -2.0f, 2.0f );
    v3_copy( momentum, target );
-   
    v3_lerp( bob, target, 0.2f, bob );
 
    /* Head */
-#if 0
-   float lslip = fabsf(slip); //vg_minf( 0.4f, slip );
+   float lslip = fabsf(player.slip); //vg_minf( 0.4f, slip );
                               
-   static float grab = 0.0f;
    float grabt = vg_get_axis( "grabr" )*0.5f+0.5f;
-   grab = vg_lerpf( grab, grabt, 0.04f );
+   player.grab = vg_lerpf( player.grab, grabt, 0.04f );
+
+   float kheight = 1.8f,
+         kleg = 0.6f;
 
    v3f head;
-   head[0] =  0.0f;//(-sinf(lslip)*0.9f * kheight) * 0.44f;
-   head[1] =  (0.3f + cosf(lslip)*0.5f) * kheight - grab*0.7f; 
-   head[2] =  0.0f;
+   head[0] = 0.0f;
+   head[1] = (0.3f+cosf(lslip)*0.5f*(1.0f-player.grab*0.7f)) * kheight;
+   head[2] = 0.0f;
 
    v3f offset;
    m3x3_mulv( player.to_local, bob, offset );
-   offset[0] *= 0.25f;
+
+   offset[0] *= 0.3333f;
    offset[1] *= -0.25f;
    offset[2] *= 0.7f;
    v3_muladds( head, offset, 0.7f, head );
+   head[1] = vg_clampf( head[1], 0.3f, kheight );
 
-   head[1] = vg_clampf( head[1], 0.3f, 20.0f );
+   m4x3_mulv( player.to_world, head, head );
 
-   player.handl_target[0] = head[0] + 0.2f;
-   player.handl_target[1] = head[1] - 0.8f*(1.0f-fabsf(slip));
-   player.handl_target[2] = head[2] + 0.2f + 0.7f*fabsf(slip);
+   v3_copy( head, player.view );
 
-   player.handr_target[0] = head[0] + 0.2f;
-   player.handr_target[1] = head[1] - 0.8f*(1.0f-fabsf(slip));
-   player.handr_target[2] = head[2] - (0.2f + 0.7f*fabsf(slip));
+   /* New board transformation */
+   v4f board_rotation; v3f board_location;
+   
+   /* TODO: Move this out of animate into update */
+   v2_lerp( player.board_xy, (v2f){ vg_get_axis("h1"), vg_get_axis("v1") },
+         ktimestep*3.0f, player.board_xy );
 
-   if( vg_maxf(lslip,grab) > 0.5f )
+   v4f rz, rx;
+   q_axis_angle( rz, (v3f){ 0.0f, 0.0f, 1.0f }, player.board_xy[0] );
+   q_axis_angle( rx, (v3f){ 1.0f, 0.0f, 0.0f }, player.board_xy[1] );
+   q_mul( rx, rz, board_rotation );
+
+   q_m3x3( board_rotation, player.mboard );
+   m3x3_mulv( player.mboard, (v3f){ 0.0f, -0.5f, 0.0f }, board_location );
+   v3_add( (v3f){0.0f,0.5f,0.0f}, board_location, board_location );
+
+   m3x3_mul( player.to_world, player.mboard, player.mboard );
+   m4x3_mulv( player.to_world, board_location, player.mboard[3] );
+
+
+   /* In the air, the dude should grab with the side thats highest,
+    * while also sliding the same foot downwards a bit */
+
+   float foot_l =  0.3f,
+         foot_r = -0.4f;
+
+   player.handl_target[0] = 0.0f;
+   player.handl_target[1] = 0.0f;
+   player.handl_target[2] = 0.6f;
+
+   player.handr_target[0] = 0.0f;
+   player.handr_target[1] = 0.0f;
+   player.handr_target[2] = -0.6f;
+   if( 1||player.in_air )
    {
-      if( slip < 0.0f && in_air )
+      float tuck = player.board_xy[1],
+            tuck_amt = fabsf( tuck ) * (1.0f-fabsf(player.board_xy[0]));
+
+      if( tuck < 0.0f )
       {
-         player.handl_target[0] = 0.15f;
-         player.handl_target[1] = 0.1f;
-         player.handl_target[2] = 0.4f;
+         foot_l *= 1.0f-tuck_amt*1.5f;
+
+         if( player.grab > 0.1f )
+         {
+            m4x3_mulv( player.mboard, (v3f){0.1f,0.14f,0.6f}, 
+                  player.handl_target );
+            m4x3_mulv( player.to_local, 
+                  player.handl_target, player.handl_target );
+         }
       }
       else
       {
-         player.handr_target[0] =  0.15f;
-         player.handr_target[1] =  0.1f;
-         player.handr_target[2] = -0.4f;
-      }
+         foot_r *= 1.0f-tuck_amt*1.4f;
 
-      if( grab > 0.5f )
-      {
-         player.handr_target[0] =  -0.15f;
-         player.handr_target[1] =  0.1f;
-         player.handr_target[2] =  0.4f;
+         if( player.grab > 0.1f )
+         {
+            m4x3_mulv( player.mboard, (v3f){0.1f,0.14f,-0.6f}, 
+                  player.handr_target );
+            m4x3_mulv( player.to_local, 
+                  player.handr_target, player.handr_target );
+         }
       }
    }
-#endif
-
-}
-
-static void debug_grid( v3f at )
-{
-   v3f base;
-   v3_floor( at, base );
-
-   for( int y=0; y<16; y++ )
-   {
-      vg_line( (v3f){ base[0] - 8, base[1], base[2]+y-8 },
-               (v3f){ base[0] + 8, base[1], base[2]+y-8 },
-               0x40ffffff );
-   }
-   for( int x=0; x<16; x++ )
+   else
    {
-      vg_line( (v3f){ base[0]+x-8, base[1], base[2]-8 },
-               (v3f){ base[0]+x-8, base[1], base[2]+8 },
-               0x40ffffff );
    }
-}
 
-static void draw_player(void)
-{
-   mesh_bind( &player.mesh );
+   m3x3_copy( player.mboard, player.mfoot_l );
+   m4x3_mulv( player.mboard, (v3f){ 0.0f,0.16f,foot_l }, player.mfoot_l[3] );
+
+   m3x3_copy( player.mboard, player.mfoot_r );
+   m4x3_mulv( player.mboard, (v3f){ 0.0f,0.16f,foot_r }, player.mfoot_r[3] );
+
    float const kleg_upper = 0.53f,
                kleg_lower = 0.5f,
                karm_ratio = 0.75f,
@@ -670,49 +770,60 @@ static void draw_player(void)
                    ik_arm_r = { .l1 = karm_upper, .l2 = karm_lower };
 
    v3f butt, fwd;
+   v4f hip_rotation;
 
-   m4x3_mulv( player.to_world, (v3f){ 0.0f,0.16f,-0.4f }, ik_leg_r.end );
-   m4x3_mulv( player.to_world, (v3f){ 0.0f,0.16f, 0.3f }, ik_leg_l.end );
-   m4x3_mulv( player.to_world, (v3f){ -0.6f,0.5f,-0.4f }, ik_leg_r.pole );
-   m4x3_mulv( player.to_world, (v3f){ -0.6f,0.5f,0.35f }, ik_leg_l.pole );
-
+   /* create hip rotation */
+   q_axis_angle( hip_rotation, (v3f){0.0f,1.0f,0.0f}, sinf(vg_time) );
+   q_m3x3( hip_rotation, player.mbutt );
+   m3x3_mul( player.to_world, player.mbutt, player.mbutt );
+   
+   /* offset */
    m3x3_mulv( player.to_world, (v3f){ 0.2f,-0.55f,0.0f}, butt );
    v3_add( butt, player.view, butt );
+   v3_copy( butt, player.mbutt[3] );
+   
+   m4x3_mulv( player.mbutt, (v3f){0.0f,0.0f,-0.1f}, ik_leg_r.base );
+   m4x3_mulv( player.mbutt, (v3f){0.0f,0.0f, 0.1f}, ik_leg_l.base );
 
-   m3x3_mulv( player.to_world, (v3f){0.0f,0.0f,-1.0f}, fwd );
-   v3_muladds( butt, fwd, 0.1f, ik_leg_r.base );
-   v3_muladds( butt, fwd,-0.1f, ik_leg_l.base );
+   m4x3_mulv( player.mboard, (v3f){  0.0f,0.16f, foot_r }, ik_leg_r.end );
+   m4x3_mulv( player.mboard, (v3f){  0.0f,0.16f, foot_l }, ik_leg_l.end );
+   m4x3_mulv( player.mboard, (v3f){ -0.6f,0.50f,-0.40f }, ik_leg_r.pole );
+   m4x3_mulv( player.mboard, (v3f){ -0.6f,0.50f, 0.35f }, ik_leg_l.pole );
 
    /* Compute IK */
-   m4x3f mleg_l, mknee_l, mleg_r, mknee_r, mboard;
-
-   ik_basic( &ik_leg_r, mleg_r, mknee_r );
-   ik_basic( &ik_leg_l, mleg_l, mknee_l );
+   ik_basic( &ik_leg_r, player.mleg_r, player.mknee_r );
+   ik_basic( &ik_leg_l, player.mleg_l, player.mknee_l );
 
    /* Arms */
-   v3f hl, hr, neckl = {0.2f,-0.1f, 0.2f},
-               neckr = {0.2f,-0.1f,-0.2f};
+   v3f hl, hr, neckl = {0.0f, 0.5f, 0.2f},
+               neckr = {0.0f, 0.5f,-0.2f};
    
-   v3_lerp( player.handl, player.handl_target, 0.04f, player.handl );
-   v3_lerp( player.handr, player.handr_target, 0.04f, player.handr );
+   m4x3_mulv( player.mbutt, neckl, ik_arm_l.base );
+   m4x3_mulv( player.mbutt, neckr, ik_arm_r.base );
 
-   m3x3_mulv( player.to_world, neckl, neckl );
-   m3x3_mulv( player.to_world, neckr, neckr );
+   v3_lerp( player.handl, player.handl_target, 0.1f, player.handl );
+   v3_lerp( player.handr, player.handr_target, 0.1f, player.handr );
 
-   v3_add( player.view, neckl, ik_arm_l.base );
-   v3_add( player.view, neckr, ik_arm_r.base );
    m4x3_mulv( player.to_world, player.handl, ik_arm_l.end );
    m4x3_mulv( player.to_world, player.handr, ik_arm_r.end );
    m4x3_mulv( player.to_world, (v3f){ 0.6f,0.7f, 0.4f  }, ik_arm_l.pole );
    m4x3_mulv( player.to_world, (v3f){ 0.6f,0.7f,-0.35f }, ik_arm_r.pole );
    
-   m4x3f marm_l, melbow_l, marm_r, melbow_r;
-   ik_basic( &ik_arm_l, marm_l, melbow_l );
-   ik_basic( &ik_arm_r, marm_r, melbow_r );
-   m4x3_scale( marm_l, karm_ratio );
-   m4x3_scale( marm_r, karm_ratio );
-   m4x3_scale( melbow_l, karm_ratio );
-   m4x3_scale( melbow_r, karm_ratio );
+   ik_basic( &ik_arm_l, player.marm_l, player.melbow_l );
+   ik_basic( &ik_arm_r, player.marm_r, player.melbow_r );
+
+   if( thirdperson )
+   {
+      v3f nv;
+      v3_copy( player.v, nv );
+      v3_normalize( nv );
+      v3_muladds( player.view, nv, -3.0f, player.view );
+   }
+}
+
+static void draw_player(void)
+{
+   mesh_bind( &player.mesh );
 
    /* Draw */
    vg_tex2d_bind( &tex_grid, 0 );
@@ -734,8 +845,7 @@ static void draw_player(void)
    glUniform4f( SHADER_UNIFORM(shader_standard_lit,"uColour"), 
          0.35f*kscale,0.35f*kscale,0.35f*kscale,1.0f );
 
-   m4x3_expand( player.to_world, mat );
-       glUniformMatrix4fv( kuMdl, 1, GL_FALSE, (float *)mat );
+       glUniformMatrix4x3fv( kuMdl, 1, GL_FALSE, (float *)player.mboard );
    submodel_draw( &player.board );
 
    glUniform4f( SHADER_UNIFORM(shader_standard_lit,"uColour"), 
@@ -749,49 +859,43 @@ static void draw_player(void)
    glUniform4f( SHADER_UNIFORM(shader_standard_lit,"uColour"), 
          0.2f*kscale,0.8f*kscale,0.4f*kscale,0.14f );
 
-   submodel_draw( &player.feet );
+       glUniformMatrix4x3fv( kuMdl, 1, GL_FALSE, (float *)player.mfoot_l );
+   submodel_draw( &player.foot_l );
+       glUniformMatrix4x3fv( kuMdl, 1, GL_FALSE, (float *)player.mfoot_r );
+   submodel_draw( &player.foot_r );
 
-   m4x3_expand( mleg_l, mat );
-       glUniformMatrix4fv( kuMdl, 1, GL_FALSE, (float *)mat );
-   submodel_draw( &player.legu );
+       glUniformMatrix4x3fv( kuMdl, 1, GL_FALSE, (float *)player.mleg_l );
+   submodel_draw( &player.leg_l0 );
 
-   m4x3_expand( mknee_l, mat );
-       glUniformMatrix4fv( kuMdl, 1, GL_FALSE, (float *)mat );
-   submodel_draw( &player.legl );
+       glUniformMatrix4x3fv( kuMdl, 1, GL_FALSE, (float *)player.mknee_l );
+   submodel_draw( &player.leg_l1 );
 
-   m4x3_expand( mleg_r, mat );
-       glUniformMatrix4fv( kuMdl, 1, GL_FALSE, (float *)mat );
-   submodel_draw( &player.legu );
+       glUniformMatrix4x3fv( kuMdl, 1, GL_FALSE, (float *)player.mleg_r );
+   submodel_draw( &player.leg_r0 );
 
-   m4x3_expand( mknee_r, mat );
-       glUniformMatrix4fv( kuMdl, 1, GL_FALSE, (float *)mat );
-   submodel_draw( &player.legl );
+       glUniformMatrix4x3fv( kuMdl, 1, GL_FALSE, (float *)player.mknee_r );
+   submodel_draw( &player.leg_r1 );
 
    /* arms */
-   m4x3_expand( marm_l, mat );
-       glUniformMatrix4fv( kuMdl, 1, GL_FALSE, (float *)mat );
-   submodel_draw( &player.legu );
+       glUniformMatrix4x3fv( kuMdl, 1, GL_FALSE, (float *)player.marm_l );
+   submodel_draw( &player.arm_l0 );
 
-   m4x3_expand( melbow_l, mat );
-       glUniformMatrix4fv( kuMdl, 1, GL_FALSE, (float *)mat );
-   submodel_draw( &player.legl );
+       glUniformMatrix4x3fv( kuMdl, 1, GL_FALSE, (float *)player.melbow_l );
+   submodel_draw( &player.arm_l1 );
 
-   m4x3_expand( marm_r, mat );
-       glUniformMatrix4fv( kuMdl, 1, GL_FALSE, (float *)mat );
-   submodel_draw( &player.legu );
+       glUniformMatrix4x3fv( kuMdl, 1, GL_FALSE, (float *)player.marm_r );
+   submodel_draw( &player.arm_r0 );
 
-   m4x3_expand( melbow_r, mat );
-       glUniformMatrix4fv( kuMdl, 1, GL_FALSE, (float *)mat );
-   submodel_draw( &player.legl );
+       glUniformMatrix4x3fv( kuMdl, 1, GL_FALSE, (float *)player.melbow_r );
+   submodel_draw( &player.arm_r1 );
 
    /* body */
-   m4x3f mbutt;
-   m3x3_copy( player.to_world, mbutt );
-   v3_copy( butt, mbutt[3] );
+       glUniformMatrix4x3fv( kuMdl, 1, GL_FALSE, (float *)player.mbutt );
+   submodel_draw( &player.body );
 
-   m4x3_expand( mbutt, mat );
-       glUniformMatrix4fv( kuMdl, 1, GL_FALSE, (float *)mat );
-   submodel_draw( &player.torso );
+   glUniform4f( SHADER_UNIFORM(shader_standard_lit,"uColour"), 
+         0.2f*kscale,0.2f*kscale,0.2f*kscale,0.14f );
+   submodel_draw( &player.head );
 
    glDisable(GL_BLEND);
    glEnable( GL_DEPTH_TEST );
@@ -825,7 +929,6 @@ void vg_render(void)
    
    m4x4f world_4x4;
    m4x3_expand( world_matrix, world_4x4 );
-
    m4x4_projection( vg_pv, 
          freecam? 90.0f: 130.0f,
          (float)vg_window_x / (float)vg_window_y, 
@@ -839,9 +942,9 @@ void vg_render(void)
    glEnable( GL_DEPTH_TEST );
    
    scene_foliage_shader_use();
-   m4x4f temp1;
-   m4x4_identity( temp1 );
-       glUniformMatrix4fv( SHADER_UNIFORM( shader_debug_vcol, "uMdl" ), 
+   m4x3f temp1;
+   m4x3_identity( temp1 );
+       glUniformMatrix4x3fv( SHADER_UNIFORM( shader_debug_vcol, "uMdl" ), 
          1, GL_FALSE, (float *)temp1 );
 
    vg_tex2d_bind( &tex_norwey, 0 );
@@ -853,10 +956,10 @@ void vg_render(void)
       scene_debugsdf( &world.foliage );
    
    SHADER_USE(shader_unlit);
-   m4x4f temp2;
-   m4x4_identity(temp2);
+   m4x3f temp2;
+   m4x3_identity(temp2);
    //m4x4_translate( temp2, player.co );
-       glUniformMatrix4fv( SHADER_UNIFORM( shader_unlit, "uMdl" ), 
+       glUniformMatrix4x3fv( SHADER_UNIFORM( shader_unlit, "uMdl" ), 
          1, GL_FALSE, (float *)temp2 );
        glUniformMatrix4fv( SHADER_UNIFORM( shader_unlit, "uPv" ), 
          1, GL_FALSE, (float *)vg_pv );
@@ -867,23 +970,24 @@ void vg_render(void)
    mesh_bind( &world.skydome );
    mesh_draw( &world.skydome );
 
+#if 0
    vg_tex2d_bind( &tex_cement, 0 );
    mesh_bind( &world.cement );
    mesh_draw( &world.cement );
+#endif
 
    SHADER_USE(shader_standard_lit);
 
        glUniformMatrix4fv( SHADER_UNIFORM( shader_standard_lit, "uPv" ), 
          1, GL_FALSE, (float *)vg_pv );
    glUniform1i( SHADER_UNIFORM( shader_standard_lit, "uTexMain" ), 0 );
-
-       glUniformMatrix4fv( SHADER_UNIFORM( shader_standard_lit, "uMdl" ), 
+       glUniformMatrix4x3fv( SHADER_UNIFORM( shader_standard_lit, "uMdl" ), 
          1, GL_FALSE, (float *)temp1 );
 
    vg_tex2d_bind( &tex_grid, 0 );
 
    scene_bind( &world.geo );
-#if 0
+#if 1
    glUniform4f( SHADER_UNIFORM(shader_standard_lit,"uColour"), 
          0.2f,0.36f,0.25f,1.0f );
    submodel_draw( &world.terrain );
@@ -905,7 +1009,7 @@ void vg_render(void)
    vg_lines_drawall( (float *)vg_pv );
 
    /* Debugger camera */
-   glViewport( 0,0, 512, 512 );
+   glViewport( 0,0, 800, 800 );
    glClearColor( 0.1f, 0.0f, 0.2f, 1.0f );
    glClear( GL_DEPTH_BUFFER_BIT );
 
@@ -928,6 +1032,7 @@ void vg_render(void)
    if(sv_debugcam)
    {
       glEnable( GL_DEPTH_TEST );
+
       draw_player();
    }
 
diff --git a/scene.h b/scene.h
index d5fa2758b314b0bc19a4bb104df6c736a0efdbcc..63ae145453d9521cb8a5d44827233322f67dc2da 100644 (file)
--- a/scene.h
+++ b/scene.h
@@ -121,7 +121,7 @@ SHADER_DEFINE( shader_debug_vcol,
    /*Include*/ VERTEX_STANDARD_ATTRIBUTES
 
        "uniform mat4 uPv;"
-   "uniform mat4 uMdl;"
+   "uniform mat4x3 uMdl;"
    "uniform float uTime;"
    "uniform float uSwayAmt;"
    ""
@@ -144,7 +144,7 @@ SHADER_DEFINE( shader_debug_vcol,
        "void main()"
        "{"
       "vec3 swaypos = compute_sway( a_co );"
-               "gl_Position = uPv * uMdl * vec4( swaypos, 1.0 );"
+               "gl_Position = uPv * vec4(uMdl * vec4(swaypos,1.0), 1.0 );"
       "aColour = a_colour;"
       "aUv = a_uv;"
       "aNorm = normalize(mat3(uMdl) * a_norm);"
@@ -241,7 +241,7 @@ SHADER_DEFINE( shader_standard_lit,
    /*Include*/ VERTEX_STANDARD_ATTRIBUTES
 
        "uniform mat4 uPv;"
-   "uniform mat4 uMdl;"
+   "uniform mat4x3 uMdl;"
    ""
    "out vec4 aColour;"
    "out vec2 aUv;"
@@ -250,7 +250,7 @@ SHADER_DEFINE( shader_standard_lit,
    ""
        "void main()"
        "{"
-               "gl_Position = uPv * uMdl * vec4( a_co, 1.0 );"
+               "gl_Position = uPv * vec4( uMdl * vec4(a_co,1.0), 1.0 );"
       "aColour = a_colour;"
       "aUv = a_uv;"
       "aNorm = mat3(uMdl) * a_norm;"
@@ -289,7 +289,7 @@ SHADER_DEFINE( shader_unlit,
    /*Include*/ VERTEX_STANDARD_ATTRIBUTES
 
        "uniform mat4 uPv;"
-   "uniform mat4 uMdl;"
+   "uniform mat4x3 uMdl;"
    ""
    "out vec4 aColour;"
    "out vec2 aUv;"
@@ -298,7 +298,7 @@ SHADER_DEFINE( shader_unlit,
    ""
        "void main()"
        "{"
-               "gl_Position = uPv * uMdl * vec4( a_co, 1.0 );"
+               "gl_Position = uPv * vec4(uMdl * vec4(a_co,1.0), 1.0);"
       "aColour = a_colour;"
       "aUv = a_uv;"
       "aNorm = mat3(uMdl) * a_norm;"
diff --git a/scope.h b/scope.h
new file mode 100644 (file)
index 0000000..8807ec9
--- /dev/null
+++ b/scope.h
@@ -0,0 +1,19 @@
+/* Scope debugger thing */
+#include "vg/vg_ui.h"
+#include "vg/vg_platform.h"
+
+static struct
+{
+   struct scope_log
+   {
+      ui_px buffer[128];
+   } 
+   logs[10];
+
+}
+dev_scope;
+
+static void scope_watch( const char *name, float value, float min, float max )
+{
+
+}