Exemplo n.º 1
0
        public override bool GetBotSpawnPosition(string behaviorType, out VRageMath.Vector3D spawnPosition)
        {
            // CH: TODO: Do this more generically, so that modders would be able to define their own bot types and the way they spawn
            if (behaviorType == "Spider")
            {
                MatrixD spawnMatrix;
                bool success = GetSpiderSpawnPosition(out spawnMatrix, null);
                spawnPosition = spawnMatrix.Translation;
                return success;
            }
            else if (MySession.Static.LocalCharacter != null)
            {
                var pos = MySession.Static.LocalCharacter.PositionComp.GetPosition();
                Vector3 up;
                Vector3D right, forward;

                up = MyGravityProviderSystem.CalculateNaturalGravityInPoint(pos);
                if (up.LengthSquared() < 0.0001f) up = Vector3.Up;
                else up = Vector3D.Normalize(up);
                forward = Vector3.CalculatePerpendicularVector(up);
                right = Vector3.Cross(forward, up);
                spawnPosition = MyUtils.GetRandomDiscPosition(ref pos, 5.0f, ref forward, ref right);
                return true;
            }

            spawnPosition = Vector3D.Zero;
            return false;
        }
        void IMyClipmapCell.UpdateWorldMatrix(ref VRageMath.MatrixD worldMatrix, bool sortIntoCullObjects)
        {
            m_worldMatrix = worldMatrix;

            Matrix m = m_worldMatrix * Matrix.CreateScale(m_scale) * Matrix.CreateTranslation(m_translation);
            m_actor.SetMatrix(ref m);
        }
Exemplo n.º 3
0
 public MyScreenShot(VRageMath.Vector2 sizeMultiplier, string path, bool ignoreSprites, bool showNotification)
 {
     IgnoreSprites = ignoreSprites;
     Path = path;
     SizeMultiplier = sizeMultiplier;
     ShowNotification = showNotification;
 }
Exemplo n.º 4
0
 VRageMath.Vector3D? IMyCubeGrid.GetLineIntersectionExactAll(ref VRageMath.LineD line, out double distance, out IMySlimBlock intersectedBlock)
 {
     MySlimBlock block;
     var retVal = GetLineIntersectionExactAll(ref line, out distance, out block);
     intersectedBlock = block;
     return retVal;
 }
Exemplo n.º 5
0
 public BindableVector3DModel(VRageMath.Vector3 vector)
     : this()
 {
     X = vector.X;
     Y = vector.Y;
     Z = vector.Z;
 }
Exemplo n.º 6
0
 public IMyClipmapCell CreateCell(MyClipmapScaleEnum scaleGroup, MyCellCoord cellCoord, ref VRageMath.MatrixD worldMatrix)
 {
     var cell = new MyClipmapCellProxy(cellCoord, ref worldMatrix, m_renderFlags);
     cell.SetVisibility(false);
     cell.ScaleGroup = scaleGroup;
     return cell;
 }
Exemplo n.º 7
0
 public BindablePoint3DIModel(VRageMath.Vector3I vector)
     : this()
 {
     X = vector.X;
     Y = vector.Y;
     Z = vector.Z;
 }
 public static SharpDX.Matrix ToSharpDX(VRageMath.Matrix matrix)
 {
     return new SharpDX.Matrix(matrix.M11, matrix.M12, matrix.M13, matrix.M14,
                               matrix.M21, matrix.M22, matrix.M23, matrix.M24,
                               matrix.M31, matrix.M32, matrix.M33, matrix.M34,
                               matrix.M41, matrix.M42, matrix.M43, matrix.M44);
 }
Exemplo n.º 9
0
        void IMyClipmapCell.UpdateWorldMatrix(ref VRageMath.MatrixD worldMatrix, bool sortIntoCullObjects)
        {
            m_worldMatrix = worldMatrix;

            MatrixD m = MatrixD.CreateScale(m_scale) * MatrixD.CreateTranslation(m_translation) * m_worldMatrix;
            m_actor.SetMatrix(ref m);
            m_actor.SetAabb((BoundingBoxD)m_localAabb.Transform(m_worldMatrix));
        }
Exemplo n.º 10
0
        protected override bool CanRotateTo(VRageMath.Vector3D targetPoint)
        {
            // if controlled by an engager, can always rotate
            if (ControllingEngager)
                return true;

            // if controlled by a turret (not implemented)
            return true;
        }
Exemplo n.º 11
0
 List<IMySlimBlock> IMyCubeGrid.GetBlocksInsideSphere(ref VRageMath.BoundingSphereD sphere)
 {
     HashSet<MySlimBlock> blocks = new HashSet<MySlimBlock>();
     GetBlocksInsideSphere(ref sphere, blocks);
     var result = new List<IMySlimBlock>(blocks.Count);
     foreach (var block in blocks)
         result.Add(block);
     return result;
 }
