Example #1
0
        public override void Update(FP dt)
        {
            TSVector2 tSVector = TSVector2.zero;

            foreach (Body current in this.World.BodyList)
            {
                bool flag = !this.IsActiveOn(current);
                if (!flag)
                {
                    foreach (Body current2 in this.Bodies)
                    {
                        bool flag2 = current == current2 || (current.IsStatic && current2.IsStatic) || !current2.Enabled;
                        if (!flag2)
                        {
                            TSVector2 value = current2.Position - current.Position;
                            FP        fP    = value.LengthSquared();
                            bool      flag3 = fP <= Settings.Epsilon || fP > this.MaxRadius * this.MaxRadius || fP < this.MinRadius * this.MinRadius;
                            if (!flag3)
                            {
                                GravityType gravityType = this.GravityType;
                                if (gravityType != GravityType.Linear)
                                {
                                    if (gravityType == GravityType.DistanceSquared)
                                    {
                                        tSVector = this.Strength / fP * current.Mass * current2.Mass * value;
                                    }
                                }
                                else
                                {
                                    tSVector = this.Strength / FP.Sqrt(fP) * current.Mass * current2.Mass * value;
                                }
                                current.ApplyForce(ref tSVector);
                            }
                        }
                    }
                    foreach (TSVector2 current3 in this.Points)
                    {
                        TSVector2 value2 = current3 - current.Position;
                        FP        fP2    = value2.LengthSquared();
                        bool      flag4  = fP2 <= Settings.Epsilon || fP2 > this.MaxRadius * this.MaxRadius || fP2 < this.MinRadius * this.MinRadius;
                        if (!flag4)
                        {
                            GravityType gravityType2 = this.GravityType;
                            if (gravityType2 != GravityType.Linear)
                            {
                                if (gravityType2 == GravityType.DistanceSquared)
                                {
                                    tSVector = this.Strength / fP2 * current.Mass * value2;
                                }
                            }
                            else
                            {
                                tSVector = this.Strength / FP.Sqrt(fP2) * current.Mass * value2;
                            }
                            current.ApplyForce(ref tSVector);
                        }
                    }
                }
            }
        }
Example #2
0
    public GravityModel(GravityType type, Position position)
    {
        Type     = type;
        Position = position;

        switch (type)
        {
        case GravityType.Nil:
            vector = new int[] { 0, 0 };
            break;

        case GravityType.Up:
            vector = new int[] { 0, 1 };
            break;

        case GravityType.Down:
            vector = new int[] { 0, -1 };
            break;

        case GravityType.Left:
            vector = new int[] { -1, 0 };
            break;

        case GravityType.Right:
            vector = new int[] { 1, 0 };
            break;
        }
    }
Example #3
0
    public void changeGravityLevel(GravityType type)
    {
        switch (type)
        {
        case GravityType.Normal:
            gravityValue = 9.81f;
            break;

        case GravityType.Reversed:
            isGravityReversed            = !isGravityReversed;
            Camera.main.transform.parent = null;
            transform.Rotate(180f, 0, 0);
            Camera.main.transform.parent = transform;
            Camera.main.GetComponent <CameraScript>().reverseGravity();

            break;

        case GravityType.High:
            gravityValue = 20f;
            break;

        case GravityType.Low:
            gravityValue = 3f;
            break;

        default:
            break;
        }
    }
Example #4
0
 public GravityController(float strength) : base(ControllerType.GravityController)
 {
     strength    = strength;
     maxRadius   = float.MaxValue;
     gravityType = GravityType.DistanceSquared;
     points      = new List <Vector2>();
     bodies      = new List <Body>();
 }
 public GravityController(float strength, float maxRadius, float minRadius) : base(ControllerType.GravityController)
 {
     this.minRadius   = minRadius;
     this.maxRadius   = maxRadius;
     this.strength    = strength;
     this.gravityType = GravityType.DistanceSquared;
     this.points      = new List <Vector2>();
     this.bodies      = new List <Body>();
 }
