Inheritance: MonoBehaviour
            public void TwoBodysWithSpringPushAway()
            {
                World w = new World ();

                Rigid r1 = new Rigid (30, new Matrix (70, 70, 70));
                r1.StartCenterOfMass = new Vector ();
                w.AddRigid (r1);
                w.AddEffect (new Force (new Vector (-30, 0, 0), r1));

                Rigid r2 = new Rigid (30, new Matrix (70, 70, 70));
                r2.StartCenterOfMass = new Vector (10, 0, 0);
                w.AddRigid (r2);
                w.AddEffect (new Force (new Vector (30, 0, 0), r2));

                Vector v = new Vector ();
                Spring spring = new Spring (r1, v, r2, v, 300, 0);
                w.AddEffect (spring);

                State s1 = new State (w);

                s1.Simulate (5);

                Assert.AreEqual (-0.0966, s1.RigidStates [r1].CenterOfMass.X, 0.001);
                Assert.AreEqual (0.0808, s1.RigidStates [r1].LinearVelocity.X, 0.001);
                Assert.AreEqual (0.9324, s1.RigidStates [r1].LinearAcceleration.X, 0.001);

                Assert.AreEqual (10.0966, s1.RigidStates [r2].CenterOfMass.X, 0.001);
                Assert.AreEqual (-0.0808, s1.RigidStates [r2].LinearVelocity.X, 0.001);
                Assert.AreEqual (-0.9324, s1.RigidStates [r2].LinearAcceleration.X, 0.001);
            }
Ejemplo n.º 2
0
 public void Init()
 {
     PositionSpring = new Spring (transform, Spring.TransformType.Position);
     PositionSpring.MinVelocity = 0.00001f;
     RotationSpring = new Spring (transform, Spring.TransformType.Rotation);
     RotationSpring.MinVelocity = 0.00001f;
 }
Ejemplo n.º 3
0
    //Scripts
    void Start()
    {
        springObject = GameObject.Find("Spring");
        springScript = springObject.GetComponent<Spring>();

        /*
         * Grabs the GameObject that holds the 'Spring' script.
         * Now that we have our external script in our hands, we can make changes in it in this script.
         */
    }
 protected override void DoBegin(object transaction, Spring.Transaction.ITransactionDefinition definition)
 {
     PromotableTxScopeTransactionObject txObject =
         (PromotableTxScopeTransactionObject)transaction;
     try
     {
         DoTxScopeBegin(txObject, definition);
     }
     catch (Exception e)
     {
         throw new CannotCreateTransactionException("Transaction Scope failure on begin", e);
     }
 }
Ejemplo n.º 5
0
    void Start()
    {
        spawner = GameObject.FindGameObjectWithTag("GameController").GetComponent<SpawnerScript>();

        springs = new Spring[springCount];
        triangles = new int[springCount * 6];
        uvs = new Vector2[springCount * 4];
        vertices = new Vector3[springCount * 4];

        for (int i = 0; i < springCount; ++i)
        {
            springs[i] = new Spring();
        }

        int j = 0;

        for (int i = 0; i < springCount * 6; )
        {
            triangles[i] = j;
            triangles[i + 1] = j + 1;
            triangles[i + 2] = j + 2;
            triangles[i + 3] = j;
            triangles[i + 4] = j + 2;
            triangles[i + 5] = j + 3;

            j += 4;
            i += 6;
        }

        for (int i = 0; i < springCount * 4; i += 4)
        {
            uvs[i] = new Vector2(1, 1);
            uvs[i + 1] = new Vector2(0, 1);
            uvs[i + 2] = new Vector2(1, 0);
            uvs[i + 3] = new Vector2(0, 0);
        }

        for (int i = 1; i < springCount; ++i)
        {
            vertices[(i - 1) * 4]     = new Vector3(0 - ((float)springCount / 8.0f) + ((float)(i - 1) / 4.0f), springs[i - 1].height, 0);
            vertices[(i - 1) * 4 + 1] = new Vector3(0 - ((float)springCount / 8.0f) + ((float)(i) / 4.0f), springs[i].height, 0);
            vertices[(i - 1) * 4 + 2] = new Vector3(0 - ((float)springCount / 8.0f) + ((float)(i) / 4.0f), -5.5f, 0);
            vertices[(i - 1) * 4 + 3] = new Vector3(0 - ((float)springCount / 8.0f) + ((float)(i - 1) / 4.0f), -5.5f, 0);
        }

        mesh = new Mesh();
        GetComponent<MeshFilter>().mesh = mesh;
        mesh.vertices = vertices;
        mesh.uv = uvs;
        mesh.triangles = triangles;
    }
Ejemplo n.º 6
0
        public static void Respond(TasClient tas, Spring spring, TasSayEventArgs e, string text)
        {
            var  p     = SayPlace.User;
            bool emote = false;

            if (e.Place == SayPlace.Battle)
            {
                p     = SayPlace.BattlePrivate;
                emote = true;
            }
            if (e.Place == SayPlace.Game && spring.IsRunning)
            {
                spring.SayGame(text);
            }
            else
            {
                tas.Say(p, e.UserName, text, emote);
            }
        }
Ejemplo n.º 7
0
 protected override void Initialize()
 {
     allSpring    = new Spring[3];
     allRectangle = new Rectangle[3];
     allTracker   = new EndPointTracker[2];
     s1           = new Spring(new Vector2(100, 0), new Vector2(100, 50), 50, 50, 25f, 1f, 5f, 0.5f);
     allSpring[0] = s1;
     s2           = new Spring(new Vector2(100, 50), new Vector2(100, 200), 150, 50, 25f, 1f, 5f, 0.5f);
     allSpring[1] = s2;
     s3           = new Spring(new Vector2(250, 0), new Vector2(250, 200), 200, 50, 50f, 1f, 5, 0.5f);
     allSpring[2] = s3;
     sO           = new SpringOperations();
     sT           = new SimulationTest();
     //t1 = new EndPointTracker(s3, new Dictionary<Vector3, int>());
     //allTracker[0] = t1;
     //t2 = new EndPointTracker(s2, new Dictionary<Vector3, int>());
     // allTracker[1] = t2;
     base.Initialize();
 }
