-#include "world_water.h"
-
-VG_STATIC void gate_transform_update( ent_gate *gate )
-{
- m4x3f to_local, recv_to_world;
-
- q_m3x3( gate->q[0], gate->to_world );
- v3_copy( gate->co[0], gate->to_world[3] );
-
- m4x3_invert_affine( gate->to_world, to_local );
-
- q_m3x3( gate->q[1], recv_to_world );
- v3_copy( gate->co[1], recv_to_world[3] );
- m4x3_mul( recv_to_world, to_local, gate->transport );
-
- m3x3_scale( gate->to_world, (v3f){ gate->dimensions[0],
- gate->dimensions[1], 1.0f } );
-}
-
-VG_STATIC void world_gates_init(void)
-{
- vg_info( "world_gates_init\n" );
-
- shader_model_gate_register();
-
- vg_linear_clear( vg_mem.scratch );
-
- mdl_context mgate;
- mdl_open( &mgate, "models/rs_gate.mdl", vg_mem.scratch );
- mdl_load_metadata_block( &mgate, vg_mem.scratch );
- mdl_load_mesh_block( &mgate, vg_mem.scratch );
-
- mdl_mesh *surface = mdl_find_mesh( &mgate, "rs_gate" );
- mdl_submesh *sm = mdl_arritm(&mgate.submeshs,surface->submesh_start);
- world_global.sm_gate_surface = *sm;
-
- const char *names[] = { "rs_gate_marker", "rs_gate_marker.001",
- "rs_gate_marker.002", "rs_gate_marker.003" };
-
- for( int i=0; i<4; i++ ){
- mdl_mesh *marker = mdl_find_mesh( &mgate, names[i] );
- sm = mdl_arritm( &mgate.submeshs, marker->submesh_start );
- world_global.sm_gate_marker[i] = *sm;
- }
-
- mdl_close( &mgate );
-
- vg_acquire_thread_sync();
- {
- mdl_unpack_glmesh( &mgate, &world_global.mesh_gate );
- }
- vg_release_thread_sync();
-}
-
-VG_STATIC int render_gate( world_instance *world_inside,
- ent_gate *gate, camera *cam, int layer_depth )
-{
- v3f viewdir, gatedir;
- m3x3_mulv( cam->transform, (v3f){0.0f,0.0f,-1.0f}, viewdir );
- q_mulv( gate->q[0], (v3f){0.0f,0.0f,-1.0f}, gatedir );
-
- v3f v0;
- v3_sub( cam->pos, gate->co[0], v0 );
-
- float dist = v3_dot(v0, gatedir);
-
- /* Hard cutoff */
- if( dist > 3.0f )
- return 0;
-
- if( v3_dist( cam->pos, gate->co[0] ) > 100.0f )
- return 0;
-
- {
- v3f a,b,c,d;
-
- m4x3_mulv( gate->to_world, (v3f){-1.0f,-1.0f,0.0f}, a );
- m4x3_mulv( gate->to_world, (v3f){ 1.0f,-1.0f,0.0f}, b );
- m4x3_mulv( gate->to_world, (v3f){ 1.0f, 1.0f,0.0f}, c );
- m4x3_mulv( gate->to_world, (v3f){-1.0f, 1.0f,0.0f}, d );
-
- vg_line( a,b, 0xffffa000 );
- vg_line( b,c, 0xffffa000 );
- vg_line( c,d, 0xffffa000 );
- vg_line( d,a, 0xffffa000 );
-
- vg_line2( gate->co[0], gate->co[1], 0xff0000ff, 0x00000000 );
- }
-
- /* update gate camera */
- gate_camera.fov = cam->fov;
- gate_camera.nearz = 0.1f;
- gate_camera.farz = 2000.0f;
-
- m4x3_mul( gate->transport, cam->transform, gate_camera.transform );
- camera_update_view( &gate_camera );
- camera_update_projection( &gate_camera );
-
- /* Add special clipping plane to projection */
- v4f surface;
- q_mulv( gate->q[1], (v3f){0.0f,0.0f,-1.0f}, surface );
- surface[3] = v3_dot( surface, gate->co[1] );
-
- m4x3_mulp( gate_camera.transform_inverse, surface, surface );
- surface[3] = -fabsf(surface[3]);