-#include "common.h"
-#include "model.h"
-#include "render.h"
-#include "shaders/gate.h"
-#include "shaders/gatelq.h"
-#include "world_water.h"
-
-typedef struct teleport_gate teleport_gate;
-
-static struct
-{
- struct framebuffer fb;
- glmesh mdl;
-
- int high_qual; /* If in high performance mode, we don't use RT's, and
- instead use stencil buffers.
- There is therefore no heat warp effect. */
-}
-grender =
-{
- .high_qual = 0,
- .fb = {
- .format = GL_RGB,
- .div = 1
- }
-};
-
-static void gate_transform_update( teleport_gate *gate )
-{
- m4x3f to_local;
-
- 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], gate->recv_to_world );
- v3_copy( gate->co[1], gate->recv_to_world[3] );
- m4x3_mul( gate->recv_to_world, to_local, gate->transport );
-}
-
-static void world_gates_init(void)
-{
- vg_info( "world_gates_init\n" );
- shader_gate_register();
- shader_gatelq_register();
-
- mdl_header *mgate = mdl_load( "models/rs_gate.mdl" );
-
- vg_acquire_thread_sync();
- {
- fb_init( &grender.fb );
- mdl_unpack_glmesh( mgate, &grender.mdl );
- }
- vg_release_thread_sync();
-}
-
-static void world_gates_free(void*_)
-{
- fb_free( &grender.fb );
-}
-
-static void gate_fb_resize(void)
-{
- fb_resize( &grender.fb );
-}
-
-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 );