Esempio n. 1
0
 public Camera(Stage aScene, CameraEnum cameraType)
 {
     name = "Whole stage";
       scene = aScene;
       cameraCase = cameraType;
       terrainCenter = scene.TerrainSize / 2;
       updateViewMatrix();
 }
Esempio n. 2
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;
 }
Esempio n. 3
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 (int i = 0; i < nClouds; i++) {
     int x = (128 + random.Next(256)) * stage.Spacing;  // 128 .. 384
     int z = (128 + random.Next(256)) * stage.Spacing;
     addObject(
         new Vector3(x , stage.surfaceHeight(x, z)  + 4000, z ),
         new Vector3(0, 1, 0), (random.Next(5)) * 0.01f,
         new Vector3(4 + random.Next(3), random.Next(4) + 1, 3 + random.Next(2)));
         }
 }
Esempio n. 4
0
        public Treasure(Stage theStage, string label, string meshFile, Vector3 pos, Vector3 rotationAxis, float rotation)
            : base(theStage, label, meshFile)
        {
            translation = pos;
            axis = rotationAxis;
            radians = rotation;
            tagged = false;

            isCollidable = false;
            int spacing = stage.Terrain.Spacing;
            Terrain terrain = stage.Terrain;
            addObject(new Vector3(translation.X, 100+terrain.surfaceHeight((int)translation.X, (int)translation.Z), translation.Z),
             axis, radians, new Vector3(100, 100, 100));
        }
Esempio n. 5
0
   /// <summary>
   /// Create an Agent.
   /// All Agents are collidable and have a single instance Object3D named agentObject.
   /// Set StepSize, create first, follow and above cameras.
   /// Set first as agentCamera
   /// <param name="stage"></param>
   /// <param name="label"></param>
   /// <param name="position"></param>
   /// <param name="orientAxis"></param>
   /// <param name="radians"></param>
   /// <param name="meshFile"></param>
   /// </summary>
   public Agent(Stage stage, string label, Vector3 position, Vector3 orientAxis, 
 float radians, string meshFile)
       : base(stage, label, meshFile)
   {
       // create an Object3D for this agent
         agentObject = addObject(position, orientAxis, radians);
         first =  new Camera(stage, agentObject, Camera.CameraEnum.FirstCamera);
         follow = new Camera(stage, agentObject, Camera.CameraEnum.FollowCamera);
         above =  new Camera(stage, agentObject, Camera.CameraEnum.AboveCamera);
         stage.addCamera(first);
         stage.addCamera(follow);
         stage.addCamera(above);
         agentCamera = first;
   }
Esempio n. 6
0
        private int 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 theStage, Model3D aModel, string label, Vector3 position, 
      Vector3 orientAxis, float radians)
        {
            scales = Vector3.One;  // no scaling of model
              stage = theStage;
              model = aModel;
              name = label;
              step = 1;
              stepSize = 10;
              pitch = yaw = roll = 0.0f;
              orientation = Matrix.Identity;
              orientation *= Matrix.CreateFromAxisAngle(orientAxis, radians);
              orientation *= Matrix.CreateTranslation(position);
              scaleObjectBoundingSphere();
        }
Esempio n. 7
0
        public NavGraph(Stage theStage)
        {
            graph = new Dictionary<String, NavNode>();
            stage = theStage;
            open = new List<NavNode>();
            closed = new List<NavNode>();
            path = new List<NavNode>();
            astar = new List<NavNode>();

            //stage = theStage;
            //x = anX;
            //z = aZ;
            //name = string.Format("{0}::{1}", x, z);
            //nodeType = NavGraphNodeType.VERTEX;
            //node = new NavNode(new Vector3(x * spacing, stage.Terrain.surfaceHeight(x, z), z * spacing), NavNode.NavNodeEnum.WAYPOINT);
        }
Esempio n. 8
0
        private int snapDistance = 20; // this should be a function of step and stepSize

        #endregion Fields

        #region Constructors

        /// <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)
            : base(theStage, label, pos, orientAxis, radians, meshFile)
        {
            // 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, make from int[x,z] array pathNode
              path = new Path(stage, pathNode, Path.PathType.LOOP); // continuous search path
              stage.Components.Add(path);
              nextGoal = path.NextNode;  // get first path goal
              agentObject.turnToFace(nextGoal.Translation);  // orient towards the first path goal
            // set snapDistance to be a little larger than step * stepSize
            snapDistance = (int) (1.5 * (agentObject.Step * agentObject.StepSize));
        }
Esempio n. 9
0
      public Player(Stage theStage, string label, Vector3 pos, Vector3 orientAxis, 
 float radians, string meshFile, List<Treasure> t, List<Treasure> m)
          : base(theStage, label, pos, orientAxis, radians, meshFile)
      {
          // change names for on-screen display of current camera
            first.Name =  "First";
            follow.Name = "Follow";
            above.Name =  "Above";
            IsCollidable = true;  // players test collision with Collidable set.
            stage.Collidable.Add(agentObject);  // player's agentObject can be collided with by others.
            rotate = 0;
            angle = 0.01f;
            initialOrientation = agentObject.Orientation;
            treasure = t;
            marked = m;
            treasureCount = 0;
      }
