Merge pull request #52878 from AnilBK/add-get-center

This commit is contained in:
Rémi Verschelde 2021-09-21 21:30:30 +02:00 committed by GitHub
commit ba57252bd8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 133 additions and 56 deletions

View file

@ -118,6 +118,10 @@ public:
return position + size; return position + size;
} }
_FORCE_INLINE_ Vector3 get_center() const {
return position + (size * 0.5);
}
operator String() const; operator String() const;
_FORCE_INLINE_ AABB() {} _FORCE_INLINE_ AABB() {}

View file

@ -101,7 +101,7 @@ public:
} }
float delta_max = MAX(rect.size.width, rect.size.height); float delta_max = MAX(rect.size.width, rect.size.height);
Vector2 center = rect.position + rect.size * 0.5; Vector2 center = rect.get_center();
points.push_back(Vector2(center.x - 20 * delta_max, center.y - delta_max)); points.push_back(Vector2(center.x - 20 * delta_max, center.y - delta_max));
points.push_back(Vector2(center.x, center.y + 20 * delta_max)); points.push_back(Vector2(center.x, center.y + 20 * delta_max));

View file

@ -46,6 +46,8 @@ struct Rect2 {
real_t get_area() const { return size.width * size.height; } real_t get_area() const { return size.width * size.height; }
_FORCE_INLINE_ Vector2 get_center() const { return position + (size * 0.5); }
inline bool intersects(const Rect2 &p_rect, const bool p_include_borders = false) const { inline bool intersects(const Rect2 &p_rect, const bool p_include_borders = false) const {
if (p_include_borders) { if (p_include_borders) {
if (position.x > (p_rect.position.x + p_rect.size.width)) { if (position.x > (p_rect.position.x + p_rect.size.width)) {
@ -259,7 +261,7 @@ struct Rect2 {
} }
_FORCE_INLINE_ bool intersects_filled_polygon(const Vector2 *p_points, int p_point_count) const { _FORCE_INLINE_ bool intersects_filled_polygon(const Vector2 *p_points, int p_point_count) const {
Vector2 center = position + size * 0.5; Vector2 center = get_center();
int side_plus = 0; int side_plus = 0;
int side_minus = 0; int side_minus = 0;
Vector2 end = position + size; Vector2 end = position + size;
@ -344,6 +346,8 @@ struct Rect2i {
int get_area() const { return size.width * size.height; } int get_area() const { return size.width * size.height; }
_FORCE_INLINE_ Vector2i get_center() const { return position + (size / 2); }
inline bool intersects(const Rect2i &p_rect) const { inline bool intersects(const Rect2i &p_rect) const {
if (position.x > (p_rect.position.x + p_rect.size.width)) { if (position.x > (p_rect.position.x + p_rect.size.width)) {
return false; return false;

View file

@ -76,7 +76,7 @@ int TriangleMesh::_create_bvh(BVH *p_bvh, BVH **p_bb, int p_from, int p_size, in
int index = r_max_alloc++; int index = r_max_alloc++;
BVH *_new = &p_bvh[index]; BVH *_new = &p_bvh[index];
_new->aabb = aabb; _new->aabb = aabb;
_new->center = aabb.position + aabb.size * 0.5; _new->center = aabb.get_center();
_new->face_index = -1; _new->face_index = -1;
_new->left = left; _new->left = left;
_new->right = right; _new->right = right;
@ -152,7 +152,7 @@ void TriangleMesh::create(const Vector<Vector3> &p_faces) {
bw[i].left = -1; bw[i].left = -1;
bw[i].right = -1; bw[i].right = -1;
bw[i].face_index = i; bw[i].face_index = i;
bw[i].center = bw[i].aabb.position + bw[i].aabb.size * 0.5; bw[i].center = bw[i].aabb.get_center();
} }
vertices.resize(db.size()); vertices.resize(db.size());

View file

@ -1513,6 +1513,7 @@ static void _register_variant_builtin_methods() {
/* Rect2 */ /* Rect2 */
bind_method(Rect2, get_center, sarray(), varray());
bind_method(Rect2, get_area, sarray(), varray()); bind_method(Rect2, get_area, sarray(), varray());
bind_method(Rect2, has_no_area, sarray(), varray()); bind_method(Rect2, has_no_area, sarray(), varray());
bind_method(Rect2, has_point, sarray("point"), varray()); bind_method(Rect2, has_point, sarray("point"), varray());
@ -1529,6 +1530,7 @@ static void _register_variant_builtin_methods() {
/* Rect2i */ /* Rect2i */
bind_method(Rect2i, get_center, sarray(), varray());
bind_method(Rect2i, get_area, sarray(), varray()); bind_method(Rect2i, get_area, sarray(), varray());
bind_method(Rect2i, has_no_area, sarray(), varray()); bind_method(Rect2i, has_no_area, sarray(), varray());
bind_method(Rect2i, has_point, sarray("point"), varray()); bind_method(Rect2i, has_point, sarray("point"), varray());
@ -1739,6 +1741,7 @@ static void _register_variant_builtin_methods() {
/* AABB */ /* AABB */
bind_method(AABB, abs, sarray(), varray()); bind_method(AABB, abs, sarray(), varray());
bind_method(AABB, get_center, sarray(), varray());
bind_method(AABB, get_area, sarray(), varray()); bind_method(AABB, get_area, sarray(), varray());
bind_method(AABB, has_no_area, sarray(), varray()); bind_method(AABB, has_no_area, sarray(), varray());
bind_method(AABB, has_no_surface, sarray(), varray()); bind_method(AABB, has_no_surface, sarray(), varray());

View file

@ -61,6 +61,12 @@
Returns the volume of the [AABB]. Returns the volume of the [AABB].
</description> </description>
</method> </method>
<method name="get_center" qualifiers="const">
<return type="Vector3" />
<description>
Returns the center of the [AABB], which is equal to [member position] + ([member size] / 2).
</description>
</method>
<method name="get_endpoint" qualifiers="const"> <method name="get_endpoint" qualifiers="const">
<return type="Vector3" /> <return type="Vector3" />
<argument index="0" name="idx" type="int" /> <argument index="0" name="idx" type="int" />

View file

@ -78,6 +78,12 @@
Returns the area of the [Rect2]. Returns the area of the [Rect2].
</description> </description>
</method> </method>
<method name="get_center" qualifiers="const">
<return type="Vector2" />
<description>
Returns the center of the [Rect2], which is equal to [member position] + ([member size] / 2).
</description>
</method>
<method name="grow" qualifiers="const"> <method name="grow" qualifiers="const">
<return type="Rect2" /> <return type="Rect2" />
<argument index="0" name="amount" type="float" /> <argument index="0" name="amount" type="float" />

View file

@ -76,6 +76,13 @@
Returns the area of the [Rect2i]. Returns the area of the [Rect2i].
</description> </description>
</method> </method>
<method name="get_center" qualifiers="const">
<return type="Vector2i" />
<description>
Returns the center of the [Rect2i], which is equal to [member position] + ([member size] / 2).
If [member size] is an odd number, the returned center value will be rounded towards [member position].
</description>
</method>
<method name="grow" qualifiers="const"> <method name="grow" qualifiers="const">
<return type="Rect2i" /> <return type="Rect2i" />
<argument index="0" name="amount" type="int" /> <argument index="0" name="amount" type="int" />

View file

@ -104,7 +104,7 @@ Vector<Ref<Texture2D>> EditorInterface::make_mesh_previews(const Vector<Ref<Mesh
RS::get_singleton()->instance_set_transform(inst, mesh_xform); RS::get_singleton()->instance_set_transform(inst, mesh_xform);
AABB aabb = mesh->get_aabb(); AABB aabb = mesh->get_aabb();
Vector3 ofs = aabb.position + aabb.size * 0.5; Vector3 ofs = aabb.get_center();
aabb.position -= ofs; aabb.position -= ofs;
Transform3D xform; Transform3D xform;
xform.basis = Basis().rotated(Vector3(0, 1, 0), -Math_PI / 6); xform.basis = Basis().rotated(Vector3(0, 1, 0), -Math_PI / 6);

View file

@ -328,7 +328,7 @@ void EditorSpinSlider::_draw_spin_slider() {
Rect2 grabber_rect = Rect2(ofs + gofs, svofs + 1, grabber_w, 2 * EDSCALE); Rect2 grabber_rect = Rect2(ofs + gofs, svofs + 1, grabber_w, 2 * EDSCALE);
draw_rect(grabber_rect, c); draw_rect(grabber_rect, c);
grabbing_spinner_mouse_pos = get_global_position() + grabber_rect.position + grabber_rect.size * 0.5; grabbing_spinner_mouse_pos = get_global_position() + grabber_rect.get_center();
bool display_grabber = (mouse_over_spin || mouse_over_grabber) && !grabbing_spinner && !(value_input_popup && value_input_popup->is_visible()); bool display_grabber = (mouse_over_spin || mouse_over_grabber) && !grabbing_spinner && !(value_input_popup && value_input_popup->is_visible());
if (grabber->is_visible() != display_grabber) { if (grabber->is_visible() != display_grabber) {
@ -354,7 +354,7 @@ void EditorSpinSlider::_draw_spin_slider() {
Vector2 scale = get_global_transform_with_canvas().get_scale(); Vector2 scale = get_global_transform_with_canvas().get_scale();
grabber->set_scale(scale); grabber->set_scale(scale);
grabber->set_size(Size2(0, 0)); grabber->set_size(Size2(0, 0));
grabber->set_position(get_global_position() + (grabber_rect.position + grabber_rect.size * 0.5 - grabber->get_size() * 0.5) * scale); grabber->set_position(get_global_position() + (grabber_rect.get_center() - grabber->get_size() * 0.5) * scale);
if (mousewheel_over_grabber) { if (mousewheel_over_grabber) {
Input::get_singleton()->warp_mouse_position(grabber->get_position() + grabber_rect.size); Input::get_singleton()->warp_mouse_position(grabber->get_position() + grabber_rect.size);

View file

@ -434,7 +434,7 @@ void SceneImportSettings::_update_camera() {
} }
} }
Vector3 center = camera_aabb.position + camera_aabb.size * 0.5; Vector3 center = camera_aabb.get_center();
float camera_size = camera_aabb.get_longest_axis_size(); float camera_size = camera_aabb.get_longest_axis_size();
camera->set_orthogonal(camera_size * zoom, 0.0001, camera_size * 2); camera->set_orthogonal(camera_size * zoom, 0.0001, camera_size * 2);

View file

@ -387,7 +387,7 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, unsig
// Self center // Self center
if ((is_snap_active && snap_node_center && (p_modes & SNAP_NODE_CENTER)) || (p_forced_modes & SNAP_NODE_CENTER)) { if ((is_snap_active && snap_node_center && (p_modes & SNAP_NODE_CENTER)) || (p_forced_modes & SNAP_NODE_CENTER)) {
if (p_self_canvas_item->_edit_use_rect()) { if (p_self_canvas_item->_edit_use_rect()) {
Point2 center = p_self_canvas_item->get_global_transform_with_canvas().xform(p_self_canvas_item->_edit_get_rect().get_position() + p_self_canvas_item->_edit_get_rect().get_size() / 2.0); Point2 center = p_self_canvas_item->get_global_transform_with_canvas().xform(p_self_canvas_item->_edit_get_rect().get_center());
_snap_if_closer_point(p_target, output, snap_target, center, SNAP_TARGET_SELF, rotation); _snap_if_closer_point(p_target, output, snap_target, center, SNAP_TARGET_SELF, rotation);
} else { } else {
Point2 position = p_self_canvas_item->get_global_transform_with_canvas().xform(Point2()); Point2 position = p_self_canvas_item->get_global_transform_with_canvas().xform(Point2());
@ -525,7 +525,7 @@ Rect2 CanvasItemEditor::_get_encompassing_rect_from_list(List<CanvasItem *> p_li
// Handles the first element // Handles the first element
CanvasItem *canvas_item = p_list.front()->get(); CanvasItem *canvas_item = p_list.front()->get();
Rect2 rect = Rect2(canvas_item->get_global_transform_with_canvas().xform(canvas_item->_edit_get_rect().position + canvas_item->_edit_get_rect().size / 2), Size2()); Rect2 rect = Rect2(canvas_item->get_global_transform_with_canvas().xform(canvas_item->_edit_get_rect().get_center()), Size2());
// Expand with the other ones // Expand with the other ones
for (CanvasItem *canvas_item2 : p_list) { for (CanvasItem *canvas_item2 : p_list) {
@ -564,7 +564,7 @@ void CanvasItemEditor::_expand_encompassing_rect_using_children(Rect2 &r_rect, c
Transform2D xform = p_parent_xform * p_canvas_xform * canvas_item->get_transform(); Transform2D xform = p_parent_xform * p_canvas_xform * canvas_item->get_transform();
Rect2 rect = canvas_item->_edit_get_rect(); Rect2 rect = canvas_item->_edit_get_rect();
if (r_first) { if (r_first) {
r_rect = Rect2(xform.xform(rect.position + rect.size / 2), Size2()); r_rect = Rect2(xform.xform(rect.get_center()), Size2());
r_first = false; r_first = false;
} }
r_rect.expand_to(xform.xform(rect.position)); r_rect.expand_to(xform.xform(rect.position));
@ -4896,7 +4896,7 @@ void CanvasItemEditor::_focus_selection(int p_op) {
}; };
if (p_op == VIEW_CENTER_TO_SELECTION) { if (p_op == VIEW_CENTER_TO_SELECTION) {
center = rect.position + rect.size / 2; center = rect.get_center();
Vector2 offset = viewport->get_size() / 2 - editor->get_scene_root()->get_global_canvas_transform().xform(center); Vector2 offset = viewport->get_size() / 2 - editor->get_scene_root()->get_global_canvas_transform().xform(center);
view_offset.x -= Math::round(offset.x / zoom); view_offset.x -= Math::round(offset.x / zoom);
view_offset.y -= Math::round(offset.y / zoom); view_offset.y -= Math::round(offset.y / zoom);

View file

@ -718,7 +718,7 @@ Ref<Texture2D> EditorMeshPreviewPlugin::generate(const RES &p_from, const Size2
RS::get_singleton()->instance_set_base(mesh_instance, mesh->get_rid()); RS::get_singleton()->instance_set_base(mesh_instance, mesh->get_rid());
AABB aabb = mesh->get_aabb(); AABB aabb = mesh->get_aabb();
Vector3 ofs = aabb.position + aabb.size * 0.5; Vector3 ofs = aabb.get_center();
aabb.position -= ofs; aabb.position -= ofs;
Transform3D xform; Transform3D xform;
xform.basis = Basis().rotated(Vector3(0, 1, 0), -Math_PI * 0.125); xform.basis = Basis().rotated(Vector3(0, 1, 0), -Math_PI * 0.125);

View file

@ -80,7 +80,7 @@ void MeshEditor::edit(Ref<Mesh> p_mesh) {
_update_rotation(); _update_rotation();
AABB aabb = mesh->get_aabb(); AABB aabb = mesh->get_aabb();
Vector3 ofs = aabb.position + aabb.size * 0.5; Vector3 ofs = aabb.get_center();
float m = aabb.get_longest_axis_size(); float m = aabb.get_longest_axis_size();
if (m != 0) { if (m != 0) {
m = 1.0 / m; m = 1.0 / m;

View file

@ -2652,7 +2652,7 @@ void VisibleOnScreenNotifier3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p
Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 4096) }; Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 4096) };
Vector3 ofs = aabb.position + aabb.size * 0.5; Vector3 ofs = aabb.get_center();
Vector3 axis; Vector3 axis;
axis[p_id] = 1.0; axis[p_id] = 1.0;
@ -2728,7 +2728,7 @@ void VisibleOnScreenNotifier3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
handles.push_back(ax); handles.push_back(ax);
} }
Vector3 center = aabb.position + aabb.size * 0.5; Vector3 center = aabb.get_center();
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
Vector3 ax; Vector3 ax;
ax[i] = 1.0; ax[i] = 1.0;
@ -2744,7 +2744,7 @@ void VisibleOnScreenNotifier3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
if (p_gizmo->is_selected()) { if (p_gizmo->is_selected()) {
Ref<Material> solid_material = get_material("visibility_notifier_solid_material", p_gizmo); Ref<Material> solid_material = get_material("visibility_notifier_solid_material", p_gizmo);
p_gizmo->add_solid_box(solid_material, aabb.get_size(), aabb.get_position() + aabb.get_size() / 2.0); p_gizmo->add_solid_box(solid_material, aabb.get_size(), aabb.get_center());
} }
p_gizmo->add_handles(handles, get_material("handles")); p_gizmo->add_handles(handles, get_material("handles"));
@ -2843,7 +2843,7 @@ void GPUParticles3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int
Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 4096) }; Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 4096) };
Vector3 ofs = aabb.position + aabb.size * 0.5; Vector3 ofs = aabb.get_center();
Vector3 axis; Vector3 axis;
axis[p_id] = 1.0; axis[p_id] = 1.0;
@ -2919,7 +2919,7 @@ void GPUParticles3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
handles.push_back(ax); handles.push_back(ax);
} }
Vector3 center = aabb.position + aabb.size * 0.5; Vector3 center = aabb.get_center();
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
Vector3 ax; Vector3 ax;
ax[i] = 1.0; ax[i] = 1.0;
@ -2935,7 +2935,7 @@ void GPUParticles3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
if (p_gizmo->is_selected()) { if (p_gizmo->is_selected()) {
Ref<Material> solid_material = get_material("particles_solid_material", p_gizmo); Ref<Material> solid_material = get_material("particles_solid_material", p_gizmo);
p_gizmo->add_solid_box(solid_material, aabb.get_size(), aabb.get_position() + aabb.get_size() / 2.0); p_gizmo->add_solid_box(solid_material, aabb.get_size(), aabb.get_center());
} }
p_gizmo->add_handles(handles, get_material("handles")); p_gizmo->add_handles(handles, get_material("handles"));

View file

@ -99,7 +99,7 @@ void AtlasMergingDialog::_generate_merged(Vector<Ref<TileSetAtlasSource>> p_atla
if (dst_rect_wide.get_end().x > output_image->get_width() || dst_rect_wide.get_end().y > output_image->get_height()) { if (dst_rect_wide.get_end().x > output_image->get_width() || dst_rect_wide.get_end().y > output_image->get_height()) {
output_image->crop(MAX(dst_rect_wide.get_end().x, output_image->get_width()), MAX(dst_rect_wide.get_end().y, output_image->get_height())); output_image->crop(MAX(dst_rect_wide.get_end().x, output_image->get_width()), MAX(dst_rect_wide.get_end().y, output_image->get_height()));
} }
output_image->blit_rect(atlas_source->get_texture()->get_image(), src_rect, (dst_rect_wide.get_position() + dst_rect_wide.get_end()) / 2 - src_rect.size / 2); output_image->blit_rect(atlas_source->get_texture()->get_image(), src_rect, dst_rect_wide.get_center() - src_rect.size / 2);
} }
// Compute the atlas offset. // Compute the atlas offset.

View file

@ -330,7 +330,7 @@ void TileAtlasView::_draw_base_tiles_shape_grid() {
// Draw only if the tile shape fits in the texture region // Draw only if the tile shape fits in the texture region
Transform2D tile_xform; Transform2D tile_xform;
tile_xform.set_origin(texture_region.position + texture_region.size / 2 + in_tile_base_offset); tile_xform.set_origin(texture_region.get_center() + in_tile_base_offset);
tile_xform.set_scale(tile_shape_size); tile_xform.set_scale(tile_shape_size);
tile_set->draw_tile_shape(base_tiles_shape_grid, tile_xform, grid_color); tile_set->draw_tile_shape(base_tiles_shape_grid, tile_xform, grid_color);
} }

View file

@ -1495,7 +1495,7 @@ void TileDataTerrainsEditor::forward_draw_over_atlas(TileAtlasView *p_tile_atlas
TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(hovered_coords, 0)); TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(hovered_coords, 0));
int terrain_set = tile_data->get_terrain_set(); int terrain_set = tile_data->get_terrain_set();
Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(hovered_coords); Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(hovered_coords);
Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(hovered_coords, 0); Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(hovered_coords, 0);
if (terrain_set >= 0 && terrain_set == int(dummy_object->get("terrain_set"))) { if (terrain_set >= 0 && terrain_set == int(dummy_object->get("terrain_set"))) {
// Draw hovered bit. // Draw hovered bit.
@ -1540,7 +1540,7 @@ void TileDataTerrainsEditor::forward_draw_over_atlas(TileAtlasView *p_tile_atlas
// Text // Text
p_canvas_item->draw_set_transform_matrix(Transform2D()); p_canvas_item->draw_set_transform_matrix(Transform2D());
Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords); Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords);
Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0);
Color color = Color(1, 1, 1); Color color = Color(1, 1, 1);
String text; String text;
@ -1632,7 +1632,7 @@ void TileDataTerrainsEditor::forward_draw_over_atlas(TileAtlasView *p_tile_atlas
Vector2i coords = E->get().get_atlas_coords(); Vector2i coords = E->get().get_atlas_coords();
Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords); Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords);
Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0);
for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); TileSet::CellNeighbor bit = TileSet::CellNeighbor(i);
@ -1668,7 +1668,7 @@ void TileDataTerrainsEditor::forward_draw_over_alternatives(TileAtlasView *p_til
TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(hovered_coords, hovered_alternative)); TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(hovered_coords, hovered_alternative));
int terrain_set = tile_data->get_terrain_set(); int terrain_set = tile_data->get_terrain_set();
Rect2i texture_region = p_tile_atlas_view->get_alternative_tile_rect(hovered_coords, hovered_alternative); Rect2i texture_region = p_tile_atlas_view->get_alternative_tile_rect(hovered_coords, hovered_alternative);
Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(hovered_coords, hovered_alternative); Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(hovered_coords, hovered_alternative);
if (terrain_set == int(dummy_object->get("terrain_set"))) { if (terrain_set == int(dummy_object->get("terrain_set"))) {
// Draw hovered bit. // Draw hovered bit.
@ -1715,7 +1715,7 @@ void TileDataTerrainsEditor::forward_draw_over_alternatives(TileAtlasView *p_til
// Text // Text
p_canvas_item->draw_set_transform_matrix(Transform2D()); p_canvas_item->draw_set_transform_matrix(Transform2D());
Rect2i texture_region = p_tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile); Rect2i texture_region = p_tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile);
Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0);
Color color = Color(1, 1, 1); Color color = Color(1, 1, 1);
String text; String text;
@ -1796,7 +1796,7 @@ void TileDataTerrainsEditor::forward_painting_atlas_gui_input(TileAtlasView *p_t
// Set the terrains bits. // Set the terrains bits.
Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords); Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords);
Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0);
for (int j = 0; j < TileSet::CELL_NEIGHBOR_MAX; j++) { for (int j = 0; j < TileSet::CELL_NEIGHBOR_MAX; j++) {
TileSet::CellNeighbor bit = TileSet::CellNeighbor(j); TileSet::CellNeighbor bit = TileSet::CellNeighbor(j);
if (tile_data->is_valid_peering_bit_terrain(bit)) { if (tile_data->is_valid_peering_bit_terrain(bit)) {
@ -1824,7 +1824,7 @@ void TileDataTerrainsEditor::forward_painting_atlas_gui_input(TileAtlasView *p_t
TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(coords, 0)); TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(coords, 0));
int terrain_set = tile_data->get_terrain_set(); int terrain_set = tile_data->get_terrain_set();
Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords); Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords);
Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0);
dummy_object->set("terrain_set", terrain_set); dummy_object->set("terrain_set", terrain_set);
dummy_object->set("terrain", -1); dummy_object->set("terrain", -1);
for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
@ -1922,7 +1922,7 @@ void TileDataTerrainsEditor::forward_painting_atlas_gui_input(TileAtlasView *p_t
// Set the terrain bit. // Set the terrain bit.
Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords); Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords);
Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0);
for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); TileSet::CellNeighbor bit = TileSet::CellNeighbor(i);
@ -2055,7 +2055,7 @@ void TileDataTerrainsEditor::forward_painting_atlas_gui_input(TileAtlasView *p_t
TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); TileSet::CellNeighbor bit = TileSet::CellNeighbor(i);
if (tile_set->is_valid_peering_bit_terrain(terrain_set, bit)) { if (tile_set->is_valid_peering_bit_terrain(terrain_set, bit)) {
Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords); Rect2i texture_region = p_tile_set_atlas_source->get_tile_texture_region(coords);
Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0);
Vector<Vector2> polygon = tile_set->get_terrain_bit_polygon(terrain_set, bit); Vector<Vector2> polygon = tile_set->get_terrain_bit_polygon(terrain_set, bit);
for (int j = 0; j < polygon.size(); j++) { for (int j = 0; j < polygon.size(); j++) {
@ -2138,7 +2138,7 @@ void TileDataTerrainsEditor::forward_painting_alternatives_gui_input(TileAtlasVi
// Set the terrains bits. // Set the terrains bits.
Rect2i texture_region = p_tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile); Rect2i texture_region = p_tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile);
Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, alternative_tile); Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, alternative_tile);
for (int j = 0; j < TileSet::CELL_NEIGHBOR_MAX; j++) { for (int j = 0; j < TileSet::CELL_NEIGHBOR_MAX; j++) {
TileSet::CellNeighbor bit = TileSet::CellNeighbor(j); TileSet::CellNeighbor bit = TileSet::CellNeighbor(j);
if (tile_data->is_valid_peering_bit_terrain(bit)) { if (tile_data->is_valid_peering_bit_terrain(bit)) {
@ -2167,7 +2167,7 @@ void TileDataTerrainsEditor::forward_painting_alternatives_gui_input(TileAtlasVi
TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(coords, alternative_tile)); TileData *tile_data = Object::cast_to<TileData>(p_tile_set_atlas_source->get_tile_data(coords, alternative_tile));
int terrain_set = tile_data->get_terrain_set(); int terrain_set = tile_data->get_terrain_set();
Rect2i texture_region = p_tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile); Rect2i texture_region = p_tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile);
Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, alternative_tile); Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, alternative_tile);
dummy_object->set("terrain_set", terrain_set); dummy_object->set("terrain_set", terrain_set);
dummy_object->set("terrain", -1); dummy_object->set("terrain", -1);
for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
@ -2242,7 +2242,7 @@ void TileDataTerrainsEditor::forward_painting_alternatives_gui_input(TileAtlasVi
// Set the terrain bit. // Set the terrain bit.
Rect2i texture_region = p_tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile); Rect2i texture_region = p_tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile);
Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, alternative_tile); Vector2i position = texture_region.get_center() + p_tile_set_atlas_source->get_tile_effective_texture_offset(coords, alternative_tile);
for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) { for (int i = 0; i < TileSet::CELL_NEIGHBOR_MAX; i++) {
TileSet::CellNeighbor bit = TileSet::CellNeighbor(i); TileSet::CellNeighbor bit = TileSet::CellNeighbor(i);
if (tile_set->is_valid_peering_bit_terrain(terrain_set, bit)) { if (tile_set->is_valid_peering_bit_terrain(terrain_set, bit)) {

View file

@ -1638,7 +1638,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_unscaled_draw() {
for (int i = 0; i < tile_set_atlas_source->get_tiles_count(); i++) { for (int i = 0; i < tile_set_atlas_source->get_tiles_count(); i++) {
Vector2i coords = tile_set_atlas_source->get_tile_id(i); Vector2i coords = tile_set_atlas_source->get_tile_id(i);
Rect2i texture_region = tile_set_atlas_source->get_tile_texture_region(coords); Rect2i texture_region = tile_set_atlas_source->get_tile_texture_region(coords);
Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0); Vector2i position = texture_region.get_center() + tile_set_atlas_source->get_tile_effective_texture_offset(coords, 0);
Transform2D xform = tile_atlas_control->get_parent_control()->get_transform(); Transform2D xform = tile_atlas_control->get_parent_control()->get_transform();
xform.translate(position); xform.translate(position);
@ -1661,7 +1661,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_unscaled_draw() {
continue; continue;
} }
Rect2i texture_region = tile_set_atlas_source->get_tile_texture_region(E->get().tile); Rect2i texture_region = tile_set_atlas_source->get_tile_texture_region(E->get().tile);
Vector2i position = (texture_region.position + texture_region.get_end()) / 2 + tile_set_atlas_source->get_tile_effective_texture_offset(E->get().tile, 0); Vector2i position = texture_region.get_center() + tile_set_atlas_source->get_tile_effective_texture_offset(E->get().tile, 0);
Transform2D xform = tile_atlas_control->get_parent_control()->get_transform(); Transform2D xform = tile_atlas_control->get_parent_control()->get_transform();
xform.translate(position); xform.translate(position);
@ -1805,7 +1805,7 @@ void TileSetAtlasSourceEditor::_tile_alternatives_control_unscaled_draw() {
continue; continue;
} }
Rect2i rect = tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile); Rect2i rect = tile_atlas_view->get_alternative_tile_rect(coords, alternative_tile);
Vector2 position = (rect.get_position() + rect.get_end()) / 2; Vector2 position = rect.get_center();
Transform2D xform = alternative_tiles_control->get_parent_control()->get_transform(); Transform2D xform = alternative_tiles_control->get_parent_control()->get_transform();
xform.translate(position); xform.translate(position);
@ -1829,7 +1829,7 @@ void TileSetAtlasSourceEditor::_tile_alternatives_control_unscaled_draw() {
continue; continue;
} }
Rect2i rect = tile_atlas_view->get_alternative_tile_rect(E->get().tile, E->get().alternative); Rect2i rect = tile_atlas_view->get_alternative_tile_rect(E->get().tile, E->get().alternative);
Vector2 position = (rect.get_position() + rect.get_end()) / 2; Vector2 position = rect.get_center();
Transform2D xform = alternative_tiles_control->get_parent_control()->get_transform(); Transform2D xform = alternative_tiles_control->get_parent_control()->get_transform();
xform.translate(position); xform.translate(position);

View file

@ -517,7 +517,7 @@ int CSGBrushOperation::MeshMerge::_create_bvh(FaceBVH *facebvhptr, FaceBVH **fac
int index = r_max_alloc++; int index = r_max_alloc++;
FaceBVH *_new = &facebvhptr[index]; FaceBVH *_new = &facebvhptr[index];
_new->aabb = aabb; _new->aabb = aabb;
_new->center = aabb.position + aabb.size * 0.5; _new->center = aabb.get_center();
_new->face = -1; _new->face = -1;
_new->left = left; _new->left = left;
_new->right = right; _new->right = right;
@ -678,7 +678,7 @@ void CSGBrushOperation::MeshMerge::mark_inside_faces() {
facebvh[i].aabb.position = points[faces[i].points[0]]; facebvh[i].aabb.position = points[faces[i].points[0]];
facebvh[i].aabb.expand_to(points[faces[i].points[1]]); facebvh[i].aabb.expand_to(points[faces[i].points[1]]);
facebvh[i].aabb.expand_to(points[faces[i].points[2]]); facebvh[i].aabb.expand_to(points[faces[i].points[2]]);
facebvh[i].center = facebvh[i].aabb.position + facebvh[i].aabb.size * 0.5; facebvh[i].center = facebvh[i].aabb.get_center();
facebvh[i].aabb.grow_by(vertex_snap); facebvh[i].aabb.grow_by(vertex_snap);
facebvh[i].next = -1; facebvh[i].next = -1;

View file

@ -66,6 +66,16 @@ namespace Godot
return new AABB(topLeft, _size.Abs()); return new AABB(topLeft, _size.Abs());
} }
/// <summary>
/// Returns the center of the <see cref="AABB"/>, which is equal
/// to <see cref="Position"/> + (<see cref="Size"/> / 2).
/// </summary>
/// <returns>The center.</returns>
public Vector3 GetCenter()
{
return _position + (_size * 0.5f);
}
/// <summary> /// <summary>
/// Returns <see langword="true"/> if this <see cref="AABB"/> completely encloses another one. /// Returns <see langword="true"/> if this <see cref="AABB"/> completely encloses another one.
/// </summary> /// </summary>

View file

@ -164,6 +164,16 @@ namespace Godot
return _size.x * _size.y; return _size.x * _size.y;
} }
/// <summary>
/// Returns the center of the <see cref="Rect2"/>, which is equal
/// to <see cref="Position"/> + (<see cref="Size"/> / 2).
/// </summary>
/// <returns>The center.</returns>
public Vector2 GetCenter()
{
return _position + (_size * 0.5f);
}
/// <summary> /// <summary>
/// Returns a copy of the <see cref="Rect2"/> grown by the specified amount /// Returns a copy of the <see cref="Rect2"/> grown by the specified amount
/// on all sides. /// on all sides.

View file

@ -151,7 +151,7 @@ namespace Godot
} }
/// <summary> /// <summary>
/// Returns the area of the <see cref="Rect2"/>. /// Returns the area of the <see cref="Rect2i"/>.
/// </summary> /// </summary>
/// <returns>The area.</returns> /// <returns>The area.</returns>
public int GetArea() public int GetArea()
@ -159,6 +159,18 @@ namespace Godot
return _size.x * _size.y; return _size.x * _size.y;
} }
/// <summary>
/// Returns the center of the <see cref="Rect2i"/>, which is equal
/// to <see cref="Position"/> + (<see cref="Size"/> / 2).
/// If <see cref="Size"/> is an odd number, the returned center
/// value will be rounded towards <see cref="Position"/>.
/// </summary>
/// <returns>The center.</returns>
public Vector2i GetCenter()
{
return _position + (_size / 2);
}
/// <summary> /// <summary>
/// Returns a copy of the <see cref="Rect2i"/> grown by the specified amount /// Returns a copy of the <see cref="Rect2i"/> grown by the specified amount
/// on all sides. /// on all sides.

View file

@ -198,7 +198,7 @@ Transform2D Camera2D::get_camera_transform() {
screen_rect.position += offset; screen_rect.position += offset;
} }
camera_screen_center = screen_rect.position + screen_rect.size * 0.5; camera_screen_center = screen_rect.get_center();
Transform2D xform; Transform2D xform;
xform.scale_basis(zoom); xform.scale_basis(zoom);

