Example #1
0
        //Constructor------------------------------------------------------------------------
        /// <summary>
        /// Construct a pack with an Object3D leader
        /// </summary>
        /// <param name="theStage"> the scene     </param>
        /// <param name="label">    name of pack  </param>
        /// <param name="meshFile"> model of a pack instance</param>
        /// <param name="xPos, zPos">  approximate position of the pack </param>
        /// <param name="aLeader"> alpha dog can be used for flock center and alignment </param>
        public Pack(Stage theStage, string label, string meshFile, int nDogs, int xPos, int zPos, Object3D theLeader, bool isCollidable = true)
            : base(theStage, label, meshFile)
        {
            this.isCollidable = isCollidable;
            this.random = new Random();
            this.leader = theLeader;

            //Local Variables
            UInt32 spacing = (UInt32)stage.Spacing;
            Int32 x, z;
            float scale;

            //Initial vertex offset of dogs around (xPos, zPos)
            Int32[,] position = { { 0, 0 }, { 7, -4 }, { -5, -2 }, { -7, 4 }, { 5, 2 } };

            for (int i = 0; i < position.GetLength(0); i++)
            {
                //Position the dogs
                x = xPos + position[i, 0];
                z = zPos + position[i, 1];

                //Scale the dogs
                scale = (float)(0.5 + random.NextDouble());

                //Add the pack member to the instance list
                addObject(new Vector3(x * spacing, stage.surfaceHeight(x, z), z * spacing),
                              new Vector3(0, 1, 0),
                              0.0f,
                              new Vector3(scale, scale, scale));
            }
        }
Example #2
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     using (Stage stage = new Stage())
     {
         stage.Run();
     }
 }
Example #3
0
        //Variables---------------------------------------------------------------------------------------------
        //Void
        //Constructor-------------------------------------------------------------------------------------------
        public Wall(Stage theStage, string label, string meshFile, bool isCollidable = true)
            : base(theStage, label, meshFile, isCollidable)
        {
            //Local Variables
            UInt32  spacing = (UInt32)stage.Terrain.Spacing;
            Terrain terrain = stage.Terrain;

            // brick[x,z] vertex positions on terrain
            UInt32[,] brick = { // "just another brick in the wall", Pink Floyd
            {450, 450}, {451, 450}, {452, 450}, {453, 450}, {454, 450}, {455, 450}, {456, 450},  // 7 right
            {457, 443}, {457, 444}, {457, 445}, {457, 446}, {457, 447}, {457, 448}, {457, 449}, {457, 450}, {457, 451},
            {457, 452}, {457, 453}, {457, 454}, {457, 455}, {457, 456}, {457, 457}, {457, 458}, {457, 459}, {457, 460}, // 18 down
            {451, 460}, {451, 459}, {451, 458}, {451, 457},  // 4 up
            {451, 456}, {450, 456}, {449, 456}, {448, 456}, {447, 456}, {446, 456}, {445, 456}, {444, 456}, // 8 left
            {444, 455}, {444, 454}, {444, 453}, {444, 452}, {444, 451}, {444, 450}, {444, 449}, {444, 448}, {444, 447},
            {444, 446}, {444, 445}, {444, 444},  // 12 up
            {444, 444}, {445, 444}, {446, 444}, {447, 444}, {448, 444}, {449, 444}, {450, 444}, {451, 444},  // 8 right
            {451, 444}, {451, 443} // 2 up
            };

            //Add the bricks to the stage
            for (UInt32 i = 0; i < brick.GetLength(0); i++)
            {
                UInt32 xPos = brick[i, 0];
                UInt32 zPos = brick[i, 1];
                addObject(new Vector3(xPos * spacing, terrain.surfaceHeight((int)xPos, (int)zPos), zPos * spacing), Vector3.Up, 0.0f, Vector3.One);
            }
        }
Example #4
0
 public Camera(Stage aScene, CameraEnum cameraType)
 {
     name = "Whole stage";
       scene = aScene;
       cameraCase = cameraType;
       terrainCenter = scene.TerrainSize / 2;
       updateViewMatrix();
 }
