예제 #1
0
        internal void Integrate(float delay, float mass)
        {
            Velocity += Force * (delay / mass);
            //Limit Veloctiy Maximum
            if (Velocity.LengthSquared() > JellyWorld.MaximumVelocitySq)
            {
                Velocity.Normalize();
                Velocity *= JellyWorld.MaximumVelocity;
            }
            Position += Velocity * delay;

            FX = FY = 0;
        }
예제 #2
0
        public static void ProcessEdgeForce(JellyVertex[] polygon, JellyVertex jv)
        {
            if (JellyMath.PointInPolygon(polygon, jv.Position, new JellyVector2(-10000, -10000)))
            {
                jv.Velocity.X = -jv.Velocity.X * JellyWorld.Friciton;
                jv.Velocity.Y = -jv.Velocity.Y * JellyWorld.Friciton;
                jv.FX         = jv.FY = 0;
                jv.Position   = ClosestPoint(jv.Position, polygon);
            }
            else
            {
#if _DIS_RANGE_
                const float threshold = 44.7213595499958f;
#else
                const float threshold = 3162.27766016838f;
#endif
                const float  forcek = 100000;
                int          i      = 0;
                JellyVector2 cpt;
                bool         inVertex, inThreshold, inBack;
                while (i < polygon.Length - 1)
                {
                    FindClosestPointThreshold(jv.Position, polygon[i].Position, polygon[i + 1].Position, threshold * threshold,
                                              out cpt, out inVertex, out inThreshold, out inBack);
                    ++i;
                    if (!inBack && inThreshold)
                    {
                        JellyVector2 diff  = jv.Position - cpt;
                        float        dissq = diff.LengthSquared();
                        dissq = dissq == 0 ? 0.001f : dissq;
#if _DIS_RANGE_
                        float norsize = forcek / dissq - 50;
#else
                        float norsize = forcek / dissq;
#endif
                        norsize = norsize < 0 ? 0 : norsize;
                        if (inVertex)
                        {
                            norsize *= 0.5f;
                        }
                        diff.Normalize();
                        diff     *= norsize;
                        jv.Force += diff;
                    }
                }
                FindClosestPointThreshold(jv.Position, polygon[i].Position, polygon[0].Position, threshold * threshold,
                                          out cpt, out inVertex, out inThreshold, out inBack);
                if (!inBack && inThreshold)
                {
                    JellyVector2 diff  = jv.Position - cpt;
                    float        dissq = diff.LengthSquared();
                    dissq = dissq == 0 ? 0.001f : dissq;
#if _DIS_RANGE_
                    float norsize = forcek / dissq - 50;
#else
                    float norsize = forcek / dissq;
#endif
                    norsize = norsize < 0 ? 0 : norsize;
                    if (inVertex)
                    {
                        norsize *= 0.5f;
                    }
                    diff.Normalize();
                    diff     *= norsize;
                    jv.Force += diff;
                }
            }
        }