Transform() public static method

Transforms the vector (x, y, 0, 1) by the specified matrix. Transforms a Vector2 by the given Matrix. Transforms a 2D vector normal by a matrix. Transforms a vector normal by a matrix. Transforms a single Vector2, or the vector normal (x, y, 0, 0), by a specified Quaternion rotation. Transforms a Vector2, or the vector normal (x, y, 0, 0), by a specified Quaternion rotation. Transforms an array of Vector2s by a specified Matrix. Transforms a specified range in an array of Vector2s by a specified Matrix and places the results in a specified range in a destination array. Transforms an array of Vector2 vector normals by a specified Matrix. Transforms a specified range in an array of Vector2 vector normals by a specified Matrix and places the results in a specified range in a destination array. Transforms an array of Vector2s by a specified Quaternion. Transforms a specified range in an array of Vector2s by a specified Quaternion and places the results in a specified range in a destination array.
public static Transform ( Vector2 position, Matrix matrix ) : Vector2
position Vector2 The source vector.
matrix Matrix The transformation matrix.
return Vector2
コード例 #1
0
ファイル: InputManager.cs プロジェクト: toffen/EvoNet
        public void Zoom(float zoomFactor, Vector2 mousePos)
        {
            // Track where we are before scale
            Vector2 mousePositionBeforeScale = Vector2.Transform(mousePos, Matrix.Invert(camera.Matrix));

            camera.Scale += (gameConfiguration.ScaleFactor * zoomFactor) / (camera.Scale < 1 ? 1 / camera.Scale : camera.Scale);

            // Track where we are after scale
            Vector2 mousePositionAfterScale = Vector2.Transform(mousePos, Matrix.Invert(camera.Matrix));

            // Adjust screen position with respect to scale to achieve zoom to Mouse cursor functionality
            camera.Move(mousePositionAfterScale - mousePositionBeforeScale);
        }
コード例 #2
0
ファイル: Autonomous.cs プロジェクト: Zeldorks/Zeldorks
        private static void CreateSpreadshots(
            Entity owner,
            Comps.Autonomous autonomousComp,
            Entity centerProjectile,
            Registry registry
            )
        {
            var centerVelocityComp = registry
                                     .GetComponentUnsafe <Comps.Velocity>(centerProjectile);

            PhysicalVector2 centerVelocity = centerVelocityComp.data;

            List <PhysicalVector2> velocities = new List <PhysicalVector2> {
                PhysicalVector2.Transform(
                    centerVelocity,
                    Matrix.CreateRotationZ((float)Math.PI / 6)
                    ),
                PhysicalVector2.Transform(
                    centerVelocity,
                    Matrix.CreateRotationZ(-(float)Math.PI / 6)
                    )
            };

            foreach (PhysicalVector2 velocity in velocities)
            {
                var projectile = Factories.Projectile.Create(
                    autonomousComp.attackType,
                    owner,
                    registry
                    );

                var velocityComp = registry
                                   .GetComponentUnsafe <Comps.Velocity>(projectile);

                velocityComp.data = velocity;

                // TODO: Make this less hacky.
                //
                // To prevent the spreadshots from immediately colliding with
                // each other, give them some position offset

                var positionComp = registry
                                   .GetComponentUnsafe <Comps.Position>(projectile);

                PhysicalVector2 offset = velocity * 16.0f;
                positionComp.data += offset;
            }
        }
コード例 #3
0
ファイル: InputManager.cs プロジェクト: toffen/EvoNet
        public void OnMouseClick(Vector2 mousePosition)
        {
            Vector2  mousePos        = Vector2.Transform(mousePosition, Matrix.Invert(camera.Matrix));
            float    distanceSq      = float.MaxValue;
            Creature closestCreature = null;

            foreach (Creature creature in simulation.CreatureManager.Creatures)
            {
                float distance = (creature.Pos.ToXNA() - mousePos).LengthSquared();
                if (distance < distanceSq)
                {
                    distanceSq      = distance;
                    closestCreature = creature;
                }
            }
            if (closestCreature != null)
            {
                simulation.CreatureManager.SelectedCreature = closestCreature;
            }
        }
コード例 #4
0
        public void drawGridSystem(MapInfoObject mapInfo, Camera2d camera, GraphicsDeviceManager graphics)
        {
            barriersList.Clear();
            spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);
            for (int i = 0; i < mapInfo.gridSizeX; ++i)
            {
                for (int j = 0; j < mapInfo.gridSizeY; ++j)
                {
                    Vector2    transformedV = Vector2.Transform(new Vector2(j * mapInfo.tileSize, i * mapInfo.tileSize), Matrix.Invert(camera.get_transformation(graphics.GraphicsDevice)));
                    var        tile         = new Rectangle((int)transformedV.X, (int)transformedV.Y, mapInfo.tileSize, mapInfo.tileSize);
                    TileObject tile2        = new TileObject();
                    tile2.Rectangle = tile;
                    tile2.isGreen   = false;
                    barriersList.Add(tile2);
                    DrawBorder(tile, 2, Color.Red);
                    var positionsLabel = "(" + tile2.Rectangle.X + ":" + tile2.Rectangle.Y + ")";

                    spriteBatch.DrawString(verdana36, positionsLabel, new Vector2(tile2.Rectangle.X, tile2.Rectangle.Y), Color.White);
                }
            }
            spriteBatch.End();
        }
