Skip to content

Commit

Permalink
TCAGuiEditor: improved performance of update_mass_and_CoM, _inertia_t…
Browse files Browse the repository at this point in the history
…ensor

Related to #95 #94
  • Loading branch information
allista committed Jul 29, 2020
1 parent d86b2f0 commit fe1176d
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions GUI/TCAGuiEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ void update_inertia_tensor(Part part)
if(!EditorLogic.RootPart) return;
var partMass = part.mass;
if(use_wet_mass) partMass += part.GetResourceMass();
var T = part.transform;
Vector3 partPosition = EditorLogic.RootPart.transform
.InverseTransformDirection(part.transform.position + part.transform.rotation * part.CoMOffset - CoM);
.InverseTransformDirection(T.position + T.rotation * part.CoMOffset - CoM);
for(int i = 0; i < 3; i++)
{
InertiaTensor.Add(i, i, partMass * partPosition.sqrMagnitude);
Expand All @@ -203,11 +204,20 @@ void update_mass_and_CoM(Part part)
var wetMass = dryMass + part.GetResourceMass();
Vector3 pos = Vector3.zero;
if(part.physicalSignificance == Part.PhysicalSignificance.FULL)
pos = part.transform.position + part.transform.rotation * part.CoMOffset;
{
var T = part.transform;
pos = T.position + T.rotation * part.CoMOffset;
}
else if(part.parent != null)
pos = part.parent.transform.position + part.parent.transform.rotation * part.parent.CoMOffset;
{
var T = part.parent.transform;
pos = T.position + T.rotation * part.parent.CoMOffset;
}
else if(part.potentialParent != null)
pos = part.potentialParent.transform.position + part.potentialParent.transform.rotation * part.potentialParent.CoMOffset;
{
var T = part.potentialParent.transform;
pos = T.position + T.rotation * part.potentialParent.CoMOffset;
}
WetCoM += pos * wetMass;
DryCoM += pos * dryMass;
WetMass += wetMass;
Expand Down

0 comments on commit fe1176d

Please sign in to comment.