示例#1
0
文件: Scene.cs 项目: DavidMann10k/nyx
        private void CreatePlayer()
        {
            SceneNode sceneNode = new SceneNode();

            Player player = new Player(new Vector3(0, 3, 0), Quaternion.Identity, Vector3.One, 0.75f, 1.75f, 8.0f);

            sceneNode.AttachEntity(player);

            this.AttachSceneNodeToRoot(sceneNode);
        }
示例#2
0
        /// <summary>
        /// Parses a <see cref="DirectionalLight" /> from the given XML node.
        /// </summary>
        /// <param name="node">The XML node.</param>
        /// <returns>A <see cref="SceneNode" /> instance.</returns>
        public SceneNode ParseDirectionalLight(XElement node)
        {
            var directionalLight = new DirectionalLight(
                Vector3.Zero,
                Quaternion.Identity,
                Vector3.One,
                this.ParseColor(node.Element("color")),
                float.Parse(node.Attribute("intensity").Value),
                this.ParseVector3(node.Element("direction")));

            var sceneNode = new SceneNode();
            sceneNode.AttachEntity(directionalLight);
            return sceneNode;
        }
示例#3
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;
        }
示例#4
0
        /// <summary>
        /// Parses a <see cref="SpotLight" /> from the given XML node.
        /// </summary>
        /// <param name="node">The XML node.</param>
        /// <returns>A <see cref="SceneNode" /> instance.</returns>
        public SceneNode ParseSpotLight(XElement node)
        {
            SpotLight spotLight = new SpotLight(
                this.ParseVector3(node.Element("position")),
                Quaternion.Identity,
                Vector3.One,
                this.ParseVector3(node.Element("direction")),
                this.ParseColor(node.Element("color")),
                float.Parse(node.Attribute("intensity").Value),
                float.Parse(node.Element("clip").Attribute("near").Value),
                float.Parse(node.Element("clip").Attribute("far").Value),
                float.Parse(node.Element("projection").Attribute("field-of-view").Value),
                float.Parse(node.Attribute("bias").Value),
                bool.Parse(node.Attribute("cast-shadows").Value),
                int.Parse(node.Attribute("resolution").Value));

            SceneNode sceneNode = new SceneNode();
            sceneNode.AttachEntity(spotLight);
            return sceneNode;
        }
示例#5
0
        /// <summary>
        /// Parses a <see cref="RenderableObject" /> from the given XML node.
        /// </summary>
        /// <param name="node">The XML node.</param>
        /// <returns>A <see cref="SceneNode" /> instance.</returns>
        public SceneNode ParseRenderableObject(XElement node)
        {
            var renderableObject = new RenderableObject(
                this.ParseVector3(node.Element("position")),
                this.ParseQuaternion(node.Element("rotation")),
                this.ParseVector3(node.Element("scale")),
                node.Element("mesh").Attribute("file").Value);

            var sceneNode = new SceneNode();
            sceneNode.AttachEntity(renderableObject);
            return sceneNode;
        }
示例#6
0
        /// <summary>
        /// Parses a <see cref="PointLight" /> from the given XML node.
        /// </summary>
        /// <param name="node">The XML node.</param>
        /// <returns>A <see cref="SceneNode" /> instance.</returns>
        public SceneNode ParsePointLight(XElement node)
        {
            var pointLight = new PointLight(
                this.ParseVector3(node.Element("position")),
                Quaternion.Identity,
                Vector3.One,
                float.Parse(node.Attribute("radius").Value),
                this.ParseColor(node.Element("color")),
                float.Parse(node.Attribute("intensity").Value),
                bool.Parse(node.Attribute("cast-shadows").Value),
                int.Parse(node.Attribute("resolution").Value),
                float.Parse(node.Attribute("bias").Value));

            var sceneNode = new SceneNode();
            sceneNode.AttachEntity(pointLight);
            return sceneNode;
        }