internal float SampleField(ref Vector3 position) { Vector3 localPosition = position - m_translation; Vector3I samplePos; Vector2 pos = Vector2.Zero; MyCsgPrecomputedHelpres.CalculateSamplePosition(ref localPosition, out samplePos, ref pos, m_header.Resolution); return(GetValueForPosition(ref samplePos, ref pos, true)); }
private float SignedDistanceInternal(float lodVoxelSize, IMyModule macroModulator, IMyModule detailModulator, ref Vector3 localPosition, float distance) { if (distance > 0.0f) { float signedDistance = distance - m_averageRadius; Vector3I samplePos; Vector2 pos = Vector2.Zero; MyCsgPrecomputedHelpres.CalculateSamplePosition(ref localPosition, out samplePos, ref pos, m_header.Resolution); float value = GetValueForPosition(ref samplePos, ref pos, true); return((signedDistance - value) / lodVoxelSize); } return(0.0f); }
internal override ContainmentType Contains(ref BoundingBox queryAabb, ref BoundingSphere querySphere, float lodVoxelSize) { ContainmentType outerContainment, innerContainment; BoundingSphere sphere = new BoundingSphere( m_translation, m_outerRadius + lodVoxelSize); sphere.Contains(ref queryAabb, out outerContainment); if (outerContainment == ContainmentType.Disjoint) { return(ContainmentType.Disjoint); } sphere.Radius = m_innerRadius - lodVoxelSize; sphere.Contains(ref queryAabb, out innerContainment); if (innerContainment == ContainmentType.Contains) { return(ContainmentType.Contains); } float minDistance = float.MaxValue; float maxDistance = -float.MaxValue; Vector3 localPosition = queryAabb.Min - m_translation; float distance = localPosition.LengthSquared(); if (distance < 0.01f) { return(ContainmentType.Intersects); } Vector3I samplePos; Vector2 pos = Vector2.Zero; MyCsgPrecomputedHelpres.CalculateSamplePosition(ref localPosition, out samplePos, ref pos, m_header.Resolution); float value = GetValueForPosition(ref samplePos, ref pos, true); minDistance = MathHelper.Min(minDistance, value); maxDistance = MathHelper.Max(maxDistance, value); localPosition = queryAabb.Max - m_translation; distance = localPosition.LengthSquared(); if (distance < 0.01f) { return(ContainmentType.Intersects); } MyCsgPrecomputedHelpres.CalculateSamplePosition(ref localPosition, out samplePos, ref pos, m_header.Resolution); value = GetValueForPosition(ref samplePos, ref pos, true); minDistance = MathHelper.Min(minDistance, value); maxDistance = MathHelper.Max(maxDistance, value); sphere.Radius = m_innerRadius + maxDistance + lodVoxelSize; sphere.Contains(ref queryAabb, out outerContainment); if (outerContainment == ContainmentType.Disjoint) { return(ContainmentType.Disjoint); } sphere.Radius = m_innerRadius + minDistance - lodVoxelSize; sphere.Contains(ref queryAabb, out innerContainment); if (innerContainment == ContainmentType.Contains) { return(ContainmentType.Contains); } return(ContainmentType.Intersects); }