Example #1
0
        private static Vector3D?FindFreePlaceImproved(Vector3D pos, Quaternion orientation, Vector3 halfExtents, Vector3 gravity)
        {
            if (IsFreePlace(pos, orientation, halfExtents))
            {
                return(pos);
            }
            var distanceStepSize = halfExtents.Length() / 10f;

            for (var distanceStep = 1; distanceStep <= 20; distanceStep++)
            {
                var distance = distanceStep * distanceStepSize;
                for (var attempt = 0; attempt < 50; attempt++)
                {
                    var dir     = MyUtils.GetRandomVector3HemisphereNormalized(-gravity);
                    var testPos = pos + dir * distance;
                    if (IsFreePlace(testPos, orientation, halfExtents))
                    {
                        var planet        = MyPlanets.GetPlanets()[0];
                        var centerVoxData = planet.WorldPositionToStorage(testPos);
                        VoxelData.Resize(new Vector3I(1));
                        planet.Storage.ReadRange(VoxelData, MyStorageDataTypeFlags.Content, 0, centerVoxData, centerVoxData);
                        return(testPos);
                    }
                }
            }

            return(null);
        }
 private void RefreshSectors()
 {
     foreach (var planet in MyPlanets.GetPlanets())
     {
         var component = planet.Components.Get <MyPlanetEnvironmentComponent>();
         component.CloseAll();
     }
 }
Example #3
0
        protected void WritePlanetSectors(BitStream stream)
        {
            stream.WriteInt32(PlanetMagic);

            var planets = MyPlanets.GetPlanets();

            // Planets are not enabled if session component is not loaded.
            if (planets == null)
            {
                stream.WriteInt32(0);
                return;
            }

            stream.WriteInt32(planets.Count);

            foreach (var planet in planets)
            {
                stream.WriteInt64(planet.EntityId);

                MyPlanetEnvironmentComponent env = planet.Components.Get <MyPlanetEnvironmentComponent>();

                var syncLod = env.EnvironmentDefinition.SyncLod;

                foreach (var provider in env.Providers)
                {
                    foreach (var sector in provider.LogicalSectors)
                    {
                        if (sector.MinLod <= syncLod)
                        {
                            stream.WriteInt64(sector.Id);
                        }
                    }
                }

                // don't know how many in advance so I will use ~0 termination instead of count.
                stream.WriteInt64(~0);
            }
        }
        private void WritePlanetSectors(BitStream stream)
        {
            stream.WriteInt32(0x42424242);

            var planets = MyPlanets.GetPlanets();

            stream.WriteInt32(planets.Count);

            foreach (var planet in planets)
            {
                stream.WriteInt64(planet.EntityId);

                foreach (var sector in planet.EnvironmentSectors.Values)
                {
                    if (sector.HasPhysics || sector.ServerOwned)
                    {
                        stream.WriteInt64(sector.SectorId.Pack64());
                    }
                }

                // don't know how many in advance so I will use -1 termination instead of count.
                stream.WriteInt64(-1);
            }
        }
            private void UpdateViewRange(MyPlanet planet)
            {
                var pos = MySector.MainCamera.Position;

                double dist = double.MaxValue;

                foreach (var p in MyPlanets.GetPlanets())
                {
                    double dsq = Vector3D.DistanceSquared(pos, p.WorldMatrix.Translation);
                    if (dsq < dist)
                    {
                        planet = p;
                        dist   = dsq;
                    }
                }

                var    radius = planet.MinimumRadius;
                double altitude;

                m_height = planet.MaximumRadius - radius;

                var center = planet.WorldMatrix.Translation;


                m_radius = HyperSphereHelpers.DistanceToTangentProjected(ref center, ref pos, radius, out altitude);

                var up = center - pos;

                up.Normalize();

                m_center = pos + up * altitude;

                var forward = Vector3D.CalculatePerpendicularVector(up);

                m_orientation = QuaternionD.CreateFromForwardUp(forward, up);
            }