Example #5
0
 /// <summary>
 /// Create a path
 /// </summary>
 /// <param name="theStage"> "world's stage" </param>
 /// <param name="apath"> collection of nodes in path</param>
 /// <param name="aPathType"> SINGLE, REVERSE, or LOOP path traversal</param>
 public Path(Stage theStage, List<NavNode> aPath, PathType aPathType)
     : base(theStage)
 {
     node = aPath;
     nextNode = 0;
     pathType = aPathType;
     stage = theStage;
     done = false;
 }
Example #6
0
        //Variables---------------------------------------------------------------------------------------------
        //Void
        //Constructor-------------------------------------------------------------------------------------------
        public EyeCandy_Rocket(Stage theStage, string label, string meshFile, bool isCollidable = true)
            : base(theStage, label, meshFile, isCollidable)
        {
            //Local Variables
            UInt32 spacing = (UInt32)stage.Terrain.Spacing;
            Terrain terrain = stage.Terrain;

            UInt32[,] location = { { 450, 325 } };

            //Add the bricks to the stage
            for (UInt32 i = 0; i < location.GetLength(0); i++)
            {
                UInt32 xPos = location[i, 0];
                UInt32 zPos = location[i, 1];
                addObject(new Vector3(xPos * spacing, terrain.surfaceHeight((int)xPos, (int)zPos), zPos * spacing), Vector3.Up, (float)Math.PI, new Vector3(30, 30, 30));
            }
        }
Example #7
0
        // Constructor
        public Cloud(Stage stage, string label, string meshFile, int nClouds)
            : base(stage, label, meshFile)
        {
            random = new Random();

            //Add nClouds random cloud instances
            for (UInt32 i = 0; i < nClouds; i++)
            {
                UInt32 x = (UInt32)((128 + random.Next(256)) * stage.Spacing);
                UInt32 z = (UInt32)((128 + random.Next(256)) * stage.Spacing);

                addObject(
                    new Vector3(x, stage.surfaceHeight(x, z) + 15000, z),
                    new Vector3(0, 1, 0), 4.0f,
                    new Vector3(15, 4, 15));
            }
        }
Example #8
0
        //Constructor------------------------------------------------------------------------
        public Player(Stage theStage, string label, Vector3 pos, Vector3 orientAxis, float radians, string meshFile, TreasureList tl, bool isCollidable = true)
            : base(theStage, label, pos, orientAxis, radians, meshFile)
        {
            //Camera Name ID's
            first.Name = "First";
            follow.Name = "Follow";
            above.Name = "Above";

            //Set if this object is collidable
            this.IsCollidable = isCollidable;
            if(this.isCollidable)
                stage.Collidable.Add(agentObject);

            this.treasreList = tl;
            this.treasureCount = 0;

            //Set initial orientation of player
            this.rotate = 0;
            this.angle = 0.01f;
            initialOrientation = agentObject.Orientation;
        }
Example #9
0
        public TreasureList(Stage theStage, string label, string meshFile, bool isCollidable = false)
            : base(theStage, label, meshFile)
        {
            this.isCollidable = isCollidable;

            //The following represents a list of treausre locations..
            int[,] treasure = {
                                  {393,400},
                                  {509,493},
                                  {320,460},
                                  {447,453},
                                  {320,493}
                              };
            this.treasuresRemaining = treasure.Length;

            //Create a list of treasures
            this.treasureNode = new TreasureNode[treasure.GetLength(0)];
            int x, z;

            for (int i = 0; i < treasure.GetLength(0); i++)
            {
                //Positions
                x = treasure[i, 0];
                z = treasure[i, 1];

                //Keep a list of these locations
                this.treasureNode[i].x = x;
                this.treasureNode[i].z = z;
                this.treasureNode[i].isTagged = false;

                //Add the treasure
                addObject(new Vector3(x * stage.Spacing, stage.Terrain.surfaceHeight(x, z), z * stage.Spacing),
                          new Vector3(0, 1, 0),
                          0.0f,
                          new Vector3(1, 1, 1));

            }
        }
