コード例 #1
0
        void CheckGRBD()
        {
            Pair <double, PGravityBody> force = new Pair <double, PGravityBody>(0, null);

            foreach (var gb in world.Gravitybodies)
            {
                double f = PWorld.G * gb.Mass * Mass / (Position - gb.Position).sqrMagnitude;
                force = f > force.a ? new Pair <double, PGravityBody>(f, gb) : force;
            }
            if (GravityBody == force.b)
            {
                return;
            }
            var vel = Velocity;

            GravityBody = force.b;
            newVelocity = vel;
        }
コード例 #2
0
ファイル: PWorld.cs プロジェクト: okeanz/Trajectories
        public PGravityBody AddGravityBody(PVector3 position, PVector3 speed, string name, double mass)
        {
            var body = new PGravityBody(name, position, this)
            {
                Mass = mass
            };

            if (Gravitybodies.Count > 0)
            {
                body.GravityBody = Gravitybodies[0];
            }
            if (speed != PVector3.zero)
            {
                body.Trajectory.UpdateCurve(speed);
            }
            Gravitybodies.Add(body);
            Gravitybodies.Sort((x, y) => (int)(x.CatchDistance - y.CatchDistance));
            return(body);
        }