Exemple #1
0
        private void SetCollisionObjectInfo(CollisionObject collisionObject, TreeNode objectsNode)
        {
            string         objectName = collisionObject.GetType().Name;
            CollisionShape shape      = collisionObject.CollisionShape;
            string         shapeName  = shape.GetType().Name;

            string text = $"{objectName} ({shapeName})";

            GetOrCreateChildNode(collisionObject, text, objectsNode);
        }
        public XmlNode WriteShape(CollisionShape shape, XmlDocument document)
        {
            XmlNode node = document.CreateElement("shape");


            if (shape is CollisionAABB)
            {
                CollisionAABB aabbShape = shape as CollisionAABB;

                // convert to meters (or other scaled unit) before writing out
                Vector3 center     = shape.center / unitConversion;
                Vector3 halfExtent = (aabbShape.max - aabbShape.center) / unitConversion;

                XmlNode translate = WriteTranslate(center, document);
                node.AppendChild(translate);
                XmlNode boxNode = WriteBox(halfExtent, document);
                node.AppendChild(boxNode);
            }
            else if (shape is CollisionOBB)
            {
                CollisionOBB obbShape = shape as CollisionOBB;

                // convert to meters (or other scaled unit) before writing out
                Vector3 center     = shape.center / unitConversion;
                Vector3 halfExtent = obbShape.extents / unitConversion;

                Quaternion rot = Quaternion.Identity;
                rot.FromAxes(obbShape.axes[0], obbShape.axes[1], obbShape.axes[2]);
                XmlNode rotate = WriteRotate(rot, document);
                node.AppendChild(rotate);
                XmlNode translate = WriteTranslate(center, document);
                node.AppendChild(translate);

                XmlNode boxNode = WriteBox(halfExtent, document);
                node.AppendChild(boxNode);
            }
            else if (shape is CollisionCapsule)
            {
                CollisionCapsule capsuleShape = shape as CollisionCapsule;

                // convert to meters (or other scaled unit) before writing out
                Vector3 center = shape.center / unitConversion;
                float   height = capsuleShape.height / unitConversion;
                float   radius = capsuleShape.capRadius / unitConversion;

                Vector3    halfExtent = capsuleShape.topcenter - capsuleShape.center;
                Quaternion rot        = Vector3.UnitY.GetRotationTo(halfExtent);
                XmlNode    rotate     = WriteRotate(rot, document);
                node.AppendChild(rotate);
                XmlNode translate = WriteTranslate(center, document);
                node.AppendChild(translate);
                XmlNode capsuleNode = WriteCapsule(height, radius, document);
                node.AppendChild(capsuleNode);
            }
            else if (shape is CollisionSphere)
            {
                // convert to meters (or other scaled unit) before writing out
                Vector3 center = shape.center / unitConversion;
                float   radius = shape.radius / unitConversion;

                XmlNode translate = WriteTranslate(center, document);
                node.AppendChild(translate);
                XmlNode sphereNode = WriteSphere(radius, document);
                node.AppendChild(sphereNode);
            }
            else
            {
                log.ErrorFormat("Unsupported collision shape: {0}", shape.GetType());
            }
            return(node);
        }