コード例 #1
0
ファイル: MegaSoft2D.cs プロジェクト: jsr2k1/videojocjj
    public static Constraint2D CreatePointCon(int _p1, Vector2 _pos)
    {
        Constraint2D con = new Constraint2D();
        con.p1 = _p1;
        con.pos = _pos;
        con.active = true;
        con.contype = 1;

        return con;
    }
コード例 #2
0
ファイル: MegaSoft2D.cs プロジェクト: jsr2k1/videojocjj
    public static Constraint2D CreatePointTargetCon(int _p1, Transform trans)
    {
        Constraint2D con = new Constraint2D();
        con.p1 = _p1;
        con.active = true;
        con.contype = 2;
        con.obj = trans;

        return con;
    }
コード例 #3
0
ファイル: MegaSoft2D.cs プロジェクト: jsr2k1/videojocjj
    public static Constraint2D CreateLenCon(int _p1, int _p2, float _len)
    {
        Constraint2D con = new Constraint2D();
        con.p1 = _p1;
        con.p2 = _p2;
        con.length = _len;
        con.active = true;
        con.contype = 0;

        return con;
    }
コード例 #4
0
 public override void SetPrefab(ConstraintMotor2DPrefab instance, Constraint2D value)
 {
     instance.AttachedConstraint = value;
 }
コード例 #5
0
    public void Init()
    {
        if (soft.masses == null)
        {
            soft.masses = new List <Mass2D>();
        }

        soft.masses.Clear();
        float ms = Mass / (float)(NumMasses);

        int ax = (int)axis;

        Vector2 pos = Vector2.zero;

        //DampingRatio = Mathf.Clamp01(DampingRatio);

        damp = (DampingRatio * 0.45f) * (2.0f * Mathf.Sqrt(ms * spring));

        for (int i = 0; i < NumMasses; i++)
        {
            float alpha = (float)i / (float)(NumMasses - 1);

            pos.x = Mathf.Lerp(bbox.min[ax], bbox.max[ax], alpha);
            //Debug.Log("m[" + i + "] alpha " + alpha + " " + pos.x);

            Mass2D rm = new Mass2D(ms, pos);
            soft.masses.Add(rm);
        }

        masspos = new Vector2[soft.masses.Count + 2];

        for (int i = 0; i < soft.masses.Count; i++)
        {
            masspos[i + 1] = soft.masses[i].pos;
        }

        if (soft.springs == null)
        {
            soft.springs = new List <Spring2D>();
        }

        soft.springs.Clear();

        if (soft.constraints == null)
        {
            soft.constraints = new List <Constraint2D>();
        }

        soft.constraints.Clear();

        for (int i = 0; i < soft.masses.Count - 1; i++)
        {
            Spring2D spr = new Spring2D(i, i + 1, spring, damp, soft);

            //float len = spr.restLen;
            spr.restLen *= SpringCompress;
            soft.springs.Add(spr);

            if (Constraints)
            {
                // Do we use restLen or len here?
                Constraint2D lcon = Constraint2D.CreateLenCon(i, i + 1, spr.restLen);
                soft.constraints.Add(lcon);
            }
        }
#if true
        if (BendSprings)
        {
            int gap = 2;
            for (int i = 0; i < soft.masses.Count - gap; i++)
            {
                float    alpha = (float)i / (float)soft.masses.Count;
                Spring2D spr   = new Spring2D(i, i + gap, stiffspring * stiffnessCrv.Evaluate(alpha), stiffdamp * stiffnessCrv.Evaluate(alpha), soft);
                soft.springs.Add(spr);

                Constraint2D lcon = Constraint2D.CreateLenCon(i, i + gap, spr.restLen);
                soft.constraints.Add(lcon);
            }
        }
#endif
        // Apply fixed end constraints
        Constraint2D pcon;

        //if ( left )
        //{
        //	pcon = Constraint2D.CreatePointTargetCon(0, left);
        //}
        //else
        {
            pos.x = bbox.min[ax];
            pos.y = 0.0f;
            pcon  = Constraint2D.CreatePointCon(0, pos);
        }
        pconl = soft.constraints.Count;
        soft.constraints.Add(pcon);

        //if ( right )
        //{
        //	pcon = Constraint2D.CreatePointTargetCon(soft.masses.Count - 1, left);
        //}
        //else
        {
            pos.x = bbox.max[ax];
            pcon  = Constraint2D.CreatePointCon(soft.masses.Count - 1, pos);
        }
        pconr = soft.constraints.Count;
        soft.constraints.Add(pcon);

        soft.DoConstraints();
    }
コード例 #6
0
 public override void SetUrho(ConstraintRope2D instance, Constraint2D value)
 {
     instance.AttachedConstraint = value;
 }
コード例 #7
0
 public void AddConstraint(Constraint2D c)
 {
     constraints.Add(c);
 }
コード例 #8
0
ファイル: MegaSoft2D.cs プロジェクト: jsr2k1/videojocjj
 //public void ApplyPointTargetConstraint2D(MegaSoft2D soft)
 //{
 //    if ( active && obj )
 //        soft.masses[p1].pos = tobj.position;
 //}
 // Semi rigid job
 public static void CreateSemiRigidCon(int _p1, int _p2, float min, float mid, float max, float force)
 {
     Constraint2D con = new Constraint2D();
     con.p1 = _p1;
     con.p2 = _p2;
     con.min = min;
     con.mid = min;
     con.max = min;
     con.force = min;
 }
コード例 #9
0
 public override void SetUrho(ConstraintGear2D instance, Constraint2D value)
 {
     instance.OtherConstraint = value;
 }
コード例 #10
0
 public override void SetPrefab(ConstraintGear2DPrefab instance, Constraint2D value)
 {
     instance.OtherConstraint = value;
 }
コード例 #11
0
 public override bool TryParsePrefab(string text, out Constraint2D value)
 {
     throw new System.NotImplementedException();
 }