本文整理汇总了C++中Transform2D::scale_basis方法的典型用法代码示例。如果您正苦于以下问题:C++ Transform2D::scale_basis方法的具体用法?C++ Transform2D::scale_basis怎么用?C++ Transform2D::scale_basis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transform2D
的用法示例。
在下文中一共展示了Transform2D::scale_basis方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _region_draw
void TextureRegionEditor::_region_draw() {
Ref<Texture> base_tex = NULL;
if (node_sprite)
base_tex = node_sprite->get_texture();
else if (node_patch9)
base_tex = node_patch9->get_texture();
else if (obj_styleBox.is_valid())
base_tex = obj_styleBox->get_texture();
else if (atlas_tex.is_valid())
base_tex = atlas_tex->get_atlas();
if (base_tex.is_null())
return;
Transform2D mtx;
mtx.elements[2] = -draw_ofs;
mtx.scale_basis(Vector2(draw_zoom, draw_zoom));
VS::get_singleton()->canvas_item_add_set_transform(edit_draw->get_canvas_item(), mtx);
edit_draw->draw_texture(base_tex, Point2());
VS::get_singleton()->canvas_item_add_set_transform(edit_draw->get_canvas_item(), Transform2D());
if (snap_mode == SNAP_GRID) {
Size2 s = edit_draw->get_size();
int last_cell;
if (snap_step.x != 0) {
if (snap_separation.x == 0)
for (int i = 0; i < s.width; i++) {
int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(i, 0)).x - snap_offset.x) / snap_step.x));
if (i == 0)
last_cell = cell;
if (last_cell != cell)
edit_draw->draw_line(Point2(i, 0), Point2(i, s.height), Color(0.3, 0.7, 1, 0.3));
last_cell = cell;
}
else
for (int i = 0; i < s.width; i++) {
int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(i, 0)).x - snap_offset.x) / (snap_step.x + snap_separation.x)));
if (i == 0)
last_cell = cell;
if (last_cell != cell)
edit_draw->draw_rect(Rect2(i - snap_separation.x * draw_zoom, 0, snap_separation.x * draw_zoom, s.height), Color(0.3, 0.7, 1, 0.3));
last_cell = cell;
}
}
if (snap_step.y != 0) {
if (snap_separation.y == 0)
for (int i = 0; i < s.height; i++) {
int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(0, i)).y - snap_offset.y) / snap_step.y));
if (i == 0)
last_cell = cell;
if (last_cell != cell)
edit_draw->draw_line(Point2(0, i), Point2(s.width, i), Color(0.3, 0.7, 1, 0.3));
last_cell = cell;
}
else
for (int i = 0; i < s.height; i++) {
int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(0, i)).y - snap_offset.y) / (snap_step.y + snap_separation.y)));
if (i == 0)
last_cell = cell;
if (last_cell != cell)
edit_draw->draw_rect(Rect2(0, i - snap_separation.y * draw_zoom, s.width, snap_separation.y * draw_zoom), Color(0.3, 0.7, 1, 0.3));
last_cell = cell;
}
}
} else if (snap_mode == SNAP_AUTOSLICE) {
for (List<Rect2>::Element *E = autoslice_cache.front(); E; E = E->next()) {
Rect2 r = E->get();
Vector2 endpoints[4] = {
mtx.basis_xform(r.position),
mtx.basis_xform(r.position + Vector2(r.size.x, 0)),
mtx.basis_xform(r.position + r.size),
mtx.basis_xform(r.position + Vector2(0, r.size.y))
};
for (int i = 0; i < 4; i++) {
int next = (i + 1) % 4;
edit_draw->draw_line(endpoints[i] - draw_ofs, endpoints[next] - draw_ofs, Color(0.3, 0.7, 1, 1), 2);
}
}
}
Ref<Texture> select_handle = get_icon("EditorHandle", "EditorIcons");
Rect2 scroll_rect(Point2(), mtx.basis_xform(base_tex->get_size()));
scroll_rect.expand_to(mtx.basis_xform(edit_draw->get_size()));
Vector2 endpoints[4] = {
mtx.basis_xform(rect.position),
mtx.basis_xform(rect.position + Vector2(rect.size.x, 0)),
mtx.basis_xform(rect.position + rect.size),
mtx.basis_xform(rect.position + Vector2(0, rect.size.y))
};
Color color(0.9, 0.5, 0.5);
for (int i = 0; i < 4; i++) {
int prev = (i + 3) % 4;
int next = (i + 1) % 4;
Vector2 ofs = ((endpoints[i] - endpoints[prev]).normalized() + ((endpoints[i] - endpoints[next]).normalized())).normalized();
//.........这里部分代码省略.........
示例2: _region_input
void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
Transform2D mtx;
mtx.elements[2] = -draw_ofs;
mtx.scale_basis(Vector2(draw_zoom, draw_zoom));
Vector2 endpoints[8] = {
mtx.xform(rect.position) + Vector2(-4, -4),
mtx.xform(rect.position + Vector2(rect.size.x / 2, 0)) + Vector2(0, -4),
mtx.xform(rect.position + Vector2(rect.size.x, 0)) + Vector2(4, -4),
mtx.xform(rect.position + Vector2(rect.size.x, rect.size.y / 2)) + Vector2(4, 0),
mtx.xform(rect.position + rect.size) + Vector2(4, 4),
mtx.xform(rect.position + Vector2(rect.size.x / 2, rect.size.y)) + Vector2(0, 4),
mtx.xform(rect.position + Vector2(0, rect.size.y)) + Vector2(-4, 4),
mtx.xform(rect.position + Vector2(0, rect.size.y / 2)) + Vector2(-4, 0)
};
Ref<InputEventMouseButton> mb = p_input;
if (mb.is_valid()) {
if (mb->get_button_index() == BUTTON_LEFT) {
if (mb->is_pressed()) {
if (node_patch9 || obj_styleBox.is_valid()) {
edited_margin = -1;
float margins[4];
if (node_patch9) {
margins[0] = node_patch9->get_patch_margin(MARGIN_TOP);
margins[1] = node_patch9->get_patch_margin(MARGIN_BOTTOM);
margins[2] = node_patch9->get_patch_margin(MARGIN_LEFT);
margins[3] = node_patch9->get_patch_margin(MARGIN_RIGHT);
} else if (obj_styleBox.is_valid()) {
margins[0] = obj_styleBox->get_margin_size(MARGIN_TOP);
margins[1] = obj_styleBox->get_margin_size(MARGIN_BOTTOM);
margins[2] = obj_styleBox->get_margin_size(MARGIN_LEFT);
margins[3] = obj_styleBox->get_margin_size(MARGIN_RIGHT);
}
Vector2 pos[4] = {
mtx.basis_xform(rect.position + Vector2(0, margins[0])) - draw_ofs,
mtx.basis_xform(rect.position + rect.size - Vector2(0, margins[1])) - draw_ofs,
mtx.basis_xform(rect.position + Vector2(margins[2], 0)) - draw_ofs,
mtx.basis_xform(rect.position + rect.size - Vector2(margins[3], 0)) - draw_ofs
};
if (Math::abs(mb->get_position().y - pos[0].y) < 8) {
edited_margin = 0;
prev_margin = margins[0];
} else if (Math::abs(mb->get_position().y - pos[1].y) < 8) {
edited_margin = 1;
prev_margin = margins[1];
} else if (Math::abs(mb->get_position().x - pos[2].x) < 8) {
edited_margin = 2;
prev_margin = margins[2];
} else if (Math::abs(mb->get_position().x - pos[3].x) < 8) {
edited_margin = 3;
prev_margin = margins[3];
}
if (edited_margin >= 0) {
drag_from = Vector2(mb->get_position().x, mb->get_position().y);
drag = true;
}
}
if (edited_margin < 0 && snap_mode == SNAP_AUTOSLICE) {
Vector2 point = mtx.affine_inverse().xform(Vector2(mb->get_position().x, mb->get_position().y));
for (List<Rect2>::Element *E = autoslice_cache.front(); E; E = E->next()) {
if (E->get().has_point(point)) {
rect = E->get();
if (Input::get_singleton()->is_key_pressed(KEY_CONTROL) && !(Input::get_singleton()->is_key_pressed(KEY_SHIFT | KEY_ALT))) {
Rect2 r;
if (node_sprite)
r = node_sprite->get_region_rect();
else if (node_patch9)
r = node_patch9->get_region_rect();
else if (obj_styleBox.is_valid())
r = obj_styleBox->get_region_rect();
else if (atlas_tex.is_valid())
r = atlas_tex->get_region();
rect.expand_to(r.position);
rect.expand_to(r.position + r.size);
}
undo_redo->create_action(TTR("Set Region Rect"));
if (node_sprite) {
undo_redo->add_do_method(node_sprite, "set_region_rect", rect);
undo_redo->add_undo_method(node_sprite, "set_region_rect", node_sprite->get_region_rect());
} else if (node_patch9) {
undo_redo->add_do_method(node_patch9, "set_region_rect", rect);
undo_redo->add_undo_method(node_patch9, "set_region_rect", node_patch9->get_region_rect());
} else if (obj_styleBox.is_valid()) {
undo_redo->add_do_method(obj_styleBox.ptr(), "set_region_rect", rect);
undo_redo->add_undo_method(obj_styleBox.ptr(), "set_region_rect", obj_styleBox->get_region_rect());
} else if (atlas_tex.is_valid()) {
undo_redo->add_do_method(atlas_tex.ptr(), "set_region", rect);
undo_redo->add_undo_method(atlas_tex.ptr(), "set_region", atlas_tex->get_region());
}
undo_redo->add_do_method(edit_draw, "update");
undo_redo->add_undo_method(edit_draw, "update");
undo_redo->commit_action();
break;
}
}
} else if (edited_margin < 0) {
drag_from = mtx.affine_inverse().xform(Vector2(mb->get_position().x, mb->get_position().y));
//.........这里部分代码省略.........
示例3: rect
void Polygon2DEditor::_uv_draw() {
Ref<Texture> base_tex = node->get_texture();
if (base_tex.is_null())
return;
Transform2D mtx;
mtx.elements[2] = -uv_draw_ofs;
mtx.scale_basis(Vector2(uv_draw_zoom, uv_draw_zoom));
VS::get_singleton()->canvas_item_add_set_transform(uv_edit_draw->get_canvas_item(), mtx);
uv_edit_draw->draw_texture(base_tex, Point2());
VS::get_singleton()->canvas_item_add_set_transform(uv_edit_draw->get_canvas_item(), Transform2D());
if (snap_show_grid) {
Size2 s = uv_edit_draw->get_size();
int last_cell;
if (snap_step.x != 0) {
for (int i = 0; i < s.width; i++) {
int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(i, 0)).x - snap_offset.x) / snap_step.x));
if (i == 0)
last_cell = cell;
if (last_cell != cell)
uv_edit_draw->draw_line(Point2(i, 0), Point2(i, s.height), Color(0.3, 0.7, 1, 0.3));
last_cell = cell;
}
}
if (snap_step.y != 0) {
for (int i = 0; i < s.height; i++) {
int cell = Math::fast_ftoi(Math::floor((mtx.affine_inverse().xform(Vector2(0, i)).y - snap_offset.y) / snap_step.y));
if (i == 0)
last_cell = cell;
if (last_cell != cell)
uv_edit_draw->draw_line(Point2(0, i), Point2(s.width, i), Color(0.3, 0.7, 1, 0.3));
last_cell = cell;
}
}
}
PoolVector<Vector2> uvs = node->get_uv();
Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons");
Rect2 rect(Point2(), mtx.basis_xform(base_tex->get_size()));
rect.expand_to(mtx.basis_xform(uv_edit_draw->get_size()));
for (int i = 0; i < uvs.size(); i++) {
int next = (i + 1) % uvs.size();
uv_edit_draw->draw_line(mtx.xform(uvs[i]), mtx.xform(uvs[next]), Color(0.9, 0.5, 0.5), 2);
uv_edit_draw->draw_texture(handle, mtx.xform(uvs[i]) - handle->get_size() * 0.5);
rect.expand_to(mtx.basis_xform(uvs[i]));
}
rect = rect.grow(200);
updating_uv_scroll = true;
uv_hscroll->set_min(rect.position.x);
uv_hscroll->set_max(rect.position.x + rect.size.x);
uv_hscroll->set_page(uv_edit_draw->get_size().x);
uv_hscroll->set_value(uv_draw_ofs.x);
uv_hscroll->set_step(0.001);
uv_vscroll->set_min(rect.position.y);
uv_vscroll->set_max(rect.position.y + rect.size.y);
uv_vscroll->set_page(uv_edit_draw->get_size().y);
uv_vscroll->set_value(uv_draw_ofs.y);
uv_vscroll->set_step(0.001);
updating_uv_scroll = false;
}
示例4: screen_rect
//.........这里部分代码省略.........
camera_pos.y = new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM] * v_ofs;
}
}
} else if (anchor_mode == ANCHOR_MODE_FIXED_TOP_LEFT) {
camera_pos = new_camera_pos;
}
Point2 screen_offset = (anchor_mode == ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5 * zoom) : Point2());
Rect2 screen_rect(-screen_offset + camera_pos, screen_size * zoom);
if (offset != Vector2())
screen_rect.position += offset;
if (limit_smoothing_enabled) {
if (screen_rect.position.x < limit[MARGIN_LEFT])
camera_pos.x -= screen_rect.position.x - limit[MARGIN_LEFT];
if (screen_rect.position.x + screen_rect.size.x > limit[MARGIN_RIGHT])
camera_pos.x -= screen_rect.position.x + screen_rect.size.x - limit[MARGIN_RIGHT];
if (screen_rect.position.y + screen_rect.size.y > limit[MARGIN_BOTTOM])
camera_pos.y -= screen_rect.position.y + screen_rect.size.y - limit[MARGIN_BOTTOM];
if (screen_rect.position.y < limit[MARGIN_TOP])
camera_pos.y -= screen_rect.position.y - limit[MARGIN_TOP];
}
if (smoothing_enabled && !Engine::get_singleton()->is_editor_hint()) {
float c = smoothing * get_fixed_process_delta_time();
smoothed_camera_pos = ((camera_pos - smoothed_camera_pos) * c) + smoothed_camera_pos;
ret_camera_pos = smoothed_camera_pos;
//camera_pos=camera_pos*(1.0-smoothing)+new_camera_pos*smoothing;
} else {
ret_camera_pos = smoothed_camera_pos = camera_pos;
}
} else {
ret_camera_pos = smoothed_camera_pos = camera_pos = new_camera_pos;
first = false;
}
Point2 screen_offset = (anchor_mode == ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5 * zoom) : Point2());
float angle = get_global_transform().get_rotation();
if (rotating) {
screen_offset = screen_offset.rotated(angle);
}
Rect2 screen_rect(-screen_offset + ret_camera_pos, screen_size * zoom);
if (screen_rect.position.x < limit[MARGIN_LEFT])
screen_rect.position.x = limit[MARGIN_LEFT];
if (screen_rect.position.x + screen_rect.size.x > limit[MARGIN_RIGHT])
screen_rect.position.x = limit[MARGIN_RIGHT] - screen_rect.size.x;
if (screen_rect.position.y + screen_rect.size.y > limit[MARGIN_BOTTOM])
screen_rect.position.y = limit[MARGIN_BOTTOM] - screen_rect.size.y;
if (screen_rect.position.y < limit[MARGIN_TOP])
screen_rect.position.y = limit[MARGIN_TOP];
if (offset != Vector2()) {
screen_rect.position += offset;
if (screen_rect.position.x + screen_rect.size.x > limit[MARGIN_RIGHT])
screen_rect.position.x = limit[MARGIN_RIGHT] - screen_rect.size.x;
if (screen_rect.position.y + screen_rect.size.y > limit[MARGIN_BOTTOM])
screen_rect.position.y = limit[MARGIN_BOTTOM] - screen_rect.size.y;
if (screen_rect.position.x < limit[MARGIN_LEFT])
screen_rect.position.x = limit[MARGIN_LEFT];
if (screen_rect.position.y < limit[MARGIN_TOP])
screen_rect.position.y = limit[MARGIN_TOP];
}
camera_screen_center = screen_rect.position + screen_rect.size * 0.5;
Transform2D xform;
if (rotating) {
xform.set_rotation(angle);
}
xform.scale_basis(zoom);
xform.set_origin(screen_rect.position /*.floor()*/);
/*
if (0) {
xform = get_global_transform() * xform;
} else {
xform.elements[2]+=get_global_transform().get_origin();
}
*/
return (xform).affine_inverse();
}
示例5: if
void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
Transform2D mtx;
mtx.elements[2] = -uv_draw_ofs;
mtx.scale_basis(Vector2(uv_draw_zoom, uv_draw_zoom));
Ref<InputEventMouseButton> mb = p_input;
if (mb.is_valid()) {
if (mb->get_button_index() == BUTTON_LEFT) {
if (mb->is_pressed()) {
uv_drag_from = Vector2(mb->get_position().x, mb->get_position().y);
uv_drag = true;
uv_prev = node->get_uv();
uv_move_current = uv_mode;
if (uv_move_current == UV_MODE_EDIT_POINT) {
if (mb->get_shift() && mb->get_command())
uv_move_current = UV_MODE_SCALE;
else if (mb->get_shift())
uv_move_current = UV_MODE_MOVE;
else if (mb->get_command())
uv_move_current = UV_MODE_ROTATE;
}
if (uv_move_current == UV_MODE_EDIT_POINT) {
uv_drag_index = -1;
for (int i = 0; i < uv_prev.size(); i++) {
Vector2 tuv = mtx.xform(uv_prev[i]);
if (tuv.distance_to(Vector2(mb->get_position().x, mb->get_position().y)) < 8) {
uv_drag_from = tuv;
uv_drag_index = i;
}
}
if (uv_drag_index == -1) {
uv_drag = false;
}
}
} else if (uv_drag) {
undo_redo->create_action(TTR("Transform UV Map"));
undo_redo->add_do_method(node, "set_uv", node->get_uv());
undo_redo->add_undo_method(node, "set_uv", uv_prev);
undo_redo->add_do_method(uv_edit_draw, "update");
undo_redo->add_undo_method(uv_edit_draw, "update");
undo_redo->commit_action();
uv_drag = false;
}
} else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) {
if (uv_drag) {
uv_drag = false;
node->set_uv(uv_prev);
uv_edit_draw->update();
}
} else if (mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed()) {
uv_zoom->set_value(uv_zoom->get_value() / (1 - (0.1 * mb->get_factor())));
} else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && mb->is_pressed()) {
uv_zoom->set_value(uv_zoom->get_value() * (1 - (0.1 * mb->get_factor())));
}
}
Ref<InputEventMouseMotion> mm = p_input;
if (mm.is_valid()) {
if (mm->get_button_mask() & BUTTON_MASK_MIDDLE || Input::get_singleton()->is_key_pressed(KEY_SPACE)) {
Vector2 drag(mm->get_relative().x, mm->get_relative().y);
uv_hscroll->set_value(uv_hscroll->get_value() - drag.x);
uv_vscroll->set_value(uv_vscroll->get_value() - drag.y);
} else if (uv_drag) {
Vector2 uv_drag_to = mm->get_position();
Vector2 drag = mtx.affine_inverse().xform(uv_drag_to) - mtx.affine_inverse().xform(uv_drag_from);
switch (uv_move_current) {
case UV_MODE_EDIT_POINT: {
PoolVector<Vector2> uv_new = uv_prev;
uv_new.set(uv_drag_index, uv_new[uv_drag_index] + drag);
node->set_uv(uv_new);
} break;
case UV_MODE_MOVE: {
PoolVector<Vector2> uv_new = uv_prev;
//.........这里部分代码省略.........