From c1153f5041f896536957b851329b5adaa1de6dc4 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 26 Dec 2017 12:44:58 -0300 Subject: [PATCH] Change the rotate function of Spatial to be local, makes more sense. Closes #14569 --- core/math/matrix3.cpp | 9 +++++++++ core/math/matrix3.h | 3 +++ scene/3d/spatial.cpp | 8 ++++---- scene/3d/voxel_light_baker.cpp | 4 +--- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/core/math/matrix3.cpp b/core/math/matrix3.cpp index ab3bca79ae2..5346141470f 100644 --- a/core/math/matrix3.cpp +++ b/core/math/matrix3.cpp @@ -311,6 +311,15 @@ void Basis::rotate(const Vector3 &p_axis, real_t p_phi) { *this = rotated(p_axis, p_phi); } +void Basis::rotate_local(const Vector3 &p_axis, real_t p_phi) { + + *this = rotated_local(p_axis, p_phi); +} +Basis Basis::rotated_local(const Vector3 &p_axis, real_t p_phi) const { + + return (*this) * Basis(p_axis, p_phi); +} + Basis Basis::rotated(const Vector3 &p_euler) const { return Basis(p_euler) * (*this); } diff --git a/core/math/matrix3.h b/core/math/matrix3.h index 9a33b8203dc..9a75308f08e 100644 --- a/core/math/matrix3.h +++ b/core/math/matrix3.h @@ -75,6 +75,9 @@ public: void rotate(const Vector3 &p_axis, real_t p_phi); Basis rotated(const Vector3 &p_axis, real_t p_phi) const; + void rotate_local(const Vector3 &p_axis, real_t p_phi); + Basis rotated_local(const Vector3 &p_axis, real_t p_phi) const; + void rotate(const Vector3 &p_euler); Basis rotated(const Vector3 &p_euler) const; diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index d9f88ac6934..e890533ab7d 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -558,27 +558,27 @@ bool Spatial::is_visible() const { void Spatial::rotate(const Vector3 &p_normal, float p_radians) { Transform t = get_transform(); - t.basis.rotate(p_normal, p_radians); + t.basis.rotate_local(p_normal, p_radians); //use local rotation here, as it makes more sense here in tree hierarchy set_transform(t); } void Spatial::rotate_x(float p_radians) { Transform t = get_transform(); - t.basis.rotate(Vector3(1, 0, 0), p_radians); + t.basis.rotate_local(Vector3(1, 0, 0), p_radians); set_transform(t); } void Spatial::rotate_y(float p_radians) { Transform t = get_transform(); - t.basis.rotate(Vector3(0, 1, 0), p_radians); + t.basis.rotate_local(Vector3(0, 1, 0), p_radians); set_transform(t); } void Spatial::rotate_z(float p_radians) { Transform t = get_transform(); - t.basis.rotate(Vector3(0, 0, 1), p_radians); + t.basis.rotate_local(Vector3(0, 0, 1), p_radians); set_transform(t); } diff --git a/scene/3d/voxel_light_baker.cpp b/scene/3d/voxel_light_baker.cpp index 17aa649dff3..bd7e52d9478 100644 --- a/scene/3d/voxel_light_baker.cpp +++ b/scene/3d/voxel_light_baker.cpp @@ -1799,7 +1799,6 @@ Vector3 VoxelLightBaker::_compute_ray_trace_at_pos(const Vector3 &p_pos, const V void VoxelLightBaker::_lightmap_bake_point(uint32_t p_x, LightMap *p_line) { - LightMap *pixel = &p_line[p_x]; if (pixel->pos == Vector3()) return; @@ -1814,7 +1813,6 @@ void VoxelLightBaker::_lightmap_bake_point(uint32_t p_x, LightMap *p_line) { // pixel->light = Vector3(1, 1, 1); //} } - } Error VoxelLightBaker::make_lightmap(const Transform &p_xform, Ref &p_mesh, LightMapData &r_lightmap, bool (*p_bake_time_func)(void *, float, float), void *p_bake_time_ud) { @@ -1882,7 +1880,7 @@ Error VoxelLightBaker::make_lightmap(const Transform &p_xform, Ref &p_mesh for (int i = 0; i < height; i++) { - thread_process_array(width,this,&VoxelLightBaker::_lightmap_bake_point,&lightmap_ptr[i*width]); + thread_process_array(width, this, &VoxelLightBaker::_lightmap_bake_point, &lightmap_ptr[i * width]); lines = MAX(lines, i); //for multithread if (p_bake_time_func) {