• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Engine.Vector类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Engine.Vector的典型用法代码示例。如果您正苦于以下问题:C# Vector类的具体用法?C# Vector怎么用?C# Vector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Vector类属于Engine命名空间,在下文中一共展示了Vector类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: VectorToDirection

        // Take a normalized vector and return the direction it's facing.
        // There's a quite of lot of operations here I'm sure it could be made more efficent.
        private Direction VectorToDirection(Vector direction)
        {
            Vector up = new Vector(0, 1, 0);
            Vector down = new Vector(0, -1, 0);
            Vector left = new Vector(-1, 0, 0);
            Vector right = new Vector(1, 0, 0);

            double upDiff = Math.Acos(direction.DotProduct(up));
            double downDiff = Math.Acos(direction.DotProduct(down));
            double leftDiff = Math.Acos(direction.DotProduct(left));
            double rightDiff = Math.Acos(direction.DotProduct(right));

            double smallest = Math.Min(Math.Min(upDiff, downDiff), Math.Min(leftDiff, rightDiff));

            // yes there's a precidence if they're the same value, it doesn't matter
            if (smallest == upDiff)
            {
                return Direction.Up;
            }
            else if (smallest == downDiff)
            {
                return Direction.Down;
            }
            else if (smallest == leftDiff)
            {
                return Direction.Left;
            }
            else
            {
                return Direction.Right;
            }
        }
开发者ID:iq110,项目名称:csharpgameprogramming,代码行数:34,代码来源:PlayerCharacter.cs


示例2: Matrix

 public Matrix(Vector x, Vector y, Vector z, Vector o)
 {
     _m11 = x.X; _m12 = x.Y; _m13 = x.Z;
     _m21 = y.X; _m22 = y.Y; _m23 = y.Z;
     _m31 = z.X; _m32 = z.Y; _m33 = z.Z;
     _m41 = o.X; _m42 = o.Y; _m43 = o.Z;
 }
开发者ID:iq110,项目名称:csharpgameprogramming,代码行数:7,代码来源:Matrix.cs


示例3: NextMove

        public Vector NextMove(Vector currentPosition, double elapsedTime)
        {
            _elapsedTime += elapsedTime;
            var prng = new Random();
            double ranTime = (double) prng.Next(5, 25)/10;

            if (currentPosition.X > 600) _lastMove = new Vector(-1, 0, 0);
            else if (currentPosition.X < -600) _lastMove = new Vector(1, 0, 0);
            else if (currentPosition.Y > 370) _lastMove = new Vector(0, -1, 0);
            else if (currentPosition.Y < -370) _lastMove = new Vector(0, 1, 0);

            else if (_elapsedTime > ranTime)
            {
                _elapsedTime = 0;
                int ranNum = prng.Next(0, 3);

                switch (ranNum)
                {
                    case 0:
                        _lastMove = new Vector(0, 1, 0);
                        break;
                    case 1:
                        _lastMove = new Vector(1, 0, 0);
                        break;
                    case 2:
                        _lastMove = new Vector(0, -1, 0);
                        break;
                    case 3:
                        _lastMove = new Vector(-1, 0, 0);
                        break;
                }
            }
            return _lastMove;
        }
开发者ID:Drahkir,项目名称:AnotherCastle,代码行数:34,代码来源:SkeletonBrain.cs


示例4: Tile

 public Tile(string tileName, Texture texture, TileCollision tileCollision, Vector position)
 {
     TileName = tileName;
     TileCollision = tileCollision;
     Sprite.Texture = texture;
     Sprite.SetPosition(position);
 }
开发者ID:Drahkir,项目名称:AnotherCastle,代码行数:7,代码来源:Tile.cs


示例5: Ship

 public Ship(Vector pos, Game game, ParticleEngine particleEngine, Arena arena)
 {
     position = pos;
     gameref = game;
     particles = particleEngine;
     arenaref = arena;
 }
开发者ID:hallgeirl,项目名称:Hiage,代码行数:7,代码来源:Ship.cs


示例6: AddExplosion

 public void AddExplosion(Vector position)
 {
     var explosion = new AnimatedSprite {Texture = _textureManager.Get("explosion")};
     explosion.SetAnimation(4, 4);
     explosion.SetPosition(position);
     _effects.Add(explosion);
 }
开发者ID:Drahkir,项目名称:AnotherCastle,代码行数:7,代码来源:EffectsManager.cs


示例7: CreateText

        private void CreateText(double x, double y, double maxWidth)
        {
            _bitmapText.Clear();
            double currentX = 0;
            double currentY = 0;

            string[] words = _text.Split(' ');

            foreach (string word in words)
            {
                Vector nextWordLength = _font.MeasureFont(word);

                if (maxWidth != -1 &&
                    (currentX + nextWordLength.X) > maxWidth)
                {
                    currentX = 0;
                    currentY += nextWordLength.Y;
                }

                string wordWithSpace = word + " "; // add the space character that was removed.

                foreach (char c in wordWithSpace)
                {
                    CharacterSprite sprite = _font.CreateSprite(c);
                    float xOffset = ((float)sprite.Data.XOffset) / 2;
                    float yOffset = (((float)sprite.Data.Height) * 0.5f) + ((float)sprite.Data.YOffset);
                    sprite.Sprite.SetPosition(x + currentX + xOffset, y - currentY - yOffset);
                    currentX += sprite.Data.XAdvance;
                    _bitmapText.Add(sprite);
                }
            }
            _dimensions = _font.MeasureFont(_text, _maxWidth);
            _dimensions.Y = currentY;
            SetColor(_color);
        }
