#include "bvh.h"
#include "lighting.h"
#include "model.h"
+#include "traffic.h"
#include "shaders/terrain.h"
#include "shaders/sky.h"
teleport_gate gates[64];
u32 gate_count;
+
+ /* Paths */
+ traffic_node traffic[128];
+ u32 traffic_count;
+
+ traffic_driver van_man[6];
/* Physics */
rigidbody temp_rbs[128];
u32 rb_count;
- bh_tree bhcubes;
/* Rendering & geometry */
- scene geo, foliage, props;
- mdl_submesh sm_surface;
+ scene geo, foliage;
+
+ mdl_submesh sm_geo_std_oob, sm_geo_std, sm_geo_vb;
glmesh skybox, skydome;
mdl_submesh dome_upper, dome_lower;
+
+ glmesh cars;
+ mdl_submesh car_holden;
+
+ rigidbody mr_ball;
}
world;
static int ray_hit_is_ramp( ray_hit *hit )
{
- return hit->tri[0] < world.sm_surface.vertex_count;
+ return hit->tri[0] > world.sm_geo_std_oob.vertex_count;
}
static void world_register(void)
world.spawn_count = 0;
world.gate_count = 0;
world.rb_count = 0;
+ world.traffic_count = 0;
scene_init( &world.geo );
- scene_init( &world.props );
/*
* Compile meshes into the world scenes
mat_vertex_blend = i;
}
- if( mat_surf )
- add_all_if_material( &world.geo, mworld, mat_surf );
-
- scene_copy_slice( &world.geo, &world.sm_surface );
-
if( mat_surf_oob )
add_all_if_material( &world.geo, mworld, mat_surf_oob );
else
vg_warn( "No OOB surface\n" );
+ scene_copy_slice( &world.geo, &world.sm_geo_std_oob );
- scene_bh_create( &world.geo );
- scene_upload( &world.geo );
+ if( mat_surf )
+ add_all_if_material( &world.geo, mworld, mat_surf );
+ scene_copy_slice( &world.geo, &world.sm_geo_std );
if( mat_vertex_blend )
- add_all_if_material( &world.props, mworld, mat_vertex_blend );
+ add_all_if_material( &world.geo, mworld, mat_vertex_blend );
+ scene_copy_slice( &world.geo, &world.sm_geo_vb );
- /* TODO bvh? */
+ scene_upload( &world.geo );
+ scene_bh_create( &world.geo );
/*
* Process entities
else if( pnode->classtype == k_classtype_gate )
{
struct classtype_gate *entgate = mdl_get_entdata( mworld, pnode );
- mdl_node *pother = mdl_node_from_id( mworld, entgate->target );
-
- teleport_gate *gate = &world.gates[ world.gate_count ++ ];
-
- v3_copy( pnode->co, gate->co[0] );
- v3_copy( pother->co, gate->co[1] );
- v4_copy( pnode->q, gate->q[0] );
- v4_copy( pother->q, gate->q[1] );
- v2_copy( pnode->s, gate->dims );
- gate_transform_update( gate );
+ if( entgate->target )
+ {
+ mdl_node *pother = mdl_node_from_id( mworld, entgate->target );
+
+ teleport_gate *gate = &world.gates[ world.gate_count ++ ];
+
+ v3_copy( pnode->co, gate->co[0] );
+ v3_copy( pother->co, gate->co[1] );
+ v4_copy( pnode->q, gate->q[0] );
+ v4_copy( pother->q, gate->q[1] );
+ v2_copy( pnode->s, gate->dims );
+
+ gate_transform_update( gate );
+ }
}
else if( pnode->classtype == k_classtype_block )
{
water_set_surface( &surf, pnode->co[1] );
}
}
- }
+ else if( pnode->classtype == k_classtype_car_path )
+ {
+ struct classtype_car_path *p = mdl_get_entdata( mworld, pnode );
+ traffic_node *tn = &world.traffic[ world.traffic_count ];
+ tn->mn_next = NULL;
+ tn->mn_next1 = NULL;
+
+ if( p->target ) tn->mn_next = mdl_node_from_id( mworld, p->target );
+ if( p->target1 ) tn->mn_next1 = mdl_node_from_id( mworld, p->target1 );
- scene_upload( &world.props );
+ m4x3f transform;
+ mdl_node_transform( pnode, transform );
+ m3x3_mulv( transform, (v3f){1.0f,0.0f,0.0f}, tn->h );
+ v3_copy( transform[3], tn->co );
- bh_create( &world.bhcubes,
- &bh_system_rigidbodies, world.temp_rbs, world.rb_count );
+ pnode->sub_uid = world.traffic_count ++;
+ }
+ }
+
+ traffic_finalize( world.traffic, world.traffic_count );
+ for( int i=0; i<vg_list_size(world.van_man); i++ )
+ world.van_man[i].current =&world.traffic[vg_randint(world.traffic_count)];
world_apply_foliage();
free( mworld );
winfo->g_water_fog = 0.04f;
render_update_lighting_ub();
+
+
+ world.mr_ball.type = k_rb_shape_sphere;
+ world.mr_ball.inf.sphere.radius = 2.0f;
+ v3_copy( (v3f){ 0.0f, 110.0f, 0.0f }, world.mr_ball.co );
+
+ q_identity(world.mr_ball.q);
+ rb_init( &world.mr_ball );
}
static void world_init(void)
world.dome_lower = *mdl_node_submesh( msky, nlower, 0 );
world.dome_upper = *mdl_node_submesh( msky, nupper, 0 );
free(msky);
+
+ mdl_header *mcars = mdl_load( "models/rs_cars.mdl" );
+ mdl_unpack_glmesh( mcars, &world.cars );
+ mdl_node *nholden = mdl_node_from_name( mcars, "holden" );
+ world.car_holden = *mdl_node_submesh( mcars, nholden, 0 );
+ free(mcars);
+}
+
+static void world_update(void)
+{
+ rb_solver_reset();
+ rb_build_manifold_terrain_sphere( &world.mr_ball );
+
+ for( int i=0; i<5; i++ )
+ rb_solve_contacts( rb_contact_buffer, rb_contact_count );
+
+ rb_iter( &world.mr_ball );
+ rb_update_transform( &world.mr_ball );
+ rb_debug( &world.mr_ball, 0 );
+
+ for( int i=0; i<vg_list_size(world.van_man); i++ )
+ {
+ traffic_drive( &world.van_man[i] );
+ traffic_visualize_car( &world.van_man[i] );
+ }
}
/*
vg_tex2d_bind( &tex_terrain_colours, 1 );
}
-static void render_props( m4x4f projection, v3f camera )
+static void render_world_vb( m4x4f projection, v3f camera )
{
m4x3f identity_matrix;
m4x3_identity( identity_matrix );
shader_vblend_uMdl( identity_matrix );
shader_vblend_uCamera( camera );
- scene_bind( &world.props );
- scene_draw( &world.props );
+ scene_bind( &world.geo );
+ mdl_draw_submesh( &world.sm_geo_vb );
+
+ mesh_bind( &world.cars );
+
+ for( int i=0; i<vg_list_size(world.van_man); i++ )
+ {
+ shader_vblend_uMdl( world.van_man[i].transform );
+ mdl_draw_submesh( &world.car_holden );
+ }
}
static void render_terrain( m4x4f projection, v3f camera )
shader_terrain_uCamera( camera );
scene_bind( &world.geo );
- scene_draw( &world.geo );
+ mdl_draw_submesh( &world.sm_geo_std_oob );
+ mdl_draw_submesh( &world.sm_geo_std );
glDisable(GL_CULL_FACE);
scene_bind( &world.foliage );
static void render_world( m4x4f projection, m4x3f camera )
{
render_sky( camera );
- render_props( projection, camera[3] );
+ render_world_vb( projection, camera[3] );
render_terrain( projection, camera[3] );
}
scene_draw( &world.foliage );
glEnable(GL_CULL_FACE);
#endif
-
- scene_bind( &world.props );
- scene_draw( &world.props );
}
#endif /* WORLD_H */