Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SceneGraph" /> class.
        /// </summary>
        public SceneGraph()
        {
            this.root = new SceneNode();

            this.collisionSystem = new CollisionSystemSAP();
            this.world = new World(this.collisionSystem);
            this.world.Gravity = new JVector(0f, -12f, 0f);

            this.directionalLights = new List<DirectionalLight>();
            this.spotLights = new List<SpotLight>();
            this.pointLights = new List<PointLight>();
            this.renderableObjects = new List<RenderableObject>();

            this.camera = new Camera(this.engine);
        }
Пример #2
0
 public void AttachSceneNodeToRoot(SceneNode node)
 {
     this.sceneGraph.AttachSceneNodeToRoot(node);
 }
Пример #3
0
        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);
        }
Пример #4
0
        /// <summary>
        /// Attaches the scene node as a child of the root node.
        /// </summary>
        /// <param name="node">The node.</param>
        public void AttachSceneNodeToRoot(SceneNode node)
        {
            this.root.Children.Add(node);

            foreach (var entity in node.Entities)
            {
            }
        }
Пример #5
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;
        }
Пример #6
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;
        }
Пример #7
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;
        }
Пример #8
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;
        }
Пример #9
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;
        }