X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world_gate.h;h=bd4510b8aad89dd301235cad21b176e95a916d6c;hb=0ca7f5ca2560908de1a03db112df67e52b476107;hp=b6942519c4fe93059a9f881284dcd51db9a799d3;hpb=34a8df54eb962f3ad2e036355041f5bc5cabe5a0;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world_gate.h b/world_gate.h index b694251..bd4510b 100644 --- a/world_gate.h +++ b/world_gate.h @@ -15,16 +15,18 @@ VG_STATIC void gate_transform_update( teleport_gate *gate ) { - m4x3f to_local; + 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], gate->recv_to_world ); - v3_copy( gate->co[1], gate->recv_to_world[3] ); - m4x3_mul( gate->recv_to_world, to_local, gate->transport ); + 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 ); + + m4x3_scalev( gate->to_world, (v3f){ gate->dims[0], gate->dims[1], 1.0f } ); } VG_STATIC void world_gates_init(void) @@ -48,7 +50,7 @@ VG_STATIC int render_gate( world_instance *world_inside, { 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 ); + q_mulv( gate->q[0], (v3f){0.0f,0.0f,-1.0f}, gatedir ); v3f v0; v3_sub( cam->pos, gate->co[0], v0 ); @@ -65,12 +67,10 @@ VG_STATIC int render_gate( world_instance *world_inside, { 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 ); + 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 ); @@ -91,7 +91,7 @@ VG_STATIC int render_gate( world_instance *world_inside, /* Add special clipping plane to projection */ v4f surface; - m3x3_mulv( gate->recv_to_world, (v3f){0.0f,0.0f,-1.0f}, 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 ); @@ -105,13 +105,9 @@ VG_STATIC int render_gate( world_instance *world_inside, vg_line_pt3( gate_camera.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_model_gate_use(); shader_model_gate_uPv( cam->mtx.pv ); - shader_model_gate_uMdl( gate_xform ); + shader_model_gate_uMdl( gate->to_world ); shader_model_gate_uCam( cam->pos ); shader_model_gate_uTime( vg.time*0.25f ); shader_model_gate_uInvRes( (v2f){ @@ -155,7 +151,7 @@ VG_STATIC int gate_intersect_plane( teleport_gate *gate, v3f pos, v3f last, v2f where ) { v4f surface; - m3x3_mulv( gate->to_world, (v3f){0.0f,0.0f,-1.0f}, surface ); + q_mulv( gate->q[0], (v3f){0.0f,0.0f,-1.0f}, surface ); surface[3] = v3_dot( surface, gate->co[0] ); v3f v0, c, delta, p0; @@ -181,12 +177,11 @@ VG_STATIC int gate_intersect_plane( teleport_gate *gate, v3f pos, v3f last, v3_muladds( last, v0, t, local ); v3_sub( gate->co[0], local, rel ); - v3f vup, vside; - m3x3_mulv( gate->to_world, (v3f){0.0f,1.0f,0.0f}, vup ); - m3x3_mulv( gate->to_world, (v3f){1.0f,0.0f,0.0f}, vside ); + where[0] = v3_dot( rel, gate->to_world[0] ); + where[1] = v3_dot( rel, gate->to_world[1] ); - where[0] = v3_dot( rel, vside ); - where[1] = v3_dot( rel, vup ); + where[0] /= v3_dot( gate->to_world[0], gate->to_world[0] ); + where[1] /= v3_dot( gate->to_world[1], gate->to_world[1] ); return 1; } @@ -201,7 +196,7 @@ VG_STATIC int gate_intersect( teleport_gate *gate, v3f pos, v3f last ) if( gate_intersect_plane( gate, pos, last, xy ) ) { - if( fabsf(xy[0]) <= gate->dims[0] && fabsf(xy[1]) <= gate->dims[1] ) + if( fabsf(xy[0]) <= 1.0f && fabsf(xy[1]) <= 1.0f ) { return 1; }