diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 2cef3e659..79fcb0fac 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -2185,6 +2185,7 @@ void EditorComponent::Update(float dt) componentsWnd.emitterWnd.UpdateData(); componentsWnd.hairWnd.UpdateData(); + componentsWnd.humanoidWnd.UpdateHumanoids(); // Follow camera proxy: if (cameraWnd.followCheckBox.IsEnabled() && cameraWnd.followCheckBox.GetCheck()) diff --git a/Editor/HumanoidWindow.cpp b/Editor/HumanoidWindow.cpp index fa47a3294..1af266e2f 100644 --- a/Editor/HumanoidWindow.cpp +++ b/Editor/HumanoidWindow.cpp @@ -505,31 +505,6 @@ void HumanoidWindow::RefreshBoneList() } } -void HumanoidWindow::Update(const wi::Canvas& canvas, float dt) -{ - wi::gui::Window::Update(canvas, dt); - - if (lookatMouseCheckBox.GetCheck()) - { - Scene& scene = editor->GetCurrentScene(); - const CameraComponent& camera = editor->GetCurrentEditorScene().camera; - wi::primitive::Ray ray = editor->pickRay; - - for (size_t i = 0; i < scene.humanoids.GetCount(); ++i) - { - HumanoidComponent& humanoid = scene.humanoids[i]; - - Entity bone = humanoid.bones[size_t(HumanoidComponent::HumanoidBone::Head)]; - const TransformComponent* transform = scene.transforms.GetComponent(bone); - if (transform != nullptr) - { - float dist = wi::math::Distance(transform->GetPosition(), ray.origin); - dist = std::min(1.0f, dist); - XMStoreFloat3(&humanoid.lookAt, camera.GetEye() + XMLoadFloat3(&ray.direction) * dist); // look at near plane position - } - } - } -} void HumanoidWindow::ResizeLayout() { wi::gui::Window::ResizeLayout(); @@ -586,3 +561,28 @@ void HumanoidWindow::ResizeLayout() add_fullwidth(boneList); } + +void HumanoidWindow::UpdateHumanoids() +{ + // Update humanoids to look at mouse: + if (lookatMouseCheckBox.GetCheck()) + { + Scene& scene = editor->GetCurrentScene(); + const CameraComponent& camera = editor->GetCurrentEditorScene().camera; + wi::primitive::Ray ray = editor->pickRay; + + for (size_t i = 0; i < scene.humanoids.GetCount(); ++i) + { + HumanoidComponent& humanoid = scene.humanoids[i]; + + Entity bone = humanoid.bones[size_t(HumanoidComponent::HumanoidBone::Head)]; + const TransformComponent* transform = scene.transforms.GetComponent(bone); + if (transform != nullptr) + { + float dist = wi::math::Distance(transform->GetPosition(), ray.origin); + dist = std::min(1.0f, dist); + XMStoreFloat3(&humanoid.lookAt, camera.GetEye() + XMLoadFloat3(&ray.direction) * dist); // look at near plane position + } + } + } +} diff --git a/Editor/HumanoidWindow.h b/Editor/HumanoidWindow.h index 653f8f142..4f4619273 100644 --- a/Editor/HumanoidWindow.h +++ b/Editor/HumanoidWindow.h @@ -26,7 +26,8 @@ public: wi::gui::Slider ragdollHeadSizeSlider; wi::gui::TreeList boneList; - void Update(const wi::Canvas& canvas, float dt) override; void ResizeLayout() override; + + void UpdateHumanoids(); }; diff --git a/WickedEngine/Utility/dds.h b/WickedEngine/Utility/dds.h index 416c13b43..e45562f4f 100644 --- a/WickedEngine/Utility/dds.h +++ b/WickedEngine/Utility/dds.h @@ -741,11 +741,11 @@ namespace dds // returns the size of a specific mipmap in bytes constexpr unsigned long long mip_size(unsigned mip) const { - const unsigned bpe = bits_per_element(); - const unsigned blocksize = block_size(); - unsigned num_blocks_x = (width() + blocksize - 1) / blocksize; - unsigned num_blocks_y = (height() + blocksize - 1) / blocksize; - unsigned num_elements_z = depth(); + const unsigned long long bpe = bits_per_element(); + const unsigned long long blocksize = block_size(); + unsigned long long num_blocks_x = (width() + blocksize - 1) / blocksize; + unsigned long long num_blocks_y = (height() + blocksize - 1) / blocksize; + unsigned long long num_elements_z = depth(); num_blocks_x >>= mip; num_blocks_y >>= mip; num_elements_z >>= mip; @@ -797,24 +797,24 @@ namespace dds // returns the size of one row in a specific mip level in bytes constexpr unsigned row_pitch(unsigned mip) const { - const unsigned bpe = bits_per_element(); - const unsigned blocksize = block_size(); - unsigned num_blocks_x = (width() + blocksize - 1) / blocksize; + const unsigned long long bpe = bits_per_element(); + const unsigned long long blocksize = block_size(); + unsigned long long num_blocks_x = (width() + blocksize - 1) / blocksize; num_blocks_x >>= mip; num_blocks_x = num_blocks_x < 1 ? 1 : num_blocks_x; - return num_blocks_x * bpe / 8; + return unsigned(num_blocks_x * bpe / 8); } // returns the size of a specific slice at a specific mip level in bytes constexpr unsigned slice_pitch(unsigned mip) const { - const unsigned blocksize = block_size(); - unsigned num_blocks_y = (width() + blocksize - 1) / blocksize; - unsigned num_elements_z = depth(); + const unsigned long long blocksize = block_size(); + unsigned long long num_blocks_y = (width() + blocksize - 1) / blocksize; + unsigned long long num_elements_z = depth(); num_blocks_y >>= mip; num_elements_z >>= mip; num_blocks_y = num_blocks_y < 1 ? 1 : num_blocks_y; num_elements_z = num_elements_z < 1 ? 1 : num_elements_z; - return row_pitch(mip) * num_blocks_y * num_elements_z; + return unsigned(row_pitch(mip) * num_blocks_y * num_elements_z); } }; diff --git a/WickedEngine/wiMath.cpp b/WickedEngine/wiMath.cpp index 8f50f2623..b230bdb78 100644 --- a/WickedEngine/wiMath.cpp +++ b/WickedEngine/wiMath.cpp @@ -40,9 +40,9 @@ namespace wi::math } XMFLOAT3 GetQuadraticBezierPos(const XMFLOAT3& a, const XMFLOAT3&b, const XMFLOAT3& c, float t){ float param0, param1, param2; - param0 = powf(1 - t, 2); - param1 = 2 * (1 - t)*t; - param2 = powf(t, 2); + param0 = sqr(1 - t); + param1 = 2 * (1 - t) * t; + param2 = sqr(t); float x = param0*a.x + param1*b.x + param2*c.x; float y = param0*a.y + param1*b.y + param2*c.y; float z = param0*a.z + param1*b.z + param2*c.z; diff --git a/WickedEngine/wiMath.h b/WickedEngine/wiMath.h index 59dd6edc9..f651b1934 100644 --- a/WickedEngine/wiMath.h +++ b/WickedEngine/wiMath.h @@ -38,6 +38,9 @@ namespace wi::math constexpr float saturate(float x) { return std::min(std::max(x, 0.0f), 1.0f); } + template + constexpr T sqr(T x) { return x * x; } + inline float Length(const XMFLOAT2& v) { return std::sqrt(v.x*v.x + v.y*v.y); @@ -340,9 +343,9 @@ namespace wi::math inline XMVECTOR GetQuadraticBezierPos(const XMVECTOR& a, const XMVECTOR& b, const XMVECTOR& c, float t) { // XMVECTOR optimized version - const float param0 = std::pow(1 - t, 2.0f); + const float param0 = sqr(1 - t); const float param1 = 2 * (1 - t) * t; - const float param2 = std::pow(t, 2.0f); + const float param2 = sqr(t); const XMVECTOR param = XMVectorSet(param0, param1, param2, 1); const XMMATRIX M = XMMATRIX(a, b, c, XMVectorSet(0, 0, 0, 1)); return XMVector3TransformNormal(param, M); diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index a707ece72..5bb399cdd 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 71; // minor bug fixes, alterations, refactors, updates - const int revision = 477; + const int revision = 478; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);