Example #1
0
        /**
         * Get the height for a position using the coefficient cache. Calculated position is for LOD0.
         */
        public double GetDistanceToSurfaceCacheless(Vector3 localPos)
        {
            float length = localPos.Length();

            if (length.IsZero())
            {
                Debug.Fail("Cannot project to surface from the center of the planet!");
                return(0);
            }

            if (!length.IsValid())
            {
                Debug.Fail("Cannot project from such number!");
                return(0);
            }

            int     face;
            Vector2 tex;

            MyCubemapHelpers.CalculateSampleTexcoord(ref localPos, out face, out tex);

            Vector3 norm;
            float   value = GetValueForPositionCacheless(face, ref tex, out norm);

            value += Radius;

            return(length - value);
        }
Example #2
0
        public void GetPositionParams(ref Vector3 pos, float lodSize, out MaterialSampleParams ps, bool skipCache = false)
        {
            Vector3 localPos = pos - this.m_planetShape.Center();

            ps.DistanceToCenter = localPos.Length();
            ps.LodSize          = lodSize;
            if (ps.DistanceToCenter < 0.01f)
            {
                ps.SurfaceDepth  = 0f;
                ps.Gravity       = Vector3.Down;
                ps.Latitude      = 0f;
                ps.Longitude     = 0f;
                ps.Texcoord      = Vector2.One / 2f;
                ps.Face          = 0;
                ps.Normal        = Vector3.Backward;
                ps.SampledHeight = 0f;
            }
            else
            {
                ps.Gravity = localPos / ps.DistanceToCenter;
                MyCubemapHelpers.CalculateSampleTexcoord(ref localPos, out ps.Face, out ps.Texcoord);
                ps.SampledHeight = !skipCache?this.m_planetShape.GetValueForPositionWithCache(ps.Face, ref ps.Texcoord, out ps.Normal) : this.m_planetShape.GetValueForPositionCacheless(ps.Face, ref ps.Texcoord, out ps.Normal);

                ps.SurfaceDepth = this.m_planetShape.SignedDistanceWithSample(lodSize, ps.DistanceToCenter, ps.SampledHeight) * ps.Normal.Z;
                ps.Latitude     = ps.Gravity.Y;
                Vector2 vector2 = new Vector2(-ps.Gravity.X, -ps.Gravity.Z);
                vector2.Normalize();
                ps.Longitude = vector2.Y;
                if (-ps.Gravity.X > 0f)
                {
                    ps.Longitude = 2f - ps.Longitude;
                }
            }
        }
