// Update is called once per frame

    public override void UpdateForce(ref PhysicsDataPtr pData, float dt)
    {
        if (mPlanet == null)
        {
            ForceManager.DeleteForceGenerator(this);
            return;
        }

        Vector2 radiusVec = mPlanet.mpPhysicsData.pos - pData.pos;

        if (radiusVec.magnitude == 0)
        {
            return;
        }

        //radiusVec *= .5f;
        float gravitationalForce = (universalGavitationalConstant * (1 / mPlanet.mpPhysicsData.inverseMass) * (1 / pData.inverseMass)) / (radiusVec.magnitude * radiusVec.magnitude);

        radiusVec.Normalize();
        pData.accumulatedForces += gravitationalForce * radiusVec;
        //mPlanet.mpPhysicsData.accumulatedForces -= gravitationalForce * radiusVec;
    }
示例#2
0
    static public void ApplyAllForces(float dt)
    {
        while (springToDelete.Count != 0)
        {
            springForceGenerators.Remove(springToDelete[0]);
            springToDelete.RemoveAt(0);
        }

        foreach (SpringForceGenerator2D fg in springForceGenerators)
        {
            if (fg.GetShouldEffectAll())
            {
                foreach (Particle2D particle2D in GameObject.FindObjectsOfType <Particle2D>())
                {
                    fg.UpdateForce(ref particle2D.mpPhysicsData, dt);
                }
            }
            else
            {
                PhysicsDataPtr p = new PhysicsDataPtr();
                fg.UpdateForce(ref p, dt);
            }
        }

        while (pointToDelete.Count != 0)
        {
            pointForceGenerators.Remove(pointToDelete[0]);
            pointToDelete.RemoveAt(0);
        }
        foreach (PointForceGenerator2D fg in pointForceGenerators)
        {
            if (fg.GetShouldEffectAll())
            {
                foreach (Particle2D particle2D in GameObject.FindObjectsOfType <Particle2D>())
                {
                    fg.UpdateForce(ref particle2D.mpPhysicsData, dt);
                }
            }
            else
            {
                PhysicsDataPtr p = new PhysicsDataPtr();
                fg.UpdateForce(ref p, dt);
            }
        }

        while (bouyancyToDelete.Count != 0)
        {
            bouyancyForceGenerators.Remove(bouyancyToDelete[0]);
            bouyancyToDelete.RemoveAt(0);
        }
        foreach (BouyancyForceGenerator2D fg in bouyancyForceGenerators)
        {
            PhysicsDataPtr p = new PhysicsDataPtr();
            fg.UpdateForce(ref p, dt);
        }

        while (rodToDelete.Count != 0)
        {
            rodForceGenerators.Remove(rodToDelete[0]);
            rodToDelete.RemoveAt(0);
        }
        foreach (RodForceGenerator2D fg in rodForceGenerators)
        {
            if (fg.GetShouldEffectAll())
            {
                foreach (Particle2D particle2D in GameObject.FindObjectsOfType <Particle2D>())
                {
                    fg.UpdateForce(ref particle2D.mpPhysicsData, dt);
                }
            }
            else
            {
                PhysicsDataPtr p = new PhysicsDataPtr();
                fg.UpdateForce(ref p, dt);
            }
        }

        while (planetaryToDelete.Count != 0)
        {
            planetaryForceGenerators.Remove(planetaryToDelete[0]);
            planetaryToDelete.RemoveAt(0);
        }

        foreach (PlanetaryForceGenerator fg in planetaryForceGenerators)
        {
            foreach (Particle2D particle2D in GameObject.FindObjectsOfType <Particle2D>())
            {
                fg.UpdateForce(ref particle2D.mpPhysicsData, dt);
            }
        }
    }
 abstract public void UpdateForce(ref PhysicsDataPtr pData, float dt);