private void UpdateQuadGrid()
 {
     foreach (QuadGrid quadGrid in quadGrids)
     {
         quadGrid.SetDimensions(MinBoundary.get(), MaxBoundary.get(), Cells.get());
     }
 }
        public void AddParticle(Vector3 position, Vector3 velocity)
        {
            // Figure out where in the circular queue to allocate the new particle.
            int nextFreeParticle = firstFreeParticle + 1;

            if (nextFreeParticle >= (int)MaxParticles.get())
                nextFreeParticle = 0;

            // If there are no free particles, we just have to give up.
            if (nextFreeParticle == firstRetiredParticle)
                return;

            // Adjust the input velocity based on how much
            // this particle system wants to be affected by it.
            //velocity *= settings.EmitterVelocitySensitivity;

            // Add in some random amount of horizontal velocity.
            float horizontalVelocity = MathHelper.Lerp(MinVelocity.get().X,
                                                       MaxVelocity.get().X,
                                                       (float)random.NextDouble());

            double horizontalAngle = random.NextDouble() * MathHelper.TwoPi;

            velocity.X += horizontalVelocity * (float)Math.Cos(horizontalAngle);
            velocity.Z += horizontalVelocity * (float)Math.Sin(horizontalAngle);

            // Add in some random amount of vertical velocity.
            velocity.Y += MathHelper.Lerp(MinVelocity.get().Y,
                                          MaxVelocity.get().Y,
                                          (float)random.NextDouble());

            // Choose four random control values. These will be used by the vertex
            // shader to give each particle a different size, rotation, and color.
            Color randomValues = new Color((byte)random.Next(255),
                                           (byte)random.Next(255),
                                           (byte)random.Next(255),
                                           (byte)random.Next(255));

            for (int i = 0; i < 4; i++)
            {
                particles[firstFreeParticle * 4 + i].Position = position;
                particles[firstFreeParticle * 4 + i].Velocity = velocity;
                particles[firstFreeParticle * 4 + i].Random = randomValues;
                particles[firstFreeParticle * 4 + i].Time = Level.Time;
            }

            firstFreeParticle = nextFreeParticle;
        }
        public void DrawGrid()
        {
#if EDITOR && WINDOWS
            if (UseGrid.get() && GridSize.get().X > 0 && GridSize.get().Y > 0)
            {
                Vector2 StartPos = new Vector2(
                    (float)Math.Floor(DrawCamera.getTopLeftCorner().X / GridSize.get().X) * GridSize.get().X
                    ,
                    (float)Math.Floor(DrawCamera.getTopLeftCorner().Y / GridSize.get().Y) * GridSize.get().Y
                    );
                //StartPos.X = Math.Max(StartPos.X, MinBoundary.X());
                //StartPos.Y = Math.Max(StartPos.Y, MinBoundary.Y());

                Vector2 EndPos = DrawCamera.getBottomRightCorner();
                //EndPos.X = Math.Min(EndPos.X, MaxBoundary.X());
                //EndPos.Y = Math.Min(EndPos.Y, MaxBoundary.Y());

                for (float x = StartPos.X; x < EndPos.X; x += GridSize.get().X)
                {
                    if (x >= MinBoundary.X() && x <= MaxBoundary.X())
                    {
                        Render.DrawLine(new Vector2(x, Math.Max(StartPos.Y, MinBoundary.Y())), new Vector2(x, Math.Min(EndPos.Y, MaxBoundary.Y())), GridColor * 0.5f, 1 / DrawCamera.getZoom());
                    }
                }
                for (float y = StartPos.Y; y < EndPos.Y; y += GridSize.get().Y)
                {
                    if (y >= MinBoundary.Y() && y <= MaxBoundary.Y())
                    {
                        Render.DrawLine(new Vector2(Math.Max(StartPos.X, MinBoundary.X()), y), new Vector2(Math.Min(EndPos.X, MaxBoundary.X()), y), GridColor * 0.5f, 1 / DrawCamera.getZoom());
                    }
                }
            }
            Render.DrawOutlineRect(MinBoundary.get(), MaxBoundary.get(), 1 / DrawCamera.getZoom(), Color.Red);
#endif
        }
Exemplo n.º 4
0
        public override bool RayCast(GameTime gameTime)
        {
            if (MouseManager.MouseClicked && !EditorSelected)
            {
                if (Logic.Rect(Position.get(), Size.get(), Parent2DScene.DrawCamera.ViewMatrix).Contains(WorldViewer.self.RelativeMousePoint))
                {
                    if (!KeyboardManager.ControlPressed())
                    {
                        if (!KeyboardManager.ShiftPressed())
                        {
                            ParentScene.ClearSelected();
                        }
                        ParentScene.AddSelected(this);
                    }
                    else
                    {
                        if (EditorSelected)
                        {
                            ParentScene.RemoveSelected(this);
                        }
                        else
                        {
                            ParentScene.AddSelected(this);
                        }
                    }
                    ParentLevel.ModifyWindows();
                    return(true);
                }
            }
            else if (MouseManager.RMouseClicked)
            {
                if (Logic.Rect(Position.get(), Size.get(), Parent2DScene.DrawCamera.ViewMatrix).Contains(WorldViewer.self.RelativeMousePoint))
                {
                    if (!KeyboardManager.AltPressed())
                    {
                        ParentScene.ClearSelected();
                        ParentScene.AddSelected(this);
                        RightClick(gameTime);
                        ParentLevel.ModifyWindows();
                    }
                    else
                    {
                        Destroy();
                    }

                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 5
0
 public static void DrawSprite(Texture2D tex, Vector2Value Position, Vector2Value Size, FloatValue Rotation, Color color)
 {
     DrawSprite(tex, Position.get(), Size.get(), Rotation.getAsRadians(), color);
 }