Added ability to modify single vertex color

main
noah metz 2024-11-17 17:06:07 -07:00
parent d129f3432d
commit 60f518580a
2 changed files with 47 additions and 14 deletions

@ -895,7 +895,14 @@ bool ray_hex_intersect(
float intersect_distance = glm_vec3_dot(v0v2, q) / det; float intersect_distance = glm_vec3_dot(v0v2, q) / det;
if(intersect_distance < *distance) { if(intersect_distance < *distance) {
*distance = intersect_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;
}
} }
} }

@ -16,14 +16,23 @@
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
typedef struct EditorContextStruct { typedef struct EditorDataStruct {
uint32_t selected_region; uint32_t selected_region;
uint32_t last_selected_region; uint32_t last_selected_region;
uint32_t last_clicked_region; uint32_t last_clicked_region;
uint32_t last_clicked_hex; uint32_t last_clicked_hex;
uint32_t last_clicked_vertex; 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 { typedef struct ClientContextStruct {
GLFWwindow* window; GLFWwindow* window;
@ -48,7 +57,8 @@ typedef struct ClientContextStruct {
float zoom_speed; float zoom_speed;
float move_speed; float move_speed;
EditorContext editor; EditorData editor;
ColorUIData color;
} ClientContext; } ClientContext;
void* network_thread(void* data) { void* network_thread(void* data) {
@ -58,6 +68,11 @@ void* network_thread(void* data) {
return NULL; return NULL;
} }
uint32_t hex_color(vec4 color) {
// TODO: implement vec4 -> uint32 color conversion
return 0x0000000;
}
uint32_t add_hex_region(ClientContext* context) { uint32_t add_hex_region(ClientContext* context) {
HexRegion* region; HexRegion* region;
@ -92,15 +107,6 @@ uint32_t add_hex_region(ClientContext* context) {
return i; 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) { void update_hex_string(UIContext* ui, RenderContext* gpu, ColorUIData* data) {
snprintf(data->string, 10, "#%02X%02X%02X%02X", snprintf(data->string, 10, "#%02X%02X%02X%02X",
(uint)rintf(data->current[0]*255), (uint)rintf(data->current[0]*255),
@ -607,7 +613,7 @@ VkResult color_ui(ClientContext* context) {
.num_drawables = sizeof(drawables)/sizeof(GPUDrawable), .num_drawables = sizeof(drawables)/sizeof(GPUDrawable),
}; };
ColorUIData* data = malloc(sizeof(ColorUIData)); ColorUIData* data = &context->color;
data->string_len = 8; data->string_len = 8;
data->string[0] = '#'; data->string[0] = '#';
data->string[1] = '0'; data->string[1] = '0';
@ -1382,6 +1388,26 @@ void key_callback(GLFWwindow* window, int key, int scancode, int action, int mod
} }
} }
break; 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(
&region->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;
} }
} }