Example #6
0
 public GravityController(float strength, float maxRadius, float minRadius) : base(ControllerType
                                                                                   .GravityController)
 {
     this.MinRadius   = minRadius;
     this.MaxRadius   = maxRadius;
     this.Strength    = strength;
     this.GravityType = GravityType.DistanceSquared;
     this.Points      = new List <System.Numerics.Vector2>();
     this.Bodies      = new List <Body>();
 }
        private bool IsGravity(GravityType gravityType, params GravityType[] gravityTypes)
        {
            if (gravityType == GravityType.None)
            {
                return(Gravity == (int)GravityType.None);
            }

            return((Gravity & (int)gravityType) == (int)gravityType &&
                   gravityTypes.All(g => (Gravity & (int)g) == (int)g));
        }
 public GravityController(float strength, float maxRadius, float minRadius) : base(ControllerType
                                                                                   .GravityController)
 {
     MinRadius   = minRadius;
     MaxRadius   = maxRadius;
     Strength    = strength;
     GravityType = GravityType.DistanceSquared;
     Points      = new List <Vector2>();
     Bodies      = new List <Body>();
 }
        public bool shortMistake = false; //if mistake is of short type (either pause or speakingtime) it stil does not have to be a mistake

        public Mistake(Type type, SubType subType, GravityType gravityType)
        {
            timeStarted = DateTime.Now.TimeOfDay.TotalMilliseconds;            
            this.subType = subType;
            this.type = type;
            this.gravityType = gravityType;
            setGravity(gravityType);
            hasEnded = false;
            volumeMistakeLongEnough = false;
            classtype = "Mistake";
        }
Example #10
0
            /// <summary>
            /// Sets gravity of the image on the canvas it is plotted on.
            /// <para>
            /// Defaults to <see cref="GravityType.None"/>.
            /// </para>
            /// </summary>
            /// <param name="gravityType">first gravity</param>
            /// <param name="gravityTypes">rest of gravity types</param>
            /// <returns>this Builder for chaining</returns>
            public Builder SetGravity(GravityType gravityType, params GravityType[] gravityTypes)
            {
                Gravity = (int)gravityType;

                foreach (var g in gravityTypes)
                {
                    Gravity |= (int)g;
                }

                return(this);
            }
Example #11
0
        /// <summary> The static method to return an ICosmonaut with a specified gravity value. </summary>
        public static ICosmonaut GetCosmonaut(GravityType gravity)
        {
            switch (gravity)
            {
            case GravityType.Weightless:
                return(new WeightlessPassengerFactory().NewCosmonaut());

            default:
                return(new PassengerFactory().NewCosmonaut());
            }
        }
Example #12
0
        /// <summary> The static method to return an IToy with a specified gravity value. </summary>
        public static IToy GetToy(GravityType gravity)
        {
            switch (gravity)
            {
            case GravityType.Weightless:
                return(new WeightlessPassengerFactory().NewToy());

            default:
                return(new PassengerFactory().NewToy());
            }
        }