Example #10
0
        /// <summary>
        /// Create a path from XZ nodes defined in a pathFile.
        /// The file must be accessible from the executable environment.
        /// </summary>
        /// <param name="theStage"> "world's stage" </param>
        /// <param name="aPathType"> SINGLE, REVERSE, or LOOP path traversal</param>
        /// <param name="pathFile"> text file, each line a node of X Z values, separated by a single space </x></param>
        public Path(Stage theStage, PathType aPathType, string pathFile)
            : base(theStage)
        {
            node = new List<NavNode>();
            stage = theStage;
            nextNode = 0;
            pathType = aPathType;
            done = false;
            // read file for WayPoint vertex (x,z) positions
            int spacing = stage.Spacing;
            int x, z;
            string line;
            string[] tokens;
            using (System.IO.StreamReader fileIn = System.IO.File.OpenText(pathFile))
            {

                line = fileIn.ReadLine();
                do
                {
                    tokens = line.Split(new char[] { });  // use default separators
                    x = Int32.Parse(tokens[0]);
                    z = Int32.Parse(tokens[1]);
                    node.Add(new NavNode(new Vector3(x * spacing, stage.Terrain.surfaceHeight(x, z), z * spacing),
                        NavNode.NavNodeEnum.PATH));
                    line = fileIn.ReadLine();
                } while (line != null);
            }
        }
Example #11
0
        //Constructors-----------------------------------------------------------------------------------
        public Model3D(Stage stage, string name, string fileOfModel, bool isCollidable = false)
            : base(stage)
        {
            this.name = name;
            this.stage = stage;
            this.isCollidable = isCollidable;

            instance = new List<Object3D>();
            model = stage.Content.Load<Model>(fileOfModel);

            // compute the translation to the model's bounding sphere
            // center and radius;
            float minX, minY, minZ, maxX, maxY, maxZ;
            minX = minY = minZ = Int32.MaxValue;
            maxX = maxY = maxZ = Int32.MinValue;

            for (int i = 0; i < model.Meshes.Count; i++)
            {
                // See if this mesh extends the bounding sphere.
                BoundingSphere aBoundingSphere = model.Meshes[i].BoundingSphere;
                boundingSphereRadius = aBoundingSphere.Radius;

                // minimum value
                if ((aBoundingSphere.Center.X - aBoundingSphere.Radius) < minX)
                    minX = aBoundingSphere.Center.X - aBoundingSphere.Radius;
                if ((aBoundingSphere.Center.Y - aBoundingSphere.Radius) < minY)
                    minY = aBoundingSphere.Center.Y - aBoundingSphere.Radius;
                if ((aBoundingSphere.Center.Z - aBoundingSphere.Radius) < minZ)
                    minZ = aBoundingSphere.Center.Z - aBoundingSphere.Radius;

                // maximum value
                if ((aBoundingSphere.Center.X + aBoundingSphere.Radius) > maxX)
                    maxX = aBoundingSphere.Center.X + aBoundingSphere.Radius;
                if ((aBoundingSphere.Center.Y + aBoundingSphere.Radius) > maxY)
                    maxY = aBoundingSphere.Center.Y + aBoundingSphere.Radius;
                if ((aBoundingSphere.Center.Z + aBoundingSphere.Radius) > maxZ)
                    maxZ = aBoundingSphere.Center.Z + aBoundingSphere.Radius;
            }

            // get the diameter of model's bounding sphere
            // radius temporarily holds the largest diameter
            if ((maxX - minX) > boundingSphereRadius) boundingSphereRadius = maxX - minX;

            // Since a bounding cylinder is used for collision height values not needed
            // if ((maxY - minY) > boundingSphereRadius) boundingSphereRadius = maxY - minY;
            if ((maxZ - minZ) > boundingSphereRadius) boundingSphereRadius = maxZ - minZ;

            // set boundingSphereRadius
            boundingSphereRadius = boundingSphereRadius * 1.05f / 2.0f;  // set the radius from largest diameter

            // set the center of model's bounding sphere
            boundingSphereCenter = new Vector3(minX + boundingSphereRadius, minY + boundingSphereRadius, minZ + boundingSphereRadius);
        }