Ejemplo n.º 8
0
        private void AddPointsAndSprings(List <TriangleVertexIndices> indices, List <JVector> vertices)
        {
            for (int i = 0; i < vertices.Count; i++)
            {
                MassPoint point = new MassPoint(sphere, this, material);
                point.Position = vertices[i];

                point.Mass = 0.1f;

                points.Add(point);
            }

            for (int i = 0; i < indices.Count; i++)
            {
                TriangleVertexIndices index = indices[i];

                Triangle t = new Triangle(this);

                t.indices = index;
                triangles.Add(t);

                t.boundingBox = JBBox.SmallBox;
                t.boundingBox.AddPoint(points[t.indices.I0].position);
                t.boundingBox.AddPoint(points[t.indices.I1].position);
                t.boundingBox.AddPoint(points[t.indices.I2].position);

                t.dynamicTreeID = dynamicTree.AddProxy(ref t.boundingBox, t);
            }

            HashSet <Edge> edges = GetEdges(indices);

            int count = 0;

            foreach (Edge edge in edges)
            {
                Spring spring = new Spring(points[edge.Index1], points[edge.Index2]);
                spring.Softness   = 0.01f; spring.BiasFactor = 0.1f;
                spring.SpringType = SpringType.EdgeSpring;

                springs.Add(spring);
                count++;
            }
        }
Ejemplo n.º 9
0
            /**
             * Creations a new motion object.
             *
             * @param spring
             *      the spring to use
             * @param motionProperties
             *      the properties of the event to track
             * @param springListeners
             *      additional spring listeners to add
             * @param trackStrategy
             *      the tracking strategy
             * @param followStrategy
             *      the follow strategy
             * @param restValue
             *      the spring rest value
             * @return a motion object
             */

            private Motion CreateMotionFromProperties(Spring spring,
                                                      MotionProperty[] motionProperties,
                                                      ISpringListener[] springListeners,
                                                      int trackStrategy, int followStrategy,
                                                      int restValue)
            {
                MotionImitator[] motionImitators = new MotionImitator[motionProperties.Length];
                Performer[]      performers      = new Performer[motionProperties.Length];

                for (int i = 0; i < motionProperties.Length; i++)
                {
                    MotionProperty property = motionProperties[i];

                    motionImitators[i] = new MotionImitator(spring, property, restValue, trackStrategy, followStrategy);
                    performers[i]      = new Performer(mView, property.ViewProperty);
                }

                return(new Motion(spring, motionImitators, performers, springListeners));
            }