Exemplo n.º 12
0
 public override bool Draw(VRageMath.Vector2 position)
 {
     if (m_highlight)
         MyGuiManager.DrawString(MyFontEnum.White, Text, position, Scale, null, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
     else
         MyGuiManager.DrawString(MyFontEnum.Blue, Text, position, Scale, VRageMath.Color.PowderBlue, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP);
     m_linkImg.Draw(position + new Vector2(base.Size.X + m_linkImgSpace, 0));
     m_highlight = false;
     return true;
 }
Exemplo n.º 13
0
        public override void AccumulateCorrection(ref VRageMath.Vector3 correction, ref float weight)
        {
            Vector3D position = Parent.PositionAndOrientation.Translation;

            BoundingBoxD box = new BoundingBoxD(position - Vector3D.One, position + Vector3D.One);

            Vector3D currentMovement = Parent.ForwardVector * Parent.Speed;
            if (Parent.Speed > 0.01f)
                currentMovement.Normalize();

            // Don't do any correction if we're not moving
            if (currentMovement.LengthSquared() < 0.01)
            {
                return;
            }

            var entities = MyEntities.GetEntitiesInAABB(ref box);
            foreach (var entity in entities)
            {
                var environmentItems = entity as MyEnvironmentItems;
                if (environmentItems == null) continue;

                environmentItems.GetItemsInRadius(ref position, 6.0f, m_trees);

                foreach (var item in m_trees)
                {
                    Vector3D dir = item - position;
                    var dist = dir.Normalize();
                    dir = Vector3D.Reject(currentMovement, dir);

                    dir.Y = 0.0f;
                    if (dir.Z * dir.Z + dir.X * dir.X < 0.1)
                    {
                        Vector3D dirLocal = Vector3D.TransformNormal(dir, Parent.PositionAndOrientationInverted);
                        dir = position - item;
                        dir = Vector3D.Cross(Vector3D.Up, dir);
                        if (dirLocal.X < 0)
                            dir = -dir;
                    }

                    dir.Normalize();

                    correction += (6f - dist) * Weight * dir;
                    if (!correction.IsValid())
                    {
                        System.Diagnostics.Debugger.Break();
                    }
                }
                m_trees.Clear();
            }

            weight += Weight;

            entities.Clear();
        }
        public MyCsgShapeExcludedSphere(VRageMath.Vector3 translation, float radius,float exclusionRadius, float halfDeviation = 0, float deviationFrequency = 0, float detailFrequency = 0)
        {
            m_translation = translation;
            m_radius = radius;
            m_halfDeviation = halfDeviation;
            m_deviationFrequency = deviationFrequency;
            m_detailFrequency = detailFrequency;


            m_sphere = new MyCsgSphere(translation, radius, halfDeviation, deviationFrequency, detailFrequency);
            m_exclusionSphere = new MyCsgSphere(translation, exclusionRadius, halfDeviation, deviationFrequency, detailFrequency); 
        }
Exemplo n.º 15
0
		internal MyClipmapCellProxy(MyCellCoord cellCoord, ref VRageMath.MatrixD worldMatrix, RenderFlags additionalFlags = 0)
        {
            m_worldMatrix = worldMatrix;

            m_actor = MyActorFactory.CreateSceneObject();
            m_actor.SetMatrix(ref worldMatrix);
            m_actor.AddComponent(MyComponentFactory<MyFoliageComponent>.Create());

            m_lod = cellCoord.Lod;

            Mesh = MyMeshes.CreateVoxelCell(cellCoord.CoordInLod, cellCoord.Lod);
            m_actor.GetRenderable().SetModel(Mesh);
			m_actor.GetRenderable().m_additionalFlags = MyProxiesFactory.GetRenderableProxyFlags(additionalFlags);
        }
Exemplo n.º 16
0
        public MyScreenshot(VRageMath.Vector2 sizeMultiplier, string saveToPath, bool ignoreSprites, bool showNotification)
        {
            MyRender.Log.WriteLine("MyScreenshot.Constructor() - START");
            MyRender.Log.IncreaseIndent();

            System.Diagnostics.Debug.Assert(sizeMultiplier.X > 0 && sizeMultiplier.Y > 0);
            m_sizeMultiplier = sizeMultiplier;
            IgnoreSprites = ignoreSprites;
            ShowNotification = showNotification;

            m_fullPathToSave = saveToPath;
            m_datetimePrefix = MyValueFormatter.GetFormatedDateTimeForFilename(DateTime.Now);

            MyRender.Log.DecreaseIndent();
            MyRender.Log.WriteLine("MyScreenshot.Constructor() - END");
        }
        protected override MyProceduralCell GenerateProceduralCell(ref VRageMath.Vector3I cellId)
        {
            MyProceduralCell cell = new MyProceduralCell(cellId, this);
            ProfilerShort.Begin("GenerateProceduralCell");

            IMyModule densityFunctionFilled = GetCellDensityFunctionFilled(cell.BoundingVolume);
            if (densityFunctionFilled == null)
            {
                ProfilerShort.End();
                return null;
            }
            IMyModule densityFunctionRemoved = GetCellDensityFunctionRemoved(cell.BoundingVolume);

            int cellSeed = GetCellSeed(ref cellId);
            var random = MyRandom.Instance;
            using (random.PushSeed(cellSeed))
            {
                Vector3D position = new Vector3D(random.NextDouble(), random.NextDouble(), random.NextDouble());
                position *= (CELL_SIZE - 2 * OBJECT_SEED_RADIUS) / CELL_SIZE;
                position += OBJECT_SEED_RADIUS / CELL_SIZE;
                position += (Vector3D)cellId;
                position *= CELL_SIZE;

                if (MyEntities.IsInsideWorld(position))
                {
                    ProfilerShort.Begin("GetValue");
                    var value = densityFunctionFilled.GetValue(position.X, position.Y, position.Z);
                    ProfilerShort.End();

                    if (value < m_objectDensity) // -1..+1
                    {
                        var size = MathHelper.Lerp(PLANET_SIZE_MIN, PLANET_SIZE_MAX, random.NextDouble());
                        var objectSeed = new MyObjectSeed(cell, position, size);
                        objectSeed.Type = MyObjectSeedType.Planet;
                        objectSeed.Seed = random.Next();
                        objectSeed.Index = 0;
                        objectSeed.UserData = new MySphereDensityFunction(position, OBJECT_SEED_RADIUS, OBJECT_SEED_RADIUS);

                        int index = 1;
                        GenerateObject(cell, objectSeed, ref index, random, densityFunctionFilled, densityFunctionRemoved);
                    }
                }
            }

            ProfilerShort.End();
            return cell;
        }
Exemplo n.º 18
0
 public override bool HandleInput(VRageMath.Vector2 position)
 {
     var mouse = MyGuiManager.MouseCursorPosition;
     if (mouse.X > position.X + 0.001f && mouse.Y > position.Y && mouse.X < position.X + Size.X && mouse.Y < position.Y + Size.Y)
     {
         m_highlight = true;
         if (MyInput.Static.IsLeftMousePressed() && MyGuiManager.TotalTimeInMilliseconds - m_lastTimeClicked > MyGuiConstants.REPEAT_PRESS_DELAY)
         {
             m_onClick(Url);
             m_lastTimeClicked = MyGuiManager.TotalTimeInMilliseconds;
             return true;
         }
     }
     else
         m_highlight = false;
     return false;
 }
Exemplo n.º 19
0
        internal MyClipmapCellProxy(MyCellCoord cellCoord, ref VRageMath.Matrix worldMatrix)
        {
            m_worldMatrix = worldMatrix;

            m_actor = MyActorFactory.CreateSceneObject();
            //m_mesh = new MyVoxelMesh(cellCoord.CoordInLod, cellCoord.Lod, "");
            //m_actor.GetRenderable().SetModel(m_mesh);
            m_actor.SetMatrix(ref worldMatrix);
            m_actor.AddComponent(MyComponentFactory<MyFoliageComponent>.Create());

            m_lod = cellCoord.Lod;

            Mesh = MyMeshes.CreateVoxelCell(cellCoord.CoordInLod, cellCoord.Lod);
            m_actor.GetRenderable().SetModel(Mesh);

            m_discardingOn = false;
        }
Exemplo n.º 20
0
        public override bool GetBotSpawnPosition(string behaviorType, out VRageMath.Vector3D spawnPosition)
        {
            if (MySession.LocalCharacter != null)
            {
                var pos = MySession.LocalCharacter.PositionComp.GetPosition();
                Vector3 up;
                Vector3D right, forward;

                up = MyGravityProviderSystem.CalculateNaturalGravityInPoint(pos);
                if (up.LengthSquared() < 0.0001f) up = Vector3.Up;
                else up = Vector3D.Normalize(up);
                forward = Vector3.CalculatePerpendicularVector(up);
                right = Vector3.Cross(forward, up);
                spawnPosition = MyUtils.GetRandomDiscPosition(ref pos, 5.0f, ref forward, ref right);
                return true;
            }

            spawnPosition = Vector3D.Zero;
            return false;
        }
Exemplo n.º 21
0
 void IMyEntity.SetColorMaskForSubparts(VRageMath.Vector3 colorMaskHsv)
 {
     if (Subparts != null)
     {
         foreach (var subPart in Subparts)
         {
             subPart.Value.Render.ColorMaskHsv = colorMaskHsv;
         }
     }
 }
Exemplo n.º 22
0
        //  Calculates intersection of line with object.
        public override bool GetIntersectionWithLine(ref VRageMath.LineD line)
        {
            double? t = m_aabb.Intersects(new RayD(line.From, line.Direction));
            if (t.HasValue && t.Value < line.Length && t.Value > 0)
            {
                return true;
            }

            return false;
        }
 internal static float DrawTextShadow(Vector2 screenCoord, StringBuilder text, VRageMath.Color color, float scale)
 {
     return MyRender.DebugFont.DrawString(
         screenCoord,
         color,
         text,
         scale);
 }
Exemplo n.º 24
0
 private static Viewport ScaleViewport(Viewport viewport, VRageMath.Vector2 scale)
 {
     return new Viewport((int)(viewport.X * scale.X), (int)(viewport.Y * scale.Y), (int)(viewport.Width * scale.X), (int)(viewport.Height * scale.Y));
 }
Exemplo n.º 25
0
        internal static float DrawText(Vector2 screenCoord, StringBuilder text, VRageMath.Color color, float scale, MyGuiDrawAlignEnum align = MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP)
        {
            var font = MyRender11.DebugFont;

            return font.DrawString(
                MyUtils.GetCoordAligned(screenCoord, font.MeasureString(text, scale), align),
                color,
                text,
                scale);
        }
 public void SetDiffuseColor4(VRageMath.Vector4 diffuseColor)
 {
     m_D3DEffect.SetValue(m_diffuseColor, diffuseColor);
 }
Exemplo n.º 27
0
 void IMyEntity.SetWorldMatrix(VRageMath.MatrixD worldMatrix, object source)
 {
     PositionComp.SetWorldMatrix(worldMatrix, source);
 }
Exemplo n.º 28
0
 void IMyEntity.SetPosition(VRageMath.Vector3D pos)
 {
     PositionComp.SetPosition(pos);
 }
        protected override MyProceduralCell GenerateProceduralCell(ref VRageMath.Vector3I cellId)
        {
            MyProceduralCell cell = new MyProceduralCell(cellId, this);
            ProfilerShort.Begin("GenerateObjectSeedsCell");

            IMyModule densityFunctionFilled = GetCellDensityFunctionFilled(cell.BoundingVolume);
            if (densityFunctionFilled == null)
            {
                ProfilerShort.End();
                return null;
            }
            IMyModule densityFunctionRemoved = GetCellDensityFunctionRemoved(cell.BoundingVolume);

            int cellSeed = GetCellSeed(ref cellId);
            var random = MyRandom.Instance;
            using (random.PushSeed(cellSeed))
            {
                int index = 0;
                Vector3I subCellId = Vector3I.Zero;
                Vector3I max = new Vector3I(SUBCELLS - 1);
                for (var iter = new Vector3I.RangeIterator(ref Vector3I.Zero, ref max); iter.IsValid(); iter.GetNext(out subCellId))
                {
                    // there is a bug in the position calculation which can very rarely cause overlaping objects but backwards compatibility so meh
                    Vector3D position = new Vector3D(random.NextDouble(), random.NextDouble(), random.NextDouble());
                    position += (Vector3D)subCellId / SUBCELL_SIZE;
                    position += cellId;
                    position *= CELL_SIZE;

                    if (!MyEntities.IsInsideWorld(position))
                    {
                        continue;
                    }

                    ProfilerShort.Begin("Density functions");
                    double valueRemoved = -1;
                    if (densityFunctionRemoved != null)
                    {
                        valueRemoved = densityFunctionRemoved.GetValue(position.X, position.Y, position.Z);

                        if (valueRemoved <= -1)
                        {
                            ProfilerShort.End();
                            continue;
                        }
                    }

                    var valueFilled = densityFunctionFilled.GetValue(position.X, position.Y, position.Z);

                    if (densityFunctionRemoved != null)
                    {
                        if (valueRemoved < valueFilled)
                        {
                            ProfilerShort.End();
                            continue;
                        }
                    }
                    ProfilerShort.End();

                    if (valueFilled < m_objectDensity) // -1..+1
                    {
                        var objectSeed = new MyObjectSeed(cell, position, GetObjectSize(random.NextDouble()));
                        objectSeed.Type = GetSeedType(random.NextDouble());
                        objectSeed.Seed = random.Next();
                        objectSeed.Index = index++;

                        GenerateObject(cell, objectSeed, ref index, random, densityFunctionFilled, densityFunctionRemoved);
                    }
                }
            }

            ProfilerShort.End();
            return cell;
        }
Exemplo n.º 30
0
 public override void UpdateRenderEntity(VRageMath.Vector3 colorMaskHSV)
 {
 }