-
Автор темы
- #1
C++:
void custom_cursor(c_vector_2d position, float rotation_angle_degrees, c_color color) {
float arrow_base_width = 8;
float arrow_height = 9;
float arrow_middle_width = 7;
float outline_thickness = 2.0f;
ux::imgui::vec2 verts[4];
verts[0] = ux::imgui::vec2(position.x, position.y);
verts[1] = ux::imgui::vec2(position.x - arrow_base_width / 2, position.y + arrow_height);
verts[2] = ux::imgui::vec2(position.x, position.y + arrow_middle_width);
verts[3] = ux::imgui::vec2(position.x + arrow_base_width / 2, position.y + arrow_height);
ux::imgui::vec2 center = ux::imgui::vec2(position.x, position.y + arrow_height / 2);
float angle_radians = rotation_angle_degrees * (3.14159f / 180.0f);
auto rotate_vertex = [&](ux::imgui::vec2 point, ux::imgui::vec2 center, float angle) -> ux::imgui::vec2 {
float translated_x = point.x - center.x;
float translated_y = point.y - center.y;
float rotated_x = translated_x * cos(angle) - translated_y * sin(angle);
float rotated_y = translated_x * sin(angle) + translated_y * cos(angle);
return ux::imgui::vec2(rotated_x + center.x, rotated_y + center.y);
};
verts[0] = rotate_vertex(verts[0], center, angle_radians);
verts[1] = rotate_vertex(verts[1], center, angle_radians);
verts[2] = rotate_vertex(verts[2], center, angle_radians);
verts[3] = rotate_vertex(verts[3], center, angle_radians);
ux::imgui::draw_list->AddPolyline(verts, 4, color.convert(), true, outline_thickness);
ux::imgui::draw_list->AddConvexPolyFilled(verts, 4, color.convert());
}