#define VG__CYAN 0xffffff00
#define VG__NONE 0x00000000
-static struct vg_shader _shader_lines =
-{
+static struct vg_shader _shader_lines = {
.name = "[vg] lines",
.link = NULL,
- .vs =
- {
+ .vs = {
.orig_file = NULL,
.static_src =
" gl_Position = vert_pos;"
"}"
},
- .fs =
- {
+ .fs = {
.orig_file = NULL,
.static_src =
}
};
-
-struct
-{
+struct{
u32 draw,
allow_input;
- struct vg_lines_vert
- {
+ struct vg_lines_vert{
v3f co;
u32 colour;
}
{
vg_info( "vg_lines_init\n" );
- vg_var_push( (struct vg_var){
- .name = "vg_lines",
- .data = &vg_lines.draw,
- .data_type = k_var_dtype_i32,
- .opt_i32 = { .min=0, .max=1, .clamp=1 },
- .persistent = 1
- });
-
+ vg_console_reg_var( "vg_lines", &vg_lines.draw, k_var_dtype_i32,
+ VG_VAR_CHEAT );
vg_shader_register( &_shader_lines );
vg_acquire_thread_sync();
vg_lines.allow_input = 1;
}
-VG_STATIC void vg_lines_drawall( float* projection )
+VG_STATIC void vg_lines_drawall( void )
{
glUseProgram( _shader_lines.id );
- glUniformMatrix4fv
- ( glGetUniformLocation( _shader_lines.id, "uPv" ), 1, GL_FALSE, projection );
+ glUniformMatrix4fv( glGetUniformLocation( _shader_lines.id, "uPv" ),
+ 1, GL_FALSE, (float *)vg.pv );
glBindVertexArray( vg_lines.vao );
glBindBuffer( GL_ARRAY_BUFFER, vg_lines.vbo );
vg_line2( from, to, colour, colour );
}
+VG_STATIC void line_tangent_basis( v3f n, v3f tx, v3f ty )
+{
+ /* Compute tangent basis (box2d) */
+ if( fabsf( n[0] ) >= 0.57735027f ){
+ tx[0] = n[1];
+ tx[1] = -n[0];
+ tx[2] = 0.0f;
+ }
+ else{
+ tx[0] = 0.0f;
+ tx[1] = n[2];
+ tx[2] = -n[1];
+ }
+
+ v3_normalize( tx );
+ v3_cross( n, tx, ty );
+}
+
+VG_STATIC void vg_line_arrow( line_co co, line_co dir, float size, u32 colour )
+{
+ v3f p1, tx, ty, p2, p3;
+ v3_muladds( co, dir, size, p1 );
+ line_tangent_basis( dir, tx, ty );
+
+ v3_muladds( p1, dir, -size * 0.125f, p2 );
+ v3_muladds( p2, ty, size * 0.125f, p3 );
+ v3_muladds( p2, ty, -size * 0.125f, p2 );
+
+ vg_line( co, p1, colour );
+ vg_line( p1, p2, colour );
+ vg_line( p1, p3, colour );
+}
+
VG_STATIC void vg_line_boxf( boxf box, u32 colour )
{
v3f p000, p001, p010, p011, p100, p101, p110, p111;