#include "allocator.h" #include "kitty.h" #include "matrix.h" #include "object.h" #include "types.h" #include struct Trig { struct Kitty *kitty; struct mat3x3 model; }; #define TRIG_VERTEX_COUNT 6 struct Vertex trig_vertices[TRIG_VERTEX_COUNT] = { (struct Vertex){(struct Vec2){.x = 0.0f, .y = 0.0f}, (struct Vec3){1.0f, 0.0f, 1.0f}}, (struct Vertex){(struct Vec2){.x = 1.0f, .y = 0.0f}, (struct Vec3){1.0f, 0.0f, 0.2f}}, (struct Vertex){(struct Vec2){.x = 1.0f, .y = 1.0f}, (struct Vec3){0.2f, 0.0f, 1.0f}}, (struct Vertex){(struct Vec2){.x = 0.0f, .y = 0.0f}, (struct Vec3){1.0f, 0.0f, 1.0f}}, (struct Vertex){(struct Vec2){.x = 1.0f, .y = 1.0f}, (struct Vec3){1.0f, 0.0f, 0.2f}}, (struct Vertex){(struct Vec2){.x = 0.0f, .y = 1.0f}, (struct Vec3){0.2f, 0.0f, 1.0f}}, }; struct TrigUBO { struct mat3x3 model; struct mat3x3 view; struct mat3x3 proj; }; struct Trig *trig_make_args(struct Scene *scene) { struct Trig *trig = mem_malloc(scene->mem, sizeof(struct Trig)); trig->kitty = kitty_make(); kitty_set_vertex_shader(trig->kitty, "./Shaders/vert.spv"); kitty_set_fragment_shader(trig->kitty, "./Shaders/frag.spv"); kitty_set_vertex_buffer(trig->kitty, trig_vertices, TRIG_VERTEX_COUNT, sizeof(struct Vertex)); kitty_add_vertex_buffer_format(trig->kitty, VK_FORMAT_R32G32_SFLOAT); kitty_add_vertex_buffer_format(trig->kitty, VK_FORMAT_R32G32B32_SFLOAT); kitty_attatch_ubo(trig->kitty, sizeof(struct TrigUBO)); kitty_attatch_image(trig->kitty, "./image.png"); kitty_finalise(scene->vk, trig->kitty); return trig; } struct Trig *make_trig(struct Scene *scene, char *_data, int _len) { return trig_make_args(scene); } void free_trig(struct Scene *scene, struct Trig *trig) { free_kitty(scene->vk, trig->kitty); mem_free(scene->mem, trig); } void trig_tick(struct Scene *scene, struct Trig *trig) { struct TrigUBO ubo = {0}; ubo.model = multiply3x3( translate3x3( (struct Vec2){sinf((double)(scene->msecs) * 0.000001f), 0.f}), multiply3x3(rotate3x3(PI / 2.f * (double)(scene->msecs) * 0.000001f), scale3x3((struct Vec2){0.5f, 0.5f}))); ubo.view = IDENT3x3; ubo.proj = scale3x3( (struct Vec2){1.f, (float)scene->vk->width / (float)scene->vk->heigh}); kitty_set_next_ubo(scene->vk, trig->kitty, 0, &ubo); }