View file

@ -420,7 +420,7 @@ Ref<Image> GPUParticlesCollisionSDF::bake() {
} }
//test against original bounds //test against original bounds
if (!Geometry3D::triangle_box_overlap(aabb.position + aabb.size * 0.5, aabb.size * 0.5, face.vertex)) { if (!Geometry3D::triangle_box_overlap(aabb.get_center(), aabb.size * 0.5, face.vertex)) {
continue; continue;
} }
@ -438,7 +438,7 @@ Ref<Image> GPUParticlesCollisionSDF::bake() {
} }
//test against original bounds //test against original bounds
if (!Geometry3D::triangle_box_overlap(aabb.position + aabb.size * 0.5, aabb.size * 0.5, face.vertex)) { if (!Geometry3D::triangle_box_overlap(aabb.get_center(), aabb.size * 0.5, face.vertex)) {
continue; continue;
} }

View file

@ -467,7 +467,7 @@ int32_t LightmapGI::_compute_bsp_tree(const Vector<Vector3> &p_points, const Loc
} }
} }
if (i == 0) { if (i == 0) {
centers.push_back(bounds.position + bounds.size * 0.5); centers.push_back(bounds.get_center());
} else { } else {
bounds_all.merge_with(bounds); bounds_all.merge_with(bounds);
} }
@ -555,7 +555,7 @@ void LightmapGI::_plot_triangle_into_octree(GenProbesOctree *p_cell, float p_cel
subcell.position = Vector3(pos) * p_cell_size; subcell.position = Vector3(pos) * p_cell_size;
subcell.size = Vector3(half_size, half_size, half_size) * p_cell_size; subcell.size = Vector3(half_size, half_size, half_size) * p_cell_size;
if (!Geometry3D::triangle_box_overlap(subcell.position + subcell.size * 0.5, subcell.size * 0.5, p_triangle)) { if (!Geometry3D::triangle_box_overlap(subcell.get_center(), subcell.size * 0.5, p_triangle)) {
continue; continue;
} }

View file

@ -173,7 +173,7 @@ void Voxelizer::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p_z, co
//could not in any way get texture information.. so use closest point to center //could not in any way get texture information.. so use closest point to center
Face3 f(p_vtx[0], p_vtx[1], p_vtx[2]); Face3 f(p_vtx[0], p_vtx[1], p_vtx[2]);
Vector3 inters = f.get_closest_point_to(p_aabb.position + p_aabb.size * 0.5); Vector3 inters = f.get_closest_point_to(p_aabb.get_center());
Vector3 lnormal; Vector3 lnormal;
Vector2 uv; Vector2 uv;
@ -434,7 +434,7 @@ void Voxelizer::plot_mesh(const Transform3D &p_xform, Ref<Mesh> &p_mesh, const V
} }
//test against original bounds //test against original bounds
if (!Geometry3D::triangle_box_overlap(original_bounds.position + original_bounds.size * 0.5, original_bounds.size * 0.5, vtxs)) { if (!Geometry3D::triangle_box_overlap(original_bounds.get_center(), original_bounds.size * 0.5, vtxs)) {
continue; continue;
} }
//plot //plot
@ -466,7 +466,7 @@ void Voxelizer::plot_mesh(const Transform3D &p_xform, Ref<Mesh> &p_mesh, const V
} }
//test against original bounds //test against original bounds
if (!Geometry3D::triangle_box_overlap(original_bounds.position + original_bounds.size * 0.5, original_bounds.size * 0.5, vtxs)) { if (!Geometry3D::triangle_box_overlap(original_bounds.get_center(), original_bounds.size * 0.5, vtxs)) {
continue; continue;
} }
//plot face //plot face
@ -885,7 +885,7 @@ Vector<uint8_t> Voxelizer::get_sdf_3d_image() const {
void Voxelizer::_debug_mesh(int p_idx, int p_level, const AABB &p_aabb, Ref<MultiMesh> &p_multimesh, int &idx) { void Voxelizer::_debug_mesh(int p_idx, int p_level, const AABB &p_aabb, Ref<MultiMesh> &p_multimesh, int &idx) {
if (p_level == cell_subdiv - 1) { if (p_level == cell_subdiv - 1) {
Vector3 center = p_aabb.position + p_aabb.size * 0.5; Vector3 center = p_aabb.get_center();
Transform3D xform; Transform3D xform;
xform.origin = center; xform.origin = center;
xform.basis.scale(p_aabb.size * 0.5); xform.basis.scale(p_aabb.size * 0.5);

View file

@ -1576,7 +1576,7 @@ void ConcavePolygonShape3DSW::_setup(const Vector<Vector3> &p_faces, bool p_back
Face3 face(facesr[i * 3 + 0], facesr[i * 3 + 1], facesr[i * 3 + 2]); Face3 face(facesr[i * 3 + 0], facesr[i * 3 + 1], facesr[i * 3 + 2]);
bvh_arrayw[i].aabb = face.get_aabb(); bvh_arrayw[i].aabb = face.get_aabb();
bvh_arrayw[i].center = bvh_arrayw[i].aabb.position + bvh_arrayw[i].aabb.size * 0.5; bvh_arrayw[i].center = bvh_arrayw[i].aabb.get_center();
bvh_arrayw[i].face_index = i; bvh_arrayw[i].face_index = i;
facesw[i].indices[0] = i * 3 + 0; facesw[i].indices[0] = i * 3 + 0;
facesw[i].indices[1] = i * 3 + 1; facesw[i].indices[1] = i * 3 + 1;

View file

@ -1621,7 +1621,7 @@ void RendererCanvasRenderRD::light_update_directional_shadow(RID p_rid, int p_sh
Vector2 light_dir = p_light_xform.elements[1].normalized(); Vector2 light_dir = p_light_xform.elements[1].normalized();
Vector2 center = p_clip_rect.position + p_clip_rect.size * 0.5; Vector2 center = p_clip_rect.get_center();
float to_edge_distance = ABS(light_dir.dot(p_clip_rect.get_support(light_dir)) - light_dir.dot(center)); float to_edge_distance = ABS(light_dir.dot(p_clip_rect.get_support(light_dir)) - light_dir.dot(center));

View file

@ -2575,7 +2575,7 @@ void RendererSceneGIRD::VoxelGIInstance::update(bool p_update_light_instances, c
Vector3 render_dir = render_z[j]; Vector3 render_dir = render_z[j];
Vector3 up_dir = render_up[j]; Vector3 up_dir = render_up[j];
Vector3 center = aabb.position + aabb.size * 0.5; Vector3 center = aabb.get_center();
Transform3D xform; Transform3D xform;
xform.set_look_at(center - aabb.size * 0.5 * render_dir, center, up_dir); xform.set_look_at(center - aabb.size * 0.5 * render_dir, center, up_dir);

View file

@ -1286,7 +1286,7 @@ void RendererSceneCull::_update_instance_visibility_dependencies(Instance *p_ins
vd.range_end = p_instance->visibility_range_end; vd.range_end = p_instance->visibility_range_end;
vd.range_begin_margin = p_instance->visibility_range_begin_margin; vd.range_begin_margin = p_instance->visibility_range_begin_margin;
vd.range_end_margin = p_instance->visibility_range_end_margin; vd.range_end_margin = p_instance->visibility_range_end_margin;
vd.position = p_instance->transformed_aabb.get_position() + p_instance->transformed_aabb.get_size() / 2.0f; vd.position = p_instance->transformed_aabb.get_center();
vd.array_index = p_instance->array_index; vd.array_index = p_instance->array_index;
InstanceGeometryData *geom_data = static_cast<InstanceGeometryData *>(p_instance->base_data); InstanceGeometryData *geom_data = static_cast<InstanceGeometryData *>(p_instance->base_data);
@ -1636,7 +1636,7 @@ void RendererSceneCull::_update_instance(Instance *p_instance) {
} }
if (p_instance->visibility_index != -1) { if (p_instance->visibility_index != -1) {
p_instance->scenario->instance_visibility[p_instance->visibility_index].position = p_instance->transformed_aabb.get_position() + p_instance->transformed_aabb.get_size() / 2.0f; p_instance->scenario->instance_visibility[p_instance->visibility_index].position = p_instance->transformed_aabb.get_center();
} }
//move instance and repair //move instance and repair
@ -1851,7 +1851,7 @@ void RendererSceneCull::_update_instance_lightmap_captures(Instance *p_instance)
} }
Transform3D to_bounds = lightmap->transform.affine_inverse(); Transform3D to_bounds = lightmap->transform.affine_inverse();
Vector3 center = p_instance->transform.xform(p_instance->aabb.position + p_instance->aabb.size * 0.5); //use aabb center Vector3 center = p_instance->transform.xform(p_instance->aabb.get_center()); //use aabb center
Vector3 lm_pos = to_bounds.xform(center); Vector3 lm_pos = to_bounds.xform(center);

View file

@ -65,6 +65,9 @@ TEST_CASE("[AABB] Basic getters") {
CHECK_MESSAGE( CHECK_MESSAGE(
aabb.get_end().is_equal_approx(Vector3(2.5, 7, 3.5)), aabb.get_end().is_equal_approx(Vector3(2.5, 7, 3.5)),
"get_end() should return the expected value."); "get_end() should return the expected value.");
CHECK_MESSAGE(
aabb.get_center().is_equal_approx(Vector3(0.5, 4.5, 0.5)),
"get_center() should return the expected value.");
} }
TEST_CASE("[AABB] Basic setters") { TEST_CASE("[AABB] Basic setters") {

View file

@ -76,6 +76,12 @@ TEST_CASE("[Rect2] Basic getters") {
CHECK_MESSAGE( CHECK_MESSAGE(
rect.get_end().is_equal_approx(Vector2(1280, 820)), rect.get_end().is_equal_approx(Vector2(1280, 820)),
"get_end() should return the expected value."); "get_end() should return the expected value.");
CHECK_MESSAGE(
rect.get_center().is_equal_approx(Vector2(640, 460)),
"get_center() should return the expected value.");
CHECK_MESSAGE(
Rect2(0, 100, 1281, 721).get_center().is_equal_approx(Vector2(640.5, 460.5)),
"get_center() should return the expected value.");
} }
TEST_CASE("[Rect2] Basic setters") { TEST_CASE("[Rect2] Basic setters") {
@ -288,6 +294,12 @@ TEST_CASE("[Rect2i] Basic getters") {
CHECK_MESSAGE( CHECK_MESSAGE(
rect.get_end() == Vector2i(1280, 820), rect.get_end() == Vector2i(1280, 820),
"get_end() should return the expected value."); "get_end() should return the expected value.");
CHECK_MESSAGE(
rect.get_center() == Vector2i(640, 460),
"get_center() should return the expected value.");
CHECK_MESSAGE(
Rect2i(0, 100, 1281, 721).get_center() == Vector2i(640, 460),
"get_center() should return the expected value.");
} }
TEST_CASE("[Rect2i] Basic setters") { TEST_CASE("[Rect2i] Basic setters") {