Esempio n. 1
0
    /// <summary>
    /// Get the latest contact info from the simulation and parse that infor into easily readable arrays of structs</summary>
    public void Update()
    {
        IntPtr contactinfo = LPAPIContacts.UpdateContactListener(ContactListenerPtr);

        //find out how many contacts there were
        float[] info = new float[3];
        Marshal.Copy(contactinfo, info, 0, 3);
        int fixfixnum   = (int)info[0];
        int fixpartnum  = (int)info[1];
        int partpartnum = (int)info[2];          //Debug.Log("fixfix "+fixfixnum +" fixpart "+fixpartnum+ " partpart "+partpartnum );
        int totalnum    = 3 + fixfixnum * ff + fixpartnum * pf + partpartnum * pp;

        float[] allinfo = new float[totalnum];
        Marshal.Copy(contactinfo, allinfo, 0, totalnum);

        //Parse contacts into structsS
        FixtureFixtureContacts = new LPContactFixFix[fixfixnum];
        for (int i = 0; i < fixfixnum; i++)
        {
            FixtureFixtureContacts[i] = new LPContactFixFix
            {
                BodyAIndex       = (int)allinfo[3 + (i * ff)]
                , BodyBIndex     = (int)allinfo[4 + (i * ff)]
                , FixtureAIndex  = (int)allinfo[5 + (i * ff)]
                , FixtureBIndex  = (int)allinfo[6 + (i * ff)]
                , ManifoldPoint1 = new Vector3(allinfo[7 + (i * ff)], allinfo[8 + (i * ff)])
                , ManifoldPoint2 = new Vector3(allinfo[9 + (i * ff)], allinfo[10 + (i * ff)])
                , Normal         = new Vector3(allinfo[11 + (i * ff)], allinfo[12 + (i * ff)])
                , IsTouching     = floattoBool(allinfo[12 + (i * ff)])
            };
        }

        int start = 3 + (fixfixnum * ff);

        ParticleFixtureContacts = new LPContactPartFix[fixpartnum];
        for (int i = 0; i < fixpartnum; i++)
        {
            ParticleFixtureContacts[i] = new LPContactPartFix
            {
                ParticleSystemIndex = (int)allinfo[start + (i * pf)]
                , ParticleIndex     = (int)allinfo[start + (i * pf) + 1]
                , BodyIndex         = (int)allinfo[start + (i * pf) + 2]
                , FixtureIndex      = (int)allinfo[start + (i * pf) + 3]
                , Normal            = new Vector3((int)allinfo[start + (i * pf) + 4], (int)allinfo[start + (i * pf) + 5])
            };
        }

        start = 3 + (fixfixnum * ff) + (fixpartnum * pf);
        ParticleParticleContacts = new LPContactPartPart[partpartnum];
        for (int i = 0; i < partpartnum; i++)
        {
            ParticleParticleContacts[i] = new LPContactPartPart
            {
                ParticleSystemIndex = (int)allinfo[start + (i * pp)]
                , ParticleAIndex    = (int)allinfo[start + (i * pp) + 1]
                , ParticleBIndex    = (int)allinfo[start + (i * pp) + 2]
                                      //,Normal = new Vector3((int)allinfo[start+(i*pp)+3],(int)allinfo[start+(i*pp)+4])
            };
        }
    }
    /// <summary>
    /// Get the latest contact info from the simulation and parse that infor into easily readable arrays of structs</summary>
    public void Update()
    {
        IntPtr contactinfo = LPAPIContacts.UpdateContactListener(ContactListenerPtr);

        //find out how many contacts there were
        float[] info = new float[3];
        Marshal.Copy (contactinfo,info,0,3);
        int fixfixnum = (int)info[0];
        int fixpartnum = (int)info[1];
        int partpartnum = (int)info[2];  //Debug.Log("fixfix "+fixfixnum +" fixpart "+fixpartnum+ " partpart "+partpartnum );
        int totalnum = 3+ fixfixnum*ff + fixpartnum*pf + partpartnum*pp;
        float[] allinfo = new float[totalnum];
        Marshal.Copy (contactinfo,allinfo,0,totalnum);

        //Parse contacts into structsS
        FixtureFixtureContacts = new LPContactFixFix[fixfixnum];
        for (int i = 0; i < fixfixnum; i++)
        {
            FixtureFixtureContacts[i] = new LPContactFixFix
            {
                 BodyAIndex = (int)allinfo[3+(i*ff)]
                ,BodyBIndex = (int)allinfo[4+(i*ff)]
                ,FixtureAIndex = (int)allinfo[5+(i*ff)]
                ,FixtureBIndex = (int)allinfo[6+(i*ff)]
                ,ManifoldPoint1 = new Vector3(allinfo[7+(i*ff)],allinfo[8+(i*ff)])
                ,ManifoldPoint2 = new Vector3(allinfo[9+(i*ff)],allinfo[10+(i*ff)])
                ,Normal = new Vector3(allinfo[11+(i*ff)],allinfo[12+(i*ff)])
                ,IsTouching = floattoBool(allinfo[12+(i*ff)])
            };
        }

        int start = 3+(fixfixnum*ff);
        ParticleFixtureContacts = new LPContactPartFix[fixpartnum];
        for (int i = 0; i < fixpartnum; i++)
        {
            ParticleFixtureContacts[i] = new LPContactPartFix
            {
                ParticleSystemIndex = (int)allinfo[start+(i*pf)]
                ,ParticleIndex = (int)allinfo[start+(i*pf)+1]
                ,BodyIndex = (int)allinfo[start+(i*pf)+2]
                ,FixtureIndex = (int)allinfo[start+(i*pf)+3]
                ,Normal = new Vector3((int)allinfo[start+(i*pf)+4],(int)allinfo[start+(i*pf)+5])
            };
        }

        start = 3+(fixfixnum*ff)+(fixpartnum*pf);
        ParticleParticleContacts = new LPContactPartPart[partpartnum];
        for (int i = 0; i < partpartnum; i++)
        {
            ParticleParticleContacts[i] = new LPContactPartPart
            {
                 ParticleSystemIndex = (int)allinfo[start+(i*pp)]
                ,ParticleAIndex = (int)allinfo[start+(i*pp)+1]
                ,ParticleBIndex = (int)allinfo[start+(i*pp)+2]
                //,Normal = new Vector3((int)allinfo[start+(i*pp)+3],(int)allinfo[start+(i*pp)+4])
            };
        }
    }