Ejemplo n.º 10
0
        public static void Respond(TasClient tas, Spring spring, TasSayEventArgs e, string text)
        {
            TasClient.SayPlace p = TasClient.SayPlace.User;
            bool emote           = false;

            if (e.Place == TasSayEventArgs.Places.Battle)
            {
                p     = TasClient.SayPlace.Battle;
                emote = true;
            }
            if (e.Place == TasSayEventArgs.Places.Game)
            {
                spring.SayGame(text);
            }
            else
            {
                tas.Say(p, e.UserName, text, emote);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Шпилька с шагом по ширине распределения и кол рядов
        /// </summary>
        /// <param name="propDiam">Диаметр</param>
        /// <param name="propPos">Значение атр позиции</param>
        /// <param name="propStep">Параметр шага</param>
        /// <param name="thickness">Толщина бетона</param>
        /// <param name="a">Защ слой до центра раб арм</param>
        /// <param name="width">Ширина распределения (по бетону)</param>
        /// <param name="propCount">Параметр рядов шпилек</param>
        protected Spring defineSpring(string propDiam, string propPos, string propStep,
                                      int thickness, int a, int width, string propCount)
        {
            int diam = Block.GetPropValue <int>(propDiam);

            if (diam == 0)
            {
                return(null);
            }
            string pos  = Block.GetPropValue <string>(propPos);
            int    step = Block.GetPropValue <int>(propStep);
            var    rows = Block.GetPropValue <int>(propCount);
            // ширина распределения шпилек по горизонтале
            var    lRabSpring = thickness - 2 * a;
            Spring sp         = new Spring(diam, lRabSpring, step, width - 100, rows, pos, this);

            sp.Calc();
            return(sp);
        }
Ejemplo n.º 12
0
        public override void OnHandleCollision(ActorBase other)
        {
            base.OnHandleCollision(other);

            if (!canJump && state != StateDead)
            {
                // It can only die by collision with spring in the air
                Spring spring = other as Spring;
                if (spring != null)
                {
                    // Collide only with hitbox
                    if (spring.Hitbox.Intersects(ref currentHitbox))
                    {
                        Vector2 force = spring.Activate();
                        int     sign  = ((force.X + force.Y) > float.Epsilon ? 1 : -1);
                        if (Math.Abs(force.X) > float.Epsilon)
                        {
                            speedX         = (4 + Math.Abs(force.X)) * sign;
                            externalForceX = force.X;
                        }
                        else if (Math.Abs(force.Y) > float.Epsilon)
                        {
                            speedY         = (4 + Math.Abs(force.Y)) * sign;
                            externalForceY = -force.Y;
                        }
                        else
                        {
                            return;
                        }
                        canJump = false;

                        SetAnimation(AnimState.Fall);
                        PlaySound("Spring");

                        api.BroadcastLevelText(endText);

                        state     = StateDead;
                        stateTime = 50f;
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public AutoHost(TasClient tas, Spring spring, AutoHostConfig conf)
        {
            banList = new BanList(this, tas);

            if (conf == null)
            {
                LoadConfig();
            }
            else
            {
                config = conf;
            }
            SaveConfig();

            this.tas    = tas;
            this.spring = spring;

            tas.Said += new EventHandler <TasSayEventArgs>(tas_Said);

            pollTimer           = new Timer(PollTimeout * 1000);
            pollTimer.Enabled   = false;
            pollTimer.AutoReset = false;
            pollTimer.Elapsed  += new ElapsedEventHandler(pollTimer_Elapsed);

            spring.SpringExited += new EventHandler(spring_SpringExited);
            spring.GameOver     += new EventHandler <SpringLogEventArgs>(spring_GameOver);

            tas.BattleUserLeft          += new EventHandler <TasEventArgs>(tas_BattleUserLeft);
            tas.UserStatusChanged       += new EventHandler <TasEventArgs>(tas_UserStatusChanged);
            tas.BattleUserJoined        += new EventHandler <TasEventArgs>(tas_BattleUserJoined);
            tas.BattleMapChanged        += new EventHandler <TasEventArgs>(tas_BattleMapChanged);
            tas.BattleUserStatusChanged += new EventHandler <TasEventArgs>(tas_BattleUserStatusChanged);
            tas.BattleLockChanged       += new EventHandler <TasEventArgs>(tas_BattleLockChanged);
            tas.BattleOpened            += new EventHandler <TasEventArgs>(tas_BattleOpened);

            linker         = new UnknownFilesLinker(spring);
            fileDownloader = new FileDownloader(spring);
            fileDownloader.DownloadCompleted += new EventHandler <FileDownloader.DownloadEventArgs>(fileDownloader_DownloadCompleted);
            //fileDownloader.DownloadProgressChanged += new EventHandler<TasEventArgs>(fileDownloader_DownloadProgressChanged);

            tas.BattleFound += new EventHandler <TasEventArgs>(tas_BattleFound);
        }
Ejemplo n.º 14
0
        private void DrawSprings(DxRenderContext renderContext, Cell cell, SimParams parameters, float normalizer)
        {
            SlimDX.Direct3D11.Device device = DeviceContext.Device;
            DxMesh tube = parameters.GetValue(SimParameter.Int.Spring_Type) == 0
            ? Meshes.GetMesh("rod") : Meshes.GetMesh("spring");

            SetMesh(device, tube);

            var prevMode = DeviceContext.Device.ImmediateContext.InputAssembler.PrimitiveTopology;

            PrimitiveTopology[] modes = { PrimitiveTopology.LineList, PrimitiveTopology.TriangleList };

            for (int j = 0; j < modes.Length; j++)
            {
                DeviceContext.Device.ImmediateContext.InputAssembler.PrimitiveTopology = modes[j];

                foreach (ChromosomePair pair in cell.ChromosomePairs)
                {
                    Spring spring = pair.Spring;
                    if (spring != null)
                    {
                        SpringStyle springStyle = renderContext.StyleAspect.Resolve <SpringStyle>(spring);
                        ConstBuffer.Material = springStyle.Spring;
                        float  scale     = (float)spring.Length * normalizer;
                        Matrix transform = Matrix.Scaling((float)springStyle.Width, (float)springStyle.Width, scale);

                        transform *= RotationVectors(new Vector3(0, 0, -1),
                                                     new Vector3((float)(spring.RightJoint.X - spring.LeftJoint.X),
                                                                 (float)(spring.RightJoint.Y - spring.LeftJoint.Y),
                                                                 (float)(spring.RightJoint.Z - spring.LeftJoint.Z)));
                        transform *= Matrix.Translation((float)spring.LeftJoint.X * normalizer,
                                                        (float)spring.LeftJoint.Y * normalizer,
                                                        (float)spring.LeftJoint.Z * normalizer);

                        ConstBuffer.World = Matrix.Transpose(transform);
                        SetBuffer(device, ConstBuffer);
                        DrawMesh(device, tube);
                    }
                }
            }
            DeviceContext.Device.ImmediateContext.InputAssembler.PrimitiveTopology = prevMode;
        }
Ejemplo n.º 15
0
        public override void OnHandleCollision(ActorBase other)
        {
            base.OnHandleCollision(other);

            if (state != StateDead)
            {
                // It can only die by collision with spring in the air
                Spring spring = other as Spring;
                if (spring != null)
                {
                    // Collide only with hitbox
                    if (AABB.TestOverlap(ref spring.AABBInner, ref AABBInner))
                    {
                        Vector2 force = spring.Activate();
                        int     sign  = ((force.X + force.Y) > float.Epsilon ? 1 : -1);
                        if (Math.Abs(force.X) > float.Epsilon)
                        {
                            speedX         = (4 + Math.Abs(force.X)) * sign;
                            externalForceX = force.X;
                        }
                        else if (Math.Abs(force.Y) > float.Epsilon)
                        {
                            speedY         = (4 + Math.Abs(force.Y)) * sign;
                            externalForceY = -force.Y;
                        }
                        else
                        {
                            return;
                        }
                        canJump = false;

                        SetAnimation(AnimState.Fall);
                        PlaySound(Transform.Pos, "Spring");

                        levelHandler.BroadcastLevelText(levelHandler.GetLevelText(endText));

                        state     = StateDead;
                        stateTime = 50f;
                    }
                }
            }
        }
Ejemplo n.º 16
0
    public void SpraySprings()
    {
        base.Use();
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit rayHit;

        if (Physics.Raycast(ray, out rayHit, 10.0f, hitMask))
        {
            Collider[] colliders = Physics.OverlapSphere(rayHit.point, SprayRadius, hitMask);
            for (int i = 0; i < colliders.Length; i++)
            {
                SpringTemp = Instantiate(SpringType.gameObject, rayHit.point, Quaternion.identity) as GameObject;
                Spring spring = SpringTemp.GetComponent <Spring>();
                spring.FirstNodeAt(rayHit);
                spring.SecondNodeAt(colliders[i].transform);
                spring.active = true;
                SpringShooter.ConnectedSprings.Add(spring);
            }
        }
    }
Ejemplo n.º 17
0
        public static void StartDownloadedMission(ScriptMissionData profile, string modInternalName)
        {
            var spring = new Spring(Program.SpringPaths);
            var name   = Program.Conf.LobbyPlayerName;

            if (string.IsNullOrEmpty(name))
            {
                name = "Player";
            }

            if (Utils.VerifySpringInstalled())
            {
                spring.StartGame(Program.TasClient,
                                 null,
                                 null,
                                 profile.StartScript.Replace("%MOD%", modInternalName).Replace("%MAP%", profile.MapName).Replace("%NAME%", name), Program.Conf.UseSafeMode, Program.Conf.UseMtEngine);
                var serv = GlobalConst.GetContentService();
                serv.NotifyMissionRun(Program.Conf.LobbyPlayerName, profile.Name);
            }
        }
Ejemplo n.º 18
0
        private void defineFields()
        {
            Length    = Block.GetPropValue <int>(PropNameLength);
            Height    = Block.GetPropValue <int>(PropNameHeight);
            Thickness = Block.GetPropValue <int>(PropNameThickness);
            Outline   = Block.GetPropValue <int>(PropNameOutline);
            var concrete = Block.GetPropValue <string>(PropNameConcrete);

            Concrete = new ConcreteH(concrete, Length, Thickness, Height, this);
            Concrete.Calc();
            // Определние вертикальной арматуры
            int widthVerticArm = Length;

            ArmVertic = defineVerticArm(widthVerticArm, PropNameArmVerticDiam, PropNameArmVerticStep, PropNameArmVerticPos);
            // Определние горизонтальной арматуры
            ArmHor = defineArmHor(Length, PropNameArmHorDiam, PropNameArmHorPos, PropNameArmHorStep);
            // Шпильки
            Spring = defineSpring(PropNameSpringDiam, PropNamePosSpring, PropNameSpringStepHor, PropNameSpringStepVertic,
                                  Thickness, a, Length, Height);
        }
Ejemplo n.º 19
0
 public void OnSpringUpdate(Spring spring)
 {
     if (mSpring != null)
     {
         double restPosition = CalculateRestPosition();
         if (mSpring.SpringConfig.Equals(SPRING_CONFIG_FRICTION))
         {
             if (mSpring.CurrentValue > mMaxValue && restPosition > mMaxValue)
             {
                 mSpring.SetSpringConfig(mOriginalConfig);
                 mSpring.SetEndValue(mMaxValue);
             }
             else if (mSpring.CurrentValue < mMinValue && restPosition < mMinValue)
             {
                 mSpring.SetSpringConfig(mOriginalConfig);
                 mSpring.SetEndValue(mMinValue);
             }
         }
     }
 }
Ejemplo n.º 20
0
        private static int FilterMaps(string[] words, TasClient tas, Spring spring, Ladder ladder, out string[] vals, out int[] indexes)
        {
            string[] temp = new string[spring.UnitSync.MapList.Keys.Count];
            int      cnt  = 0;

            foreach (string s in spring.UnitSync.MapList.Keys)
            {
                if (ladder != null)
                {
                    if (ladder.Maps.Contains(s.ToLower()))
                    {
                        temp[cnt++] = s;
                    }
                }
                else
                {
                    string[] limit = Program.main.AutoHost.config.LimitMaps;
                    if (limit != null && limit.Length > 0)
                    {
                        bool allowed = false;
                        for (int i = 0; i < limit.Length; ++i)
                        {
                            if (s.ToLower().Contains(limit[i].ToLower()))
                            {
                                allowed = true;
                                break;
                            }
                        }
                        if (allowed)
                        {
                            temp[cnt++] = s;
                        }
                    }
                    else
                    {
                        temp[cnt++] = s;
                    }
                }
            }
            return(Filter(temp, words, out vals, out indexes));
        }
Ejemplo n.º 21
0
        public bool Start()
        {
            if (config.AttemptToRecconnect)
            {
                recon          = new Timer(config.AttemptReconnectInterval * 1000);
                recon.Elapsed += recon_Elapsed;
            }

            recon.Enabled = false;
            spring        = new Spring();


            tas = new TasClient();
            tas.ConnectionLost          += tas_ConnectionLost;
            tas.Connected               += tas_Connected;
            tas.LoginDenied             += tas_LoginDenied;
            tas.LoginAccepted           += tas_LoginAccepted;
            tas.Said                    += tas_Said;
            tas.MyStatusChangedToInGame += tas_MyStatusChangedToInGame;
            tas.ChannelUserAdded        += tas_ChannelUserAdded;
            spring.SpringExited         += spring_SpringExited;
            spring.SpringStarted        += spring_SpringStarted;
            spring.PlayerSaid           += spring_PlayerSaid;
            autoHost                     = new AutoHost(tas, spring, null);
            if (config.PlanetWarsEnabled)
            {
                InitializePlanetWarsServer();
            }
            autoUpdater = new AutoUpdater(spring, tas);

            if (config.StatsEnabledReal)
            {
                stats = new Stats(tas, spring);
            }
            try {
                tas.Connect(config.ServerHost, config.ServerPort);
            } catch {
                recon.Start();
            }
            return(true);
        }
Ejemplo n.º 22
0
        public Stats(TasClient tas, Spring spring)
        {
            this.tas    = tas;
            this.spring = spring;

            LoadAccounts();

            tas.LoginAccepted += new EventHandler <TasEventArgs>(tas_LoginAccepted);
            if (Program.main.config.GargamelMode)
            {
                tas.UserRemoved          += new EventHandler <TasEventArgs>(tas_UserRemoved);
                tas.BattleUserIpRecieved += new EventHandler <TasEventArgs>(tas_BattleUserIpRecieved);
                tas.UserStatusChanged    += new EventHandler <TasEventArgs>(tas_UserStatusChanged);
            }
            spring.SpringStarted      += new EventHandler(spring_SpringStarted);
            spring.PlayerJoined       += new EventHandler <SpringLogEventArgs>(spring_PlayerJoined);
            spring.PlayerLeft         += new EventHandler <SpringLogEventArgs>(spring_PlayerLeft);
            spring.PlayerLost         += new EventHandler <SpringLogEventArgs>(spring_PlayerLost);
            spring.PlayerDisconnected += new EventHandler <SpringLogEventArgs>(spring_PlayerDisconnected);
            spring.GameOver           += new EventHandler <SpringLogEventArgs>(spring_GameOver);
        }
Ejemplo n.º 23
0
    private void UpdatePoints()
    {
        float omega = 2 * Mathf.PI * freq;
        float zeta  = Mathf.Log(percDecay) / (-omega * timeDecay);

        CycleThroughPoints((index, point) =>
        {
            var springPoint = springPoints[index];

            if (!(grabbing && inRadiusPoints.Contains(index)))
            {
                springPoint.Position = Spring.Vector3Spring(springPoint.Position, ref springPoint.Velocity,
                                                            springPoint.Anchor, zeta, omega, Time.deltaTime);
            }

            if (hasPolygonShape)
            {
                polygonShape.SetPointPosition(index, springPoint.Position);
            }
        });
    }
Ejemplo n.º 24
0
        public Stats(TasClient tas, Spring spring)
        {
            this.tas    = tas;
            this.spring = spring;

            LoadAccounts();

            tas.LoginAccepted += tas_LoginAccepted;
            if (Program.main.config.GargamelMode)
            {
                tas.UserRemoved          += tas_UserRemoved;
                tas.BattleUserIpRecieved += tas_BattleUserIpRecieved;
                tas.UserStatusChanged    += tas_UserStatusChanged;
            }
            spring.SpringStarted      += spring_SpringStarted;
            spring.PlayerJoined       += spring_PlayerJoined;
            spring.PlayerLeft         += spring_PlayerLeft;
            spring.PlayerLost         += spring_PlayerLost;
            spring.PlayerDisconnected += spring_PlayerDisconnected;
            spring.GameOver           += spring_GameOver;
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Creates a new Rope.
        /// </summary>
        /// <param name="id">The ID of the Rope.</param>
        /// <param name="drawLayer">The layer to draw the Rope on.</param>
        /// <param name="smoothness">The smoothnes of the Rope.</param>
        /// <param name="springsMass">The mass of each individual Spring in the Rope.</param>
        /// <param name="springsStiffness">The stiffness of each Spring.</param>
        /// <param name="springsFriction">The friction that each spring applies.</param>
        /// <param name="totalSpringLenght">The total lenght of the Rope.</param>
        /// <param name="pointOfConnection">The point from where the Rope will swing from.</param>
        /// <param name="textureFilepath">The texture filepath fgor each segment of the Rope.</param>
        /// <param name="normalMapFilepath">The normal map texture filepath for each segement of the Rope.</param>
        /// <param name="ropeThickness">The thickness of the Rope.</param>
        public Rope(string id, int drawLayer, int smoothness, float springsMass,
                    float springsStiffness, float springsFriction,
                    float totalSpringLenght, Vector2 pointOfConnection,
                    string textureFilepath, string normalMapFilepath, float ropeThickness)
        {
            this.id        = id;
            this.drawLayer = drawLayer;

            this.textureFilepath   = textureFilepath;
            this.normalMapFilepath = normalMapFilepath;
            this.ropeThickness     = ropeThickness;

            this.pointOfConnection = pointOfConnection;

            lenght = new Vector2(0, totalSpringLenght / smoothness);

            springs = new Spring[smoothness];
            sprites = new Sprite[smoothness];

            for (int i = 0; i < springs.Length; i++)
            {
                Spring spring;

                if (i == 0)
                {
                    ParticleObject start = new ParticleObject(pointOfConnection, Vector2.Zero, springsMass);
                    ParticleObject end   = new ParticleObject(pointOfConnection + lenght, Vector2.Zero, springsMass);

                    spring = new Spring(start, end, springsStiffness, lenght.Y, springsFriction);
                }
                else
                {
                    ParticleObject end = new ParticleObject(springs[i - 1].EndParticle.Position + lenght, Vector2.Zero, springsMass);

                    spring = new Spring(springs[i - 1].EndParticle, end, springsStiffness, lenght.Y, springsFriction);
                }

                springs[i] = spring;
            }
        }
Ejemplo n.º 26
0
        public void TestGetForce1()
        {
            var p0s = new[]
            {
                new Point(0, 0),
                new Point(1, 0),
                new Point(0, 1),
            };
            var p1s = new[]
            {
                new Point(1, 0),
                new Point(2, 0),
                new Point(1, 1),
            };

            var spring = new Spring(_rng, 1, 1, 1);

            for (int i = 0; i < p0s.Length; ++i)
            {
                spring.GetForce(p0s[i], p1s[i], new Vector(0, 0)).Should().Be(new Vector(0, 0), "because a spring with its vertices at rest length should not be under any stress");
            }
        }
Ejemplo n.º 27
0
        public override void Read(AssetStream stream)
        {
            base.Read(stream);

            DynamicFriction = stream.ReadSingle();
            StaticFriction  = stream.ReadSingle();
            Bounciness      = stream.ReadSingle();
            FrictionCombine = stream.ReadInt32();
            BounceCombine   = stream.ReadInt32();

            if (IsReadFrictionDirection2(stream.Version))
            {
                FrictionDirection2.Read(stream);
                DynamicFriction2 = stream.ReadSingle();
                StaticFriction2  = stream.ReadSingle();
            }
            if (IsReadUseSpring(stream.Version))
            {
                UseSpring = stream.ReadBoolean();
                Spring.Read(stream);
            }
        }
Ejemplo n.º 28
0
        public AutoHost(TasClient tas, Spring spring, AutoHostConfig conf)
        {
            banList = new BanList(this, tas);

            if (conf == null)
            {
                LoadConfig();
            }
            else
            {
                config = conf;
            }
            SaveConfig();

            this.tas    = tas;
            this.spring = spring;

            tas.Said += tas_Said;

            pollTimer           = new Timer(PollTimeout * 1000);
            pollTimer.Enabled   = false;
            pollTimer.AutoReset = false;
            pollTimer.Elapsed  += pollTimer_Elapsed;

            spring.SpringExited      += spring_SpringExited;
            spring.GameOver          += spring_GameOver;
            spring.NotifyModsChanged += spring_NotifyModsChanged;

            tas.BattleUserLeft          += tas_BattleUserLeft;
            tas.UserStatusChanged       += tas_UserStatusChanged;
            tas.BattleUserJoined        += tas_BattleUserJoined;
            tas.BattleMapChanged        += tas_BattleMapChanged;
            tas.BattleUserStatusChanged += tas_BattleUserStatusChanged;
            tas.BattleLockChanged       += tas_BattleLockChanged;
            tas.BattleOpened            += tas_BattleOpened;

            linkProvider = new ResourceLinkProvider();
            spring.UnitSyncWrapper.Downloader.LinksRecieved += linkProvider.Downloader_LinksRecieved;
        }
Ejemplo n.º 29
0
        public override void Read(AssetReader reader)
        {
            base.Read(reader);

            DynamicFriction = reader.ReadSingle();
            StaticFriction  = reader.ReadSingle();
            Bounciness      = reader.ReadSingle();
            FrictionCombine = reader.ReadInt32();
            BounceCombine   = reader.ReadInt32();

            if (HasFrictionDirection2(reader.Version))
            {
                FrictionDirection2.Read(reader);
                DynamicFriction2 = reader.ReadSingle();
                StaticFriction2  = reader.ReadSingle();
            }
            if (HasUseSpring(reader.Version))
            {
                UseSpring = reader.ReadBoolean();
                Spring.Read(reader);
            }
        }
Ejemplo n.º 30
0
    //float walkOffsetMagnitude = 0f;

    //float extraPitch = 0f;

    void Awake()
    {
        instance = this;

        this.fpCamera = Camera.main;

        this.fpCamera.fieldOfView = CAMERA_HIP_FOV;
        this.movementProbe        = this.transform.parent;
        this.positionSpring       = new Spring(POSITION_SPRING, POSITION_DRAG, -Vector3.one * MAX_POSITION_OFFSET, Vector3.one * MAX_POSITION_OFFSET, POSITION_SPRING_ITERAIONS);
        this.rotationSpring       = new Spring(ROTATION_SPRING, ROTATION_DRAG, -Vector3.one * MAX_ROTATION_OFFSET, Vector3.one * MAX_ROTATION_OFFSET, ROTATION_SPRING_ITERAIONS);
        this.weaponParent         = this.transform;
        //this.weaponParentOrigin = this.weaponParent.transform.localPosition;
        //this.fpCameraParent = this.fpCamera.transform.parent;

        this.movementProbe = this.transform;

        this.localOrigin  = this.transform.localPosition;
        this.lastPosition = this.movementProbe.position;
        this.lastRotation = this.movementProbe.eulerAngles;

        SetupHorizontalFov(90f);
        SetAimFov(CAMERA_AIM_FOV);
    }
Ejemplo n.º 31
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View rootView = inflater.Inflate(Resource.Layout.fragment_scale, container, false);

            View rect = rootView.FindViewById(Resource.Id.rect);

            SpringSystem springSystem = SpringSystem.Create();
            Spring       spring       = springSystem.CreateSpring();

            spring.AddListener(new Performer(rect, View.ScaleXs));
            spring.AddListener(new Performer(rect, View.ScaleYs));

            spring.SetCurrentValue(1.0f);

            ScaleGestureDetector scaleGestureDetector = new ScaleGestureDetector(this.Activity, new OnScaleGestureListener(spring));

            rootView.Touch += (sender, e) =>
            {
                e.Handled = scaleGestureDetector.OnTouchEvent(e.Event);
            };

            return(rootView);
        }
Ejemplo n.º 32
0
        public override void Awake(Scene scene)
        {
            base.Awake(scene);
            Color color         = Calc.HexToColor("667da5");
            Color disabledColor = new Color(color.R / 255f * (color.R / 255f), color.G / 255f * (color.G / 255f), color.B / 255f * (color.B / 255f), 1f);

            foreach (var mover in staticMovers)
            {
                Spikes spikes = mover.Entity as Spikes;
                if (spikes != null)
                {
                    spikes.EnabledColor        = Color.White;
                    spikes.DisabledColor       = disabledColor;
                    spikes.VisibleWhenDisabled = true;
                }
                Spring spring = mover.Entity as Spring;
                if (spring != null)
                {
                    spring.DisabledColor       = disabledColor;
                    spring.VisibleWhenDisabled = true;
                }
            }
        }
Ejemplo n.º 33
0
            private static void createCircle(Context context, ViewGroup rootView, SpringSystem springSystem, SpringConfig coasting, SpringConfig gravity, int diameter, Drawable backgroundDrawable)
            {
                Spring xSpring = springSystem.CreateSpring().SetSpringConfig(coasting);
                Spring ySpring = springSystem.CreateSpring().SetSpringConfig(gravity);

                // create view
                View view = new View(context);

                RelativeLayout.LayoutParams paramss = new RelativeLayout.LayoutParams(diameter, diameter);
                paramss.AddRule(LayoutRules.CenterInParent);
                view.LayoutParameters = paramss;
                view.Background       = backgroundDrawable;

                rootView.AddView(view);

                // generate random direction and magnitude
                double magnitude = new Random().NextDouble() * 1000 + 3000;
                double angle     = new Random().NextDouble() * System.Math.PI / 2 + System.Math.PI / 4;

                xSpring.SetVelocity(magnitude * System.Math.Cos(angle));
                ySpring.SetVelocity(-magnitude * System.Math.Sin(angle));

                int maxX = rootView.MeasuredWidth / 2 + diameter;

                xSpring.AddListener(new Destroyer(rootView, view, -maxX, maxX));

                int maxY = rootView.MeasuredHeight / 2 + diameter;

                ySpring.AddListener(new Destroyer(rootView, view, -maxY, maxY));

                xSpring.AddListener(new Performer(view, ViewHelper.TranslationX));
                ySpring.AddListener(new Performer(view, ViewHelper.TranslationY));

                // set a different end value to cause the animation to play
                xSpring.SetEndValue(2);
                ySpring.SetEndValue(9001);
            }
Ejemplo n.º 34
0
        public bool HitSpring(Spring spring)
        {
            if (!Hold.IsHeld)
            {
                if (spring.Orientation == Spring.Orientations.Floor && Speed.Y >= 0f)
                {
                    Speed.X       *= 0.5f;
                    Speed.Y        = -160f;
                    noGravityTimer = 0.15f;

                    return(true);
                }

                if (spring.Orientation == Spring.Orientations.WallLeft && Speed.X <= 0f)
                {
                    MoveTowardsY(spring.CenterY + 5f, 4f);
                    Speed.X        = 220f;
                    Speed.Y        = -80f;
                    noGravityTimer = 0.1f;

                    return(true);
                }

                if (spring.Orientation == Spring.Orientations.WallRight && Speed.X >= 0f)
                {
                    MoveTowardsY(spring.CenterY + 5f, 4f);
                    Speed.X        = -220f;
                    Speed.Y        = -80f;
                    noGravityTimer = 0.1f;

                    return(true);
                }
            }

            return(false);
        }
        private Spring GetFakeSpring()
        {
            Spring spring;

            switch (Orientation)
            {
            default:
            case Orientations.WallLeftUp:
            case Orientations.WallRightUp:
                spring = new Spring(Position, Spring.Orientations.Floor, true);
                break;

            case Orientations.WallLeftDown:
            case Orientations.FloorLeft:
                spring = new Spring(Position, Spring.Orientations.WallLeft, true);
                break;

            case Orientations.WallRightDown:
            case Orientations.FloorRight:
                spring = new Spring(Position, Spring.Orientations.WallRight, true);
                break;
            }
            return(spring);
        }
Ejemplo n.º 36
0
 public LinkThem(Spring.Data.NHibernate.HibernateTemplate ht, Spring.Web.UI.Page page, Common.Logging.ILog log)
   {
       this.ht = ht;
       this.page = page;
       this.log = log;
   }
        private void DoTxScopeBegin(PromotableTxScopeTransactionObject txObject, 
                                    Spring.Transaction.ITransactionDefinition definition)
        {

            TransactionScopeOption txScopeOption = CreateTransactionScopeOptions(definition);     
            TransactionOptions txOptions = CreateTransactionOptions(definition);
            txObject.TxScopeAdapter.CreateTransactionScope(txScopeOption, txOptions, definition.EnterpriseServicesInteropOption);            
            
        }
Ejemplo n.º 38
0
        /// <summary>
        /// Creates a 2D-Cloth. Connects Nearest Neighbours (4x, called EdgeSprings) and adds additional
        /// shear/bend constraints (4xShear+4xBend).
        /// </summary>
        /// <param name="sizeX"></param>
        /// <param name="sizeY"></param>
        /// <param name="scale"></param>
        public SoftBody(int sizeX,int sizeY, float scale)
        {
            List<TriangleVertexIndices> indices = new List<TriangleVertexIndices>();
            List<JVector> vertices = new List<JVector>();

            for (int i = 0; i < sizeY; i++)
            {
                for (int e = 0; e < sizeX; e++)
                {
                    vertices.Add(new JVector(i, 0, e) *scale);
                }
            }
            
            for (int i = 0; i < sizeX-1; i++)
            {
                for (int e = 0; e < sizeY-1; e++)
                {
                    TriangleVertexIndices index = new TriangleVertexIndices();
                    {

                        index.I0 = (e + 0) * sizeX + i + 0;
                        index.I1 = (e + 0) * sizeX + i + 1;
                        index.I2 = (e + 1) * sizeX + i + 1;

                        indices.Add(index);

                        index.I0 = (e + 0) * sizeX + i + 0;
                        index.I1 = (e + 1) * sizeX + i + 1;
                        index.I2 = (e + 1) * sizeX + i + 0;

                        indices.Add(index);    
                    }
                }
            }

            EdgeSprings = new ReadOnlyCollection<Spring>(springs);
            VertexBodies = new ReadOnlyCollection<MassPoint>(points);
            Triangles = new ReadOnlyCollection<Triangle>(triangles);

            AddPointsAndSprings(indices, vertices);

            for (int i = 0; i < sizeX - 1; i++)
            {
                for (int e = 0; e < sizeY - 1; e++)
                {
                    Spring spring = new Spring(points[(e + 0) * sizeX + i + 1], points[(e + 1) * sizeX + i + 0]);
                    spring.Softness = 0.01f; spring.BiasFactor = 0.1f;
                    springs.Add(spring);
                }
            }

            foreach (Spring spring in springs)
            {
                JVector delta = spring.body1.position - spring.body2.position;

                if (delta.Z != 0.0f && delta.X != 0.0f) spring.SpringType = SpringType.ShearSpring;
                else spring.SpringType = SpringType.EdgeSpring;
            }


            for (int i = 0; i < sizeX - 2; i++)
            {
                for (int e = 0; e < sizeY - 2; e++)
                {
                    Spring spring1 = new Spring(points[(e + 0) * sizeX + i + 0], points[(e + 0) * sizeX + i + 2]);
                    spring1.Softness = 0.01f; spring1.BiasFactor = 0.1f;

                    Spring spring2 = new Spring(points[(e + 0) * sizeX + i + 0], points[(e + 2) * sizeX + i + 0]);
                    spring2.Softness = 0.01f; spring2.BiasFactor = 0.1f;

                    spring1.SpringType = SpringType.BendSpring;
                    spring2.SpringType = SpringType.BendSpring;

                    springs.Add(spring1);
                    springs.Add(spring2);
                }
            }
        }
Ejemplo n.º 39
0
        private void AddPointsAndSprings(List<TriangleVertexIndices> indices, List<JVector> vertices)
        {
            for (int i = 0; i < vertices.Count; i++)
            {
                MassPoint point = new MassPoint(sphere, this,material);
                point.Position = vertices[i];

                point.Mass = 0.1f;

                points.Add(point);
            }

            for (int i = 0; i < indices.Count; i++)
            {
                TriangleVertexIndices index = indices[i];
                
                Triangle t = new Triangle(this);

                t.indices = index;
                triangles.Add(t);

                t.boundingBox = JBBox.SmallBox;
                t.boundingBox.AddPoint(points[t.indices.I0].position);
                t.boundingBox.AddPoint(points[t.indices.I1].position);
                t.boundingBox.AddPoint(points[t.indices.I2].position);

                t.dynamicTreeID = dynamicTree.AddProxy(ref t.boundingBox, t);
            }

            HashSet<Edge> edges = GetEdges(indices);

            int count = 0;

            foreach (Edge edge in edges)
            {
                Spring spring = new Spring(points[edge.Index1], points[edge.Index2]);
                spring.Softness = 0.01f; spring.BiasFactor = 0.1f;
                spring.SpringType = SpringType.EdgeSpring;

                springs.Add(spring);
                count++;
            }

        }
Ejemplo n.º 40
0
        public static double SpringAttraction(Node a, Spring p)
        {
            if (!a.Links.Contains (p))
                throw new InvalidOperationException ("Node is not attached to this spring");

            double r = Point.Distance (a.Location , p.Other(a).Location);
            double x = r - p.NaturalLength;
            double F = (-1 * SpringConstant * x);

            return F;
        }
Ejemplo n.º 41
0
        public Spring Join(Node a, Node b)
        {
            Spring p = new Spring () {
                NaturalLength = SpringNatualLength,
                NodeA = a,
                NodeB = b
            };

            a.Links.Add( p );
            b.Links.Add( p );

            springs.Add( p );
            return p;
        }
Ejemplo n.º 42
0
        /*
        public static IBasicProperties ExtractBasicProperties(IClientSession channel, Message message)
        {
            MessageProperties properties = (MessageProperties) message.MessageProperties;
            return properties.BasicProperties;
           
        }*/

        public static DeliveryProperties ExtractDeliveryProperties(Spring.Messaging.Amqp.Core.Message message)
        {
            Spring.Messaging.Amqp.Qpid.Core.MessageProperties properties = (Spring.Messaging.Amqp.Qpid.Core.MessageProperties)message.MessageProperties;
            return properties.DeliveryProperites;
        }
        // Init Functions
        void InitPhysicsEngine()
        {
            pemitter = new ParticleEmmiter(PhysicsManager, new Vector2(1f, .5f), Vector2.One, 10f, 50f, 3f);

            var ground = new PolyBody(1, 4);
            ground.MakeRect(20, 1, (new Vector2(size.Width / 2, 0)));
            ground.IsFixed = true;
            AddAndInit(ground);

            /*var polybody = new PolyBody(1f, (new Random()).Next(5, 5)); //3,8
            polybody.MakeRegularFromRad(.8f);
            polybody.Mass = 1f;
            polybody.Position = new Vector2(size.Width / 2, size.Height / 2);
            polybody.Restitution = 0.0f;

            AddAndInit(polybody);*/

            var rotPlat = new PolyBody(1f, 4);
            rotPlat.MakeRect(8, 1);
            rotPlat.Mass = 4f;
            rotPlat.Position = new Vector2(size.Width / 2, size.Height / 2);
            rotPlat.Restitution = 0.0f;
            rotPlat.IsPivot = true;

            AddAndInit(rotPlat);

            #region bouncer
            float width1 = 4f;
            float width2 = 2f;

            float height = .5f;

            var p1 = new PolyBody(3, 4);
            p1.MakeRect(width1, height);
            p1.Position = new Vector2(size.Width / 2, 1);
            var p1_con1 = -(Vector2.UnitX * width1 / 2 * 3 / 4);
            var p1_con2 = (Vector2.UnitX * width1 / 2 * 3 / 4);

            var p2 = new PolyBody(1, 4);
            p2.MakeRect(width2, height);
            p2.Position = new Vector2(size.Width / 2, 3.5f);
            var p2_con1 = -(Vector2.UnitX * width2 / 2 * 3 / 4) - (Vector2.UnitY * height/2 * 2 / 3);
            var p2_con2 = (Vector2.UnitX * width2 / 2 * 3 / 4) - (Vector2.UnitY * height/2 * 2 / 3);

            Spring s1 = new Spring(p1, p2, p1_con1, p2_con1, 3f, 30f, 1.0f);
            Spring s2 = new Spring(p1, p2, p1_con2, p2_con2, 3f, 30f, 1.0f);

            Spring s3 = new Spring(p1, p2, p1_con1, p2_con2, 3f, 30f, 1.0f);
            Spring s4 = new Spring(p1, p2, p1_con2, p2_con1, 3f, 30f, 1.0f);

            s1.SetLengthToCurrent();
            s2.SetLengthToCurrent();

            PhysicsManager.AddBinaryForceComponent(s1);
            PhysicsManager.AddBinaryForceComponent(s2);
            PhysicsManager.AddBinaryForceComponent(s3);
            PhysicsManager.AddBinaryForceComponent(s4);

            AddAndInit(p1);
            AddAndInit(p2);
            #endregion bouncer
        }
Ejemplo n.º 44
0
		public void AfterCompletion(Spring.Transaction.Support.TransactionSynchronizationStatus status)
		{
			// TODO:  Add MockTxnSync.AfterCompletion implementation
		}
Ejemplo n.º 45
0
 void AddLooseBullet( bool spring  )
 {
     loose_bullets.Add(Instantiate(casing_with_bullet));
     var new_spring= new Spring(0.3f,0.3f,kAimSpringStrength,kAimSpringDamping);
     loose_bullet_spring.Add(new_spring);
     if(spring){
         new_spring.vel = 3.0f;
         picked_up_bullet_delay = 2.0f;
     }
 }
Ejemplo n.º 46
0
        private void AddParticle(string label, Particle newParticle)
        {
            var constraint = new Spring(this._center, newParticle, 0, 0.01);

            this._particles.Add(label, newParticle);
            this._engine.Add(constraint);
            this._engine.AddEntity(newParticle);
        }