Example #3
0
        public void PrepareSides()
        {
            int x = this.m_resolution - 1;

            this.Front.CopyRange(new Vector2I(0, -1), new Vector2I(x, -1), this.Top, new Vector2I(0, x), new Vector2I(x, x));
            this.Front.CopyRange(new Vector2I(0, this.m_resolution), new Vector2I(x, this.m_resolution), this.Bottom, new Vector2I(x, x), new Vector2I(0, x));
            this.Front.CopyRange(new Vector2I(-1, 0), new Vector2I(-1, x), this.Left, new Vector2I(x, 0), new Vector2I(x, x));
            this.Front.CopyRange(new Vector2I(this.m_resolution, 0), new Vector2I(this.m_resolution, x), this.Right, new Vector2I(0, 0), new Vector2I(0, x));
            this.Back.CopyRange(new Vector2I(x, -1), new Vector2I(0, -1), this.Top, new Vector2I(0, 0), new Vector2I(x, 0));
            this.Back.CopyRange(new Vector2I(x, this.m_resolution), new Vector2I(0, this.m_resolution), this.Bottom, new Vector2I(x, 0), new Vector2I(0, 0));
            this.Back.CopyRange(new Vector2I(-1, 0), new Vector2I(-1, x), this.Right, new Vector2I(x, 0), new Vector2I(x, x));
            this.Back.CopyRange(new Vector2I(this.m_resolution, 0), new Vector2I(this.m_resolution, x), this.Left, new Vector2I(0, 0), new Vector2I(0, x));
            this.Left.CopyRange(new Vector2I(x, -1), new Vector2I(0, -1), this.Top, new Vector2I(0, x), new Vector2I(0, 0));
            this.Left.CopyRange(new Vector2I(x, this.m_resolution), new Vector2I(0, this.m_resolution), this.Bottom, new Vector2I(x, x), new Vector2I(x, 0));
            this.Left.CopyRange(new Vector2I(this.m_resolution, 0), new Vector2I(this.m_resolution, x), this.Front, new Vector2I(0, 0), new Vector2I(0, x));
            this.Left.CopyRange(new Vector2I(-1, 0), new Vector2I(-1, x), this.Back, new Vector2I(x, 0), new Vector2I(x, x));
            this.Right.CopyRange(new Vector2I(x, -1), new Vector2I(0, -1), this.Top, new Vector2I(x, 0), new Vector2I(x, x));
            this.Right.CopyRange(new Vector2I(x, this.m_resolution), new Vector2I(0, this.m_resolution), this.Bottom, new Vector2I(0, 0), new Vector2I(0, x));
            this.Right.CopyRange(new Vector2I(this.m_resolution, 0), new Vector2I(this.m_resolution, x), this.Back, new Vector2I(0, 0), new Vector2I(0, x));
            this.Right.CopyRange(new Vector2I(-1, 0), new Vector2I(-1, x), this.Front, new Vector2I(x, 0), new Vector2I(x, x));
            this.Top.CopyRange(new Vector2I(0, this.m_resolution), new Vector2I(x, this.m_resolution), this.Front, new Vector2I(0, 0), new Vector2I(x, 0));
            this.Top.CopyRange(new Vector2I(0, -1), new Vector2I(x, -1), this.Back, new Vector2I(x, 0), new Vector2I(0, 0));
            this.Top.CopyRange(new Vector2I(this.m_resolution, 0), new Vector2I(this.m_resolution, x), this.Right, new Vector2I(x, 0), new Vector2I(0, 0));
            this.Top.CopyRange(new Vector2I(-1, 0), new Vector2I(-1, x), this.Left, new Vector2I(0, 0), new Vector2I(x, 0));
            this.Bottom.CopyRange(new Vector2I(0, this.m_resolution), new Vector2I(x, this.m_resolution), this.Front, new Vector2I(x, x), new Vector2I(0, x));
            this.Bottom.CopyRange(new Vector2I(0, -1), new Vector2I(x, -1), this.Back, new Vector2I(0, x), new Vector2I(x, x));
            this.Bottom.CopyRange(new Vector2I(-1, 0), new Vector2I(-1, x), this.Right, new Vector2I(x, x), new Vector2I(0, x));
            this.Bottom.CopyRange(new Vector2I(this.m_resolution, 0), new Vector2I(this.m_resolution, x), this.Left, new Vector2I(0, x), new Vector2I(x, x));
            for (int i = 0; i < 6; i++)
            {
                this.Faces[i].FinishFace($"{this.Name}_{MyCubemapHelpers.GetNameForFace(i)}");
            }
        }
Example #4
0
        internal float SignedDistanceLocalCacheless(Vector3 position)
        {
            float distance = position.Length();

            if (distance > .1 && distance >= InnerRadius - 1)
            {
                if (distance > OuterRadius + 1)
                {
                    return(float.PositiveInfinity);
                }

                float   signedDistance = distance - m_radius;
                int     face;
                Vector2 tex;
                MyCubemapHelpers.CalculateSampleTexcoord(ref position, out face, out tex);

                Vector3 normal;

                float value = GetValueForPositionCacheless(face, ref tex, out normal);

                if (m_detail.Matches(normal.Z))
                {
                    float dtx = tex.X * m_detail.Factor;
                    float dty = tex.Y * m_detail.Factor;

                    dtx -= (float)Math.Floor(dtx);
                    dty -= (float)Math.Floor(dty);

                    value += m_detail.GetValue(dtx, dty, normal.Z);
                }

                return((signedDistance - value) * normal.Z);
            }
            return(-1);
        }
