コード例 #1
0
ファイル: Agent.cs プロジェクト: Jesus-MP/Comp565P1
   /// <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;
   }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Project1Game" /> class.
        /// </summary>
        public Project1Game()
        {
            // Creates a graphics manager. This is mandatory.
            graphicsDeviceManager = new GraphicsDeviceManager(this);

            // Setup the relative directory to the executable directory
            // for loading contents with the ContentManager
            Content.RootDirectory = "Content";

            // Create the camera
            camera = new Camera();

            // Create the keyboard and mouse manager
            keyboardManager = new KeyboardManager(this);
            mouseManager = new MouseManager(this);
        }
コード例 #3
0
ファイル: Stage.cs プロジェクト: Jesus-MP/Comp565P1
 /// <summary>
 /// Set GraphicDevice display and rendering BasicEffect effect.  
 /// Create SpriteBatch, font, and font positions.
 /// Creates the traceViewport to display information and the sceneViewport
 /// to render the environment.
 /// Create and add all DrawableGameComponents and Cameras.
 /// First, add all required contest:  Inspector, Cameras, Terrain, Agents
 /// Second, add all optional (scene specific) content
 /// </summary>
 protected override void LoadContent()
 {
     display = graphics.GraphicsDevice;
       effect = new BasicEffect(display);
       // Set up Inspector display
       spriteBatch = new SpriteBatch(display);      // Create a new SpriteBatch
       inspectorFont = Content.Load<SpriteFont> ("Consolas");    // Windows XNA && MonoGames
       // viewports
       defaultViewport = GraphicsDevice.Viewport;
       inspectorViewport = defaultViewport;
       sceneViewport = defaultViewport;
       inspectorViewport.Height = InfoPaneSize * inspectorFont.LineSpacing;
       inspectorProjection = Matrix.CreatePerspectiveFieldOfView((float) Math.PI/4.0f,
      inspectorViewport.Width/inspectorViewport.Height, 1.0f, 200.0f);
       sceneViewport.Height = defaultViewport.Height - inspectorViewport.Height;
       sceneViewport.Y = inspectorViewport.Height;
       sceneProjection = Matrix.CreatePerspectiveFieldOfView((float) Math.PI/4.0f,
      sceneViewport.Width /sceneViewport.Height, 1.0f, 1000.0f);
       // create Inspector display
       Texture2D inspectorBackground = Content.Load<Texture2D>("inspectorBackground");
       inspector = new Inspector(display, inspectorViewport, inspectorFont, Color.Black, inspectorBackground);
       // create information display strings
       // help strings
       inspector.setInfo(0, "AGMGSKv7 -- Academic Graphics MonoGames/XNA Starter Kit for CSUN Comp 565 assignments.");
       inspector.setInfo(1, "Press keyboard for input (not case sensitive 'H' || 'h')");
       inspector.setInfo(2, "Inspector toggles:  'H' help or info   'M'  matrix or info   'I'  displays next info pane.");
       inspector.setInfo(3, "Arrow keys move the player in, out, left, or right.  'R' resets player to initial orientation.");
       inspector.setInfo(4, "Stage toggles:  'B' bounding spheres, 'C' || 'X' cameras, 'F' fog, 'T' updates, 'Y' yon");
       // initialize empty info strings
       for (int i = 5; i < 20; i++) inspector.setInfo(i, "  ");
       // set blending for bounding sphere drawing
       blending = new BlendState();
       blending.ColorSourceBlend = Blend.SourceAlpha;
       blending.ColorDestinationBlend = Blend.InverseSourceAlpha;
       blending.ColorBlendFunction = BlendFunction.Add;
       notBlending = new BlendState();
       notBlending = display.BlendState;
       // Create and add stage components
       // You must have a TopDownCamera, BoundingSphere3D, WayPoint3D, Terrain, and Agents (player, npAgent) in your stage!
       // Place objects at a position, provide rotation axis and rotation radians.
       // All location vectors are specified relative to the center of the stage.
       // Create a top-down "Whole stage" camera view, make it first camera in collection.
       topDownCamera = new Camera(this, Camera.CameraEnum.TopDownCamera);
       camera.Add(topDownCamera);
     // Set initial camera and projection matrix
     setCamera(0);  // select the first camera
       boundingSphere3D = Content.Load<Model>("boundingSphereV3");
       wayPoint3D = Content.Load<Model>("100x50x100Marker");				// model for navigation node display
       // Create required entities:
       collidable = new List<Object3D>();  // collection of objects to test for collisions
     terrain = new Terrain(this, "terrain", "heightTexture", "colorTexture");
       Components.Add(terrain);
       // Load Agent mesh objects, meshes do not have textures
       player = new Player(this, "Chaser",
      new Vector3(510 * spacing, terrain.surfaceHeight(510, 507), 507 * spacing),
      new Vector3(0, 1, 0), 0.78f, "redAvatarV6");  // face looking diagonally across stage
       player.IsCollidable = true; // test collisions for player
       Components.Add(player);
       npAgent = new NPAgent(this, "Evader",
      new Vector3(490 * spacing, terrain.surfaceHeight(490, 450), 450 * spacing),
      new Vector3(0, 1, 0), 0.0f, "magentaAvatarV6");  // facing +Z
     npAgent.IsCollidable = false;  // npAgent does not test for collisions
       Components.Add(npAgent);
     // create file output stream for trace()
     fout = new StreamWriter("trace.txt", false);
     Trace = string.Format("{0} trace output from AGMGSKv7", DateTime.Today.ToString("MMMM dd, yyyy"));
     //  ------ The wall and pack are required for Comp 565 projects, but not AGMGSK   ---------
     // create walls for navigation algorithms
     Wall wall = new Wall(this, "wall", "100x100x100Brick");
     Components.Add(wall);
     // create a pack for "flocking" algorithms
     // create a Pack of 6 dogs centered at (450, 500) that is leaderless
     Pack pack = new Pack(this, "dog", "dogV6", 6, 450, 430, null);
     Components.Add(pack);
       // ----------- OPTIONAL CONTENT HERE -----------------------
       // Load content for your project here
       // create a temple
       Model3D m3d = new Model3D(this, "temple", "templeV3");
       m3d.IsCollidable = true;  // must be set before addObject(...) and Model3D doesn't set it
       m3d.addObject(new Vector3(340 * spacing, terrain.surfaceHeight(340, 340), 340 * spacing),
      new Vector3(0, 1, 0), 0.79f); // , new Vector3(1, 4, 1));
       Components.Add(m3d);
       Model3D treasure = new Model3D(this, "treasure", "treasure2");
       treasure.IsCollidable = true;  // must be set before addObject(...) and Model3D doesn't set it
       treasure.addObject(new Vector3(67050,100,67950),
      new Vector3(0, 1, 0), 0.0f, new Vector3(10,10,10)); // , new Vector3(1, 4, 1));
       Components.Add(treasure);
     // create 20 clouds
     Cloud cloud = new Cloud(this, "cloud", "cloudV3", 20);
     Components.Add(cloud);
     Trace = string.Format("Scene created with {0} collidable objects.", Collidable.Count);
 }
