Example #1
0
        /// <summary>
        /// Parses a <see cref="PhysicsObject" /> from the given XML node.
        /// </summary>
        /// <param name="node">The XML node.</param>
        /// <returns>A <see cref="SceneNode" /> instance.</returns>
        private SceneNode ParsePhysicsObject(XElement node)
        {
            Type collisionShapeType;

            switch (node.Element("physics").Element("collider").Attribute("type").Value)
            {
                case "box":
                    collisionShapeType = typeof(BoxShape);
                    break;
                case "sphere":
                    collisionShapeType = typeof(SphereShape);
                    break;
                case "mesh":
                    collisionShapeType = typeof(TriangleMeshShape);
                    break;
                default:
                    throw new Exception("Unknown collision shape");
            }

            bool isStatic = true;

            string physicsType = node.Element("physics").Attribute("type").Value;
            if (physicsType == "rigid_body")
            {
                isStatic = false;
            }

            var newObject = new PhysicsObject(
                node.Element("mesh").Attribute("file").Value,
                this.ParseVector3(node.Element("position")),
                this.ParseQuaternion(node.Element("rotation")),
                this.ParseVector3(node.Element("scale")),
                collisionShapeType,
                isStatic);

            var sceneNode = new SceneNode();
            sceneNode.AttachEntity(newObject);
            return sceneNode;
        }
Example #2
0
        public void Initialize(Engine engine)
        {
            this.engine = engine;

            this.CreatePlayer();

            var r = new Random();
            for (int i = 0; i < 100; i++)
            {
                var node = new SceneNode();
                var box = new PhysicsObject(
                    "Cube",
                    new Vector3(r.Next(20) - 10, r.Next(500) + 200, r.Next(20) - 10),
                    Quaternion.Identity,
                    Vector3.One,
                    typeof(BoxShape),
                    false);
                node.AttachEntity(box);
                this.AttachSceneNodeToRoot(node);
            }

            this.sceneGraph.Initialize(this.engine);
        }