-static int render_gate( teleport_gate *gate, v3f viewpos, m4x3f camera )
-{
- v3f viewdir, gatedir;
- m3x3_mulv( camera, (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( viewpos, gate->co[0], v0 );
- if( v3_dot(v0, gatedir) >= 0.0f )
- return 0;
-
- if( v3_dist( viewpos, 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 );
-
- m4x3f cam_new;
- m4x3_mul( gate->transport, camera, cam_new );
-
- vg_line_pt3( cam_new[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 } );
-
- m4x3f inverse;
- m4x3_invert_affine( cam_new, inverse );
-
- m4x4f view;
- m4x3_expand( inverse, view );
-
- v4f surface;
- m3x3_mulv( gate->recv_to_world, (v3f){0.0f,0.0f,-1.0f}, surface );
- surface[3] = v3_dot( surface, gate->co[1] );
-
- m4x4f projection;
- pipeline_projection( projection, 0.1f, 900.0f );
-
- m4x3_mulp( inverse, surface, surface );
- surface[3] = -fabsf(surface[3]);
- plane_clip_projection( projection, surface );
-
- m4x4_mul( projection, view, projection );
-
- if( grender.high_qual )
- {
- fb_use( &grender.fb );
- glClearColor( 0.11f, 0.35f, 0.37f, 1.0f );
- glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
- }
- else
- {
- shader_gatelq_use();
- shader_gatelq_uPv( vg_pv );
- shader_gatelq_uMdl( gate_xform );
- shader_gatelq_uCam( viewpos );
- shader_gatelq_uTime( vg_time*0.25f );
- shader_gatelq_uInvRes( (v2f){
- 1.0f / (float)vg_window_x,
- 1.0f / (float)vg_window_y });