Esempio n. 10
0
 public Model3D(Stage theStage, string label, string fileOfModel)
     : base(theStage)
 {
     name = label;
     stage =theStage;
     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);
     new Vector3(minX + boundingSphereRadius, minY + boundingSphereRadius, minZ + boundingSphereRadius);
     // need to scale boundingSphereRadius for each object instances in Object3D
 }
Esempio n. 11
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) );
     }
 }
Esempio n. 12
0
 /// <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)
     : base(theStage, label, meshFile)
 {
     isCollidable = true;
     random = new Random();
       leader = theLeader;
     int spacing = stage.Spacing;
     // initial vertex offset of dogs around (xPos, zPos)
     int [,] position = { {0, 0}, {7, -4}, {-5, -2}, {-7, 4}, {5, 2} , {3,9}, {12, 0}, {5, -10}};
     for( int i = 0; i < position.GetLength(0); i++) {
     int x = xPos + position[i, 0];
     int z = zPos + position[i, 1];
     float scale = (float)(0.5 + random.NextDouble());
     addObject( new Vector3(x * spacing, stage.surfaceHeight(x, z), z * spacing),
                   new Vector3(0, 1, 0), 0.0f,
                   new Vector3(scale, scale, scale));
     }
 }
Esempio n. 13
0
 public Terrain(Stage theStage, string label, string terrainDataFile)
     : base(theStage, label)
 {
     constructorInit();  // common constructor initialization code, base call sets "stage"
      // read vertex data from "terrain.dat" file
     System.IO.TextReader file = System.IO.File.OpenText(terrainDataFile);
     file.ReadLine(); // skip the first description line x y z r g b
     int i = 0;   // index for vertex[]
     string line;
     string[] token;
     for (int z = 0; z < height; z++)
     for (int x = 0; x < width; x++) {
         line = file.ReadLine();
         token = line.Split(' ');
         terrainHeight[x, z] = int.Parse(token[1]) * multiplier;  // Y
         vertex[i] = new VertexPositionColor(
             new Vector3( int.Parse(token[0]) * spacing, terrainHeight[x,z], int.Parse(token[2]) * spacing), // position
             new Color(int.Parse(token[3]), int.Parse(token[4]), int.Parse(token[5])) );  // material
         i++;
     }
     file.Close();
     makeIndicesSetData();
 }
Esempio n. 14
0
 public IndexVertexBuffers(Stage theStage, string label)
     : base(theStage)
 {
     stage = theStage;
       name = label;
 }
Esempio n. 15
0
 /// <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)
 {
 }
Esempio n. 16
0
 /// <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)
 {
     Texture2D heightTexture, colorTexture;
     Microsoft.Xna.Framework.Color[] heightMap, colorMap;
     constructorInit();  // common constructor initialization code, base call sets "stage"
       heightTexture = stage.Content.Load<Texture2D>(heightFile);
       heightMap =
      new Microsoft.Xna.Framework.Color[width * height];
       heightTexture.GetData<Microsoft.Xna.Framework.Color>(heightMap);
       // create colorMap values from colorTexture
       colorTexture = stage.Content.Load<Texture2D>(colorFile);
       colorMap =
      new Microsoft.Xna.Framework.Color[width * height];
       colorTexture.GetData<Microsoft.Xna.Framework.Color>(colorMap);
       // create  vertices for terrain
       Vector4 vector4;
       int vertexHeight;
       int i = 0;
       for (int z = 0; z < height; z++)
      for (int x = 0; x < width; x++)  {
     vector4 = heightMap[i].ToVector4();       // convert packed Rgba32 values to floats
     vertexHeight = (int) (vector4.X * 255);   // scale vertexHeight 0..255
     vertexHeight *= multiplier;               // multiply height
     terrainHeight[x, z] = vertexHeight;       // save height for navigation
     vertex[i] = new VertexPositionColor(
        new Vector3(x * spacing, vertexHeight, z * spacing),
        new Color(colorMap[i].ToVector4()));
     i++;
     }
       // free up unneeded maps
       colorMap = null;
       heightMap = null;
     makeIndicesSetData();
 }
Esempio n. 17
0
 public Camera(Stage aScene, Object3D anAgentObject, CameraEnum cameraType)
 {
     scene = aScene;
       agent = anAgentObject;
       cameraCase = cameraType;
 }
Esempio n. 18
0
 public Wall(Stage theStage, string label, string meshFile)
     : base(theStage, label, meshFile)
 {
     initWall(450, 460);  // origin of wall on terrain
 }
Esempio n. 19
0
 public Wall(Stage theStage, string label, string meshFile, int xOffset, int zOffset)
     : base(theStage, label, meshFile)
 {
     initWall(xOffset, zOffset);
 }
Esempio n. 20
0
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     using (Stage stage = new Stage()) {
     stage.Run();
       }
 }
Esempio n. 21
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);
      }
 }