Example #5
0
        private byte GetOcclusionForPosition(ref Vector3 localPos, float lodVoxelSize)
        {
            int     face;
            Vector2 texcoord;

            Vector3 localPosition    = localPos - m_planetShape.Center();
            var     distanceToCenter = localPosition.Length();

            MyCubemapHelpers.CalculateSampleTexcoord(ref localPosition, out face, out texcoord);

            Vector3 normal;
            float   sampledHeight = m_planetShape.GetValueForPositionWithCache(face, ref texcoord, out normal);

            var surfaceDepth = m_planetShape.SignedDistanceWithSample(lodVoxelSize, distanceToCenter, sampledHeight) * normal.Z;

            if (m_occlusionMap != null && surfaceDepth > -(lodVoxelSize * 1.5f))
            {
                if (m_biomePixelSize < lodVoxelSize)
                {
                    return(m_occlusionMap[face].GetValue(texcoord.X, texcoord.Y));
                }
                else
                {
                    return(ComputeMapBlend(texcoord, face, ref m_occlusionBC,
                                           m_occlusionMap[face]));
                }
            }

            return(0);
        }
Example #6
0
        internal float SignedDistanceLocal(Vector3 position, float lodVoxelSize)
        {
            float distance = position.Length();

            if (distance > .1 && distance >= InnerRadius - lodVoxelSize)
            {
                if (distance > OuterRadius + lodVoxelSize)
                {
                    return(float.PositiveInfinity);
                }

                float   signedDistance = distance - m_radius;
                int     face;
                Vector2 tex;
                MyCubemapHelpers.CalculateSampleTexcoord(ref position, out face, out tex);

                Vector3 Norm;

                float value = GetValueForPositionInternal(face, ref tex, lodVoxelSize, distance, out Norm);

                if (m_detail.Matches(Norm.Z))
                {
                    float dtx = tex.X * m_detail.Factor;
                    float dty = tex.Y * m_detail.Factor;

                    dtx -= (float)Math.Floor(dtx);
                    dty -= (float)Math.Floor(dty);

                    value += m_detail.GetValue(dtx, dty, Norm.Z);
                }

                return((signedDistance - value) * Norm.Z);
            }
            return(-lodVoxelSize);
        }
Example #7
0
 public Vector3 GetColorShift(Vector3 position, byte material, float maxDepth = 1f)
 {
     if (maxDepth >= 1f)
     {
         int                       num;
         Vector2                   vector2;
         List <PlanetOre>          list;
         MyVoxelMaterialDefinition voxelMaterialDefinition = MyDefinitionManager.Static.GetVoxelMaterialDefinition(material);
         if ((voxelMaterialDefinition == null) || (voxelMaterialDefinition.ColorKey == null))
         {
             return(Vector3.Zero);
         }
         MyCubemapHelpers.CalculateSampleTexcoord(ref position - this.m_planetShape.Center(), out num, out vector2);
         if (this.m_oreMap == null)
         {
             return(Vector3.Zero);
         }
         byte key = this.m_oreMap.Faces[num].GetValue(vector2.X, vector2.Y);
         if (!this.m_ores.TryGetValue(key, out list))
         {
             return(Vector3.Zero);
         }
         float num3 = (float)MathHelper.Saturate(this.m_perlin.GetValue((double)(vector2.X * 1000f), (double)(vector2.Y * 1000f), 0.0));
         using (List <PlanetOre> .Enumerator enumerator = list.GetEnumerator())
         {
             while (true)
             {
                 if (!enumerator.MoveNext())
                 {
                     break;
                 }
                 PlanetOre current        = enumerator.Current;
                 float     colorInfluence = current.ColorInfluence;
                 colorInfluence = 256f;
                 if ((colorInfluence >= 1f) && ((colorInfluence >= current.Start) && ((current.Start <= maxDepth) && (current.TargetColor != null))))
                 {
                     Vector3 targetShift = current.TargetColor.Value;
                     Color   violet      = Color.Violet;
                     if (targetShift == Vector3.Backward)
                     {
                         targetShift = new Vector3(0f, 1f, -0.08f);
                     }
                     else
                     {
                         targetShift = this.m_targetShift;
                     }
                     return((Vector3)((num3 * targetShift) * (1f - (current.Start / colorInfluence))));
                 }
             }
         }
     }
     return(Vector3.Zero);
 }
Example #8
0
        public double GetDistanceToSurfaceWithCache(Vector3 localPos)
        {
            int     num2;
            Vector2 vector;
            Vector3 vector2;
            float   f = localPos.Length();

            if (f.IsZero(0.0001f))
            {
                return(0.0);
            }
            MyCubemapHelpers.CalculateSampleTexcoord(ref localPos, out num2, out vector);
            return((double)(f - (this.GetValueForPositionWithCache(num2, ref vector, out vector2) + this.Radius)));
        }
