/apps/tools/twndel: thingies
This commit is contained in:
parent
73db3e57dc
commit
75890b1a71
@ -51,7 +51,8 @@ static uint16_t push_face(uint8_t object,
|
||||
.p = {p0, p1, p2, p3},
|
||||
.texture = texture,
|
||||
.tex_scale = tex_scale,
|
||||
.tex_x = tex_x, .tex_y = tex_y,
|
||||
.tex_x = tex_x,
|
||||
.tex_y = tex_y,
|
||||
};
|
||||
return o->faces_sz-1;
|
||||
}
|
||||
@ -107,6 +108,7 @@ static inline Vec3 point_to_vec3(uint8_t object, uint16_t point) {
|
||||
}
|
||||
|
||||
|
||||
/* TODO: something is wrong, figure out how to introduce rotation to this. */
|
||||
static inline Vec2 project_texture_coordinate(Vec2 origin, Vec3 plane, Vec3 point, float scale) {
|
||||
Vec3 right = vec3_norm(vec3_cross(plane, fabsf(0.0f - plane.y) < 1e-9f ? (Vec3){0,1,0} : (Vec3){1,0,0}));
|
||||
Vec3 up = vec3_norm(vec3_cross(right, plane));
|
||||
@ -187,12 +189,12 @@ static uint8_t new_cube(Point pos, Point size) {
|
||||
uint16_t p7 = new_point(pos.x + size.x / 2, pos.y - size.y / 2, pos.z + size.z / 2);
|
||||
|
||||
uint8_t tex = push_texture(object, "/data/placeholder.png");
|
||||
push_face(object, p2, p3, p0, p1, tex, 128, 0, 0);
|
||||
push_face(object, p5, p4, p7, p6, tex, 128, 0, 0);
|
||||
push_face(object, p1, p0, p4, p5, tex, 128, 0, 0);
|
||||
push_face(object, p6, p7, p3, p2, tex, 128, 0, 0);
|
||||
push_face(object, p2, p1, p5, p6, tex, 128, 0, 0);
|
||||
push_face(object, p0, p3, p7, p4, tex, 128, 0, 0);
|
||||
push_face(object, p2, p3, p0, p1, tex, 128, pos.x - size.x / 2, pos.y - size.y / 2);
|
||||
push_face(object, p5, p4, p7, p6, tex, 128, pos.x - size.x / 2, pos.y - size.y / 2);
|
||||
push_face(object, p1, p0, p4, p5, tex, 128, pos.x - size.x / 2, pos.y - size.y / 2);
|
||||
push_face(object, p6, p7, p3, p2, tex, 128, pos.x - size.x / 2, pos.y - size.y / 2);
|
||||
push_face(object, p2, p1, p5, p6, tex, 128, pos.x - size.x / 2, pos.y - size.y / 2);
|
||||
push_face(object, p0, p3, p7, p4, tex, 128, pos.x - size.x / 2, pos.y - size.y / 2);
|
||||
|
||||
return object;
|
||||
}
|
||||
@ -318,7 +320,7 @@ static bool find_closest_point(uint8_t* object_result, uint16_t *point_result) {
|
||||
float ray_dist = vec3_length(b);
|
||||
if (ray_dist > ((float)SELECTION_SPHERE_RADIUS / POINTS_PER_METER))
|
||||
continue;
|
||||
float dist = vec3_length(vec3_add(p, b));
|
||||
float dist = vec3_length(vec3_sub(pos_and_ray.position, vec3_add(p, b)));
|
||||
if (dist < closest_distance) {
|
||||
closest_distance = dist;
|
||||
closest_obj = obj;
|
||||
@ -603,6 +605,9 @@ static void try_subdividing_from_moving(uint8_t object, uint16_t point) {
|
||||
|
||||
|
||||
static void process_undo(void) {
|
||||
if (state.op_active)
|
||||
state.op_active = false;
|
||||
|
||||
/* TODO: checks and defined limit */
|
||||
Operation *op = &state.op_stack[state.op_stack_ptr % UNDO_STACK_SIZE];
|
||||
state.op_stack_ptr--;
|
||||
@ -638,7 +643,7 @@ static void process_operations(void) {
|
||||
|
||||
if (!state.op_active) {
|
||||
/* point dragging */
|
||||
if (!state.solid_display_mode) {
|
||||
if (!state.current_texture) {
|
||||
uint16_t point_select; uint8_t obj_select;
|
||||
if (find_closest_point(&obj_select, &point_select)) {
|
||||
draw_billboard("/data/point.png",
|
||||
@ -780,7 +785,7 @@ static void draw_hovered_face_border(void) {
|
||||
}
|
||||
|
||||
|
||||
static void display_textures(void) {
|
||||
static void display_texture_selection(void) {
|
||||
String list = file_read("/data/assets/", ":images");
|
||||
if (!list.data)
|
||||
return;
|
||||
@ -800,6 +805,9 @@ static void display_textures(void) {
|
||||
0, false, false, true);
|
||||
count++;
|
||||
|
||||
if (state.current_texture && SDL_strcmp(part, state.current_texture) == 0)
|
||||
draw_box(box, 1, (Color){255,255,255,255});
|
||||
|
||||
if (rect_intersects(box, (Rect){ctx.mouse_position.x, ctx.mouse_position.y, 1, 1}))
|
||||
selected = SDL_strdup(part);
|
||||
|
||||
@ -816,6 +824,81 @@ static void display_textures(void) {
|
||||
}
|
||||
|
||||
|
||||
static void process_camera_inputs(void) {
|
||||
if (input_action_just_pressed("toggle_display_mode")) {
|
||||
audio_play("/data/click.wav", NULL, false, 0.7f, 0.0f);
|
||||
state.solid_display_mode = !state.solid_display_mode;
|
||||
if (state.current_texture) {
|
||||
SDL_free(state.current_texture);
|
||||
state.current_texture = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (input_action_just_pressed("toggle_projection")) {
|
||||
audio_play("/data/pop.wav", NULL, false, 0.8f, 0.0f);
|
||||
state.camera_is_orthographic = !state.camera_is_orthographic;
|
||||
}
|
||||
|
||||
if (input_action_just_pressed("toggle_x_axis")) {
|
||||
state.axis_mask[0] = 0; state.axis_mask[1] = 1; state.axis_mask[2] = 1;
|
||||
}
|
||||
|
||||
if (input_action_just_pressed("toggle_y_axis")) {
|
||||
state.axis_mask[0] = 1; state.axis_mask[1] = 0; state.axis_mask[2] = 1;
|
||||
}
|
||||
|
||||
if (input_action_just_pressed("toggle_z_axis")) {
|
||||
state.axis_mask[0] = 1; state.axis_mask[1] = 1; state.axis_mask[2] = 0;
|
||||
}
|
||||
|
||||
/* TODO: determine bounding box for this? */
|
||||
/* TODO: no idea whether it's all correct in terms of directions. */
|
||||
if (input_action_just_pressed("camera_front")) {
|
||||
audio_play("/data/pop.wav", NULL, false, 0.8f, 0.0f);
|
||||
state.camera_is_orthographic = true;
|
||||
state.camera_direction = (Vec3){0,0,-1};
|
||||
state.camera_position = vec3_add(state.active_center, (Vec3){0,0,2});
|
||||
}
|
||||
|
||||
if (input_action_just_pressed("camera_back")) {
|
||||
audio_play("/data/pop.wav", NULL, false, 0.8f, 0.0f);
|
||||
state.camera_is_orthographic = true;
|
||||
state.camera_direction = (Vec3){0,0,1};
|
||||
state.camera_position = vec3_add(state.active_center, (Vec3){0,0,-2});
|
||||
}
|
||||
|
||||
if (input_action_just_pressed("camera_left")) {
|
||||
audio_play("/data/pop.wav", NULL, false, 0.8f, 0.0f);
|
||||
state.camera_is_orthographic = true;
|
||||
state.camera_direction = (Vec3){1,0,0};
|
||||
state.camera_position = vec3_add(state.active_center, (Vec3){-2,0,0});
|
||||
}
|
||||
|
||||
if (input_action_just_pressed("camera_right")) {
|
||||
audio_play("/data/pop.wav", NULL, false, 0.8f, 0.0f);
|
||||
state.camera_is_orthographic = true;
|
||||
state.camera_direction = (Vec3){-1,0,0};
|
||||
state.camera_position = vec3_add(state.active_center, (Vec3){2,0,0});
|
||||
}
|
||||
|
||||
/* TODO: broken */
|
||||
if (input_action_just_pressed("camera_above")) {
|
||||
audio_play("/data/pop.wav", NULL, false, 0.8f, 0.0f);
|
||||
state.camera_is_orthographic = true;
|
||||
state.camera_direction = (Vec3){0,-1,0};
|
||||
state.camera_position = vec3_add(state.active_center, (Vec3){0,2,0});
|
||||
}
|
||||
|
||||
/* TODO: broken */
|
||||
if (input_action_just_pressed("camera_below")) {
|
||||
audio_play("/data/pop.wav", NULL, false, 0.8f, 0.0f);
|
||||
state.camera_is_orthographic = true;
|
||||
state.camera_direction = (Vec3){0,1,0};
|
||||
state.camera_position = vec3_add(state.active_center, (Vec3){0,-2,0});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void game_tick(void) {
|
||||
if (!init) {
|
||||
/* default state */
|
||||
@ -834,36 +917,22 @@ void game_tick(void) {
|
||||
input_action("toggle_display_mode", "Q");
|
||||
input_action("toggle_projection", "TAB");
|
||||
|
||||
input_action("toggle_x_axis", "Z");
|
||||
input_action("toggle_y_axis", "X");
|
||||
input_action("toggle_z_axis", "C");
|
||||
input_action("toggle_x_axis", "Z");
|
||||
input_action("toggle_y_axis", "X");
|
||||
input_action("toggle_z_axis", "C");
|
||||
|
||||
input_action("select", "LCLICK");
|
||||
input_action("rotate", "R");
|
||||
input_action("undo", "F");
|
||||
input_action("select", "LCLICK");
|
||||
input_action("rotate", "R");
|
||||
input_action("undo", "F");
|
||||
|
||||
if (input_action_just_pressed("toggle_display_mode")) {
|
||||
audio_play("/data/click.wav", NULL, false, 0.7f, 0.0f);
|
||||
state.solid_display_mode = !state.solid_display_mode;
|
||||
}
|
||||
|
||||
if (input_action_just_pressed("toggle_projection")) {
|
||||
audio_play("/data/pop.wav", NULL, false, 0.8f, 0.0f);
|
||||
state.camera_is_orthographic = !state.camera_is_orthographic;
|
||||
}
|
||||
|
||||
if (input_action_just_pressed("toggle_x_axis")) {
|
||||
state.axis_mask[0] = 0; state.axis_mask[1] = 1; state.axis_mask[2] = 1;
|
||||
}
|
||||
|
||||
if (input_action_just_pressed("toggle_y_axis")) {
|
||||
state.axis_mask[0] = 1; state.axis_mask[1] = 0; state.axis_mask[2] = 1;
|
||||
}
|
||||
|
||||
if (input_action_just_pressed("toggle_z_axis")) {
|
||||
state.axis_mask[0] = 1; state.axis_mask[1] = 1; state.axis_mask[2] = 0;
|
||||
}
|
||||
input_action("camera_front", "KP0");
|
||||
input_action("camera_back", "KP1");
|
||||
input_action("camera_left", "KP2");
|
||||
input_action("camera_right", "KP3");
|
||||
input_action("camera_above", "KP4");
|
||||
input_action("camera_below", "KP5");
|
||||
|
||||
process_camera_inputs();
|
||||
process_camera_movement();
|
||||
process_operations();
|
||||
|
||||
@ -875,7 +944,7 @@ void game_tick(void) {
|
||||
render_object(obj);
|
||||
|
||||
if (state.solid_display_mode)
|
||||
display_textures();
|
||||
display_texture_selection();
|
||||
|
||||
draw_text("twndel\x03", (Vec2){0, 2}, 32, (Color){255,255,255,200}, NULL);
|
||||
draw_camera(
|
||||
@ -896,6 +965,8 @@ void game_end(void) {
|
||||
SDL_free(o->textures[t]);
|
||||
SDL_free(o->name);
|
||||
}
|
||||
if (state.current_texture)
|
||||
if (state.current_texture) {
|
||||
SDL_free(state.current_texture);
|
||||
state.current_texture = NULL;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user