diff --git a/Dev/Cpp/Effekseer/Effekseer/Effekseer.Instance.cpp b/Dev/Cpp/Effekseer/Effekseer/Effekseer.Instance.cpp index 2073296f3b..b30c83e74a 100644 --- a/Dev/Cpp/Effekseer/Effekseer/Effekseer.Instance.cpp +++ b/Dev/Cpp/Effekseer/Effekseer/Effekseer.Instance.cpp @@ -231,6 +231,7 @@ void Instance::Initialize(Instance* parent, float spawnDeltaFrame, int32_t insta prevPosition_ = SIMD::Vec3f(0, 0, 0); prevLocalVelocity_ = SIMD::Vec3f(0, 0, 0); + location_modify_global_ = SIMD::Vec3f(0, 0, 0); } void Instance::FirstUpdate() @@ -669,7 +670,6 @@ void Instance::UpdateTransform(float deltaFrame) } localAcc = (steeringVec_ - prevSteering) * deltaFrame * m_pEffectNode->m_effect->GetMaginification(); - localVelocity = steeringVec_; } else { @@ -680,10 +680,10 @@ void Instance::UpdateTransform(float deltaFrame) // TODO : check rotation(It seems has bugs and it can optimize it) localAcc = SIMD::Vec3f::Transform(localAcc, m_GenerationLocation.Get3x3SubMatrix()); } - localVelocity += localAcc; - } + localVelocity += localAcc; + auto matRot = RotationFunctions::CalculateRotation(rotation_values, m_pEffectNode->RotationParam, m_randObject, m_pEffectNode->GetEffect(), m_pContainer->GetRootInstance(), m_LivingTime, m_LivedTime, m_pParent, m_pEffectNode->DynamicFactor, m_pManager->GetLayerParameter(GetInstanceGlobal()->GetLayer()).ViewerPosition); auto scaling = ScalingFunctions::UpdateScaling(scaling_values, m_pEffectNode->ScalingParam, m_randObject, m_pEffectNode->GetEffect(), m_pContainer->GetRootInstance(), m_LivingTime, m_LivedTime, m_pParent, m_pEffectNode->DynamicFactor); @@ -731,8 +731,8 @@ void Instance::UpdateTransform(float deltaFrame) if (m_pEffectNode->LocalForceField.IsGlobalEnabled) { InstanceGlobal* instanceGlobal = m_pContainer->GetRootInstance(); - forceField_.UpdateGlobal(m_pEffectNode->LocalForceField, prevGlobalPosition_, m_pEffectNode->GetEffect()->GetMaginification(), instanceGlobal->GetTargetLocation(), deltaFrame, m_pEffectNode->GetEffect()->GetSetting()->GetCoordinateSystem()); - SIMD::Mat43f MatTraGlobal = SIMD::Mat43f::Translation(forceField_.GlobalModifyLocation); + location_modify_global_ += forceField_.UpdateGlobal(m_pEffectNode->LocalForceField, prevGlobalPosition_, m_pEffectNode->GetEffect()->GetMaginification(), instanceGlobal->GetTargetLocation(), deltaFrame, m_pEffectNode->GetEffect()->GetSetting()->GetCoordinateSystem()); + SIMD::Mat43f MatTraGlobal = SIMD::Mat43f::Translation(location_modify_global_); calcMat *= MatTraGlobal; } diff --git a/Dev/Cpp/Effekseer/Effekseer/Effekseer.Instance.h b/Dev/Cpp/Effekseer/Effekseer/Effekseer.Instance.h index 9c558fba7a..c2d5ba4afb 100644 --- a/Dev/Cpp/Effekseer/Effekseer/Effekseer.Instance.h +++ b/Dev/Cpp/Effekseer/Effekseer/Effekseer.Instance.h @@ -77,6 +77,8 @@ class alignas(16) Instance : public IntrusiveList::Node SIMD::Vec3f steeringVec_; + SIMD::Vec3f location_modify_global_; + public: static const int32_t ChildrenMax = 16; diff --git a/Dev/Cpp/Effekseer/Effekseer/ForceField/ForceFields.cpp b/Dev/Cpp/Effekseer/Effekseer/ForceField/ForceFields.cpp index 905806a017..3b6cabc699 100644 --- a/Dev/Cpp/Effekseer/Effekseer/ForceField/ForceFields.cpp +++ b/Dev/Cpp/Effekseer/Effekseer/ForceField/ForceFields.cpp @@ -365,7 +365,6 @@ SIMD::Vec3f LocalForceFieldInstance::Update(const LocalForceFieldParameter& para std::array accs; accs.fill(SIMD::Vec3f(0, 0, 0)); - for (size_t i = 0; i < parameter.LocalForceFields.size(); i++) { auto& field = parameter.LocalForceFields[i]; @@ -474,11 +473,19 @@ SIMD::Vec3f LocalForceFieldInstance::Update(const LocalForceFieldParameter& para return acc_sum * deltaFrame; } -void LocalForceFieldInstance::UpdateGlobal(const LocalForceFieldParameter& parameter, const SIMD::Vec3f& location, float magnification, const SIMD::Vec3f& targetPosition, float deltaFrame, CoordinateSystem coordinateSystem) +SIMD::Vec3f LocalForceFieldInstance::UpdateGlobal(const LocalForceFieldParameter& parameter, const SIMD::Vec3f& location, float magnification, const SIMD::Vec3f& targetPosition, float deltaFrame, CoordinateSystem coordinateSystem) { if (deltaFrame == 0.0f) { - return; + return SIMD::Vec3f(0, 0, 0); + } + + SIMD::Vec3f velocity_sum_prev = SIMD::Vec3f(0, 0, 0); + for (size_t i = 0; i < parameter.LocalForceFields.size(); i++) + { + if (!parameter.LocalForceFields[i].IsGlobal) + continue; + velocity_sum_prev += Velocities[i]; } for (size_t i = 0; i < parameter.LocalForceFields.size(); i++) @@ -495,7 +502,7 @@ void LocalForceFieldInstance::UpdateGlobal(const LocalForceFieldParameter& param ForceFieldCommonParameter ffcp; ffcp.FieldCenter = parameter.LocalForceFields[i].Position; ffcp.Position = location / magnification; - ffcp.PreviousSumVelocity = GlobalVelocitySum / magnification; + ffcp.PreviousSumVelocity = velocity_sum_prev / magnification; ffcp.PreviousVelocity = Velocities[i] / magnification; ffcp.TargetPosition = targetPosition / magnification; ffcp.DeltaFrame = deltaFrame; @@ -564,24 +571,20 @@ void LocalForceFieldInstance::UpdateGlobal(const LocalForceFieldParameter& param Velocities[i] += acc; } - GlobalVelocitySum = SIMD::Vec3f(0, 0, 0); - + SIMD::Vec3f velocity_sum = SIMD::Vec3f(0, 0, 0); for (size_t i = 0; i < parameter.LocalForceFields.size(); i++) { if (!parameter.LocalForceFields[i].IsGlobal) continue; - - GlobalVelocitySum += Velocities[i]; + velocity_sum += Velocities[i]; } - GlobalModifyLocation += GlobalVelocitySum * deltaFrame; + return velocity_sum * deltaFrame; } void LocalForceFieldInstance::Reset() { Velocities.fill(SIMD::Vec3f(0, 0, 0)); - GlobalVelocitySum = SIMD::Vec3f(0, 0, 0); - GlobalModifyLocation = SIMD::Vec3f(0, 0, 0); } } // namespace Effekseer \ No newline at end of file diff --git a/Dev/Cpp/Effekseer/Effekseer/ForceField/ForceFields.h b/Dev/Cpp/Effekseer/Effekseer/ForceField/ForceFields.h index e1bc6fdb77..6ce2a3129d 100644 --- a/Dev/Cpp/Effekseer/Effekseer/ForceField/ForceFields.h +++ b/Dev/Cpp/Effekseer/Effekseer/ForceField/ForceFields.h @@ -433,12 +433,9 @@ struct LocalForceFieldInstance { std::array Velocities; - SIMD::Vec3f GlobalVelocitySum; - SIMD::Vec3f GlobalModifyLocation; - SIMD::Vec3f Update(const LocalForceFieldParameter& parameter, const SIMD::Vec3f& location, const SIMD::Vec3f& local_velocity_per_update, float magnification, float deltaFrame, CoordinateSystem coordinateSystem); - void UpdateGlobal(const LocalForceFieldParameter& parameter, const SIMD::Vec3f& location, float magnification, const SIMD::Vec3f& targetPosition, float deltaTime, CoordinateSystem coordinateSystem); + SIMD::Vec3f UpdateGlobal(const LocalForceFieldParameter& parameter, const SIMD::Vec3f& location, float magnification, const SIMD::Vec3f& targetPosition, float deltaTime, CoordinateSystem coordinateSystem); void Reset(); };