#include "vg/vg_audio.h"
#include "vg/vg_shader.h"
-#include "vg/vg_lines.h"
#include "vg/vg_tex.h"
#include "vg/vg_input.h"
#include "vg/vg_ui.h"
#include "vg/vg_console.h"
+#include "vg/vg_lines.h"
#include "vg/vg_debug.h"
#ifdef VG_STEAM
{
const char *name;
int bind;
+ int controller;
int value; int prev;
}
{
vg_gamepad_ready = 0;
}
-
/* Update button inputs */
for( int i = 0; i < vg_list_size( vg_button_binds ); i ++ )
{
struct button_binding *binding = vg_button_binds + i;
binding->prev = binding->value;
-
- if( vg_input_mode == k_EInputMode_pc )
- {
- binding->value = get_button_cross_device( binding->bind );
- }
- else
- {
- binding->value = vg_gamepad.buttons[ binding->bind ];
- }
+
+ if( binding->controller )
+ binding->value = vg_gamepad.buttons[ binding->controller ];
+ else
+ binding->value = get_button_cross_device( binding->bind );
}
/* Update axis inputs */
/* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */
+static int debug_lines_enable = 1;
+
#ifdef VG_3D
typedef v3f line_co;
#else
static void vg_lines_init(void)
{
+ vg_convar_push( (struct vg_convar){
+ .name = "debug_lines",
+ .data = &debug_lines_enable,
+ .data_type = k_convar_dtype_i32,
+ .opt_i32 = { .min=0, .max=1, .clamp=1 },
+ .persistent = 1
+ });
+
SHADER_INIT( vg_line_shader );
glGenVertexArrays( 1, &vg_lines.vao );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glBlendEquation( GL_FUNC_ADD );
- glDrawArrays( GL_LINES, 0, vg_lines.draw_idx );
+
+ if( debug_lines_enable )
+ glDrawArrays( GL_LINES, 0, vg_lines.draw_idx );
glDisable( GL_BLEND );
vg_lines.draw_idx = 0;
vg_line( (v2f){max[0],min[1]}, min, colour );
#endif
}
+
+static void vg_line_boxf( boxf box, u32 colour )
+{
+ v3f p000, p001, p010, p011, p100, p101, p110, p111;
+
+ p000[0]=box[0][0];p000[1]=box[0][1];p000[2]=box[0][2];
+ p001[0]=box[0][0];p001[1]=box[0][1];p001[2]=box[1][2];
+ p010[0]=box[0][0];p010[1]=box[1][1];p010[2]=box[0][2];
+ p011[0]=box[0][0];p011[1]=box[1][1];p011[2]=box[1][2];
+
+ p100[0]=box[1][0];p100[1]=box[0][1];p100[2]=box[0][2];
+ p101[0]=box[1][0];p101[1]=box[0][1];p101[2]=box[1][2];
+ p110[0]=box[1][0];p110[1]=box[1][1];p110[2]=box[0][2];
+ p111[0]=box[1][0];p111[1]=box[1][1];p111[2]=box[1][2];
+
+ vg_line( p000, p001, colour );
+ vg_line( p001, p011, colour );
+ vg_line( p011, p010, colour );
+ vg_line( p010, p000, colour );
+
+ vg_line( p100, p101, colour );
+ vg_line( p101, p111, colour );
+ vg_line( p111, p110, colour );
+ vg_line( p110, p100, colour );
+
+ vg_line( p100, p000, colour );
+ vg_line( p101, p001, colour );
+ vg_line( p110, p010, colour );
+ vg_line( p111, p011, colour );
+}
+
+static void vg_line_pt3( v3f pt, float size, u32 colour )
+{
+ boxf box =
+ {
+ { pt[0]-size, pt[1]-size, pt[2]-size },
+ { pt[0]+size, pt[1]+size, pt[2]+size }
+ };
+
+ vg_line_boxf( box, colour );
+}
static inline float v2_cross( v2f a, v2f b )
{
- return a[0] * b[1] - a[1] * b[0];
+ return a[0]*b[1] - a[1]*b[0];
}
static inline void v2_add( v2f a, v2f b, v2f d )
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
}
-static inline void v3_cross( v3f a, v3f b, v3f d )
+static inline void v3_cross( v3f a, v3f b, v3f dest )
{
- d[0] = a[1] * b[2] - a[2] * b[1];
- d[1] = a[2] * b[0] - a[0] * b[2];
- d[2] = a[0] * b[1] - a[1] * b[0];
+ v3f d;
+ d[0] = a[1]*b[2] - a[2]*b[1];
+ d[1] = a[2]*b[0] - a[0]*b[2];
+ d[2] = a[0]*b[1] - a[1]*b[0];
+ v3_copy( d, dest );
}
static inline float v3_length2( v3f a )
v3_maxv( box[1], v, box[1] );
}
+static inline void box_addpt( boxf a, v3f pt )
+{
+ v3_minv( a[0], pt, a[0] );
+ v3_maxv( a[1], pt, a[1] );
+}
+
static inline void box_concat( boxf a, boxf b )
{
v3_minv( a[0], b[0], a[0] );
v3_copy( a[1], b[1] );
}
+static inline void box_init_inf( boxf box )
+{
+ v3_fill( box[0], INFINITY );
+ v3_fill( box[1], -INFINITY );
+}
+
static inline void m4x3_transform_aabb( m4x3f m, boxf box )
{
v3f a; v3f b;
v3_sub( target, pos, dir );
v3_normalize( dir );
- v3_negate( dir, m[2] );
+ v3_copy( dir, m[2] );
v3_cross( up, m[2], m[0] );
v3_normalize( m[0] );
d[2][1] = yz - wx;
d[0][2] = xz - wy;
}
+
+static void m3x3_q( m3x3f m, v4f q )
+{
+ float diag, r, rinv;
+
+ diag = m[0][0] + m[1][1] + m[2][2];
+ if( diag >= 0.0f )
+ {
+ r = sqrtf( 1.0f + diag );
+ rinv = 0.5f / r;
+ q[0] = rinv * (m[1][2] - m[2][1]);
+ q[1] = rinv * (m[2][0] - m[0][2]);
+ q[2] = rinv * (m[0][1] - m[1][0]);
+ q[3] = r * 0.5f;
+ }
+ else if( m[0][0] >= m[1][1] && m[0][0] >= m[2][2] )
+ {
+ r = sqrtf( 1.0f - m[1][1] - m[2][2] + m[0][0] );
+ rinv = 0.5f / r;
+ q[0] = r * 0.5f;
+ q[1] = rinv * (m[0][1] + m[1][0]);
+ q[2] = rinv * (m[0][2] + m[2][0]);
+ q[3] = rinv * (m[1][2] - m[2][1]);
+ }
+ else if( m[1][1] >= m[2][2] )
+ {
+ r = sqrtf( 1.0f - m[0][0] - m[2][2] + m[1][1] );
+ rinv = 0.5f / r;
+ q[0] = rinv * (m[0][1] + m[1][0]);
+ q[1] = r * 0.5f;
+ q[2] = rinv * (m[1][2] + m[2][1]);
+ q[3] = rinv * (m[2][0] - m[0][2]);
+ }
+ else
+ {
+ r = sqrtf( 1.0f - m[0][0] - m[1][1] + m[2][2] );
+ rinv = 0.5f / r;
+ q[0] = rinv * (m[0][2] + m[2][0]);
+ q[1] = rinv * (m[1][2] + m[2][1]);
+ q[2] = r * 0.5f;
+ q[3] = rinv * (m[0][1] - m[1][0]);
+ }
+}
typedef float v4f[4];
typedef v2f m2x2f[2];
typedef v3f m3x3f[3];
-typedef v3f m4x3f[4]; /* TODO why this is 4x4 too? */
+typedef v3f m4x3f[4];
typedef v4f m4x4f[4];
typedef v3f boxf[2];