开发者ID:iq110,项目名称:csharpgameprogramming,代码行数:35,代码来源:Text.cs


示例8: Move

        public void Move(Vector amount)
        {
            amount *= Speed;

            if (Math.Abs(amount.X) > Math.Abs(amount.Y))
            {
                if (amount.X > 0)
                {
                    MoveRight();
                }
                else
                {
                    MoveLeft();
                }
            }

            else
            {
                if (amount.Y > 0)
                {
                    MoveUp();
                }
                else
                {
                    MoveDown();
                }
            }

            Sprite.SetPosition(Sprite.GetPosition() + amount);
        }
开发者ID:Drahkir,项目名称:AnotherCastle,代码行数:30,代码来源:PlayerCharacter.cs


示例9: Enemy

 /// <summary>
 ///     Constructs an enemy given the texture and AI (IEnemyBrain)
 /// </summary>
 /// <param name="texture">The texture for the enemy</param>
 /// <param name="enemyBrain">The AI for the enemy</param>
 /// <param name="position">The spawn point for this enemy</param>
 public Enemy(Texture texture, IEnemyBrain enemyBrain, Vector position)
 {
     _enemyBrain = enemyBrain;
     Sprite.Texture = texture;
     Sprite.SetPosition(position);
     RestartShootCountDown();
 }
开发者ID:Drahkir,项目名称:AnotherCastle,代码行数:13,代码来源:Enemy.cs


示例10: GetIntersectionDepth

        /// <summary>
        ///     Calculates the signed depth of intersection between two rectangles.
        /// </summary>
        /// <returns>
        ///     The amount of overlap between two intersecting rectangles. These
        ///     depth values can be negative depending on which wides the rectangles
        ///     intersect. This allows callers to determine the correct direction
        ///     to push objects in order to resolve collisions.
        ///     If the rectangles are not intersecting, Vector2.Zero is returned.
        /// </returns>
        public static Vector GetIntersectionDepth(this RectangleF rectA, RectangleF rectB)
        {
            // Calculate half sizes.
            double halfWidthA = rectA.Width/2.0f;
            double halfHeightA = rectA.Height/2.0f;
            double halfWidthB = rectB.Width/2.0f;
            double halfHeightB = rectB.Height/2.0f;

            // Calculate centers.
            var centerA = new Vector(rectA.Left + halfWidthA, rectA.Top + halfHeightA, 0);
            var centerB = new Vector(rectB.Left + halfWidthB, rectB.Top + halfHeightB, 0);

            // Calculate current and minimum-non-intersecting distances between centers.
            double distanceX = centerA.X - centerB.X;
            double distanceY = centerA.Y - centerB.Y;
            double minDistanceX = halfWidthA + halfWidthB;
            double minDistanceY = halfHeightA + halfHeightB;

            // If we are not intersecting at all, return (0, 0).
            if (Math.Abs(distanceX) >= minDistanceX || Math.Abs(distanceY) >= minDistanceY)
                return Vector.Zero;

            // Calculate and return intersection depths.
            double depthX = distanceX > 0 ? minDistanceX - distanceX : -minDistanceX - distanceX;
            double depthY = distanceY > 0 ? minDistanceY - distanceY : -minDistanceY - distanceY;
            return new Vector(depthX, depthY, 0);
        }
开发者ID:Drahkir,项目名称:Engine,代码行数:37,代码来源:RectangleExtensions.cs


示例11: SpawnParticle

 //Spawn a new particle
 public void SpawnParticle(int timeToLive, Vector position, Vector velocity, Vector accelleration, double red, double green, double blue, double alpha, bool gradualFade, int size)
 {
     if (particles.Count < maxParticles)
     {
         particles.Add(new Particle(texture, timeToLive, position, velocity, accelleration, red, green, blue, alpha, gradualFade, size));
     }
 }
开发者ID:hallgeirl,项目名称:Hiage,代码行数:8,代码来源:ParticleEngine.cs


