コード例 #1
0
ファイル: Vector2fTest.cs プロジェクト: belzecue/Common
        public void Clamp()
        {
            Vector2f v = new Vector2f(0.4f, 1.6f);

            v.Clamp(0.5f, 1.5f);
            Assert.AreEqual(v, new Vector2f(0.5f, 1.5f));

            v = new Vector2f(0.4f, 1.6f);
            v.Clamp(new Vector2f(0.5f, 1.5f), new Vector2f(0.5f, 1.5f));
            Assert.AreEqual(v, new Vector2f(0.5f, 1.5f));
        }
コード例 #2
0
ファイル: ForceLine.cs プロジェクト: trlewis/SfmlGravityWpf
        public void CalculateLine(IEnumerable <GravityObject> objects)
        {
            //just going to use 1 second as the time.
            var totalForce = new Vector2f();

            foreach (var go in objects)
            {
                var distSquared = this._startPos.DistanceSquared(go.GlobalCenterOfMass);
                distSquared /= 10;
                var offsetVec = go.GlobalCenterOfMass - this._startPos;
                var force     = GravityObject.GravitationalConstant * (this._mass * go.Mass) * offsetVec /
                                (float)Math.Sqrt(Math.Pow((distSquared + GravityObject.Epsilon * GravityObject.Epsilon), 3));

                totalForce += force;
            }

            totalForce = totalForce.Clamp(this._maxLength);
            var endPoint = this._startPos + totalForce;

            this.Line = new[] { new Vertex(this._startPos, Color.White), new Vertex(endPoint, Color.Red) };
        }
コード例 #3
0
ファイル: Box1.cs プロジェクト: Burton-Radons/Alexandria
 /// <summary>Get the nearest point between this <see cref="Box2f"/> and a <see cref="Vector2f"/>. If the <see cref="Vector2f"/> is inside this <see cref="Box2f"/>, it is returned untouched.</summary>
 public void NearestPointTo( ref  Vector2f point , out Vector2f result)
 {
     Containment containment = Intersect(ref point);
         if(containment != Containment.Disjoint)
             result = point;
         else
             point.Clamp(ref Min, ref Max, out result);
         return;
 }
コード例 #4
0
ファイル: Box1.cs プロジェクト: Burton-Radons/Alexandria
 /// <summary>Get the nearest point between this <see cref="Box2f"/> and a <see cref="Vector2f"/>. If the <see cref="Vector2f"/> is inside this <see cref="Box2f"/>, it is returned untouched.</summary>
 public Vector2f NearestPointTo( Vector2f point )
 {
     Vector2f result;
         Containment containment = Intersect(ref point);
         if(containment != Containment.Disjoint)
             result = point;
         else
             point.Clamp(ref Min, ref Max, out result);
         return result;
 }