Example #9
0
        public void CopyRange(Vector2I start, Vector2I end, MyCubemapData <T> other, Vector2I oStart, Vector2I oEnd)
        {
            Vector2I myStep = MyCubemapHelpers.GetStep(ref start, ref end);
            Vector2I oStep  = MyCubemapHelpers.GetStep(ref oStart, ref oEnd);
            T        val;

            for (; start != end; start += myStep, oStart += oStep)
            {
                other.GetValue(oStart.X, oStart.Y, out val);
                SetValue(start.X, start.Y, ref val);
            }

            other.GetValue(oStart.X, oStart.Y, out val);
            SetValue(start.X, start.Y, ref val);
        }
Example #10
0
        /**
         * Takes the x and y bounds of the box and queries the heightmap for the minimum and maximum height in the box.
         *
         * The values are returned in the query box itself as the Z bounds.
         *
         * This only works if all vertices of the box are in the same face.
         */
        public unsafe void GetBounds(ref BoundingBox box)
        {
            int      firstFace = -1;
            Vector3 *corners   = stackalloc Vector3[8];

            box.GetCornersUnsafe(corners);

            for (int i = 0; i < 8; ++i)
            {
                int face;
                MyCubemapHelpers.GetCubeFace(ref corners[i], out face);

                if (firstFace == -1)
                {
                    firstFace = face;
                }
            }

            BoundingBox query = new BoundingBox(new Vector3(float.PositiveInfinity, float.PositiveInfinity, 0), new Vector3(float.NegativeInfinity, float.NegativeInfinity, 0));

            for (int i = 0; i < 8; ++i)
            {
                Vector2 tex;
                MyCubemapHelpers.CalculateTexcoordForFace(ref corners[i], firstFace, out tex);

                if (tex.X < query.Min.X)
                {
                    query.Min.X = tex.X;
                }
                if (tex.X > query.Max.X)
                {
                    query.Max.X = tex.X;
                }
                if (tex.Y < query.Min.Y)
                {
                    query.Min.Y = tex.Y;
                }
                if (tex.Y > query.Max.Y)
                {
                    query.Max.Y = tex.Y;
                }
            }

            m_heightmap.Faces[firstFace].GetBounds(ref query);

            box.Min.Z = query.Min.Z * m_heightRatio + InnerRadius;
            box.Max.Z = query.Max.Z * m_heightRatio + InnerRadius;
        }
Example #11
0
        public void GetPositionParams(ref Vector3 pos, float lodSize, out MaterialSampleParams ps, bool skipCache = false)
        {
            Vector3 localPosition = pos - m_planetShape.Center();

            ps.DistanceToCenter = localPosition.Length();

            ps.LodSize = lodSize;

            if (ps.DistanceToCenter < 0.01f)
            {
                ps.SurfaceDepth  = 0;
                ps.Gravity       = Vector3.Down;
                ps.Latitude      = 0;
                ps.Longitude     = 0;
                ps.Texcoord      = Vector2.One / 2;
                ps.Face          = 0;
                ps.Normal        = Vector3.Backward;
                ps.SampledHeight = 0;
                return;
            }

            ps.Gravity = localPosition / ps.DistanceToCenter;

            MyCubemapHelpers.CalculateSampleTexcoord(ref localPosition, out ps.Face, out ps.Texcoord);

            // this guarantess texcoord in [0,1)
            if (skipCache)
            {
                ps.SampledHeight = m_planetShape.GetValueForPositionCacheless(ps.Face, ref ps.Texcoord, out ps.Normal);
            }
            else
            {
                ps.SampledHeight = m_planetShape.GetValueForPositionWithCache(ps.Face, ref ps.Texcoord, out ps.Normal);
            }

            ps.SurfaceDepth = m_planetShape.SignedDistanceWithSample(lodSize, ps.DistanceToCenter, ps.SampledHeight) * ps.Normal.Z;
            ps.Latitude     = ps.Gravity.Y;

            Vector2 lon = new Vector2(-ps.Gravity.X, -ps.Gravity.Z);

            lon.Normalize();

            ps.Longitude = lon.Y;
            if (-ps.Gravity.X > 0)
            {
                ps.Longitude = 2 - ps.Longitude;
            }
        }
