/** Remove a body from physics world. */ public virtual void RemoveBody(CCPhysicsBody body) { if (body.GetWorld() != this) { cp.AssertWarn("Physics Warnning: this body doesn't belong to this world"); return; } // destory the body's joints foreach (var joint in body._joints) { // set destroy param to false to keep the iterator available RemoveJoint(joint, false); CCPhysicsBody other = (joint.BodyA == body ? joint.BodyB : joint.BodyA); other.RemoveJoint(joint); if (DelayRemoveJoints.Exists(j => j == joint)) { joint._destoryMark = true; } } body._joints.Clear(); RemoveBodyOrDelay(body); Bodies.Remove(body); body._world = null; }
public void RemoveBody(IAstronomicalObject obj) { if (obj == null) { return; } Bodies.Remove(obj); }
private void Collison(IAstronomicalObject obj1, IAstronomicalObject obj2) { var after = CollisonProcess.Run(obj1, obj2); Bodies.Remove(obj1); Bodies.Remove(obj2); Bodies.AddRange(after); }
private void RemoveBody(Body body) { if (Bodies.Contains(body)) { Bodies.Remove(body); } SetModified(true, true, true); }
// Frees a body, removes all shapes associated with the body and frees // all shapes and contacts associated and attached to this body. public void RemoveBody(Body body) { ContactManager.RemoveContactsFromBody(body); body.RemoveAllBoxes(); // Remove body from scene Bodies Assert(Bodies.Remove(body)); }
/// <summary> /// Catches the AllFrameReady-Event and saves the skeletons of the actual frame before they are available to processing. /// Addtionally it checks, if a skeleton completely left the room. /// </summary> /// <param name="sender">sender of the AllFrameReady event</param> /// <param name="e">AllFrameReadyEvent with associated data.</param> public void reader_FramesReady(object sender, BodyFrameArrivedEventArgs e) { if (e == null) { return; } Body[] bodies = new Body[0]; BodyFrameReference frameReference = e.FrameReference; using (BodyFrame bodyFrame = frameReference.AcquireFrame()) { if (bodyFrame != null) { bodies = new Body[bodyFrame.BodyCount]; bodyFrame.GetAndRefreshBodyData(bodies); } else { return; } HashSet <int> idsSeen = new HashSet <int>(); foreach (Body s in bodies) { if (s.TrackingId != 0) { idsSeen.Add((int)s.TrackingId); } } bool bodiesLastFrameNotNull = false; foreach (Body s in _bodiesLastFrame) { if (s == null && bodiesLastFrameNotNull == true) { bodiesLastFrameNotNull = false; break; } if (s != null && bodiesLastFrameNotNull == false) { bodiesLastFrameNotNull = true; } } if (bodiesLastFrameNotNull) { //checks if a skeleton doesnt exist anymore. foreach (Body s in _bodiesLastFrame.Where(s => s != null && !idsSeen.Contains((int)s.TrackingId) && s.TrackingId != 0)) { this.OnUserLeft(this, new KinectUserEventArgs((int)s.TrackingId)); for (int i = 0; i < Bodies.Count; i++) { if (Bodies[i].Id == (int)s.TrackingId) { Bodies.Remove(Bodies[i]); } } } } _bodiesLastFrame = bodies; if (checkOnEveryFrame) { } if (movingWindowCollect == true) { Body[] bodiesToSave = new Body[bodies.Length]; for (int i = 0; i < bodies.Length; i++) { bodiesToSave[i] = bodies[i]; } if (workingOnWindow == false) { if (movingWindowCollect == true && lastBodies.Count == windowSize) { lastBodies.RemoveAt(0); } lastBodies.Add(bodiesToSave); } } } }
void Update() { if (BodySourceManager == null) { return; } _bodyManager = BodySourceManager.GetComponent <BodySourceManager>(); if (_bodyManager == null) { return; } Kinect.Body[] data = _bodyManager.GetData(); if (data == null) { return; } List <ulong> trackedIds = new List <ulong>(); foreach (var body in data) { if (body == null) { continue; } if (body.IsTracked) { trackedIds.Add(body.TrackingId); break; } } List <ulong> knownIds = new List <ulong>(Bodies.Keys); // First delete untracked bodies foreach (ulong trackingId in knownIds) { if (!trackedIds.Contains(trackingId)) { Destroy(Bodies[trackingId]); Bodies.Remove(trackingId); } } foreach (var body in data) { if (body == null) { continue; } if (body.IsTracked) { if (!Bodies.ContainsKey(body.TrackingId)) { GameObject newBody = new GameObject(); KinectPlayer newPlayer = Instantiate(Resources.Load("BlockPlayer") as GameObject, new Vector3(0, 0, 0), Quaternion.identity).GetComponent <KinectPlayer>(); newPlayer.Kinect = this; if (players.Count == 0) { newPlayer.makeMainPlayer(true); } Bodies[body.TrackingId] = newPlayer.CreateBodyObject(body, newBody); newPlayer.WarpToLocation(new Vector3(0, 1.5f, 0)); players.Add(newPlayer); _bodyThread = new Thread(new ThreadStart(RefreshBody)); _bodyThread.Start(); } foreach (KinectPlayer player in players) { try { if (player.IsTracked()) { player.gameObject.SetActive(true); player.UpdateBodyObject(); player.AdjustBodyParts(); } else { player.gameObject.SetActive(false); } } catch (Exception e) { Debug.LogError("Error getting body"); Debug.LogError(e); } } break; } } }
/// <summary> /// Remove the active Body /// </summary> public static void RemoveActive() { Bodies.Remove(ActiveBody); }