Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
durswd committed Aug 27, 2023
1 parent b0c5cdd commit cd0bf5e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
10 changes: 5 additions & 5 deletions Dev/Cpp/Effekseer/Effekseer/Effekseer.Instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -669,7 +670,6 @@ void Instance::UpdateTransform(float deltaFrame)
}

localAcc = (steeringVec_ - prevSteering) * deltaFrame * m_pEffectNode->m_effect->GetMaginification();
localVelocity = steeringVec_;
}
else
{
Expand All @@ -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);

Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions Dev/Cpp/Effekseer/Effekseer/Effekseer.Instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class alignas(16) Instance : public IntrusiveList<Instance>::Node

SIMD::Vec3f steeringVec_;

SIMD::Vec3f location_modify_global_;

public:
static const int32_t ChildrenMax = 16;

Expand Down
25 changes: 14 additions & 11 deletions Dev/Cpp/Effekseer/Effekseer/ForceField/ForceFields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ SIMD::Vec3f LocalForceFieldInstance::Update(const LocalForceFieldParameter& para
std::array<SIMD::Vec3f, LocalFieldSlotMax> accs;
accs.fill(SIMD::Vec3f(0, 0, 0));


for (size_t i = 0; i < parameter.LocalForceFields.size(); i++)
{
auto& field = parameter.LocalForceFields[i];
Expand Down Expand Up @@ -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++)
Expand All @@ -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;
Expand Down Expand Up @@ -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
5 changes: 1 addition & 4 deletions Dev/Cpp/Effekseer/Effekseer/ForceField/ForceFields.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,9 @@ struct LocalForceFieldInstance
{
std::array<SIMD::Vec3f, LocalFieldSlotMax> 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();
};
Expand Down

0 comments on commit cd0bf5e

Please sign in to comment.