コード例 #4
0
ファイル: Stage.cs プロジェクト: Jesus-MP/Comp565P1
 /// <summary>
 /// Changing camera view for Agents will always set YonFlag false
 /// and provide a clipped view.
 /// 'x' selects the previous camera
 /// 'c' selects the next camera
 /// </summary>
 public void setCamera(int direction)
 {
     cameraIndex = (cameraIndex + direction);
       if (cameraIndex == camera.Count) cameraIndex = 0;
     if (cameraIndex < 0) cameraIndex = camera.Count -1;
       currentCamera = camera[cameraIndex];
       // set the appropriate projection matrix
       YonFlag = false;
       setProjection(farYon);
 }
コード例 #5
0
ファイル: Stage.cs プロジェクト: Jesus-MP/Comp565P1
 public void addCamera(Camera aCamera)
 {
     camera.Add(aCamera);
       cameraIndex++;
 }
コード例 #6
0
ファイル: Project1Game.cs プロジェクト: Nantangitan/GI-PJ1
        protected override void LoadContent()
        {
            //Load game content
            model = new Landscape(this, this.scale);
            water = new Water(this);
            lightsource = new Sun(this);
            this.camera = new Camera(this);

            base.LoadContent();
        }
コード例 #7
0
ファイル: Project1Game.cs プロジェクト: KaiminHuang/Graphics
        protected override void Initialize()
        {
            Window.Title = "Project 1";
            camera = new Camera(this);

            base.Initialize();
        }
