Ejemplo n.º 1
0
        /// <summary>
        /// Builds up the wallsToPlace map. Mutually recursive call with GetPerimeterWallsHelper function.
        /// </summary>
        /// <param name="wallsToPlace">The current map of index to perimeter walls. Will be mutated.</param>
        /// <param name="visited">The current list of coordinate indices already visited. Will be mutated.</param>
        /// <param name="curIndex">The coordinate index to contiguously search from.</param>
        /// <param name="sceneGraphManager">The ative Scene Graph</param>
        private static void GetPerimeterWalls(Dictionary <IntVector3, WWWalls> wallsToPlace, List <IntVector3> visited,
                                              IntVector3 curIndex, SceneGraphManager sceneGraphManager)
        {
            // check if there are contiguous tiles in all four directions from the current coordinate index.
            var northIndex = new IntVector3(curIndex.x, curIndex.y, curIndex.z + 1);
            var eastIndex  = new IntVector3(curIndex.x + 1, curIndex.y, curIndex.z);
            var southIndex = new IntVector3(curIndex.x, curIndex.y, curIndex.z - 1);
            var westIndex  = new IntVector3(curIndex.x - 1, curIndex.y, curIndex.z);

            visited.Add(curIndex);             // mark this index as visited.

            if (!visited.Contains(northIndex)) // if we have not visited the coordinate index one to the north...
            {
                GetPerimeterWallsHelper(northIndex, WWWalls.North, wallsToPlace, visited, curIndex,
                                        sceneGraphManager);
            }
            if (!visited.Contains(eastIndex)) // if we have not visited the coordinate index one to the east...
            {
                GetPerimeterWallsHelper(eastIndex, WWWalls.East, wallsToPlace, visited, curIndex,
                                        sceneGraphManager);
            }
            if (!visited.Contains(southIndex)) // if we have not visited the coordinate index one to the south...
            {
                GetPerimeterWallsHelper(southIndex, WWWalls.South, wallsToPlace, visited, curIndex,
                                        sceneGraphManager);
            }
            if (!visited.Contains(westIndex)) // if we have not visited the coordinate index one to the west...
            {
                GetPerimeterWallsHelper(westIndex, WWWalls.West, wallsToPlace, visited, curIndex,
                                        sceneGraphManager);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This helper function checks to see if there are any object in curIndex cooridnate index. If there are none,
        /// the origIndex must have had a perimeter wall and the wallsToPlace map is acoordingly updated. However, if
        /// there were objects at the curIndex coordinate index, the search continues on and a mutually recursive
        /// call back to GetPerimeterWalls is made.
        /// </summary>
        /// <param name="curIndex">The current coordinate index.</param>
        /// <param name="direction">The direction of the perimeter wall to test for.</param>
        /// <param name="wallsToPlace">The current threaded map of perimeter walls to place.</param>
        /// <param name="visited">The current list of coordinate Indices already visited.</param>
        /// <param name="origIndex"> The coordinate index one step before this, where the perimeter wall will be placed.</param>
        /// <param name="sceneGraphManager"> The active Scene Graph.</param>
        private static void GetPerimeterWallsHelper(IntVector3 curIndex, WWWalls direction,
                                                    Dictionary <IntVector3, WWWalls> wallsToPlace, List <IntVector3> visited, IntVector3 origIndex,
                                                    SceneGraphManager sceneGraphManager)
        {
            // TODO potentially filter out non Floor tiles, and Props.
            List <WWObject> objects = sceneGraphManager.GetObjectsInCoordinateIndex(new Coordinate(curIndex));

            if (objects.Count == 0) // empty coordinate index, must have originated from an coordinate index with a perimeter
            {
                if (wallsToPlace.ContainsKey(origIndex))
                {
                    // append by OR to existing perimeter walls at the coordinate index
                    wallsToPlace[origIndex] = direction | wallsToPlace[origIndex];
                }
                else
                {
                    // add a new entry into wallsToPlace
                    wallsToPlace.Add(origIndex, direction);
                }
            }
            else // search further for a perimeter
            {
                GetPerimeterWalls(wallsToPlace, visited, curIndex, sceneGraphManager);
            }
        }
Ejemplo n.º 3
0
        public override void Render(SceneGraphManager sceneGraph)
        {
            //get camera (View & Projection Matrix)
            Camera camera = CameraManager.Instance.GetCurrentCamera();

            //WorldMatrix = transforms[mesh.ParentBone.Index] * Utils.CreateWorldMatrix(Position, Matrix.CreateRotationY(Angle), new Vector3(0.002f, 0.002f, 0.002f));
            effect.Parameters["World"].SetValue(AbsoluteTransform);
            effect.Parameters["View"].SetValue(camera.View);
            effect.Parameters["Projection"].SetValue(camera.Projection);

            effect.CurrentTechnique.Passes[0].Apply();

            GameApplication.Instance.GetGraphics().SetVertexBuffer(this.vertexBuffer);
            GameApplication.Instance.GetGraphics().Indices = indexBuffer;

            GameApplication.Instance.GetGraphics().DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 128 * 128 * 6, 0, (127 * 127 * 6) / 3);

            //reset cullMode
            RasterizerState rs = new RasterizerState();
            rs = null;
            rs = new RasterizerState();
            rs.FillMode = FillMode.Solid;
            rs.CullMode = CullMode.CullCounterClockwiseFace;
            GameApplication.Instance.GetGraphics().RasterizerState = rs;

            base.Render(sceneGraph);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// The render method. Render the 
        /// vertices with the help of a vertex and index buffer
        /// onto the screen.
        /// </summary>
        /// <param name="sceneGraph">The scene graph responsible for this actor - <see cref="SceneGraphManager"/></param>
        public override void Render(SceneGraphManager sceneGraph)
        {
            Camera camera = CameraManager.Instance.GetCurrentCamera();

            effect.Parameters["World"].SetValue(AbsoluteTransform);
            effect.Parameters["View"].SetValue(camera.View);
            effect.Parameters["Projection"].SetValue(camera.Projection);

            effect.CurrentTechnique.Passes[0].Apply();

            GameApplication.Instance.GetGraphics().SetVertexBuffer(vertexBuffer);
            GameApplication.Instance.GetGraphics().Indices = indexBuffer;
            GameApplication.Instance.GetGraphics().DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 3, 0, 1);

            base.Render(sceneGraph);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Render the sky sphere with all its transformations and 
        /// effects.
        /// </summary>
        /// <param name="sceneGraph">The scene graph responsible for this actor - <see cref="SceneGraphManager"/></param>
        public override void Render(SceneGraphManager sceneGraph)
        {
            if (model != null)
            {
                //get camera (View & Projection Matrix)
                Camera camera = CameraManager.Instance.GetCurrentCamera();

                Matrix[] transforms = new Matrix[model.Bones.Count];
                model.CopyAbsoluteBoneTransformsTo(transforms);

                // Draw the model. A model can have multiple meshes, so loop.
                foreach (ModelMesh mesh in model.Meshes)
                {
                    // This is where the mesh orientation is set, as well
                    // as our camera and projection.
                    foreach (Effect eff in mesh.Effects)
                    {
                        //WorldMatrix = transforms[mesh.ParentBone.Index] * Utils.CreateWorldMatrix(Position, Matrix.CreateRotationY(Angle), new Vector3(0.002f, 0.002f, 0.002f));

                        effect.Parameters["World"].SetValue(AbsoluteTransform);
                        effect.Parameters["View"].SetValue(camera.View);
                        effect.Parameters["Projection"].SetValue(camera.Projection);
                        effect.Parameters["CameraPosition"].SetValue(camera.Position);
                        effect.Parameters["TextureEnabled"].SetValue(true);

                    }
                    // Draw the mesh, using the effects set above.
                    mesh.Draw();
                }

                //reset cullMode
                RasterizerState rs = new RasterizerState();
                rs = null;
                rs = new RasterizerState();
                rs.CullMode = CullMode.CullCounterClockwiseFace;
                GameApplication.Instance.GetGraphics().RasterizerState = rs;
            }

            base.Render(sceneGraph);
        }
Ejemplo n.º 6
0
 public GameView(string ID)
 {
     this.ID = ID;
     SceneGraphManager = new SceneGraphManager();
 }
Ejemplo n.º 7
0
 /// <summary>
 /// The render method. This just does nothing!
 /// </summary>
 /// <param name="sceneGraph">The scene graph responsible for this actor - <see cref="SceneGraphManager"/></param>
 public virtual void Render(SceneGraphManager sceneGraph) { }
Ejemplo n.º 8
0
 /// <summary>
 /// The update method. This just does nothing!
 /// </summary>
 /// <param name="sceneGraph">The scene graph responsible for this actor - <see cref="SceneGraphManager"/></param>
 public virtual void Update(SceneGraphManager sceneGraph)
 {
     if (Controller != null)
         Controller.UpdateSceneNode(this, sceneGraph.GameTime);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Finally render the model to the screen with some basic effect
        /// </summary>
        /// <param name="sceneGraph">The scene graph responsible for this actor - <see cref="SceneGraphManager"/></param>
        public override void Render(SceneGraphManager sceneGraph)
        {
            if (CameraManager.Instance.GetCurrentCamera() != null)
            {
                if (Model != null)
                {
                       Camera camera = CameraManager.Instance.GetCurrentCamera();

                       // Copy the model hierarchy transforms
                       Matrix[] transforms = new Matrix[Model.Bones.Count];
                       Model.CopyAbsoluteBoneTransformsTo(transforms);

                       Vector3 up = Up;
                       up.Normalize();

                       Vector3 forward = Forward;
                       forward.Normalize();

                       // Render each mesh in the model
                       foreach (ModelMesh mesh in Model.Meshes)
                       {
                           foreach (ModelMeshPart part in mesh.MeshParts)
                           {
                               Effect effect = part.Effect;

                               if (effect is BasicEffect)
                               {
                                   ((BasicEffect)effect).World = transforms[mesh.ParentBone.Index] * AbsoluteTransform;
                                   ((BasicEffect)effect).View = camera.View;
                                   ((BasicEffect)effect).Projection = camera.Projection;
                                   ((BasicEffect)effect).EnableDefaultLighting();
                               }
                               else
                               {
                                   setEffectParameter(effect, "World", transforms[mesh.ParentBone.Index] * AbsoluteTransform);
                                   setEffectParameter(effect, "View", camera.View);
                                   setEffectParameter(effect, "Projection", camera.Projection);
                                   setEffectParameter(effect, "CameraPosition", camera.Position);

                                   Material.SetEffectParameters(effect);
                               }

                           }

                           mesh.Draw();
                       }
                }
            }
        }
Ejemplo n.º 10
0
        public override void Update(SceneGraphManager sceneGraph)
        {
            Camera camera = CameraManager.Instance.GetCurrentCamera();

               // Position = new Vector3(camera.Position.X - 1000, 0, camera.Position.Z + 1000);

            base.Update(sceneGraph);
        }
Ejemplo n.º 11
0
        //render path
        public override void Render(SceneGraphManager sceneGraph)
        {
            Camera camera = CameraManager.Instance.GetCurrentCamera();

            effect.Parameters["World"].SetValue(AbsoluteTransform);
            effect.Parameters["View"].SetValue(camera.View);
            effect.Parameters["Projection"].SetValue(camera.Projection);
            effect.CurrentTechnique.Passes[0].Apply();

            GameApplication.Instance.GetGraphics().SetVertexBuffer(vertexBuffer);
            GameApplication.Instance.GetGraphics().DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineStrip,vertices, 0,vertices.Length-1);

            base.Render(sceneGraph);
        }