diff --git a/client/src/hex.c b/client/src/hex.c index 86df12f..55069dc 100644 --- a/client/src/hex.c +++ b/client/src/hex.c @@ -895,7 +895,14 @@ bool ray_hex_intersect( float intersect_distance = glm_vec3_dot(v0v2, q) / det; if(intersect_distance < *distance) { *distance = intersect_distance; - *vertex = (u > v) ? ((triangle+1) % 6)+1 : triangle+1; + float w = 1 - u - v; + if(u >= v && u >= w) { + *vertex = ((triangle + 1) % 6) + 1; + } else if(v >= u && v >= w) { + *vertex = triangle + 1; + } else { + *vertex = 0; + } } } diff --git a/client/src/main.c b/client/src/main.c index ef917e5..9837402 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -16,14 +16,23 @@ #include #include -typedef struct EditorContextStruct { +typedef struct EditorDataStruct { uint32_t selected_region; uint32_t last_selected_region; uint32_t last_clicked_region; uint32_t last_clicked_hex; uint32_t last_clicked_vertex; -} EditorContext; +} EditorData; + +#define COLOR_PICK_CONTAINER_ID 0x03 +typedef struct ColorUIDataStruct { + double current_hsv[3]; + vec4 current; + vec4 saved[12]; + char string[10]; + int string_len; +} ColorUIData; typedef struct ClientContextStruct { GLFWwindow* window; @@ -48,7 +57,8 @@ typedef struct ClientContextStruct { float zoom_speed; float move_speed; - EditorContext editor; + EditorData editor; + ColorUIData color; } ClientContext; void* network_thread(void* data) { @@ -58,6 +68,11 @@ void* network_thread(void* data) { return NULL; } +uint32_t hex_color(vec4 color) { + // TODO: implement vec4 -> uint32 color conversion + return 0x0000000; +} + uint32_t add_hex_region(ClientContext* context) { HexRegion* region; @@ -92,15 +107,6 @@ uint32_t add_hex_region(ClientContext* context) { return i; } -#define COLOR_PICK_CONTAINER_ID 0x03 -typedef struct ColorUIDataStruct { - double current_hsv[3]; - vec4 current; - vec4 saved[12]; - char string[10]; - int string_len; -} ColorUIData; - void update_hex_string(UIContext* ui, RenderContext* gpu, ColorUIData* data) { snprintf(data->string, 10, "#%02X%02X%02X%02X", (uint)rintf(data->current[0]*255), @@ -607,7 +613,7 @@ VkResult color_ui(ClientContext* context) { .num_drawables = sizeof(drawables)/sizeof(GPUDrawable), }; - ColorUIData* data = malloc(sizeof(ColorUIData)); + ColorUIData* data = &context->color; data->string_len = 8; data->string[0] = '#'; data->string[1] = '0'; @@ -1382,6 +1388,26 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod } } break; + + case GLFW_KEY_E: + if(action == GLFW_PRESS) { + HexRegion* region = context->hex->regions[context->hex->data.clicked_region]; + if(region != NULL) { + region->data.hexes[context->hex->data.clicked_hex].color[context->hex->data.clicked_vertex] = hex_color(context->color.current); + add_transfer( + ®ion->data.hexes[context->hex->data.clicked_hex].color[context->hex->data.clicked_vertex], + region->region, + offsetof(GPUHexRegion, hexes) + + sizeof(GPUHex)*context->hex->data.clicked_hex + + offsetof(GPUHex, color) + + sizeof(uint32_t)*(context->hex->data.clicked_vertex), + sizeof(uint32_t), + context->render->current_frame, + context->render); + update_hex_info_ui(context); + } + } + break; } }