public bool Grab(Body other) { if (!IsGrabbed(other) && GrabbedComponents.Count < MaxGrabs) { Matrix m = Matrix.Identity; m = GlobalTransform; m.Translation = GlobalTransform.Translation + new Vector3(0, 0.0f, 0.5f); other.GlobalTransform = m; GrabbedItem item = new GrabbedItem { Component = other, LocalTransform = Matrix.Invert(GlobalTransform) * other.GlobalTransform }; GrabbedComponents.Add(item); other.LocalTransform = item.LocalTransform; AddChild(other); return(true); } else { return(false); } }
private void RemoveComponent(Body component) { int i = 0; int index = -1; foreach (GrabbedItem grabbed in GrabbedComponents) { if (grabbed.Component == component) { index = i; break; } i++; } if (index >= 0) { GrabbedComponents.RemoveAt(index); } }
public bool IsGrabbed(Body component) { return(GrabbedComponents.Any(item => item.Component == component)); }
public Body GetFirstGrab() { return(GrabbedComponents.Count <= 0 ? null : GrabbedComponents.First().Component); }