diff options
Diffstat (limited to 'src/gizmo/gizmo.c')
-rw-r--r-- | src/gizmo/gizmo.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/gizmo/gizmo.c b/src/gizmo/gizmo.c new file mode 100644 index 0000000..e3eaaf1 --- /dev/null +++ b/src/gizmo/gizmo.c @@ -0,0 +1,83 @@ +#include "gizmo.h" +#include "../core/device.h" +#include "../math/math.h" +#include "../shaders/common.h" + +struct { + bool show_grid, g_pressing; +} gizmo_state; + +void gizmo_init() { + gizmo_state.show_grid = FALSE; + gizmo_state.g_pressing = FALSE; +} + +void gizmo_onevent(wog_Event* e, float dt) { + if (e == NULL) return; + if (e->type == WOG_EKEYDOWN) { + if (e->key == VK_G && !gizmo_state.g_pressing) { + gizmo_state.show_grid = !gizmo_state.show_grid; + gizmo_state.g_pressing = TRUE; + } + } + else if (e->type == WOG_EKEYUP) { + if(e->key == VK_G) + gizmo_state.g_pressing = FALSE; + } +} + +void gizmo_onupdate(float dt) { +} + +void gizmo_ondraw() { + if (gizmo_state.show_grid) + gizmo_grid(); +} + +// varying +#define _color reg_v4_00 +static void vert(UniformCollection* uniforms, VertexShaderIn* in, Vec4* clipcoord) { + static Vec4 p; p.xyz = in->vertex->position; p.w = 1; + object2clip(&p, clipcoord); + color_tocolor32(in->vertex->color, _color); +} +static bool frag(UniformCollection* uniforms, FragmentShaderIn* in, Color32* color) { + *color = *_color; + return 1; +} +static Program line_shader = { + vert, frag, + VARYING_V4_00 +}; + +void gizmo_grid() { + Vert verts[] = { + {0, {-10000, 0, 0}, vec3zero, vec4zero, vec2zero, 0xffff0000}, + {1, {10000, 0, 0}, vec3zero, vec4zero, vec2zero, 0xffff0000}, + {2, {0, -10000, 0}, vec3zero, vec4zero, vec2zero, 0xff00ff00}, + {3, {0, 10000, 0}, vec3zero, vec4zero, vec2zero, 0xff00ff00}, + {4, {0, 0, -10000}, vec3zero, vec4zero, vec2zero, 0xff0000ff}, + {5, {0, 0, 10000}, vec3zero, vec4zero, vec2zero, 0xff0000ff}, + }; + int grid[] = { 0, 1, 2, 3, 4, 5 }; + ssr_bindvertices(&verts, 6, &grid, 3); + ssr_matrixmode(MATRIX_MODEL); + ssr_loadidentity(); + ssr_useprogram(&line_shader); + ssr_draw(PRIMITIVE_LINE); + ssr_unuseprogram(); +} + +void gizmo_line(Vec3 start, Vec3 end, Color32 color) { + Vert verts[] = { + {0, start, vec3zero, vec4zero, vec2zero, color32_tocolor(&color)}, + {1, end, vec3zero, vec4zero, vec2zero, color32_tocolor(&color)}, + }; + int line[] = { 0, 1}; + ssr_bindvertices(&verts, 2, &line, 1); + ssr_matrixmode(MATRIX_MODEL); + ssr_loadidentity(); + ssr_useprogram(&line_shader); + ssr_draw(PRIMITIVE_LINE); + ssr_unuseprogram(); +} |