Example #12
0
        public void CopyRange(Vector2I start, Vector2I end, MyCubemapData <TPixel> other, Vector2I oStart, Vector2I oEnd)
        {
            TPixel   local;
            Vector2I step     = MyCubemapHelpers.GetStep(ref start, ref end);
            Vector2I vectori2 = MyCubemapHelpers.GetStep(ref oStart, ref oEnd);

            while (start != end)
            {
                other.GetValue(oStart.X, oStart.Y, out local);
                this.SetValue(start.X, start.Y, ref local);
                start  += step;
                oStart += vectori2;
            }
            other.GetValue(oStart.X, oStart.Y, out local);
            this.SetValue(start.X, start.Y, ref local);
        }
Example #13
0
        public bool IntersectLineFace(ref LineD ll, int face, out double startOffset, out double endOffset)
        {
            Vector2 start, end;
            Vector3 from, to;

            from = ll.From;
            to   = ll.To;

            MyCubemapHelpers.CalculateTexcoordForFace(ref from, face, out start);
            MyCubemapHelpers.CalculateTexcoordForFace(ref to, face, out end);

            int steps = (int)Math.Ceiling((end - start).Length() * m_heightmap.Resolution);

            double stepsR = 1d / steps;

            for (int i = 0; i < steps; i++)
            {
                from = ll.From + ll.Direction * ll.Length * i * stepsR;
                to   = ll.From + ll.Direction * ll.Length * (i + 1) * stepsR;

                var flen  = from.Length();
                var tolen = to.Length();

                MyCubemapHelpers.CalculateTexcoordForFace(ref from, face, out start);
                MyCubemapHelpers.CalculateTexcoordForFace(ref to, face, out end);

                from.X = start.X;
                from.Y = start.Y;
                from.Z = (flen - m_radius - m_minHillHeight) * m_heightRatioRecip;

                to.X = end.X;
                to.Y = end.Y;
                to.Z = (tolen - m_radius - m_minHillHeight) * m_heightRatioRecip;

                float newStart, newEnd;
                if (m_heightmap[face].QueryLine(ref from, ref to, out newStart, out newEnd))
                {
                    startOffset = Math.Max((i + newStart) * stepsR, 0);
                    endOffset   = 1.0;
                    return(true);
                }
            }

            startOffset = 0;
            endOffset   = 1;
            return(false);
        }
Example #14
0
        /// <summary>
        /// Get the minimum and maximum ranges of terrain height in the area determined by the provided points.
        /// </summary>
        /// <param name="localPoints">List of points to query</param>
        /// <param name="pointCount">Number of points</param>
        /// <param name="minHeight">The calculated minimum possible height of terrain</param>
        /// <param name="maxHeight">The calculated maximum possible height of terrain</param>
        public unsafe void GetBounds(Vector3 *localPoints, int pointCount, out float minHeight, out float maxHeight)
        {
            int firstFace = -1;

            for (int i = 0; i < pointCount; ++i)
            {
                int face;
                MyCubemapHelpers.GetCubeFace(ref localPoints[i], out face);

                if (firstFace == -1)
                {
                    firstFace = face;
                }
            }

            BoundingBox query = new BoundingBox(new Vector3(float.PositiveInfinity, float.PositiveInfinity, 0), new Vector3(float.NegativeInfinity, float.NegativeInfinity, 0));

            for (int i = 0; i < pointCount; ++i)
            {
                Vector2 tex;
                MyCubemapHelpers.CalculateTexcoordForFace(ref localPoints[i], firstFace, out tex);

                if (tex.X < query.Min.X)
                {
                    query.Min.X = tex.X;
                }
                if (tex.X > query.Max.X)
                {
                    query.Max.X = tex.X;
                }
                if (tex.Y < query.Min.Y)
                {
                    query.Min.Y = tex.Y;
                }
                if (tex.Y > query.Max.Y)
                {
                    query.Max.Y = tex.Y;
                }
            }

            m_heightmap.Faces[firstFace].GetBounds(ref query);

            minHeight = query.Min.Z * m_heightRatio + InnerRadius;
            maxHeight = query.Max.Z * m_heightRatio + InnerRadius;
        }
