Exemple #1
0
 public Bezier( Vector2D begin, Vector2D end, params Vector2D[] controlls )
     : this()
 {
     MidiumPoints = new List<Vector2D>( controlls );
     this.Begin = begin;
     this.End = end;
 }
Exemple #2
0
        public static void DrawExtend( this SpriteBatch spriteBatch, Texture2D texture, Vector2D position, Vector2D scale, NacRectangle? source = null,
			Color? color = null, float rotation = 0, Vector2D? origin = null, SpriteEffects effect = SpriteEffects.None, float layerDepth = 0 )
        {
            Color c = color ?? Color.White;
            XnaRectangle? s = source != null ? source.Value.ToXna() : (XnaRectangle?)null;
            Vector2 o = ( origin ?? Vector2D.Zero ).ToXna();
            spriteBatch.Draw( texture, position.ToXna(), s, c, rotation, o, scale.ToXna(), effect, layerDepth );
        }
Exemple #3
0
 public MouseHelper( Game game )
     : base(game)
 {
     var state = Mouse.GetState();
     position = new Vector2D( state.X, state.Y );
     leftButton = rightButton = middleButton = 0;
     wheel = 0;
 }
Exemple #4
0
        public static void Draw( this SpriteBatch spriteBatch, Texture2D texture, NacRectangle destination, NacRectangle? source = null, Color? color = null,
			float rotation = 0, Vector2D? origin = null, SpriteEffects effect = SpriteEffects.None, float layerDepth = 0 )
        {
            Color c = color ?? Color.White;
            XnaRectangle? s = source != null ? source.Value.ToXna() : (XnaRectangle?)null;
            Vector2 o = ( origin ?? texture.Bounds.Center.ToVector2D() ).ToXna();
            spriteBatch.Draw( texture, destination.ToXna(), s, c, rotation, o, effect, layerDepth );
        }
Exemple #5
0
        public static void DrawCenter( this SpriteBatch spriteBatch, Texture2D texture, Vector2D position, NacRectangle? source = null, Color? color = null,
			float rotation = 0, float scale = 1, SpriteEffects effect = SpriteEffects.None, float layerDepth = 0 )
        {
            XnaRectangle? so = source != null ? source.Value.ToXna() : (XnaRectangle?)null;
            Color c = color ?? Color.White;
            Vector2 o = source == null ? texture.Bounds.Center.ToVector2() : ( source.Value.Size / 2 ).ToXna();
            spriteBatch.Draw( texture, position.ToXna(), so, c, rotation, o, scale, effect, layerDepth );
        }
 public TowardMotion( Vector2D from, Vector2D to, int time, float beginWeight = 1, float endWeight = 1 )
 {
     v = new BezierValue( beginWeight, endWeight );
     this.from = from;
     this.to = to;
     this.paramater = 0;
     this.diff = 1.0f / time;
     this.restTime = time;
     Enabled = true;
 }
Exemple #7
0
 internal MouseCount( Vector2D position, Vector2D velocity, int left, int right, int middle, int wheel )
     : this()
 {
     this.Position = position;
     this.Velocity = velocity;
     this.LeftButton = left;
     this.RightButton = right;
     this.MiddleButton = middle;
     this.Wheel = wheel;
 }
        public Vector2D Move( Vector2D position )
        {
            if( restTime <= 0 )
            {
                Enabled = false;
                paramater = 1;
                return to;
            }

            paramater = MathHelper.Clamp( paramater + diff, 0, 1 );
            restTime--;
            return from + v[paramater] * ( to - from );
        }
        public void DrawCircle( Vector2D center, float radius, Color color, bool fill )
        {
            Func<float, float, Vector2D> f = ( x, y ) => center + new Vector2D( x, y );
            Vector2 draw = new Vector2( radius, 0 );
            Vector2 prev = draw;
            while( draw.X >= draw.Y )
            {
                if( fill )
                {
                    Action<float, float> d = ( x, y ) => DrawHorizon( center.Y + y, center.X - x, center.X + x, color );

                    d( draw.X, draw.Y );

                    if( draw.Y != 0 )
                        d( draw.X, -draw.Y );

                    if( draw.X != prev.X )
                    {
                        d( draw.Y, draw.X );
                        d( draw.Y, -draw.X );
                    }
                }
                else
                {
                    spriteBatch.Draw( pixel, f( draw.X, draw.Y ).ToXna(), color );
                    spriteBatch.Draw( pixel, f( draw.X, -draw.Y ).ToXna(), color );
                    spriteBatch.Draw( pixel, f( -draw.X, draw.Y ).ToXna(), color );
                    spriteBatch.Draw( pixel, f( -draw.X, -draw.Y ).ToXna(), color );
                    spriteBatch.Draw( pixel, f( draw.Y, draw.X ).ToXna(), color );
                    spriteBatch.Draw( pixel, f( draw.Y, -draw.X ).ToXna(), color );
                    spriteBatch.Draw( pixel, f( -draw.Y, draw.X ).ToXna(), color );
                    spriteBatch.Draw( pixel, f( -draw.Y, -draw.X ).ToXna(), color );
                }

                prev = draw;
                Vector2 a = new Vector2( draw.X, draw.Y + 1 );
                Vector2 b = new Vector2( draw.X - 1, draw.Y + 1 );
                float ad = Math.Abs( a.LengthSquared() - radius*radius );
                float bd = Math.Abs( b.LengthSquared() - radius*radius );
                draw = ad < bd ? a : b;
            }
        }