示例12: Update

        public void Update(double elapsedTime)
        {
            // Get controls and apply to player character
            double _x = _input.Controller.LeftControlStick.X;
            double _y = _input.Controller.LeftControlStick.Y * -1;
            Vector controlInput = new Vector(_x, _y, 0);

            if (Math.Abs(controlInput.Length()) < 0.0001)
            {
                // If the input is very small, then the player may not be using 
                // a controller;, they might be using the keyboard.
                if (_input.Keyboard.IsKeyHeld(Keys.Left))
                {
                    controlInput.X = -1;
                }

                if (_input.Keyboard.IsKeyHeld(Keys.Right))
                {
                    controlInput.X = 1;
                }

                if (_input.Keyboard.IsKeyHeld(Keys.Up))
                {
                    controlInput.Y = 1;
                }

                if (_input.Keyboard.IsKeyHeld(Keys.Down))
                {
                    controlInput.Y = -1;
                }
            }

            _playerCharacter.Move(controlInput * elapsedTime);

        }
开发者ID:iq110,项目名称:csharpgameprogramming,代码行数:35,代码来源:Level.cs


示例13: BasicGroundEnemy

        //Character attributes
        public BasicGroundEnemy(Game game, Vector position, Vector velocity, Dictionary<string, Sprite> sprites, string defaultSprite, IController controller, //GameObject attributes
		               WorldPhysics worldPhysics, ObjectPhysics objectPhysics, Dictionary<string, BoundingPolygon> boundingPolygons,	//PhysicalObject attributes
		               double runSpeed, double maxSpeed)
            : base(game, position, velocity, sprites, defaultSprite, controller, worldPhysics, objectPhysics, boundingPolygons, runSpeed, maxSpeed)
        {
            Stompable = true;
        }
开发者ID:hallgeirl,项目名称:Hiage,代码行数:8,代码来源:BasicGroundEnemy.cs


示例14: EditorModel

 public EditorModel()
 {
     Running = true;
     MousePosition = new Vector();
     Objects = new List<MapObject>();
     ExtraProperties = new Dictionary<string, string>();
 }
开发者ID:hallgeirl,项目名称:Hiage,代码行数:7,代码来源:EditorModel.cs


示例15: CollidableObject

 public CollidableObject(double x, double y, Vector v)
 {
     position = new Vector(x, y);
     velocity = v;
     LastVelocity = new Vector(0,0);
     BoundingBox = new BoundingBox(position.X-width/2, position.Y+height/2, position.X+width/2, position.Y-height/2);
 }
开发者ID:hallgeirl,项目名称:Hiage,代码行数:7,代码来源:TestState.cs


示例16: Block

 public Block(TextureManager manager, string blockType)
 {
     _sprite.Texture = manager.Get(blockType);
     DropSpeed = 30.0;
     Direction = new Vector(0, -1, 0);
     KeepAlive = true;
     _moveDistance = _sprite.GetWidth();
 }
开发者ID:harvPrentiss,项目名称:Subway-Tetris,代码行数:8,代码来源:Block.cs


示例17: VerticalMenu

 public VerticalMenu(double x, double y, Input.Input input, Color unfocused, Color focused)
 {
     this.input = input;
     position = new Vector(x, y, 0);
     Spacing = 50;
     SetUnfocusedColor(unfocused);
     SetFocusColor(focused);
 }
开发者ID:beamery,项目名称:bTris,代码行数:8,代码来源:VerticalMenu.cs


示例18: Bullet

        public Bullet(Texture bulletTexture)
        {
            _sprite.Texture = bulletTexture;

            // Some default values
            Dead = false;
            Direction = new Vector(1, 0, 0);
            Speed = 512;// pixels per second
        }
开发者ID:iq110,项目名称:csharpgameprogramming,代码行数:9,代码来源:Bullet.cs


示例19: PhysicalObject

        public PhysicalObject(Game game, Vector position, Vector velocity, Dictionary<string, Sprite> sprites, string defaultSprite, IController controller, 
		                       WorldPhysics worldPhysics, ObjectPhysics objectPhysics, Dictionary<string, BoundingPolygon> boundingPolygons)
            : base(game, position, velocity, sprites, defaultSprite, controller, boundingPolygons)
        {
            this.worldPhysics = worldPhysics;
            this.objectPhysics = objectPhysics;
            this.friction = objectPhysics.Friction*worldPhysics.GroundFrictionFactor;
            inAirTimer.Start();
        }
开发者ID:hallgeirl,项目名称:Hiage,代码行数:9,代码来源:PhysicalObject.cs


示例20: Character

        //Just pass on the constructor stuff to base
        public Character(Game game, Vector position, Vector velocity, Dictionary<string, Sprite> sprites, string defaultSprite, IController controller, 
		                 WorldPhysics worldPhysics, ObjectPhysics objectPhysics, Dictionary<string, BoundingPolygon> boundingPolygons,
		                 double runSpeed, double maxSpeed)
            : base(game, position, velocity, sprites, defaultSprite, controller, worldPhysics, objectPhysics, boundingPolygons)
        {
            CurrentSprite.PlayAnimation("stand", true);
            MaxSpeed = maxSpeed;
            RunSpeed = runSpeed;
        }
开发者ID:hallgeirl,项目名称:Hiage,代码行数:10,代码来源:Character.cs



注:本文中的Engine.Vector类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Engine3D.Object3d类代码示例发布时间:2022-05-24
下一篇:
C# Engine.Camera类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap