Very funny thing... When I shift CoG, my meshes start physically deforming. Note emphasis on my meshes, that is, the ones I made. The ones GregBurch made don't seem to mind being pushed around...
I have clearly identified the problem as moving the attachment points, as I have written a ShiftCG replacement that handles the whole moving around by itself to see if ShiftCG messes up something somewhere. The problem persists with my own method and with ShiftCG just the same. ShiftCenterOfMass and ShiftMeshes don't cause the problem, but as soon as I move attachment points it comes jumping out. It is also not caused when the vessel is merely docked, it has to be attached.
Here's a screen of the problem. Note that those tanks are supposed to be the same, but everytime ShiftCG is called, o matter how small an ammount is shifted, they start deforming in a regular pattern, that is they revert to their original state eventually to start their dance anew.
If you look at the location indicators, you can see that it is not just the mesh that deforms. The whole vessel scales, its own CoG shifting to stay in the center. As such, it's position changes, as I could confirm with a few readings. If the tanks are undocked, they stay in their current deformation, but revert to original on SQL.
Now, as I said, this seems to only happen with my meshes. Since we once had a case of a mesh modifying another mesh in memory by its sheer existance, my first guess would be that something with my mesh is not in order, but I have no Idea where to start looking. A zip with the mesh is attached in case anyone wants to take a look at it, or maybe someone is already familiar with such problems.
Here is the function I use for CoG shifting, in case someone wants to take a look at that, but there's really not much to see. If I comment out the ShiftCG line, the problem does not occur. If I enter my own methods and don't do the attachment point shifting, the problem does not occur.
I have clearly identified the problem as moving the attachment points, as I have written a ShiftCG replacement that handles the whole moving around by itself to see if ShiftCG messes up something somewhere. The problem persists with my own method and with ShiftCG just the same. ShiftCenterOfMass and ShiftMeshes don't cause the problem, but as soon as I move attachment points it comes jumping out. It is also not caused when the vessel is merely docked, it has to be attached.
Here's a screen of the problem. Note that those tanks are supposed to be the same, but everytime ShiftCG is called, o matter how small an ammount is shifted, they start deforming in a regular pattern, that is they revert to their original state eventually to start their dance anew.
If you look at the location indicators, you can see that it is not just the mesh that deforms. The whole vessel scales, its own CoG shifting to stay in the center. As such, it's position changes, as I could confirm with a few readings. If the tanks are undocked, they stay in their current deformation, but revert to original on SQL.
Now, as I said, this seems to only happen with my meshes. Since we once had a case of a mesh modifying another mesh in memory by its sheer existance, my first guess would be that something with my mesh is not in order, but I have no Idea where to start looking. A zip with the mesh is attached in case anyone wants to take a look at it, or maybe someone is already familiar with such problems.
Here is the function I use for CoG shifting, in case someone wants to take a look at that, but there's really not much to see. If I comment out the ShiftCG line, the problem does not occur. If I enter my own methods and don't do the attachment point shifting, the problem does not occur.
Code:
void IMS::SetCenterOfGravity(bool SetToZero)
{
if (SetToZero)
{
ShiftCG(centerOfGravity * -1);
centerOfGravity = _V(0,0,0);
massCenter = _V(0,0,0);
return;
}
VECTOR3 oldCoG = centerOfGravity;
VECTOR3 NewCOG = _V(0,0,0);
vector<int> ignoreX;
vector<int> ignoreY;
RefreshLoadedMass();
for (UINT i = 0; i < modules.size(); ++i)
//sieves through the modules and marks up modules that are in symetrical position on at least one axis with equal mass
{
//ignore modules close to 0,0,x for x+y axes
if (IsNear(modules[i]->pos.x, 0.0, 0.1))
{
ignoreX.push_back(i);
}
if (IsNear(modules[i]->pos.y, 0.0, 0.1))
{
ignoreY.push_back(i);
}
//check for symmetry in x+y axes
for (UINT j = i + 1; j < modules.size(); ++j)
{
if (IsNear(modules[i]->config.mass + modules[i]->loadedMass, modules[j]->config.mass + modules[j]->loadedMass, 0.01))
{
if (IsNear(modules[i]->pos.x * -1, modules[j]->pos.x, 0.1) &&
IsNear(modules[i]->pos.y * -1, modules[j]->pos.y, 0.1))
{
ignoreX.push_back(i);
ignoreX.push_back(j);
ignoreY.push_back(i);
ignoreY.push_back(j);
}
}
}
}
double runningMass = cmParams.config.mass + cmParams.loadedMass;
for (UINT i = 0; i < modules.size(); ++i)
{
bool _ignoreX = false;
bool _ignoreY = false;
VECTOR3 modPos = modules[i]->pos;
RoundVector(modPos);
modPos -= NewCOG;
for (UINT j = 0; j < ignoreX.size(); ++j)
{
if (ignoreX[j] == i)
{
_ignoreX = true;
break;
}
}
for (UINT j = 0; j < ignoreY.size(); ++j)
{
if (ignoreY[j] == i)
{
_ignoreY = true;
break;
}
}
if (!_ignoreX)
{
NewCOG.x = ((NewCOG.x * runningMass) + (modPos.x * (modules[i]->config.mass + modules[i]->loadedMass))) / (runningMass + modules[i]->config.mass + modules[i]->loadedMass);
}
if (!_ignoreY)
{
NewCOG.y = ((NewCOG.y * runningMass) + (modPos.y * (modules[i]->config.mass + modules[i]->loadedMass))) / (runningMass + modules[i]->config.mass + modules[i]->loadedMass);
}
if (!IsNear(NewCOG.z, modPos.z, 0.1))
{
NewCOG.z = ((NewCOG.z * runningMass) + (modPos.z * (modules[i]->config.mass + modules[i]->loadedMass))) / (runningMass + modules[i]->config.mass + modules[i]->loadedMass);
}
runningMass += modules[i]->config.mass + modules[i]->loadedMass;
}
centerOfGravity = NewCOG;
massCenter = NewCOG;
ShiftCG(centerOfGravity - oldCoG);
RedefineAirlockParams(SelectedAirlock);
AdjustThrusters();
}