Exemple #10
0
 /// <summary>
 /// 指定した2つのベクトルの外積(ウェッジ積)を計算します。
 /// </summary>
 /// <param name="lop">外積の左オペランド。</param>
 /// <param name="rop">外積の右オペランド。</param>
 /// <returns>外積の演算結果。</returns>
 public static float Wedge( Vector2D lop, Vector2D rop )
 {
     return lop.X * rop.Y - lop.Y * rop.X;
 }
Exemple #11
0
 public static Vector2D GetDistance( Vector2D from, Vector2D to )
 {
     return new Vector2D( to.X - from.X, to.Y - from.Y );
 }
Exemple #12
0
 /// <summary>
 /// 指定した2つのベクトルの内積(ドット積)を計算します。
 /// </summary>
 /// <param name="lop">内積の左オペランド。</param>
 /// <param name="rop">内積の右オペランド。</param>
 /// <returns>内積の演算結果。</returns>
 public static float Dot( Vector2D lop, Vector2D rop )
 {
     return lop.X * rop.X + lop.Y * rop.Y;
 }
 public void DrawRectangle( Vector2D leftTop, Vector2D size, Color color, bool fill )
 {
     DrawRectangle( new NacGeo::Rectangle( leftTop, size ), color, fill );
 }
Exemple #14
0
        public override void Update( GameTime gameTime )
        {
            var state = Mouse.GetState();
            prevPosition = position;
            position = new Vector2D( state.X, state.Y );

            if( state.LeftButton == ButtonState.Pressed ) leftButton++;
            else leftButton = 0;

            if( state.RightButton == ButtonState.Pressed ) rightButton++;
            else rightButton = 0;

            if( state.MiddleButton == ButtonState.Pressed ) middleButton++;
            else middleButton = 0;

            prevWheel = wheel;
            wheel = state.ScrollWheelValue;
        }
Exemple #15
0
 public static void DrawStringCenter( this SpriteBatch spriteBatch, SpriteFont font, string text, Vector2D location, Color color )
 {
     var size = font.MeasureString( text );
     spriteBatch.DrawString( font, text, location.ToXna() - size/2, color );
 }
Exemple #16
0
 public void Move( ref Vector2D position )
 {
     position = Move( position );
 }
Exemple #17
0
 public Circle( Vector2D center, float radius )
     : this()
 {
     Center = center;
     this.Radius = radius;
 }
        public void DrawLine( Vector2D begin, Vector2D end, Color color )
        {
            Vector2D draw = new Vector2D( begin.X, begin.Y );
            Vector2D distance = new Vector2D( ( end - begin ).X, ( end - begin ).Y );
            Vector2D diff = new Vector2D();

            diff = distance / Math.Max( Math.Abs( distance.X ), Math.Abs( distance.Y ) );

            for( ; ( draw - begin ).SquaredLength <= distance.SquaredLength; draw += diff )
                spriteBatch.Draw( pixel, draw.ToXna(), color );
        }
Exemple #19
0
        public override void Update( GameTime gameTime )
        {
            if( Value >= 100 || Value <= -100 )
            {
                Enabled = false;
                base.Update( gameTime );
                return;
            }

            Value += Speed * (float)gameTime.ElapsedGameTime.TotalSeconds;

            var count = keyboard.GetState();
            if( count[MeanOfKey.Mean1] == 1 && Speed > 0 ||
                count[MeanOfKey.Mean2] == 1 && Speed < 0 )
            {
                int add = (int)( Speed * Value );
                Score += add;

                var pos = new Vector2D( ChickenRace.materCenter + ChickenRace.box.Size.X/2 * Value / 100.0f - 30, ChickenRace.box.Top - 16 );
                scoreShows.Add( new ScoreShowing( Game, pos, add, Value > 0 ? ChickenRace.Red : ChickenRace.Blue ) );

                Speed += Math.Sign( Speed ) * 3.5f;
                Speed = -Speed;
            }

            base.Update( gameTime );
        }
 public void DrawPixel( Vector2D position, Color color, float layerDepth = 0.0f )
 {
     spriteBatch.Draw( pixel, position, color: color, layerDepth: layerDepth );
 }
Exemple #21
0
 public Circle( float centerX, float centerY, float radius )
     : this()
 {
     Center = new Vector2D( centerX, centerY );
     this.Radius = radius;
 }