rigidbody view
[vg.git] / vg_lines.h
index 5511875b9f058747c30afce32d7f40d13cb09049..8fff226106e7bc2a007611636226a339910ac294 100644 (file)
@@ -59,8 +59,8 @@ static struct vg_shader _shader_lines = {
 };
 
 struct{
-   u32 draw,
-       allow_input;
+   u32 enabled, 
+       render;
        
    struct vg_lines_vert{
       v3f co;
@@ -106,7 +106,6 @@ static void async_vg_lines_init( void *payload, u32 payload_size ){
    glEnableVertexAttribArray( 1 );
    
    VG_CHECK_GL_ERR();
-   vg_lines.allow_input = 1;
 }
 
 static void vg_lines_init(void){
@@ -116,7 +115,7 @@ static void vg_lines_init(void){
 
    vg_async_call( async_vg_lines_init, NULL, 0 );
 
-   vg_console_reg_var( "vg_lines", &vg_lines.draw, k_var_dtype_i32, 
+   vg_console_reg_var( "vg_lines", &vg_lines.render, k_var_dtype_i32, 
                        VG_VAR_CHEAT );
    vg_shader_register( &_shader_lines );
 }
@@ -131,14 +130,13 @@ static void vg_lines_drawall( void ){
        glBindBuffer( GL_ARRAY_BUFFER, vg_lines.vbo );
 
    u32 bufusage = vg_linear_get_cur(vg_lines.vertex_buffer);
-       
        glBufferSubData( GL_ARRAY_BUFFER, 0, bufusage, vg_lines.vertex_buffer );
 
        glEnable( GL_BLEND );
        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
        glBlendEquation( GL_FUNC_ADD );
 
-   if( vg_lines.draw )
+   if( vg_lines.render )
       glDrawArrays( GL_LINES, 0, bufusage / sizeof(struct vg_lines_vert) );
        
        glDisable( GL_BLEND );
@@ -146,8 +144,7 @@ static void vg_lines_drawall( void ){
 }
 
 static void vg_line2( line_co from, line_co to, u32 fc, u32 tc ){
-   if( !vg_lines.allow_input ) return;
-   if( !vg_lines.draw ) return;
+   if( !vg_lines.enabled ) return;
 
    u32 size = 2 * sizeof(struct vg_lines_vert);
        struct vg_lines_vert *v = vg_linear_alloc( vg_lines.vertex_buffer, size );
@@ -160,10 +157,14 @@ static void vg_line2( line_co from, line_co to, u32 fc, u32 tc ){
 }
 
 static void vg_line( line_co from, line_co to, u32 colour ){
+   if( !vg_lines.enabled ) return;
+
        vg_line2( from, to, colour, colour );
 }
 
 static void vg_line_arrow( line_co co, line_co dir, float size, u32 colour ){
+   if( !vg_lines.enabled ) return;
+
    v3f p1, tx, ty, p2, p3;
    v3_muladds( co, dir, size, p1 );
    v3_tangent_basis( dir, tx, ty );
@@ -178,6 +179,8 @@ static void vg_line_arrow( line_co co, line_co dir, float size, u32 colour ){
 }
 
 static void vg_line_box_verts( boxf box, v3f verts[8] ){
+   if( !vg_lines.enabled ) return;
+
    for( u32 i=0; i<8; i++ ){
       for( u32 j=0; j<3; j++ ){
          verts[i][j] = i&(0x1<<j)? box[1][j]: box[0][j];
@@ -187,12 +190,16 @@ static void vg_line_box_verts( boxf box, v3f verts[8] ){
 
 static void vg_line_mesh( v3f verts[], u32 indices[][2], u32 indice_count,
                              u32 colour ){
+   if( !vg_lines.enabled ) return;
+
    for( u32 i=0; i<indice_count; i++ ){
       vg_line( verts[indices[i][0]], verts[indices[i][1]], colour );
    }
 }
 
 static void vg_line_boxf( boxf box, u32 colour ){
+   if( !vg_lines.enabled ) return;
+
    v3f verts[8];
    vg_line_box_verts( box, verts );
    u32 indices[][2] = {{0,1},{1,3},{3,2},{2,0},
@@ -203,6 +210,8 @@ static void vg_line_boxf( boxf box, u32 colour ){
 }
 
 static void vg_line_boxf_transformed( m4x3f m, boxf box, u32 colour ){
+   if( !vg_lines.enabled ) return;
+
    v3f verts[8];
    vg_line_box_verts( box, verts );
 
@@ -218,6 +227,8 @@ static void vg_line_boxf_transformed( m4x3f m, boxf box, u32 colour ){
 }
 
 static void vg_line_cross(v3f pos,u32 colour, float scale){
+   if( !vg_lines.enabled ) return;
+
    v3f p0, p1;
    v3_add( (v3f){ scale,0.0f,0.0f}, pos, p0 );
    v3_add( (v3f){-scale,0.0f,0.0f}, pos, p1 );
@@ -231,6 +242,8 @@ static void vg_line_cross(v3f pos,u32 colour, float scale){
 }
 
 static void vg_line_point( v3f pt, float size, u32 colour ){
+   if( !vg_lines.enabled ) return;
+
    boxf box =
    {
       { pt[0]-size, pt[1]-size, pt[2]-size },
@@ -242,6 +255,8 @@ static void vg_line_point( v3f pt, float size, u32 colour ){
 
 
 static void vg_line_sphere( m4x3f m, float radius, u32 colour ){
+   if( !vg_lines.enabled ) return;
+
    v3f ly = { 0.0f, 0.0f, radius },
        lx = { 0.0f, radius, 0.0f },
        lz = { 0.0f, 0.0f, radius };
@@ -274,6 +289,8 @@ static void vg_line_sphere( m4x3f m, float radius, u32 colour ){
 }
 
 static void vg_line_capsule( m4x3f m, float radius, float h, u32 colour ){
+   if( !vg_lines.enabled ) return;
+   
    v3f ly = { 0.0f, 0.0f, radius },
        lx = { 0.0f, radius, 0.0f },
        lz = { 0.0f, 0.0f, radius };