u32 *ptri = &world.scene_geo->arrindices[ idx*3 ];
v3f tri[3];
+ struct world_material *mat = world_tri_index_material(ptri[0]);
+ if( !(mat->info.flags & k_material_flag_skate_surface) )
+ continue;
+
for( int j=0; j<3; j++ )
v3_copy( world.scene_geo->arrvertices[ptri[j]].co, tri[j] );
float a = atan2f( v[1], v[0] ),
m = v2_length( v ),
- root = m*m*m*m - k_gravity*(k_gravity*d[0]*d[0] + 2.0f*d[1]*m*m);
+ root = m*m*m*m - p->gravity*(p->gravity*d[0]*d[0] + 2.0f*d[1]*m*m);
if( root > 0.0f )
{
root = sqrtf( root );
- float a0 = atanf( (m*m + root) / (k_gravity * d[0]) ),
- a1 = atanf( (m*m - root) / (k_gravity * d[0]) );
+ float a0 = atanf( (m*m + root) / (p->gravity * d[0]) ),
+ a1 = atanf( (m*m - root) / (p->gravity * d[0]) );
if( fabsf(a0-a) > fabsf(a1-a) )
a0 = a1;
v3f p0;
v3_muls( p->v, t, p0 );
- p0[1] += -0.5f * k_gravity * t*t;
+ p0[1] += -0.5f * p->gravity * t*t;
v3_add( player->rb.co, p0, p->log[ p->log_length ++ ] );
}
struct grind_info grind;
int grind_located = 0;
- for( int m=0;m<=15; m++ )
+ for( int m=0;m<=30; m++ )
{
struct land_prediction *p = &s->predictions[ s->prediction_count ++ ];
v3_copy( player->rb.v, launch_v );
v3_copy( launch_co, co0 );
- float vt = (float)m * (1.0f/15.0f),
+ float vt = (float)m * (1.0f/30.0f),
ang = vg_lerpf( angle_begin, angle_end, vt ) * 0.15f;
v4f qbias;
q_axis_angle( qbias, axis, ang );
q_mulv( qbias, launch_v, launch_v );
+
+ float yaw_sketch = 1.0f-fabsf(player->rb.to_world[1][1]);
+
+ float yaw_bias = ((float)(m%3) - 1.0f) * 0.08f * yaw_sketch;
+ q_axis_angle( qbias, player->rb.to_world[1], yaw_bias );
+ q_mulv( qbias, launch_v, launch_v );
+
+
+ float gravity_bias = vg_lerpf( 0.85f, 1.4f, vt ),
+ gravity = k_gravity * gravity_bias;
+ p->gravity = gravity;
+
v3_copy( launch_v, p->v );
for( int i=1; i<=50; i++ )
float t = (float)i * k_trace_delta;
v3_muls( launch_v, t, co1 );
- co1[1] += -0.5f * k_gravity * t*t;
+ co1[1] += -0.5f * gravity * t*t;
v3_add( launch_co, co1, co1 );
- if( !grind_located && (launch_v[1] - k_gravity*t < 0.0f) )
+ if( !grind_located && (launch_v[1] - gravity*t < 0.0f) )
{
v3f closest;
if( bh_closest_point( world.geo_bh, co1, closest, 1.0f ) != -1 )
{
v3f ve;
v3_copy( launch_v, ve );
- ve[1] -= k_gravity * t;
+ ve[1] -= gravity * t;
if( skate_grind_scansq( closest, ve, 0.5f, &grind ) )
{
v3f ve;
v3_copy( launch_v, ve );
- ve[1] -= k_gravity * t;
+ ve[1] -= gravity * t;
struct grind_info replace_grind;
if( skate_grind_scansq( co, ve, 0.3f, &replace_grind ) )
break;
}
+
+ if( i % 3 == 0 )
+ v3_copy( co1, p->log[ p->log_length ++ ] );
- v3_copy( co1, p->log[ p->log_length ++ ] );
v3_copy( co1, co0 );
}
s->prediction_count --;
}
-
-
if( grind_located )
{
/* calculate the exact solution(s) to jump onto that grind spot */
struct land_prediction *p = &s->predictions[ s->prediction_count ];
+ p->gravity = k_gravity;
if( solve_prediction_for_target( player, grind.co, 0.125f*VG_PIf, p ) )
{
/* determine score */
v3f ve;
v3_copy( p->v, ve );
- ve[1] -= k_gravity * p->land_dist;
+ ve[1] -= p->gravity * p->land_dist;
p->score = -v3_dot( ve, grind.n ) * 0.85f;
s->prediction_count ++;
v2f steer = { player->input_js1h->axis.value,
player->input_js1v->axis.value };
v2_normalize_clamp( steer );
+ s->state.gravity_bias = best->gravity;
if( (fabsf(steer[1]) > 0.5f) && (s->land_dist >= 1.5f) )
{
v2f steer = { player->input_js1h->axis.value,
player->input_js1v->axis.value };
v2_normalize_clamp( steer );
- s->land_dist = 1.0f;
}
VG_STATIC int player_skate_trick_input( player_instance *player );
for( int i=0; i<2; i++ )
{
v3f normal, axel;
+ v3_copy( player->rb.to_world[0], axel );
+
if( skate_compute_surface_alignment( player, wheels[i].pos,
wheels[i].colour, normal, axel ) )
{
v3_add( normal, s->surface_picture, s->surface_picture );
contact_count ++;
}
+
+ m3x3_mulv( player->rb.to_local, axel, s->truckv0[i] );
}
if( contact_count )
{
s->state.activity = k_skate_activity_ground;
+ s->state.gravity_bias = k_gravity;
v3_normalize( s->surface_picture );
skate_apply_friction_model( player );
}
rb_update_transform( &player->rb );
- player->rb.v[1] += -k_gravity * s->substep_delta;
+ player->rb.v[1] += -s->state.gravity_bias * s->substep_delta;
s->substep -= s->substep_delta;
}
-
-
/* angle correction */
if( v3_length2( s->state.up_dir ) > 0.001f )
{
- mdl_keyframe *kf_board = &dest->pose[av->id_board-1],
- *kf_foot_l = &dest->pose[av->id_ik_foot_l-1],
- *kf_foot_r = &dest->pose[av->id_ik_foot_r-1];
-
+ mdl_keyframe *kf_board = &dest->pose[av->id_board-1],
+ *kf_foot_l = &dest->pose[av->id_ik_foot_l-1],
+ *kf_foot_r = &dest->pose[av->id_ik_foot_r-1],
+ *kf_wheels[] = { &dest->pose[av->id_wheel_r-1],
+ &dest->pose[av->id_wheel_l-1] };
v4f qtotal;
v4f qtrickr, qyawr, qpitchr, qrollr;
v3f eulerr;
-
v3_muls( s->board_trick_residuald, VG_TAUf, eulerr );
kf_foot_r->co[2] += s->blend_weight * 0.3f;
kf_foot_l->co[2] += s->blend_weight * 0.1f;
}
+
+ /* truck rotation */
+ for( int i=0; i<2; i++ )
+ {
+ float a = vg_minf( s->truckv0[i][0], 1.0f );
+ a = -acosf( a ) * vg_signf( s->truckv0[i][1] );
+
+ v4f q;
+ q_axis_angle( q, (v3f){0.0f,0.0f,1.0f}, a );
+ q_mul( q, kf_wheels[i]->q, kf_wheels[i]->q );
+ q_normalize( kf_wheels[i]->q );
+ }
}
/* transform */
}
}
+VG_STATIC void world_add_blob( scene *pscene, ray_hit *hit )
+{
+ m4x3f transform;
+ v4f qsurface, qrandom;
+ v3f axis;
+
+ v3_cross( (v3f){0.0f,1.0f,0.0f}, hit->normal, axis );
+
+ float angle = v3_dot(hit->normal,(v3f){0.0f,1.0f,0.0f});
+ q_axis_angle( qsurface, axis, angle );
+ q_axis_angle( qrandom, (v3f){0.0f,1.0f,0.0f}, vg_randf()*VG_TAUf );
+ q_mul( qsurface, qrandom, qsurface );
+ q_m3x3( qsurface, transform );
+ v3_copy( hit->pos, transform[3] );
+
+ mdl_vert verts[] =
+ {
+ { .co = { -1.00f, 0.0f, 0.0f } },
+ { .co = { 1.00f, 0.0f, 0.0f } },
+ { .co = { -1.00f, 1.2f, 0.0f } },
+ { .co = { 1.00f, 1.2f, 0.0f } },
+ { .co = { -0.25f, 2.0f, 0.0f } },
+ { .co = { 0.25f, 2.0f, 0.0f } }
+ };
+
+ const u32 indices[] = { 0,1,3, 0,3,2, 2,3,5, 2,5,4 };
+
+ if( pscene->vertex_count + vg_list_size(verts) > pscene->max_vertices )
+ vg_fatal_exit_loop( "Scene vertex buffer overflow" );
+
+ if( pscene->indice_count + vg_list_size(indices) > pscene->max_indices )
+ vg_fatal_exit_loop( "Scene index buffer overflow" );
+
+ mdl_vert *dst_verts = &pscene->arrvertices[ pscene->vertex_count ];
+ u32 *dst_indices = &pscene->arrindices [ pscene->indice_count ];
+
+ mdl_vert *ref = &world.scene_geo->arrvertices[ hit->tri[0] ];
+
+ for( u32 i=0; i<vg_list_size(verts); i++ )
+ {
+ mdl_vert *pvert = &dst_verts[ i ],
+ *src = &verts[ i ];
+
+ m4x3_mulv( transform, src->co, pvert->co );
+ v3_copy( transform[1], pvert->norm );
+
+ pvert->colour[0] = 0;
+ pvert->colour[1] = 0;
+ pvert->colour[2] = 0;
+ pvert->colour[3] = 0;
+ pvert->weights[0] = 0;
+ pvert->weights[1] = 0;
+ pvert->weights[2] = 0;
+ pvert->weights[3] = 0;
+
+ v2_copy( ref->uv, pvert->uv );
+ }
+
+ for( u32 i=0; i<vg_list_size(indices); i++ )
+ dst_indices[i] = indices[i] + pscene->vertex_count;
+
+ pscene->vertex_count += vg_list_size(verts);
+ pscene->indice_count += vg_list_size(indices);
+}
+
/* Sprinkle foliage models over the map on terrain material */
VG_STATIC void world_apply_procedural_foliage( struct world_material *mat )
{
v3_sub( world.scene_geo->bbx[1], world.scene_geo->bbx[0], volume );
volume[1] = 1.0f;
- m4x3f transform;
mdl_node *mblob = mdl_node_from_name( mfoliage, "blob" );
mdl_submesh *sm_blob = mdl_node_submesh( mfoliage, mblob, 0 );
struct world_material *m1 = ray_hit_material( &hit );
if((hit.normal[1] > 0.8f) && (m1 == mat) && (hit.pos[1] > 0.0f+10.0f))
{
- v4f qsurface, qrandom;
- v3f axis;
-
- v3_cross( (v3f){0.0f,1.0f,0.0f}, hit.normal, axis );
-
- float angle = v3_dot(hit.normal,(v3f){0.0f,1.0f,0.0f});
- q_axis_angle( qsurface, axis, angle );
- q_axis_angle( qrandom, (v3f){0.0f,1.0f,0.0f}, vg_randf()*VG_TAUf );
- q_mul( qsurface, qrandom, qsurface );
- q_m3x3( qsurface, transform );
-
- v3_copy( hit.pos, transform[3] );
- scene_add_submesh( world.scene_no_collide, mfoliage,
- sm_blob, transform);
-
+ world_add_blob( world.scene_no_collide, &hit );
count ++;
}
}
}
}
-VG_STATIC void edge_bh_expand_bound( void *user, boxf bound, u32 item_index )
-{
- struct grind_edge *edge_array = user,
- *edge = &edge_array[ item_index ];
-
- box_addpt( bound, edge->p0 );
- box_addpt( bound, edge->p1 );
-}
-
-VG_STATIC float edge_bh_centroid( void *user, u32 item_index, int axis )
-{
- struct grind_edge *edge_array = user,
- *edge = &edge_array[ item_index ];
-
- return (edge->p0[axis] + edge->p1[axis]) * 0.5f;
-}
-
-VG_STATIC void edge_bh_swap( void *user, u32 ia, u32 ib )
-{
- struct grind_edge *edge_array = user,
- *e0 = &edge_array[ ia ],
- *e1 = &edge_array[ ib ],
- et;
- et = *e0;
- *e0 = *e1;
- *e1 = et;
-}
-
-VG_STATIC void edge_bh_closest( void *user, u32 index, v3f point, v3f closest )
-{
- struct grind_edge *edge_array = user,
- *edge = &edge_array[ index ];
-
- closest_point_segment( edge->p0, edge->p1, point, closest );
-}
-
-VG_STATIC bh_system bh_system_edges =
-{
- .expand_bound = edge_bh_expand_bound,
- .item_centroid = edge_bh_centroid,
- .item_closest = edge_bh_closest,
- .item_swap = edge_bh_swap,
- .item_debug = NULL,
- .cast_ray = NULL
-};
-
-VG_STATIC void world_generate_edges(void)
-{
- vg_info( "Generating edge array\n" );
- world.grind_edges = vg_linear_alloc( world.dynamic_vgl,
- 5000*sizeof(struct grind_edge ) );
- world.grind_edge_count = 0;
-
- u32 fs_count = 0;
- for( u32 i=0; i<world.scene_geo->vertex_count; i++ )
- if( world.scene_geo->arrvertices[i].weights[0] )
- fs_count ++;
-
- vg_info( "Grind verts: %u\n", fs_count );
-
- for( u32 i=0; i<world.scene_geo->indice_count/3; i++ )
- {
- u32 *ptri = &world.scene_geo->arrindices[ i*3 ];
-
- for( int j=0; j<3; j++ )
- {
- u32 i0 = ptri[j],
- i1 = ptri[(j+1)%3];
-
- mdl_vert *v0 = &world.scene_geo->arrvertices[ i0 ],
- *v1 = &world.scene_geo->arrvertices[ i1 ];
-
- if( v0->weights[0] )
- {
- if( world.grind_edge_count == 5000 )
- vg_fatal_exit_loop( "Edge capacity exceeded" );
-
- struct grind_edge *ge =
- &world.grind_edges[ world.grind_edge_count ++ ];
-
- v3_copy( v0->co, ge->p0 );
- v3_copy( v1->co, ge->p1 );
- }
- }
- }
-
- vg_info( "Grind edge count: %u\n", world.grind_edge_count );
-
- world.grind_edges = vg_linear_resize( world.dynamic_vgl, world.grind_edges,
- world.grind_edge_count*sizeof(struct grind_edge) );
-
- world.grind_bh = bh_create( world.dynamic_vgl, &bh_system_edges,
- world.grind_edges, world.grind_edge_count,
- 2 );
-}
-
VG_STATIC void world_generate(void)
{
/*
vg_linear_del( world.dynamic_vgl, world.scene_no_collide );
world.scene_no_collide = NULL;
-
- world_generate_edges();
}
VG_STATIC int reset_player( int argc, char const *argv[] );
world.scene_geo = NULL;
world.scene_no_collide = NULL;
world.scene_lines = NULL;
- world.grind_edges = NULL;
- world.grind_edge_count = 0;
- world.grind_bh = NULL;
world.geo_bh = NULL;
world.trigger_bh = NULL;
world.audio_bh = NULL;