Example #15
0
        public unsafe bool IntersectLine(ref LineD ll, out double startOffset, out double endOffset)
        {
            var box = new BoundingBox(ll.From, ll.From);

            box.Include(ll.To);

            int  firstFace   = -1;
            uint faces       = 0;
            bool complicated = false;

            Vector3 *corners = stackalloc Vector3[8];

            box.GetCornersUnsafe(corners);

            for (int i = 0; i < 8; ++i)
            {
                int face;
                MyCubemapHelpers.GetCubeFace(ref corners[i], out face);

                if (firstFace == -1)
                {
                    firstFace = face;
                }
                else if (firstFace != face)
                {
                    complicated = true;
                }

                faces |= (uint)(1 << face);
            }

            if (complicated)
            {
                return(IntersectLineCornerCase(ref ll, faces, out startOffset, out endOffset));
            }

            // Later on we will have split the line per sextant already.

            // From here on I calculate how many times to split the line to account for the surface curvature.
            //

            return(IntersectLineFace(ref ll, firstFace, out startOffset, out endOffset));
        }
Example #16
0
        // assign values to the extra borders of the heightmap.
        public void PrepareSides()
        {
            int end = m_resolution - 1;

            ProfilerShort.Begin("Copy Range");
            Front.CopyRange(new Vector2I(0, -1), new Vector2I(end, -1), Top, new Vector2I(0, end), new Vector2I(end, end));
            Front.CopyRange(new Vector2I(0, m_resolution), new Vector2I(end, m_resolution), Bottom, new Vector2I(end, end), new Vector2I(0, end));
            Front.CopyRange(new Vector2I(-1, 0), new Vector2I(-1, end), Left, new Vector2I(end, 0), new Vector2I(end, end));
            Front.CopyRange(new Vector2I(m_resolution, 0), new Vector2I(m_resolution, end), Right, new Vector2I(0, 0), new Vector2I(0, end));

            Back.CopyRange(new Vector2I(end, -1), new Vector2I(0, -1), Top, new Vector2I(0, 0), new Vector2I(end, 0));
            Back.CopyRange(new Vector2I(end, m_resolution), new Vector2I(0, m_resolution), Bottom, new Vector2I(end, 0), new Vector2I(0, 0));
            Back.CopyRange(new Vector2I(-1, 0), new Vector2I(-1, end), Right, new Vector2I(end, 0), new Vector2I(end, end));
            Back.CopyRange(new Vector2I(m_resolution, 0), new Vector2I(m_resolution, end), Left, new Vector2I(0, 0), new Vector2I(0, end));

            Left.CopyRange(new Vector2I(end, -1), new Vector2I(0, -1), Top, new Vector2I(0, end), new Vector2I(0, 0));
            Left.CopyRange(new Vector2I(end, m_resolution), new Vector2I(0, m_resolution), Bottom, new Vector2I(end, end), new Vector2I(end, 0));
            Left.CopyRange(new Vector2I(m_resolution, 0), new Vector2I(m_resolution, end), Front, new Vector2I(0, 0), new Vector2I(0, end));
            Left.CopyRange(new Vector2I(-1, 0), new Vector2I(-1, end), Back, new Vector2I(end, 0), new Vector2I(end, end));

            Right.CopyRange(new Vector2I(end, -1), new Vector2I(0, -1), Top, new Vector2I(end, 0), new Vector2I(end, end));
            Right.CopyRange(new Vector2I(end, m_resolution), new Vector2I(0, m_resolution), Bottom, new Vector2I(0, 0), new Vector2I(0, end));
            Right.CopyRange(new Vector2I(m_resolution, 0), new Vector2I(m_resolution, end), Back, new Vector2I(0, 0), new Vector2I(0, end));
            Right.CopyRange(new Vector2I(-1, 0), new Vector2I(-1, end), Front, new Vector2I(end, 0), new Vector2I(end, end));

            Top.CopyRange(new Vector2I(0, m_resolution), new Vector2I(end, m_resolution), Front, new Vector2I(0, 0), new Vector2I(end, 0));
            Top.CopyRange(new Vector2I(0, -1), new Vector2I(end, -1), Back, new Vector2I(end, 0), new Vector2I(0, 0));
            Top.CopyRange(new Vector2I(m_resolution, 0), new Vector2I(m_resolution, end), Right, new Vector2I(end, 0), new Vector2I(0, 0));
            Top.CopyRange(new Vector2I(-1, 0), new Vector2I(-1, end), Left, new Vector2I(0, 0), new Vector2I(end, 0));

            Bottom.CopyRange(new Vector2I(0, m_resolution), new Vector2I(end, m_resolution), Front, new Vector2I(end, end), new Vector2I(0, end));
            Bottom.CopyRange(new Vector2I(0, -1), new Vector2I(end, -1), Back, new Vector2I(0, end), new Vector2I(end, end));
            Bottom.CopyRange(new Vector2I(-1, 0), new Vector2I(-1, end), Right, new Vector2I(end, end), new Vector2I(0, end));
            Bottom.CopyRange(new Vector2I(m_resolution, 0), new Vector2I(m_resolution, end), Left, new Vector2I(0, end), new Vector2I(end, end));

            ProfilerShort.BeginNextBlock("Assign Borders");
            for (int i = 0; i < 6; ++i)
            {
                Faces[i].FinishFace(string.Format("{0}_{1}", Name, MyCubemapHelpers.GetNameForFace(i)));
            }
            ProfilerShort.End();
        }
