Пример #1
0
            //Calculate the force that is exerted by this spring on both the connected masses
            //Uses a general Newtonian formula f=kd
            public void addForce()
            {
                this.lptr = cm.myBody.fptr;
                Vector3 dir     = alter.position - cm.position;
                float   tLength = dir.magnitude;

                float tDelta = (tLength - this.length);

                //Only calculate if the spring is a two way, or stretched beyond rest length
                if (tDelta > 0 || twoWay)
                {
                    float   forcem = (k * (tDelta));
                    Vector3 nForce = dir * forcem;

                    cm.force = cm.force + nForce;
                    cmConnect acmC = alter._cons[alterAxis];

                    //add inverse to alternate mass if it hasn't been calculated through this axis
                    //if(acmC==null) {Debug.Log(axis+"&"+alterAxis+" - "+cm.px+","+cm.py+","+cm.pz);} Debug purposes
                    if (acmC.lptr < this.lptr)
                    {
                        acmC.lptr   = this.lptr;
                        alter.force = alter.force - nForce;
                    }
                }
                else
                {
                    //set inverse as calculated, even though nothing was added
                    cmConnect acmC = alter._cons[alterAxis];
                    if (acmC.lptr < this.lptr)
                    {
                        acmC.lptr = this.lptr;
                    }
                }
            }
Пример #2
0
 //Calculate the forces across all the connections to this object, but only connections that haven't already
 //been calculated for (due to inverse axis)
 public void calcCons()
 {
     for (int j = 0; j < SoftBody.maxCon; j++)
     {
         cmConnect c = this._cons[j];
         if (c != null && c.lptr < myBody.fptr)
         {
             c.addForce();
         }
     }
 }
Пример #3
0
        //Initiate all the connections for this mass
        public int makeLattice()
        {
            cMass tm;
            int   count = 0;
            int   i;

            int[,] aa = SoftBody.allAxis;
            for (i = 0; i < SoftBody.maxCon; i++)
            {
                tm = myBody.findMass(px + aa[i, 0], py + aa[i, 1], pz + aa[i, 2]);
                if (tm != null)
                {
                    _cons[i] = new cmConnect(this, i, tm); count++;
                }
                else
                {
                    _cons[i] = null;
                }
            }

            return(count);
        }