Пример #1
0
 /// <summary> Determines what colour to draw the bodies fixtures based on its state / type  </summary>
 public Color GetColor()
 {
     if (BodyType == LPBodyTypes.Static)
     {
         if (Initialised && Application.isPlaying)
         {
             if (!LPAPIBody.GetBodyActive(ThingPtr))
             {
                 return(LPColors.StaticInactive);
             }
             if (!LPAPIBody.GetBodyAwake(ThingPtr))
             {
                 return(LPColors.StaticAsleep);
             }
         }
         return(LPColors.StaticAwake);
     }
     if (BodyType == LPBodyTypes.Dynamic)
     {
         if (Initialised && Application.isPlaying)
         {
             if (!LPAPIBody.GetBodyActive(ThingPtr))
             {
                 return(LPColors.DynamicInActive);
             }
             if (!LPAPIBody.GetBodyAwake(ThingPtr))
             {
                 return(LPColors.DynamicAsleep);
             }
         }
         return(LPColors.DynamicAwake);
     }
     if (BodyType == LPBodyTypes.Kinematic)
     {
         if (Initialised && Application.isPlaying)
         {
             if (!LPAPIBody.GetBodyActive(ThingPtr))
             {
                 return(LPColors.KinematicInActive);
             }
             if (!LPAPIBody.GetBodyAwake(ThingPtr))
             {
                 return(LPColors.KinematicAsleep);
             }
         }
         return(LPColors.KinematicAwake);
     }
     return(Color.white);
 }
Пример #2
0
 void FixedUpdate()
 {
     int[] conts = bod.GetContacts();
     if (conts.Length > 1)
     {
         Vector3 diff = getdiff();
         for (int i = 1; i < conts.Length; i++)
         {
             if (lpman.allBodies.ContainsKey(conts[i]))
             {
                 LPAPIBody.ApplyForceToCentreOfBody(lpman.allBodies[conts[i]].GetPtr(), diff.x, diff.y);
             }
         }
     }
 }
Пример #3
0
    //This creates the body and its fixtures in the physics simulation
    public void Initialise(LPManager man)
    {
        StartRotation = transform.localEulerAngles.z;
        lpman         = man;
        myIndex       = lpman.AddBody(this);
        ThingPtr      = LPAPIBody.CreateBody(lpman.GetPtr(), (int)BodyType, transform.position.x, transform.position.y
                                             , 0f
                                             , LinearDamping, AngularDamping, AllowSleep, FixedRotation, IsBullet, GravityScale
                                             , myIndex);

        foreach (LPFixture _fix in gameObject.GetComponents <LPFixture>())
        {
            _fix.Initialise(this);
        }
        Initialised = true;
    }
Пример #4
0
    /// <summary>
    /// Returns an array of the indices of every body currently in contact with this body
    /// Note that the 1st element of the array is the lenght of the array</summary>
    public int[] GetContacts()
    {
        IntPtr contactsPointer = LPAPIBody.GetBodyContacts(ThingPtr);

        int[] contactsArray = new int[1];
        Marshal.Copy(contactsPointer, contactsArray, 0, 1);
        int contsNum = contactsArray[0];

        int[] contacts = new int[contsNum + 1];
        if (contsNum > 0)
        {
            Marshal.Copy(contactsPointer, contacts, 0, contsNum + 1);
        }

        // LPAPIUtility.ReleaseIntArray(contactsPointer);
        return(contacts);
    }
Пример #5
0
 private IEnumerator Spawn()
 {
     while (true)
     {
         if (bodylist.Count > amount)
         {
             bodylist[0].Delete();
             bodylist.RemoveAt(0);
         }
         GameObject go = new GameObject("body");
         go.transform.parent   = transform;
         go.transform.position = transform.position;
         LPBody body = go.AddComponent <LPBody>();
         bodylist.Add(body);
         LPFixtureCircle circle = go.AddComponent <LPFixtureCircle>();
         circle.Density = 0.2f;
         circle.Radius  = 0.1f;
         body.BodyType  = LPBodyTypes.Dynamic;
         body.Initialise(lpman);
         LPAPIBody.ApplyForceToCentreOfBody(body.GetPtr(), SpawnVelocity.x, SpawnVelocity.y);
         yield return(new WaitForSeconds(spawninterval));
     }
 }
Пример #6
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.F6))
        {
            if (gameObject.GetComponent <Image>())
            {
                OnOff        = !OnOff;
                vise.enabled = OnOff;
                if (OnOff)
                {
                    gameObject.GetComponent <Image>().sprite = VOn;

                    LPAPIBody.SetBodyType(head.GetComponent <LPBody>().GetPtr(), (int)LPBodyTypes.Static);
                }
                else
                {
                    gameObject.GetComponent <Image>().sprite = VOff;

                    LPAPIBody.SetBodyType(head.GetComponent <LPBody>().GetPtr(), (int)LPBodyTypes.Dynamic);
                }
            }
        }
    }
Пример #7
0
    /// <summary>
    /// Update the position and rotation of non static bodies in the world.
    /// The bodies positions and angles are updated in unitys update event handler method.
    /// This is so that this information is only fetched when it is needed (ie when you are going to draw the item associated with the body)
    /// If the frame rate slow this data will be fetched less and will help improve performance.</summary>
    void Update()
    {
        List <LPBody> bodies = new List <LPBody>();

        foreach (KeyValuePair <int, LPBody> bod in allBodies)
        {
            if (bod.Value.shouldUpdate())
            {
                bodies.Add(bod.Value);
            }
        }

        if (bodies.Count > 0)
        {
            IntPtr[] ptrs = new IntPtr[bodies.Count];

            for (int i = 0; i < bodies.Count; i++)
            {
                ptrs[i] = bodies[i].GetPtr();
            }

            IntPtr bodinfoptr = LPAPIBody.GetAllBodyInfo(ptrs, bodies.Count);

            float[] bodinfo = new float[bodies.Count * 3];
            Marshal.Copy(bodinfoptr, bodinfo, 0, bodies.Count * 3);

            for (int i = 0; i < bodies.Count; i++)
            {
                bodies[i].LPmanUpdate(bodinfo[i * 3]
                                      , bodinfo[(i * 3) + 1]
                                      , bodinfo[(i * 3) + 2]

                                      );
            }
        }
    }
Пример #8
0
 //Delete the body (and its fixtures) from the physics simulation, also destroy the gameobject in unity.
 public override void Delete()
 {
     lpman.RemoveBody(myIndex);
     LPAPIBody.DeleteBody(lpman.GetPtr(), ThingPtr);
     Destroy(gameObject);
 }
Пример #9
0
    // Use this for initialization
    void Start()
    {
        Debug.Log(LPAPIBody.GetBodyUserData(GetComponent <LPBody>().GetPtr()));

        Debug.Log(LPAPIFixture.GetFixtureUserData(GetComponent <LPFixture>().GetPtr()));
    }
Пример #10
0
 public void DeleteWithoutRemovingComponents()
 {
     lpman.RemoveBody(myIndex);
     LPAPIBody.DeleteBody(lpman.GetPtr(), ThingPtr);
 }