Example #12
0
 //Constructor----------------------------------------------------------------------
 /// <summary>
 /// Constructor is a "pass-through" for arguments to Model3D's constructor
 /// </summary>
 /// <param name="theStage"></param>
 /// <param name="label"></param>
 /// <param name="meshFile"></param>
 public MovableModel3D(Stage theStage, string label, string meshFile)
     : base(theStage, label, meshFile)
 {
 }
 public IndexVertexBuffers(Stage theStage, string label)
     : base(theStage)
 {
     stage = theStage;
     name = label;
 }
Example #14
0
        private Int16 step, stepSize; // values for stepping

        #endregion Fields

        #region Constructors

        //Constructors --------------------------------------------------------------------------
        /// <summary>
        /// Object that places and orients itself.
        /// </summary>
        /// <param name="theStage">   the stage containing object </param> 
        /// <param name="aModel">     how the object looks        </param> 
        /// <param name="label">      name of object              </param> 
        /// <param name="position">   position in stage           </param> 
        /// <param name="orientAxis"> axis to orient on           </param> 
        /// <param name="radians">    orientation rotation        </param> 
        public Object3D(Stage stage, Model3D model, string name, Vector3 position,
                        Vector3 orientAxis, float radiansRot, Vector3 scale, 
                        Int16 step = 1, Int16 stepSize = 10, float boundingRadius = 0.0f)
        {
            this.scales   = scale;
            this.stage    = stage;
            this.model    = model;
            this.name     = name;
            this.step     = step;
            this.stepSize = stepSize;

            this.objectBoundingSphereRadius = boundingRadius;

            //Initialize rotating factors
            pitch = yaw = roll = 0.0f;

            //Configure resulting orientation
            orientation  = Matrix.Identity;
            orientation *= Matrix.CreateScale(scales);
            orientation *= Matrix.CreateFromAxisAngle(orientAxis, radiansRot);
            orientation *= Matrix.CreateTranslation(position);

            scaleObjectBoundingSphere();
        }
Example #15
0
 public PathFindingNode(Stage theStage, Int32 x, Int32 z)
 {
     this.nodeColor = Color.Red.ToVector3();
     this.x = x;
     this.z = z;
     this.y = (Int32)theStage.surfaceHeight((float)x, (float)z);
     this.id = string.Format("{0}::{1}", x, z);
     adjacent = new LinkedList<PathFindingNode>();
 }
Example #16
0
        //Constructor------------------------------------------------------------------------------------
        /// <summary>
        /// Make a Terrain from 2 png texture files.  
        /// Must have __XNA4__ capabilities to read from png files.
        /// </summary>
        /// <param name="theStage"></param>
        /// <param name="label"></param>
        /// <param name="heightFile"></param>
        /// <param name="colorFile"></param>
        public Terrain(Stage theStage, string label, string heightFile, string colorFile)
            : base(theStage, label)
        {
            //Local Variables
            UInt32 i = 0;
            UInt32 vertexHeight;
            Vector4   vector4;
            Texture2D heightTexture;
            Texture2D colorTexture;
            Microsoft.Xna.Framework.Color[] heightMap;
            Microsoft.Xna.Framework.Color[] colorMap;

            //Initialization of most base class variables (IndexVertexBuffers)
            constructorInit();

            //Load in height map file and load up height texture
            heightTexture = stage.Content.Load<Texture2D>(heightFile);
            heightMap = new Microsoft.Xna.Framework.Color[width * height];
            heightTexture.GetData<Microsoft.Xna.Framework.Color>(heightMap);

            //Load in color map file and load up color texture
            colorTexture = stage.Content.Load<Texture2D>(colorFile);
            colorMap = new Microsoft.Xna.Framework.Color[width * height];
            colorTexture.GetData<Microsoft.Xna.Framework.Color>(colorMap);

            //Create vertices for the plain
            for (UInt32 z = 0; z < height; z++)
            {
                for (UInt32 x = 0; x < width; x++)
                {
                    //Convert the images RBGA values into a vec4
                    vector4 = heightMap[i].ToVector4();

                    //Scale these value into a height value (Remember, R = G = B = A)
                    vertexHeight = (UInt32)(vector4.X * 255);

                    //To make things a bit more interesting, mulitply the height by a const value
                    vertexHeight *= multiplier;

                    //Save this height for navigation
                    terrainHeight[x, z] = vertexHeight;

                    //Back up the color of the vertex with its coordinance
                    vertex[i] = new VertexPositionColor(new Vector3(x * spacing, vertexHeight, z * spacing),
                                                        new Color(colorMap[i].ToVector4()));

                    i++;
                }
            }

            //Free up the now uneeded maps
            colorMap  = null;
            heightMap = null;

            //Fill in our indices, which make up our triangulated mesh pieces
            makeIndicesSetData();
        }
