public static bool GetShapeCenter(HkShape shape, uint shapeKey, MyCubeGrid grid, ref Vector3D shapeCenter) { bool shapeSet = true; switch (shape.ShapeType) { case HkShapeType.List: var listShape = (HkListShape)shape; shape = listShape.GetChildByIndex((int)shapeKey); break; case HkShapeType.Mopp: var moppShape = (HkMoppBvTreeShape)shape; shape = moppShape.ShapeCollection.GetShape(shapeKey, null); break; case HkShapeType.Box: var boxShape = (HkBoxShape)shape; shape = boxShape; break; case HkShapeType.ConvexTranslate: var convexTranslateShape = (HkConvexShape)shape; shape = convexTranslateShape; break; case HkShapeType.ConvexTransform: var convexTransformShape = (HkConvexTransformShape)shape; shape = convexTransformShape; break; /* case HkShapeType.BvTree: * var bvTreeShape = (HkBvTreeShape)shape; * var iterator = bvTreeShape.Base.GetContainer(); * while (iterator.CurrentValue.IsContainer() && iterator.CurrentValue.ShapeType != HkShapeType.ConvexTranslate && iterator.CurrentValue.ShapeType != HkShapeType.ConvexTransform) * iterator.Next(); * if (iterator.IsValid) * shape = iterator.CurrentValue; * else * shapeSet = false; * break;*/ default: shapeSet = false; break; } if (shapeSet) { Vector4 min4, max4; shape.GetLocalAABB(0.05f, out min4, out max4); Vector3 worldMin = Vector3.Transform(new Vector3(min4), grid.PositionComp.WorldMatrix); Vector3 worldMax = Vector3.Transform(new Vector3(max4), grid.PositionComp.WorldMatrix); var worldAABB = new BoundingBoxD(worldMin, worldMax); shapeCenter = worldAABB.Center; } return(shapeSet); }
public static bool GetShapeCenter(HkShape shape, uint shapeKey, MyCubeGrid grid, ref Vector3D shapeCenter) { return false; //Disabled because of bad computing shapeCenter in relation with grid (alway around grid center). //Called on grid part which has havok shape (only door?). bool shapeSet = true; switch (shape.ShapeType) { case HkShapeType.List: var listShape = (HkListShape)shape; shape = listShape.GetChildByIndex((int)shapeKey); break; case HkShapeType.Mopp: var moppShape = (HkMoppBvTreeShape)shape; shape = moppShape.ShapeCollection.GetShape(shapeKey, null); break; case HkShapeType.Box: var boxShape = (HkBoxShape)shape; shape = boxShape; break; case HkShapeType.ConvexTranslate: var convexTranslateShape = (HkConvexShape)shape; shape = convexTranslateShape; break; case HkShapeType.ConvexTransform: var convexTransformShape = (HkConvexTransformShape)shape; shape = convexTransformShape; break; /* case HkShapeType.BvTree: var bvTreeShape = (HkBvTreeShape)shape; var iterator = bvTreeShape.Base.GetContainer(); while (iterator.CurrentValue.IsContainer() && iterator.CurrentValue.ShapeType != HkShapeType.ConvexTranslate && iterator.CurrentValue.ShapeType != HkShapeType.ConvexTransform) iterator.Next(); if (iterator.IsValid) shape = iterator.CurrentValue; else shapeSet = false; break;*/ default: shapeSet = false; break; } if (shapeSet) { Vector4 min4, max4; shape.GetLocalAABB(0.05f, out min4, out max4); Vector3 worldMin = Vector3.Transform(new Vector3(min4), grid.PositionComp.WorldMatrix); Vector3 worldMax = Vector3.Transform(new Vector3(max4), grid.PositionComp.WorldMatrix); var worldAABB = new BoundingBoxD(worldMin, worldMax); shapeCenter = worldAABB.Center; } return shapeSet; }
public static bool GetShapeCenter(HkShape shape, int shapeKey, MyCubeGrid grid, ref Vector3D shapeCenter) { bool shapeSet = true; switch (shape.ShapeType) { case HkShapeType.List: var listShape = (HkListShape)shape; shape = listShape.GetChildByIndex(shapeKey); break; case HkShapeType.Mopp: var moppShape = (HkMoppBvTreeShape)shape; shape = moppShape.ShapeCollection.GetShape((uint)shapeKey, null); break; case HkShapeType.Box: var boxShape = (HkBoxShape)shape; shape = boxShape; break; case HkShapeType.ConvexTranslate: var convexTranslateShape = (HkConvexShape)shape; shape = convexTranslateShape; break; case HkShapeType.ConvexTransform: var convexTransformShape = (HkConvexTransformShape)shape; shape = convexTransformShape; break; default: shapeSet = false; break; } if (shapeSet) { Vector4 min4, max4; shape.GetLocalAABB(0.05f, out min4, out max4); Vector3 worldMin = Vector3.Transform(new Vector3(min4), grid.PositionComp.WorldMatrix); Vector3 worldMax = Vector3.Transform(new Vector3(max4), grid.PositionComp.WorldMatrix); var worldAABB = new BoundingBoxD(worldMin, worldMax); shapeCenter = worldAABB.Center; } return(shapeSet); }
public static bool GetShapeCenter(HkShape shape, int shapeKey, MyCubeGrid grid, ref Vector3D shapeCenter) { bool shapeSet = true; switch (shape.ShapeType) { case HkShapeType.List: var listShape = (HkListShape)shape; shape = listShape.GetChildByIndex(shapeKey); break; case HkShapeType.Mopp: var moppShape = (HkMoppBvTreeShape)shape; shape = moppShape.ShapeCollection.GetShape((uint)shapeKey, null); break; case HkShapeType.Box: var boxShape = (HkBoxShape)shape; shape = boxShape; break; case HkShapeType.ConvexTranslate: var convexTranslateShape = (HkConvexShape)shape; shape = convexTranslateShape; break; case HkShapeType.ConvexTransform: var convexTransformShape = (HkConvexTransformShape)shape; shape = convexTransformShape; break; default: shapeSet = false; break; } if (shapeSet) { Vector4 min4, max4; shape.GetLocalAABB(0.05f, out min4, out max4); Vector3 worldMin = Vector3.Transform(new Vector3(min4), grid.PositionComp.WorldMatrix); Vector3 worldMax = Vector3.Transform(new Vector3(max4), grid.PositionComp.WorldMatrix); var worldAABB = new BoundingBoxD(worldMin, worldMax); shapeCenter = worldAABB.Center; } return shapeSet; }