コード例 #5
0
        //http://clintbellanger.net/articles/isometric_math/
        //spriteBatch.Draw(texture, new Rectangle(400, 50, 100, 100), null, Color.Red, 0, Vector2.Zero, SpriteEffects.None, 0);



        public void drawIsometricGridSystem(MapInfoObject mapInfo, Camera2d camera, GraphicsDeviceManager graphics)
        {
            barriersList.Clear();
            spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);
            for (int i = 0; i < mapInfo.gridSizeX; ++i)
            {
                for (int j = 0; j < mapInfo.gridSizeY; ++j)
                {
                    //  tempPt.x = pt.x - pt.y;
                    //tempPt.y = (pt.x + pt.y) / 2;
                    //var x=j*mapInfo.tileSize/2;
                    //var y=i*mapInfo.tileSize/2;

                    var x = j * mapInfo.tileSize;
                    var y = i * mapInfo.tileSize;

                    //var isotileX = x - y;
                    //var isotileY = (x+y) / 2;
                    //var isotileX = (x - y) * mapInfo.tileSize / 2;
                    //var isotileY = (x + y) * mapInfo.tileSize / 2;
                    Vector2 isoPt        = TwoDToIso(new Vector2(x, y));
                    Vector2 transformedV = Vector2.Transform(new Vector2(isoPt.X, isoPt.Y), Matrix.Invert(camera.get_transformation(graphics.GraphicsDevice)));
                    var     tile         = new Rectangle((int)transformedV.X, (int)transformedV.Y, mapInfo.tileSize, mapInfo.tileSize);

                    TileObject tile2 = new TileObject();
                    tile2.Rectangle = tile;
                    tile2.isGreen   = false;
                    barriersList.Add(tile2);
                    DrawBorder(tile, 2, Color.Red);
                    var positionsLabel = "(" + tile2.Rectangle.X + ":" + tile2.Rectangle.Y + ")";

                    spriteBatch.DrawString(verdana36, positionsLabel, new Vector2(tile2.Rectangle.X, tile2.Rectangle.Y), Color.White, 0, Vector2.Zero, new Vector2(1, 1), SpriteEffects.None, 0);
                }
            }
            spriteBatch.End();
        }
コード例 #6
0
        public void updateGridSystem(Texture2D selectedTexture, Camera2d camera)
        {
            //spriteBatch.Begin();

            foreach (TileObject rect in barriersList)
            {
                if (rect.isGreen)
                {
                    if (rect.texture != null)
                    {
                        if (gridMapType == GridMapType.Default)
                        {
                            spriteBatch.Draw(rect.texture, rect.Rectangle, Color.White);
                        }
                        if (gridMapType == GridMapType.Isometric)
                        {
                            if (rect.isRotated)
                            {
                                Vector2   origin    = new Vector2(rect.texture.Width / 2, rect.texture.Height / 2);
                                Rectangle rectangle = new Rectangle();
                                rectangle    = rect.Rectangle;
                                rectangle.X += rect.Rectangle.Width / 2;
                                rectangle.Y += rect.Rectangle.Height / 2;

                                spriteBatch.Draw(rect.texture, rectangle, null, Color.White, rect.rotationAngle, origin, SpriteEffects.None, rect.layerDepth);
                            }
                            else
                            {
                                spriteBatch.Draw(rect.texture, rect.Rectangle, null, Color.White, 0, Vector2.Zero, SpriteEffects.None, rect.layerDepth);
                            }
                        }
                    }
                    else
                    {
                        Texture2D texture = new Texture2D(GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
                        texture.SetData <Color>(new Color[] { Color.White });
                        if (gridMapType == GridMapType.Default)
                        {
                            spriteBatch.Draw(texture, rect.Rectangle, Color.Green);
                        }
                        if (gridMapType == GridMapType.Isometric)
                        {
                            spriteBatch.Draw(texture, rect.Rectangle, null, Color.Green, 0, Vector2.Zero, SpriteEffects.None, rect.layerDepth);
                        }
                        Vector2 worldPos       = Vector2.Transform(new Vector2(rect.Rectangle.X, rect.Rectangle.Y), Matrix.Invert(camera._transform));
                        var     positionsLabel = "(" + rect.Rectangle.X + ":" + rect.Rectangle.Y + ")\n(" + worldPos.X + ":" + worldPos.Y + ")";

                        if (gridMapType == GridMapType.Default)
                        {
                            spriteBatch.DrawString(verdana36, positionsLabel, new Vector2(rect.Rectangle.X, rect.Rectangle.Y), Color.White);
                        }
                        if (gridMapType == GridMapType.Isometric)
                        {
                            spriteBatch.DrawString(verdana36, positionsLabel, new Vector2(rect.Rectangle.X, rect.Rectangle.Y), Color.White, 0, Vector2.Zero, new Vector2(1, 1), SpriteEffects.None, 0);
                        }
                    }
                }
                else
                {
                    DrawBorder(rect.Rectangle, 2, Color.Red);
                    Vector2 worldPos       = Vector2.Transform(new Vector2(rect.Rectangle.X, rect.Rectangle.Y), Matrix.Invert(camera._transform));
                    var     positionsLabel = "(" + rect.Rectangle.X + ":" + rect.Rectangle.Y + ")\n(" + worldPos.X + ":" + worldPos.Y + ")";

                    if (gridMapType == GridMapType.Default)
                    {
                        spriteBatch.DrawString(verdana36, positionsLabel, new Vector2(rect.Rectangle.X, rect.Rectangle.Y), Color.White);
                    }
                    if (gridMapType == GridMapType.Isometric)
                    {
                        spriteBatch.DrawString(verdana36, positionsLabel, new Vector2(rect.Rectangle.X, rect.Rectangle.Y), Color.White, 0, Vector2.Zero, Vector2.Zero, SpriteEffects.None, 0);
                    }
                }
            }



            // spriteBatch.End();
        }
コード例 #7
0
        public static V2  sovev_vector(F zavit)
        {
            MX cli_sivoov = MX.CreateRotationZ(zavit);

            return(V2.Transform(-V2.UnitY, cli_sivoov));
        }