public IntPtr RecalculateSpaceForGeom(IntPtr geom, Vector3 pos, IntPtr currentspace)
{
// Called from setting the Position and Size of an ODEPrim so
// it's already in locked space.
// we don't want to remove the main space
// we don't need to test physical here because this function should
// never be called if the prim is physical(active)
if (currentspace != space)
{
if (d.SpaceQuery(currentspace, geom) && currentspace != IntPtr.Zero)
{
if (d.GeomIsSpace(currentspace))
d.SpaceRemove(currentspace, geom);
else
{
MainConsole.Instance.Info("[ODE Physics]: Invalid Scene passed to 'recalculatespace':" +
currentspace +
" Geom:" + geom);
}
}
else
{
IntPtr sGeomIsIn = d.GeomGetSpace(geom);
if (sGeomIsIn != IntPtr.Zero)
{
if (d.GeomIsSpace(currentspace))
d.SpaceRemove(sGeomIsIn, geom);
else
{
MainConsole.Instance.Info("[ODE Physics]: Invalid Scene passed to 'recalculatespace':" +
sGeomIsIn + " Geom:" + geom);
}
}
}
/* don't delete spaces
//If there are no more geometries in the sub-space, we don't need it in the main space anymore
if (d.SpaceGetNumGeoms(currentspace) == 0)
{
if (currentspace != IntPtr.Zero)
{
if (d.GeomIsSpace(currentspace))
{
waitForSpaceUnlock(currentspace);
waitForSpaceUnlock(space);
d.SpaceRemove(space, currentspace);
// free up memory used by the space.
//d.SpaceDestroy(currentspace);
resetSpaceArrayItemToZero(currentspace);
}
else
{
MainConsole.Instance.Info("[ODE Physics]: Invalid Scene passed to 'recalculatespace':" +
currentspace + " Geom:" + geom);
}
}
}
*/
}
else
{
// this is a physical object that got disabled. ;.;
if (currentspace != IntPtr.Zero && geom != IntPtr.Zero)
{
if (d.SpaceQuery(currentspace, geom))
{
if (d.GeomIsSpace(currentspace))
d.SpaceRemove(currentspace, geom);
else
{
MainConsole.Instance.Info("[ODE Physics]: Invalid Scene passed to 'recalculatespace':" +
currentspace + " Geom:" + geom);
}
}
else
{
IntPtr sGeomIsIn = d.GeomGetSpace(geom);
if (sGeomIsIn != IntPtr.Zero)
{
if (d.GeomIsSpace(sGeomIsIn))
d.SpaceRemove(sGeomIsIn, geom);
else
{
MainConsole.Instance.Info("[ODE Physics]: Invalid Scene passed to 'recalculatespace':" +
sGeomIsIn + " Geom:" + geom);
}
}
}
}
}
// The routines in the Position and Size sections do the 'inserting' into the space,
// so all we have to do is make sure that the space that we're putting the prim into
// is in the 'main' space.
// int[] iprimspaceArrItem = calculateSpaceArrayItemFromPos(pos);
IntPtr newspace = CalculateSpaceForGeom(pos);
/* spaces aren't deleted so already created
if (newspace == IntPtr.Zero)
{
newspace = createprimspace(iprimspaceArrItem[0], iprimspaceArrItem[1]);
d.HashSpaceSetLevels(newspace, HashspaceLow, HashspaceHigh);
}
*/
return newspace;
}