Example #17
0
 public Camera(Stage aScene, Object3D anAgentObject, CameraEnum cameraType)
 {
     scene = aScene;
       agent = anAgentObject;
       cameraCase = cameraType;
 }
Example #18
0
 /// <summary>
 /// Create a path from array
 /// </summary>
 /// <param name="theStage"> "world's stage" </param>
 /// <param name="apath"> collection of nodes in path</param>
 /// <param name="pathNode"> int[x,z] array of WayPoint positions for path</param>
 /// <param name="aPathType"> SINGLE, REVERSE, or LOOP path traversal</param>
 public Path(Stage theStage, int[,] pathNode, PathType aPathType)
     : base(theStage)
 {
     nextNode = 0;
     pathType = aPathType;
     stage = theStage;
     done = false;
     int spacing = stage.Spacing;
     int x, z;
     // make a simple path, show how to set the type of the NavNode outside of construction.
     node = new List<NavNode>();
     for (int i = 0; i < pathNode.Length / 2; i++)
     {
         x = pathNode[i, 0];
         z = pathNode[i, 1];
         node.Add(new NavNode(new Vector3(x * spacing, stage.Terrain.surfaceHeight(x, z), z * spacing),
            NavNode.NavNodeEnum.WAYPOINT));
     }
 }
Example #19
0
 public jwfPath(Stage theStage, Int32 startX, Int32 startZ, Int32 dist)
     : base(theStage)
 {
     this.stage = theStage;
     setUpNavigationGraph(startX, startZ, dist);
 }
Example #20
0
 public Wall(Stage theStage, string label, string meshFile, int xOffset, int zOffset)
     : base(theStage, label, meshFile)
 {
     initWall(xOffset, zOffset);
 }
Example #21
0
        //Constructor------------------------------------------------------------------------------------
        /// <summary>
        /// Create a NPC. 
        /// AGXNASK distribution has npAgent move following a Path.
        /// </summary>
        /// <param name="theStage"> the world</param>
        /// <param name="label"> name of </param>
        /// <param name="pos"> initial position </param>
        /// <param name="orientAxis"> initial rotation axis</param>
        /// <param name="radians"> initial rotation</param>
        /// <param name="meshFile"> Direct X *.x Model in Contents directory </param>
        public NPAgent(Stage theStage, string label, Vector3 pos, Vector3 orientAxis, float radians, string meshFile, TreasureList tl, bool isCollidable = false)
            : base(theStage, label, pos, orientAxis, radians, meshFile)
        {
            //Set variables
            this.isCollidable = isCollidable;
            this.treasureList = tl;
            this.treasureCount = 0;
            this.treasurePath = false;

            //Change names for on-screen display of current camera
            first.Name = "npFirst";
            follow.Name = "npFollow";
            above.Name = "npAbove";

            // path is built to work on specific terrain, made from int[x,z] array pathNode
            path = new Path(stage, pathNode, Path.PathType.LOOP); // continuous search path
            stage.Components.Add(path);

            //Get the first path goal
            nextGoal = path.NextNode;

            //Orient to face the first goal
            agentObject.turnToFace(nextGoal.Translation);

            //Set snapDistance to be a little larger than step * stepSize
            snapDistance = (UInt32)(1.5 * (agentObject.Step * agentObject.StepSize));
        }
Example #22
0
 public Wall(Stage theStage, string label, string meshFile)
     : base(theStage, label, meshFile)
 {
     initWall(400, 400);  // origin of wall on terrain
 }