コード例 #8
0
 // Check the boundries of the landscape and move back the camera if it was out in any direction.
 private void checkBoundries(Vector3 oldPosition, Camera camera)
 {
     if (XoutOfBounds(camera.position.X / scale))
     {
         camera.position.X = oldPosition.X;
     }
     if (ZoutOfBounds(camera.position.Z / scale))
     {
         camera.position.Z = oldPosition.Z;
     }
     if (heightAtPoint(camera.position.X / scale, camera.position.Z / scale) * scale > camera.position.Y - camera.height)
     {
         camera.position.Y = heightAtPoint(camera.position.X / scale, camera.position.Z / scale) * scale + camera.height;
     }
 }
コード例 #9
0
        public override void Update(GameTime gameTime, Camera camera)
        {
            var time = (float)gameTime.TotalGameTime.TotalSeconds;
            var elapsedTime = (float)gameTime.ElapsedGameTime.Milliseconds;

            // Update camera with collisions processing
            if (collisions && (oldPosition != null))
            {
                checkBoundries(oldPosition, camera);
                camera.UpdateViewMatrix();
            }

            // Change view matrix based on camera
            basicEffect.View = camera.viewMatrix;
            oldPosition = camera.position;

            // Update perspective projection matrix
            basicEffect.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)game.GraphicsDevice.BackBuffer.Width / game.GraphicsDevice.BackBuffer.Height, 0.1f, 1000.0f);

            // Update Lighting
            Vector3 sunOrientation = new Vector3((float)Math.Sin(time * sunSpeed), -Math.Abs((float)Math.Cos(time * sunSpeed)), (float)Math.Sin(time * sunSpeed));

            // Calculate the position of the sun based on this direction.
            basicEffect.DirectionalLight0.Direction = sunOrientation;
        }
コード例 #10
0
        public override void Update(GameTime gameTime, Camera camera)
        {
            float time = (float)gameTime.TotalGameTime.TotalSeconds;
            float timechange = (float)gameTime.ElapsedGameTime.TotalSeconds;

            // Update the position of the sun based on time (should match light source in landscape.cs)
            pos = new Vector3((float)Math.Sin(time * orbitSpeed)* xScale, -Math.Abs((float)Math.Cos(time * orbitSpeed))*height, (float)Math.Sin(time * orbitSpeed) *zScale);

            // Move the world matrix based on this position
            basicEffect.World = Matrix.Translation(-pos);

            // View based on camera position
            basicEffect.View = camera.viewMatrix;
        }
コード例 #11
0
 public abstract void Update(GameTime gametime, Camera camera);
コード例 #12
0
        protected override void LoadContent()
        {
            model = new Landscape(this, 1, 1, 1, 1, 11);

            // Camera object containing all Camera specific controls and info
            int camX = 50;
            int camZ = 50;
            Vector3 pos = new Vector3(camX, model.heightMap[camX][camX] + 50, camZ);
            Vector3 target = pos + new Vector3(1, 0, 1);
            this.camera = new Camera(pos, target, Vector3.UnitY, this);

            // Create an input layout from the vertices

            base.LoadContent();
        }