Пример #1
0
        public void Remove(IGameObject obj)
        {
            if (!(obj is PhysicsObject))
            {
                throw new NotImplementedException("Currently only PhysicsObjects can be added to a structure.");
            }

            PhysicsObject physObj = (PhysicsObject)obj;

            if (!objects.Contains(physObj))
            {
                return;
            }

            physObj.ParentStructure      = null;
            physObj.CollisionIgnorer     = null;
            physObj.CollisionIgnoreGroup = 0;
            physObj.Collided            -= this.OnCollided;

            foreach (var joint in Joints.FindAll(j => j.Object1 == physObj || j.Object2 == physObj))
            {
                joint.Destroy();
                PhysicsGameBase.Instance.Remove(joint);
            }

            objects.Remove(physObj);
            CalculateMomentOfInertia();
        }
Пример #2
0
        private void LoadFile(string filename)
        {
            XDocument xdoc = XDocument.Load(filename);
            XElement  node = xdoc.Element("robot");

            Name = node.Attribute("name")?.Value;

            Materials = node.ReadMaterials();     // multiple
            Links     = node.ReadLinks();         // multiple
            Joints    = node.ReadJoints();        // multiple

            // build tree structure from link and joint lists:
            foreach (Link.Link link in Links)
            {
                link.Joints = Joints.FindAll(v => v.Parent == link.Name);
            }
            foreach (Joint.Joint joint in Joints)
            {
                joint.ChildLink = Links.Find(v => v.Name == joint.Child);
            }

            // save root node only:
            Root = FindRootLink(Links, Joints);
        }