Example #13
0
 private bool IsInto(GravityType type) // 似乎没什么用的样子
 {
     if (type == GravityType.Static_into || type == GravityType.Sphere_into || type == GravityType.UnShape_into)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #14
0
        /// <summary>
        /// The public static method to create a new IPassenger of a specified type
        /// corresponding to the enumeration of PassengerType provided with the
        /// desired gravity enumeration applied.
        /// </summary>
        public static IPassenger GetPassenger(PassengerType passengerType, GravityType gravity)
        {
            switch (passengerType)
            {
            case PassengerType.Cosmonaut:
                return(GetCosmonaut(gravity));

            case PassengerType.Toy:
                return(GetToy(gravity));

            default:
                return(GetAstronaut(gravity));
            }
        }
Example #15
0
        /// <summary>
        /// A slightly easier approach.
        /// </summary>
        private static void executeGravityCreator(GravityType gravity)
        {
            var astronaut = PassengerCreator.GetAstronaut(gravity);
            var cosmonaut = PassengerCreator.GetCosmonaut(gravity);
            var toy       = PassengerCreator.GetToy(gravity);

            // push buttons
            con(astronaut.PushButton());

            // flip switch
            con(cosmonaut.FlipSwitch());

            // pull string
            con(toy.PullString());
        }
        public void DoSendSameLaunchCommand(GravityType gravity)
        {
            string got;

            switch (gravity)
            {
            case GravityType.Weightless:
                got = m_Fix.sut_ZeroGPassenger.LaunchCommand();
                m_Output.WriteLine(got);
                Assert.Equal(m_Fix.sut_LaunchZeroGExpected, got);
                break;

            default:
                got = m_Fix.sut_Passenger.LaunchCommand();
                m_Output.WriteLine(got);
                Assert.Equal(m_Fix.sut_LaunchExpected, got);
                break;
            }
        }
        public void DoSpeakSamePhrase(GravityType gravity)
        {
            string got;

            switch (gravity)
            {
            case GravityType.Weightless:
                got = m_Fix.sut_ZeroGPassenger.Speak();
                m_Output.WriteLine(got);
                Assert.Equal(m_Fix.sut_SpeakZeroGExpected, got);
                break;

            default:
                got = m_Fix.sut_Passenger.Speak();
                m_Output.WriteLine(got);
                Assert.Equal(m_Fix.sut_SpeakExpected, got);
                break;
            }
        }
        public void SpeechShouldDiffer(GravityType gravity)
        {
            string got;
            string expected;

            switch (gravity)
            {
            case GravityType.Weightless:
                got      = m_Fix.sut_Passenger.Speak();
                expected = m_Fix.sut_SpeakZeroGExpected;
                break;

            default:
                got      = m_Fix.sut_ZeroGPassenger.Speak();
                expected = m_Fix.sut_SpeakExpected;
                break;
            }
            m_Output.WriteLine("expecting: [{0}] and got: [{1}] as expected they should not match!", expected, got);
            Assert.NotEqual(expected, got);
        }
Example #19
0
        /// <summary>
        /// A more complex approach where are passengers have different things they can do.
        /// </summary>
        private static void executeComplexLaunchCommand(PassengerType passengerType, GravityType gravity)
        {
            var passenger = PassengerCreator.GetPassenger(passengerType, gravity);

            if (passenger is IAstronaut astronaut)
            {
                con(astronaut.LaunchCommand());
                con(astronaut.PushButton()); // Astronauts push buttons
            }
            else if (passenger is ICosmonaut cosmonaut)
            {
                con(cosmonaut.LaunchCommand());
                con(cosmonaut.FlipSwitch()); // Cosmonaut flips switches
            }
            else if (passenger is IToy toy)
            {
                con(toy.LaunchCommand());
                con(toy.PullString()); // Pull Toy's string
            }
        }
        public void TheCorrectGravityCreated(GravityType gravity)
        {
            IPassenger got;
            Type       expected;

            switch (gravity)
            {
            case GravityType.Weightless:
                got      = m_Fix.sut_ZeroGPassenger;
                expected = m_Fix.sut_ZeroGTypeExpected;
                m_Output.WriteLine("expecting: [{0}] and got: [{1}]", expected.Name, got.GetType().Name);
                Assert.IsType(expected, got);
                break;

            default:
                got      = m_Fix.sut_Passenger;
                expected = m_Fix.sut_NormalTypeExpected;
                m_Output.WriteLine("expecting: [{0}] and got: [{1}]", expected.Name, got.GetType().Name);
                Assert.IsType(expected, got);
                break;
            }
        }
Example #21
0
 private extern static void ecore_x_window_gravity_set(IntPtr win,
                                                       GravityType g);
Example #22
0
 /// <summary>
 /// Creates a gravity controller and adds it to the physics simulator.
 /// </summary>
 /// <param name="simulator">the physicsSimulator used by this controller.</param>
 /// <param name="points">The points you want to generate gravity.</param>
 /// <param name="type">the type of gravity this uses.</param>
 /// <param name="strength">the maximum strength of gravity (the gravity strength when two bodies are on the same spot)</param>
 /// <param name="radius">the maximum distance that can be between 2 bodies before it will stop trying to apply gravity between them.</param>
 public GravityController CreateGravityController(PhysicsSimulator simulator, List<Vector2> points, GravityType type, float strength, float radius)
 {
     GravityController gravityController = new GravityController(simulator, points, strength, radius);
     gravityController.GravityType = type;
     simulator.Add(gravityController);
     return gravityController;
 }
 private static extern bool MagickSetGravity(IntPtr wand, GravityType gravity);
Example #24
0
    public static GravityModel Get(GravityType gravityType, Position position)
    {
        var gravityModel = new GravityModel(gravityType, position);

        return(gravityModel);
    }
Example #25
0
 internal static extern bool MagickSetImageGravity(IntPtr wand, GravityType gravity);
 internal static extern void DrawSetGravity(IntPtr wand, GravityType gravity);
 // 5 states discerned = 3,1,0,1,3. 
 // 3 states discerned = 2,0,2. 
 // 2 states discerned = 2,0.
 public void setGravity(GravityType GT)
 {
     int points = 0;
     switch (GT)
     {
         case GravityType.veryLoud:
             {
                 points = 3;                        
                 break;
             }
         case GravityType.loud:
             {
                 points = 1;
                 break;
             }
         case GravityType.verySoft:
             {
                 points = 3;
                 break;
             }
         case GravityType.soft:
             {
                 points = 1;
                 break;
             }
         case GravityType.veryLongPause:
             {
                 points = 3;
                 break;
             }
         case GravityType.longPause:
             {
                 points = 1;
                 break;
             }
         case GravityType.veryLongSpeakingTime:
             {
                 points = 3;
                 break;
             }
         case GravityType.longSpeakingTime:
             {
                 points = 1;
                 break;
             }
         case GravityType.bad:
             {
                 points = 2;
                 break;
             }
         case GravityType.notEnough:
             {
                 points = 2;
                 break;
             }
         case GravityType.tooMuch:
             {
                 points = 2;
                 break;
             }
         case GravityType.shortPause:
             {
                 if (shortMistake)
                 {
                     points = 10;
                 }  
                 break;
             }
         case GravityType.shortSpeakingTime:
             {
                 if (shortMistake)
                 {
                     points = 10;
                 }                        
                 break;
             }
     }
     this.gravity = points;
     gravityType = GT;
 }
Example #28
0
        /// <summary>
        /// Initializes the particle System. 
        /// The Particle will spawn at the specified POINT with the defined SpawnType, 
        /// with the specified Directions, speed and the specified Gravity
        /// </summary>
        /// <param name="fontaine">Determines the spawnType:
        /// Fontain: The particles will spawn continously at the specified Point
        /// Explosion: The particles will spawn all at once at the specified Point</param>
        /// <param name="pnumParticles">Maximum particle number</param>
        /// <param name="particle_s">Spawntype:
        /// Fontain: The Particle per second (must be >= 60 to spawn any particles), also controls the particle lifetime = numParticles/particle_s
        /// Explosion: The particles Lifetime</param>
        /// <param name="Size">The Size of the Particles</param>
        /// <param name="pStdColor">The Color of the Particles</param>
        /// <param name="src">The Point where the particles are going to spawn</param>
        /// <param name="pdirections">Determines the Directions in which the particles are going to go</param>
        /// <param name="maxSpeed">The Maxmimum x and y speed</param>
        /// <param name="tex">The Texture of the particles</param>
        /// <param name="Gravity">The Gravity Type.
        /// OverallForce: all particles will be forced in that direction
        /// Point: All particles are going to move to that direction
        /// Newton: All particles are going to have planetary Gravity, Masses can be defined with the AddNewtonMass() method</param>
        /// <param name="gravAim">
        /// Gravity Type:
        /// Overall Force: The force which will be applied.
        /// Point: The Point, the particles are heading to.
        /// Newton: No affect
        /// </param>
        /// <param name="pfriction">Particles speed will bei divided by this when they collided with sth.</param>
        /// <param name="collison">Defines if the particles can collide or not</param>
        public void Initialize(bool bla, SpawnType fontaine, int pnumParticles, float particle_s, int Size, Color pStdColor, Vector2 src,
			SpawnDirections pdirections, Vector2 maxSpeed, Texture2D tex, GravityType Gravity, Vector2 gravAim,
			float pfriction, CollisionType collison)
        {
            Initialize(false,
                fontaine,
                pnumParticles,
                particle_s,
                Size,
                pStdColor,
                src,
                src,
                pdirections,
                maxSpeed,
                tex,
                Gravity,
                gravAim,
                pfriction,
                collison);
        }
Example #29
0
        /// <summary>
        /// Initializes the particle System. 
        /// The Particle will spawn at the specified RECTANGLE with the defined SpawnType, 
        /// with the specified Directions, speed and the specified Gravity
        /// </summary>
        /// <param name="fontaine">Determines the spawnType:
        /// Fontain: The particles will spawn continously at the specified Point
        /// Explosion: The particles will spawn all at once at the specified Point</param>
        /// <param name="pnumParticles">Maximum particle number</param>
        /// <param name="particle_s">Spawntype:
        /// Fontain: The Particle per second (must be >= 60 to spawn any particles), also controls the particle lifetime = numParticles/particle_s
        /// Explosion: The particles Lifetime</param>
        /// <param name="Size">The Size of the Particles</param>
        /// <param name="pStdColor">The Color of the Particles</param>
        /// <param name="startpos">The Startpoint of the Rectangle where the particles are going to spawn</param>
        /// <param name="endpos">The Endpos of the Rectangle where the particles are going to spawn</param>
        /// <param name="pdirections">Determines the Directions in which the particles are going to go</param>
        /// <param name="maxSpeed">The Maxmimum x and y speed</param>
        /// <param name="tex">The Texture of the particles</param>
        /// <param name="Gravity">The Gravity Type.
        /// OverallForce: all particles will be forced in that direction
        /// Point: All particles are going to move to that direction
        /// Newton: All particles are going to have planetary Gravity, Masses can be defined with the AddNewtonMass() method</param>
        /// <param name="gravAim">
        /// Gravity Type:
        /// Overall Force: The force which will be applied.
        /// Point: The Point, the particles are heading to.
        /// Newton: No affect
        /// </param>
        /// <param name="pfriction">Particles speed will bei divided by this when they collided with sth.</param>
        /// <param name="collison">Defines if the particles can collide or not</param>
        public void Initialize(bool bla, SpawnType fontaine, int pnumParticles, float particle_s, int Size, Color pStdColor, Vector2 startpos, Vector2 endpos,
	SpawnDirections pdirections, Vector2 maxSpeed, Texture2D tex, GravityType Gravity, Vector2 gravAim,
	float pfriction, CollisionType collison)
        {
            if (startpos != endpos)
                spawnsource = SpawnSource.Rectangle;
            else
                spawnsource = SpawnSource.Point;

            masses = new List<NewtonMass>();
            collisiontype = collison;
            spawntype = fontaine;
            gravtype = Gravity;
            spawndirections = pdirections;

            size = Size;

            rand = new Random((int)DateTime.Now.Ticks);
            stdcolor = pStdColor;
            spawn = startpos;
            spawnend = endpos;
            maxspeed = maxSpeed;
            spawnperS = particle_s;
            numParticles = pnumParticles;
            positions = new Vector2[numParticles];
            velocities = new Vector2[numParticles];
            lifetimes = new float[numParticles];
            rects = new Rectangle[numParticles];
            Rotations = new float[numParticles];
            alphas = new byte[numParticles];
            floatalphas = new float[numParticles];
            collisionrectangles = new List<Rectangle>();
            collisionrectangles.Add(new Rectangle(-500000000, 0, 0, 0));
            particletex = tex;
            gravtype = Gravity;
            friction = MathHelper.Clamp(pfriction, float.Epsilon, float.MaxValue);
            gravity = gravAim;
            duration = new TimeSpan[numThreads];
            if (fontaine == SpawnType.Fontaine)
            {
                totallifetime = pnumParticles / particle_s;
            }
            else
            {
                totallifetime = particle_s;
            }
            for (int i = 0; i < pnumParticles; i++)
            {
                ResetParticle(i);
                lifetimes[i] = totallifetime + 1;
            }
            running = true;
            updatethread = new Thread[numThreads];
            newframe = new bool[numThreads];
            for (int i = 0; i < numThreads; i++)
            {
                updatethread[i] = new Thread((new ParameterizedThreadStart(UpdateThread)));
                updatethread[i].Name = "ParticleThread#" + i.ToString();
            }
            initialized = true;
            airFriction = 1;

            newSpawners = 0;
            InitalizeCUDA();
        }
Example #30
0
        /// <summary>
        /// Creates a gravity controller and adds it to the physics simulator.
        /// </summary>
        /// <param name="simulator">the physicsSimulator used by this controller.</param>
        /// <param name="points">The points you want to generate gravity.</param>
        /// <param name="type">the type of gravity this uses.</param>
        /// <param name="strength">the maximum strength of gravity (the gravity strength when two bodies are on the same spot)</param>
        /// <param name="radius">the maximum distance that can be between 2 bodies before it will stop trying to apply gravity between them.</param>
        public GravityController CreateGravityController(PhysicsSimulator simulator, List <Vector2> points, GravityType type, float strength, float radius)
        {
            GravityController gravityController = new GravityController(simulator, points, strength, radius);

            gravityController.GravityType = type;
            simulator.Add(gravityController);
            return(gravityController);
        }
Example #31
0
 private static extern bool MagickSetGravity(IntPtr wand, GravityType gravity);
 internal static extern bool MagickSetImageGravity(IntPtr wand, GravityType gravity);
Example #33
0
 internal static extern void DrawSetGravity(IntPtr wand, GravityType gravity);
Example #34
0
	   private extern static void ecore_x_window_gravity_set(IntPtr win,
								 GravityType g);