Example #17
0
 public unsafe void ComputeCombinedMaterialAndSurface(Vector3 position, bool useCache, out MySurfaceParams props)
 {
     if (this.Closed)
     {
         props = new MySurfaceParams();
     }
     else
     {
         MyPlanetMaterialProvider.MaterialSampleParams @params;
         int     num2;
         Vector2 vector2;
         position -= this.Shape.Center();
         float num = position.Length();
         @params.Gravity = position / num;
         props.Latitude  = @params.Gravity.Y;
         Vector2 vector = new Vector2([email protected], [email protected]);
         vector.Normalize();
         props.Longitude = vector.Y;
         if ([email protected] > 0f)
         {
             props.Longitude = 2f - props.Longitude;
         }
         MyCubemapHelpers.CalculateSampleTexcoord(ref position, out num2, out vector2);
         float altitude = useCache ? this.Shape.GetValueForPositionWithCache(num2, ref vector2, out props.Normal) : this.Shape.GetValueForPositionCacheless(num2, ref vector2, out props.Normal);
         @params.SampledHeight = altitude;
         @params.SurfaceDepth  = 0f;
         @params.Texcoord      = vector2;
         @params.LodSize       = 1f;
         @params.Latitude      = props.Latitude;
         @params.Longitude     = props.Longitude;
         @params.Face          = num2;
         @params.Normal        = props.Normal;
         props.Position        = (@params.Gravity * (this.Radius + altitude)) + this.Shape.Center();
         MyPlanetMaterialProvider.MaterialSampleParams *paramsPtr1 = (MyPlanetMaterialProvider.MaterialSampleParams *) ref @params;
         props.Gravity            = paramsPtr1->Gravity = [email protected];
         @params.DistanceToCenter = props.Position.Length();
         MyPlanetMaterialProvider.PlanetMaterial layeredMaterialForPosition = this.Material.GetLayeredMaterialForPosition(ref @params, out props.Biome);
         props.Material    = (layeredMaterialForPosition.FirstOrDefault != null) ? layeredMaterialForPosition.FirstOrDefault.Index : 0;
         props.Normal      = @params.Normal;
         props.HeightRatio = this.Shape.AltitudeToRatio(altitude);
     }
 }
Example #18
0
        public unsafe void GetBounds(Vector3D *localPoints, int pointCount, out float minHeight, out float maxHeight)
        {
            int face = -1;

            for (int i = 0; i < pointCount; i++)
            {
                int     num3;
                Vector3 position = *((Vector3 *)(localPoints + i));
                MyCubemapHelpers.GetCubeFace(ref position, out num3);
                if (face == -1)
                {
                    face = num3;
                }
            }
            BoundingBox query = new BoundingBox(new Vector3(float.PositiveInfinity, float.PositiveInfinity, 0f), new Vector3(float.NegativeInfinity, float.NegativeInfinity, 0f));

            for (int j = 0; j < pointCount; j++)
            {
                Vector2 vector2;
                Vector3 localPos = *((Vector3 *)(localPoints + j));
                MyCubemapHelpers.CalculateTexcoordForFace(ref localPos, face, out vector2);
                if (vector2.X < query.Min.X)
                {
                    query.Min.X = vector2.X;
                }
                if (vector2.X > query.Max.X)
                {
                    query.Max.X = vector2.X;
                }
                if (vector2.Y < query.Min.Y)
                {
                    query.Min.Y = vector2.Y;
                }
                if (vector2.Y > query.Max.Y)
                {
                    query.Max.Y = vector2.Y;
                }
            }
            this.m_heightmap.Faces[face].GetBounds(ref query);
            minHeight = (query.Min.Z * this.m_heightRatio) + this.InnerRadius;
            maxHeight = (query.Max.Z * this.m_heightRatio) + this.InnerRadius;
        }
