-VG_STATIC void world_gates_init(void)
-{
- vg_info( "world_gates_init\n" );
-
- shader_gatelq_register();
-
- vg_linear_clear( vg_mem.scratch );
- mdl_context *mgate = mdl_load_full( vg_mem.scratch, "models/rs_gate.mdl" );
-
- vg_acquire_thread_sync();
- {
- mdl_unpack_glmesh( mgate, &world.mesh_gate_surface );
- }
- vg_release_thread_sync();
-}
-
-VG_STATIC int render_gate( teleport_gate *gate, camera *cam )
-{
- v3f viewdir, gatedir;
- m3x3_mulv( cam->transform, (v3f){0.0f,0.0f,-1.0f}, viewdir );
- m3x3_mulv( gate->to_world, (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;
-
- float sx = gate->dims[0],
- sy = gate->dims[1];
- m4x3_mulv( gate->to_world, (v3f){-sx,-sy,0.0f}, a );
- m4x3_mulv( gate->to_world, (v3f){ sx,-sy,0.0f}, b );
- m4x3_mulv( gate->to_world, (v3f){ sx, sy,0.0f}, c );
- m4x3_mulv( gate->to_world, (v3f){-sx, sy,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 */
- static camera gate_view;
- gate_view.fov = cam->fov;
- gate_view.nearz = 0.1f;
- gate_view.farz = 2000.0f;
-
- m4x3_mul( gate->transport, cam->transform, gate_view.transform );
- camera_update_view( &gate_view );
- camera_update_projection( &gate_view );
-
- /* Add special clipping plane to projection */
- v4f surface;
- m3x3_mulv( gate->recv_to_world, (v3f){0.0f,0.0f,-1.0f}, surface );
- surface[3] = v3_dot( surface, gate->co[1] );
-
- m4x3_mulp( gate_view.transform_inverse, surface, surface );
- surface[3] = -fabsf(surface[3]);
-
- if( dist < -0.5f )
- m4x4_clip_projection( gate_view.mtx.p, surface );
-
- /* Ready to draw with new camrea */
- camera_finalize( &gate_view );
-
- vg_line_pt3( gate_view.transform[3], 0.3f, 0xff00ff00 );
- {
- m4x3f gate_xform;
- m4x3_copy( gate->to_world, gate_xform );
- m4x3_scalev( gate_xform, (v3f){ gate->dims[0], gate->dims[1], 1.0f } );
-
- shader_gatelq_use();
- shader_gatelq_uPv( cam->mtx.pv );
- shader_gatelq_uMdl( gate_xform );
- shader_gatelq_uCam( cam->pos );
- shader_gatelq_uTime( vg.time*0.25f );
- shader_gatelq_uInvRes( (v2f){
- 1.0f / (float)vg.window_x,
- 1.0f / (float)vg.window_y });
-
- glEnable( GL_STENCIL_TEST );
- glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );
- glStencilFunc( GL_ALWAYS, 1, 0xFF );
- glStencilMask( 0xFF );
-
- mesh_bind( &world.mesh_gate_surface );
- mesh_draw( &world.mesh_gate_surface );