示例#1
0
文件: Test1.cs 项目: bukind/chasegame
 public void Run()
 {
     Vec v = new Vec(1.0,1.0);
     Console.WriteLine("v={0}", v);
     v = v.Scale(5.0).Add(new Vec(3.0,-2.0));
     Console.WriteLine("v={0}", v);
 }
示例#2
0
文件: Test1.cs 项目: bukind/chasegame
        public void TestSort()
        {
            var list = new List<Vec>();
            const int len = 10;
            list.Capacity = len;
            for (int i = 0; i < len; ++i) {
                var s = new Vec(GetF(100.0), GetF(50.0));
                list.Add(s);
            }

            Console.WriteLine("The list is [{0}]", string.Join(", ", list));
            list.Sort(this.compareVecByX);
            Console.WriteLine("The list is [{0}]", string.Join(", ", list));

            Assert.That(false);
        }
示例#3
0
 public RibRect(Rib r)
 {
     var radius = r.Sprite.Radius;
     min = r.StartPos;
     max = r.EndPos;
     if (max.X < min.X) {
         var t = max.X;
         max.X = min.X;
         min.X = t;
     }
     if (max.Y < min.Y) {
         var t = max.Y;
         max.Y = min.Y;
         min.Y = t;
     }
     min.X -= radius;
     min.Y -= radius;
     max.X += radius;
     max.Y += radius;
 }
示例#4
0
文件: Vec.cs 项目: bukind/chasegame
 public Vec Add(Vec x)
 {
     var tmp = this;
     tmp.X += x.X;
     tmp.Y += x.Y;
     return tmp;
 }
示例#5
0
文件: Vec.cs 项目: bukind/chasegame
 public Vec Rotate(Vec a)
 {
     return Rotate(a.X, a.Y);
 }
示例#6
0
 void OnMouseUp(object sender, MouseEventArgs a)
 {
     if (a.Button == MouseButtons.Left && !mouseDownLocation.IsEmpty) {
         U.show("OnMouseUp");
         var s = new Sprite(images[curimage], 0.0F);
         s.Position = new Vec(mouseDownLocation);
         Vec spd = new Vec(a.Location).Subtract(s.Position).Scale(0.4);
         var speedlen = spd.Length;
         if (speedlen > U.maxspeed) {
             spd = spd.Scale(U.maxspeed/speedlen);
         } else if (speedlen < U.minspeed) {
             // make random speed
             double alpha = Math.PI * 2.0 * random.NextDouble();
             speedlen = (random.NextDouble() * (U.maxspeed-U.minspeed) + U.minspeed);
             spd = Vec.Dir(alpha).Scale(speedlen);
         }
         s.Speed = spd;
         s.Rotation = (float)(random.NextDouble() - 0.5) * 10.0F;
         sprites.Add(s);
         mouseDownLocation = new Point();
         mouseLastLocation = mouseDownLocation;
     } else if (a.Button == MouseButtons.Right) {
         curimage += 1;
         if (curimage >= images.Count) {
             curimage = 0;
         }
         prototype = new Sprite(images[curimage], 0.0F);
     }
 }
示例#7
0
文件: Vec.cs 项目: bukind/chasegame
 public Vec Subtract(Vec x)
 {
     var tmp = this;
     tmp.X -= x.X;
     tmp.Y -= x.Y;
     return tmp;
 }
示例#8
0
文件: Vec.cs 项目: bukind/chasegame
 public Rot(double alpha)
 {
     rot = new Vec(Math.Cos(alpha), Math.Sin(alpha));
 }
示例#9
0
文件: Vec.cs 项目: bukind/chasegame
 // return a tangental projection
 public Vec Project(Vec v)
 {
     return v.Scale(this.Scalar(v)/v.Length2);
 }
示例#10
0
文件: Vec.cs 项目: bukind/chasegame
 public double Scalar(Vec v)
 {
     return X * v.X + Y * v.Y;
 }
示例#11
0
文件: Test1.cs 项目: bukind/chasegame
 private int compareVecByX(Vec a, Vec b)
 {
     return (a.X < b.X) ? -1 : ((a.X > b.X) ? 1 : 0);
 }
示例#12
0
文件: Vec.cs 项目: bukind/chasegame
 public Vec Normal(Vec v)
 {
     return this.Subtract(Project(v));
 }
示例#13
0
 public Sprite(Bitmap theimg, double themass)
     : this()
 {
     image = theimg;
     Speed = new Vec();
     alpha = omega = 0.0;
     // init is the initial radius
     var init = Math.Min(image.Size.Width, image.Size.Height) * 0.5;
     if (themass <= 0.001) {
         themass = init * init;
     }
     mass = themass;
     radius = Math.Sqrt(mass);
     scale = radius / init * 0.5;
     Position = new Vec(image.Size).Scale(scale);
 }
示例#14
0
 public void Update(Rib rib)
 {
     Position = rib.EndPos;
     Speed    = rib.Speed;
     alpha   += omega * rib.DeltaTime;
 }
示例#15
0
 public void Update(Rib rib)
 {
     Position = rib.EndPos;
     Speed = rib.Speed;
     alpha += omega * rib.DeltaTime;
 }
示例#16
0
 public void Draw(Graphics g)
 {
     PointF[] dest = new PointF[3];
     Rot rotation = new Rot(alpha);
     Vec sz = new Vec(image.Size).Scale(scale);
     // x + px*cosa+py*sina, y - px*sina + py*cosa
     dest[0] = Position.Add(rotation.Rotate(-sz.X, -sz.Y)).Point;
     dest[1] = Position.Add(rotation.Rotate(sz.X, -sz.Y)).Point;
     dest[2] = Position.Add(rotation.Rotate(-sz.X, sz.Y)).Point;
     g.DrawImage(image, dest);
 }
示例#17
0
 public Sprite(Bitmap theimg, Sprite one, Sprite two)
     : this(theimg, one.mass + two.mass)
 {
     // now calculate the position, speed and rotation
     double invertmass = 1.0/mass;
     Position = one.Position.Scale(one.Mass).Add(two.Position.Scale(two.Mass)).Scale(invertmass);
     Speed = one.Speed.Scale(one.Mass).Add(two.Speed.Scale(two.mass)).Scale(invertmass);
     alpha = (Math.IEEERemainder(one.alpha,Math.PI*2) * one.AngularMass + Math.IEEERemainder(two.alpha,Math.PI*2) * two.AngularMass) / AngularMass;
     // sum up all moments of rotation
     double totalRotationMomentum =
         one.Mass * one.Position.Subtract(Position).Normal(one.Speed).Length +
         two.Mass * two.Position.Subtract(Position).Normal(two.Speed).Length +
         one.AngularMass * one.omega + two.AngularMass * two.omega;
     omega = totalRotationMomentum / AngularMass;
 }