Example #19
0
        /**
         * Project a position in space to the surface of the heightmap.
         */
        public void ProjectToSurface(Vector3 localPos, out Vector3 surface)
        {
            float length = localPos.Length();

            if (length.IsZero())
            {
                Debug.Fail("Cannot project to surface from the center of the planet!");
                surface = localPos;
                return;
            }
            Vector3 dir = localPos / length;

            int     face;
            Vector2 tex;

            MyCubemapHelpers.CalculateSampleTexcoord(ref localPos, out face, out tex);

            Vector3 norm;
            float   value = GetValueForPositionCacheless(face, ref tex, out norm);

            value += Radius;

            surface = value * dir;
        }
Example #20
0
        protected unsafe ContainmentType IntersectBoundingBoxInternal(ref BoundingBox box, float lodLevel)
        {
            int  firstFace   = -1;
            uint faces       = 0;
            bool complicated = false;

            float minHeight;
            float maxHeight;

            Vector3 *corners = stackalloc Vector3[8];

            box.GetCornersUnsafe(corners);

            for (int i = 0; i < 8; ++i)
            {
                int face;
                MyCubemapHelpers.GetCubeFace(ref corners[i], out face);

                if (firstFace == -1)
                {
                    firstFace = face;
                }
                else if (firstFace != face)
                {
                    complicated = true;
                }

                faces |= (uint)(1 << face);
            }

            if (Vector3.Zero.IsInsideInclusive(ref box.Min, ref box.Max))
            {
                minHeight = 0;
            }
            else
            {
                var clamp = Vector3.Clamp(Vector3.Zero, box.Min, box.Max);
                minHeight = clamp.Length();
            }

            { // Calculate furthest point in BB
                Vector3 end;
                Vector3 c = box.Center;

                if (c.X < 0)
                {
                    end.X = box.Min.X;
                }
                else
                {
                    end.X = box.Max.X;
                }

                if (c.Y < 0)
                {
                    end.Y = box.Min.Y;
                }
                else
                {
                    end.Y = box.Max.Y;
                }

                if (c.Z < 0)
                {
                    end.Z = box.Min.Z;
                }
                else
                {
                    end.Z = box.Max.Z;
                }

                maxHeight = end.Length();
            }

            if (complicated)
            {
                return(IntersectBoundingBoxCornerCase(ref box, faces, corners, minHeight, maxHeight));
            }

            BoundingBox query = new BoundingBox(new Vector3(float.PositiveInfinity, float.PositiveInfinity, minHeight), new Vector3(float.NegativeInfinity, float.NegativeInfinity, maxHeight));

            for (int i = 0; i < 8; ++i)
            {
                Vector2 tex;
                MyCubemapHelpers.CalculateTexcoordForFace(ref corners[i], firstFace, out tex);

                if (tex.X < query.Min.X)
                {
                    query.Min.X = tex.X;
                }
                if (tex.X > query.Max.X)
                {
                    query.Max.X = tex.X;
                }
                if (tex.Y < query.Min.Y)
                {
                    query.Min.Y = tex.Y;
                }
                if (tex.Y > query.Max.Y)
                {
                    query.Max.Y = tex.Y;
                }
            }

            query.Min.Z = ((query.Min.Z - m_radius - m_detailScale) - m_minHillHeight) * m_heightRatioRecip;
            query.Max.Z = ((query.Max.Z - m_radius) - m_minHillHeight) * m_heightRatioRecip;

            return(m_heightmap.Faces[firstFace].QueryHeight(ref query));
        }