X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world_gate.h;h=1bf8afef0c4584d294bbe044780fbbd4485759d3;hb=0a40a20806ec52fc13817fd78a43793de5e32ffa;hp=9d1287711782d7570fb0c26505647beb2b9c5978;hpb=1142fd5c27cf6d5bef073969b55e20b160646164;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world_gate.h b/world_gate.h index 9d12877..1bf8afe 100644 --- a/world_gate.h +++ b/world_gate.h @@ -152,7 +152,8 @@ VG_STATIC int render_gate( teleport_gate *gate, camera *cam ) return 1; } -VG_STATIC int gate_intersect( teleport_gate *gate, v3f pos, v3f last ) +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 ); @@ -185,16 +186,46 @@ VG_STATIC int gate_intersect( teleport_gate *gate, v3f pos, v3f last ) 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 ); - v2f xy = { v3_dot( rel, vside ), v3_dot( rel, vup ) }; + where[0] = v3_dot( rel, vside ); + where[1] = v3_dot( rel, vup ); + + return 1; + } + } + + return 0; +} + +VG_STATIC int gate_intersect( teleport_gate *gate, v3f pos, v3f last ) +{ + v2f xy; - if( fabsf(xy[0]) <= gate->dims[0] && fabsf(xy[1]) <= gate->dims[1] ) - { - return 1; - } + if( gate_intersect_plane( gate, pos, last, xy ) ) + { + if( fabsf(xy[0]) <= gate->dims[0] && fabsf(xy[1]) <= gate->dims[1] ) + { + return 1; } } return 0; } +/* + * Intersect all gates in the world + */ +VG_STATIC teleport_gate *world_intersect_gates( v3f pos, v3f last ) +{ + for( int i=0; igate; + + if( gate_intersect( gate, pos, last ) ) + return gate; + } + + return NULL; +} + #endif /* WORLD_GATE_H */