Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Using Statements
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Collections;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Audio;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.GamerServices;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- using Microsoft.Xna.Framework.Media;
- #endregion
- namespace _3D_Game
- {
- /// <summary>
- /// This is a game component that implements IUpdateable.
- /// </summary>
- public class ModelManager : DrawableGameComponent
- {
- #region Properties
- List<Folder> myDocumentsfolderModels = new List<Folder>();
- List<Folder> myMusicFolderModels = new List<Folder>();
- List<Folder> myPicturesFolderModels = new List<Folder>();
- BasicModel room;
- Vector3 myDocumentsPosition = new Vector3(-35, 50, 25);
- Vector3 myMusicPosition = new Vector3(-180,50,25);
- Vector3 myPicturesPosition = new Vector3(100,50,25);
- Vector3 myDocumentsfilePosition = new Vector3(-35, 15, 45);
- Vector3 myMusicFilePosition = new Vector3(-180,15,45);
- Vector3 myPicturesFilePosition = new Vector3(100, 15, 45);
- BoundingSphere camSphere = new BoundingSphere();
- Matrix camWorld = new Matrix();
- MouseState prevMouseState;
- SpriteBatch spriteBatch;
- SpriteFont hudFont;
- SpriteFont titleFont;
- List<string> myDocumentsfolders;
- List<string> myMusicFolders;
- List<string> myPicturesFolders;
- List<string> myDocumentsfolderFullPath;
- List<string> myMusicFolderFullPath;
- List<string> myPicturesFolderFullPath;
- List<File> myDocumentsfileModels = new List<File>();
- List<File> myMusicFileModels = new List<File>();
- List<File> myPicturesFileModels = new List<File>();
- int myDocumentsnumOfFiles;
- int myMusicNumOfFiles;
- int myPicturesNumOfFiles;
- List<string> myDocumentsfiles;
- List<string> myMusicFiles;
- List<string> myPicturesFiles;
- String myMusic = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
- String myDocuments = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
- String myPictures = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
- int myDocumnetsUpperLimit = 25;
- int myDocumentsLowerLimit = -35;
- int myMusicUpperLimit = -100;
- int myMusicLowerLimet = -180;
- int myPicturesUpperLimit = 180;
- int myPicturesLowerLimit = 100;
- int myDocumentsfileRowSize, myMusicFileRowSize, myPicturesFileRowSize;
- int myDocumentsfolderRowSise, myMusicFolderRowSize, myPicturesFolderRowSize;
- String myDocumentsPrevFolder;
- String myDocumentsCurrentFolder;
- String myMusicPrevFolder;
- String myMusicCurrentFolder;
- String myPicturesPrevFolder;
- String MyPicturesCurrentFolder;
- String rightClickedFolder;
- String selectedFolder = "My Documents";
- Folder myDocumentsback;
- Folder myMusicBack;
- Folder myPicturesBack;
- BasicModel musicRoom, pictureRoom;
- bool firstime = true;
- #endregion
- #region Constructor
- public ModelManager(Game game)
- : base(game)
- {
- // TODO: Construct any child components here
- }
- #endregion
- #region Initialisation
- /// <summary>
- /// Allows the game component to perform any initialization it needs to before starting
- /// to run. This is where it can query for any required services and load content.
- /// </summary>
- public override void Initialize()
- {
- // TODO: Add your initialization code here
- MyDocumentsAssignFoldersAndFiles(myDocuments);
- MyMusicAssignFoldersAndFiles(myMusic);
- MyPicturesAssignFoldersAndFiles(myPictures);
- myDocumentsCurrentFolder = myDocuments;
- base.Initialize();
- }
- #endregion
- #region Load Content
- /// <summary>
- /// Load content
- /// </summary>
- protected override void LoadContent()
- {
- spriteBatch = new SpriteBatch(GraphicsDevice);
- room = new BasicModel(Game.Content.Load<Model>(@"Models\room2"));
- hudFont = Game.Content.Load<SpriteFont>(@"Fonts\hudFont");
- titleFont = Game.Content.Load<SpriteFont>(@"Fonts\titleFont");
- myDocumentsback = new Folder(Game.Content.Load<Model>(@"Models\folder7"), 0);
- myMusicBack = new Folder(Game.Content.Load<Model>(@"Models\folder7"), 0);
- myPicturesBack = new Folder(Game.Content.Load<Model>(@"Models\folder7"), 0);
- musicRoom = new BasicModel(Game.Content.Load<Model>(@"Models\room2"));
- pictureRoom = new BasicModel(Game.Content.Load<Model>(@"Models\room2"));
- //PositionFileViewer();
- for (int i = 0; i < myDocumentsfolders.Count; i++)
- {
- myDocumentsfolderModels.Add(new Folder(Game.Content.Load<Model>(@"Models\folder7"), i));
- }
- for (int i = 0; i < myDocumentsfiles.Count; i++)
- {
- myDocumentsfileModels.Add(new File(Game.Content.Load<Model>(@"Models\folder7")));
- }
- for (int i = 0; i < myMusicFolders.Count; i++)
- {
- myMusicFolderModels.Add(new Folder(Game.Content.Load<Model>(@"Models\folder7"), i));
- }
- for (int i = 0; i < myMusicFiles.Count; i++)
- {
- myMusicFileModels.Add(new File(Game.Content.Load<Model>(@"Models\folder7")));
- }
- for (int i = 0; i < myPicturesFolders.Count; i++)
- {
- myPicturesFolderModels.Add(new Folder(Game.Content.Load<Model>(@"Models\folder7"), i));
- }
- for (int i = 0; i < myPicturesFiles.Count; i++)
- {
- myPicturesFileModels.Add(new File(Game.Content.Load<Model>(@"Models\folder7")));
- }
- AssignFolderData();
- AssignFileData();
- PositionFolders();
- PositionFiles();
- myDocumentsback.moveFolder(new Vector3(-35, 60, 25));
- myMusicBack.moveFolder(new Vector3(-180, 60, 25));
- myPicturesBack.moveFolder(new Vector3(100, 60, 25));
- musicRoom.MoveModel(new Vector3(-150, 0, 0));
- pictureRoom.MoveModel(new Vector3(150, 0, 0));
- BoundingSphereRenderer.Initialize(GraphicsDevice, 45);
- base.LoadContent();
- }
- #endregion
- #region Update
- /// <summary>
- /// Allows the game component to update itself.
- /// </summary>
- /// <param name="gameTime">Provides a snapshot of timing values.</param>
- public override void Update(GameTime gameTime)
- {
- Ray mouseRay = ((Game1)Game).cursor.CalculateCursorRay(((Game1)Game).camera.projection, ((Game1)Game).camera.view);
- camSphere = ((Game1)Game).camera.sphere;
- camWorld = ((Game1)Game).camera.world;
- // Loop through all models and call Update
- for (int i = 0; i < myDocumentsfolderModels.Count; ++i)
- {
- if (myDocumentsfolderModels[i].CollidesWith(camSphere, camWorld))
- {
- ((Game1)Game).backgrnColour = Color.Red;
- }
- if (myDocumentsfolderModels[i].CheckRayIntersection(mouseRay))
- {
- myDocumentsfolderModels[i].ScaleFolder(2.0f);
- selectedFolder = myDocumentsfolderModels[i].FolderName;
- }
- if (!myDocumentsfolderModels[i].CheckRayIntersection(mouseRay))
- {
- myDocumentsfolderModels[i].ScaleFolder(1.0f);
- }
- if (myDocumentsfolderModels[i].CheckRayIntersection(mouseRay) && Mouse.GetState().LeftButton == ButtonState.Pressed)
- {
- myDocumentsCurrentFolder = myDocumentsfolderModels[i].FolderFullPath;
- ShowNewFolders(myDocumentsCurrentFolder);
- break;
- }
- if (myDocumentsfolderModels[i].IsSelected == true)
- {
- myDocumentsfolderModels[i].ScaleFolder(2.0f);
- }
- if (myDocumentsfolderModels[i].CheckRayIntersection(mouseRay) && Mouse.GetState().RightButton == ButtonState.Pressed)
- {
- prevMouseState = Mouse.GetState();
- rightClickedFolder = myDocumentsfolderModels[i].FolderFullPath;
- ((Game1)Game).hud.Enabled = true;
- ((Game1)Game).hud.Visible = true;
- ((Game1)Game).hud.MyPosition = myDocumentsfolderModels[i].MyPosition;
- ((Game1)Game).camera.Enabled = false;
- }
- if (((Game1)Game).hud.Enabled && Mouse.GetState().LeftButton == ButtonState.Pressed)
- {
- myDocumentsfolderModels[i].CheckRayIntersection(mouseRay);
- }
- myDocumentsfolderModels[i].Update();
- }
- for (int i = 0; i < myMusicFolderModels.Count; ++i)
- {
- if (myMusicFolderModels[i].CollidesWith(camSphere, camWorld))
- {
- ((Game1)Game).backgrnColour = Color.Red;
- }
- if (myMusicFolderModels[i].CheckRayIntersection(mouseRay))
- {
- myMusicFolderModels[i].ScaleFolder(2.0f);
- selectedFolder = myMusicFolderModels[i].FolderName;
- }
- if (!myMusicFolderModels[i].CheckRayIntersection(mouseRay))
- {
- myMusicFolderModels[i].ScaleFolder(1.0f);
- }
- if (myMusicFolderModels[i].CheckRayIntersection(mouseRay) && Mouse.GetState().LeftButton == ButtonState.Pressed)
- {
- myMusicCurrentFolder = myMusicFolderModels[i].FolderFullPath;
- MusicShowNewFolders(myMusicCurrentFolder);
- break;
- }
- if (myMusicFolderModels[i].IsSelected == true)
- {
- myMusicFolderModels[i].ScaleFolder(2.0f);
- }
- if (myMusicFolderModels[i].CheckRayIntersection(mouseRay) && Mouse.GetState().RightButton == ButtonState.Pressed)
- {
- prevMouseState = Mouse.GetState();
- rightClickedFolder = myMusicFolderModels[i].FolderFullPath;
- ((Game1)Game).hud.Enabled = true;
- ((Game1)Game).hud.Visible = true;
- ((Game1)Game).hud.MyPosition = myMusicFolderModels[i].MyPosition;
- ((Game1)Game).camera.Enabled = false;
- }
- if (((Game1)Game).hud.Enabled && Mouse.GetState().LeftButton == ButtonState.Pressed)
- {
- myMusicFolderModels[i].CheckRayIntersection(mouseRay);
- }
- myMusicFolderModels[i].Update();
- }
- for (int i = 0; i < myPicturesFolderModels.Count; ++i)
- {
- if (myPicturesFolderModels[i].CollidesWith(camSphere, camWorld))
- {
- ((Game1)Game).backgrnColour = Color.Red;
- }
- if (myPicturesFolderModels[i].CheckRayIntersection(mouseRay))
- {
- myPicturesFolderModels[i].ScaleFolder(2.0f);
- selectedFolder = myPicturesFolderModels[i].FolderName;
- }
- if (!myPicturesFolderModels[i].CheckRayIntersection(mouseRay))
- {
- myPicturesFolderModels[i].ScaleFolder(1.0f);
- }
- if (myPicturesFolderModels[i].CheckRayIntersection(mouseRay) && Mouse.GetState().LeftButton == ButtonState.Pressed)
- {
- MyPicturesCurrentFolder = myPicturesFolderModels[i].FolderFullPath;
- PicturesShowNewFolders(MyPicturesCurrentFolder);
- break;
- }
- if (myPicturesFolderModels[i].IsSelected == true)
- {
- myPicturesFolderModels[i].ScaleFolder(2.0f);
- }
- if (myPicturesFolderModels[i].CheckRayIntersection(mouseRay) && Mouse.GetState().RightButton == ButtonState.Pressed)
- {
- prevMouseState = Mouse.GetState();
- rightClickedFolder = myPicturesFolderModels[i].FolderFullPath;
- ((Game1)Game).hud.Enabled = true;
- ((Game1)Game).hud.Visible = true;
- ((Game1)Game).hud.MyPosition = myPicturesFolderModels[i].MyPosition;
- ((Game1)Game).camera.Enabled = false;
- }
- if (((Game1)Game).hud.Enabled && Mouse.GetState().LeftButton == ButtonState.Pressed)
- {
- myPicturesFolderModels[i].CheckRayIntersection(mouseRay);
- }
- myPicturesFileModels[i].Update();
- }
- if (myDocumentsback.CheckRayIntersection(mouseRay) && Mouse.GetState().LeftButton == ButtonState.Pressed)
- {
- myDocumentsPrevFolder = FileOperations.UpDirectory(myDocumentsCurrentFolder);
- myDocumentsCurrentFolder = myDocumentsPrevFolder;
- ShowNewFolders(myDocumentsPrevFolder);
- }
- if (myMusicBack.CheckRayIntersection(mouseRay) && Mouse.GetState().LeftButton == ButtonState.Pressed)
- {
- myMusicPrevFolder = FileOperations.UpDirectory(myMusicCurrentFolder);
- myMusicCurrentFolder = myMusicPrevFolder;
- MusicShowNewFolders(myMusicPrevFolder);
- }
- if (myPicturesBack.CheckRayIntersection(mouseRay) && Mouse.GetState().LeftButton == ButtonState.Pressed)
- {
- myPicturesPrevFolder = FileOperations.UpDirectory(MyPicturesCurrentFolder);
- MyPicturesCurrentFolder = myPicturesPrevFolder;
- PicturesShowNewFolders(myPicturesPrevFolder);
- }
- if (Keyboard.GetState().IsKeyDown(Keys.R))
- {
- ((Game1)Game).backgrnColour = Color.CornflowerBlue;
- }
- if (Keyboard.GetState().IsKeyDown(Keys.Right))
- {
- moveMyDocumentsFoldersRight();
- }
- if (Keyboard.GetState().IsKeyDown(Keys.Left))
- {
- moveMyDocumentFoldersLeft();
- }
- if (Keyboard.GetState().IsKeyDown(Keys.Z))
- {
- MoveMyDocumentsFileLeft();
- }
- if (Keyboard.GetState().IsKeyDown(Keys.X))
- {
- MoveMyDocumentsFileRight();
- }
- if (((Game1)Game).hud.Enabled && Mouse.GetState().LeftButton == ButtonState.Pressed)
- {
- ((Game1)Game).hud.Enabled = false;
- ((Game1)Game).hud.Visible = false;
- ((Game1)Game).camera.Enabled = true;
- Mouse.SetPosition(prevMouseState.X, prevMouseState.Y);
- }
- base.Update(gameTime);
- }
- #endregion
- #region Draw
- /// <summary>
- /// Allows the game component to draw itself
- /// </summary>
- /// <param name="gameTime">Provides a snapshot of timing values.</param>
- public override void Draw(GameTime gameTime)
- {
- // Draw room
- room.Draw(((Game1)Game).camera);
- myDocumentsback.Draw(((Game1)Game).camera);
- myMusicBack.Draw(((Game1)Game).camera);
- myPicturesBack.Draw(((Game1)Game).camera);
- musicRoom.Draw(((Game1)Game).camera);
- pictureRoom.Draw(((Game1)Game).camera);
- // Loop through and draw each model
- foreach (Folder bm in myDocumentsfolderModels)
- {
- if ((bm.MyPosition.X >= myDocumentsLowerLimit) && (bm.MyPosition.X <= myDocumnetsUpperLimit))
- {
- bm.Draw(((Game1)Game).camera);
- DrawModelNames(bm);
- if (selectedFolder != null)
- {
- DrawTitle(selectedFolder);
- }
- }
- }
- foreach (File f in myDocumentsfileModels)
- {
- if ((f.MyPosition.X >= myDocumentsLowerLimit) && (f.MyPosition.X <= myDocumnetsUpperLimit))
- {
- f.Draw(((Game1)Game).camera);
- DrawFileNames(f);
- }
- }
- foreach (Folder mf in myMusicFolderModels)
- {
- if ((mf.MyPosition.X >= myMusicLowerLimet) && (mf.MyPosition.X <= myMusicUpperLimit))
- {
- mf.Draw(((Game1)Game).camera);
- DrawModelNames(mf);
- if (selectedFolder != null)
- {
- DrawTitle(selectedFolder);
- }
- }
- }
- foreach (Folder pf in myPicturesFolderModels)
- {
- if ((pf.MyPosition.X >= myPicturesLowerLimit) && (pf.MyPosition.X <= myPicturesUpperLimit))
- {
- pf.Draw(((Game1)Game).camera);
- DrawModelNames(pf);
- if (selectedFolder != null)
- {
- DrawTitle(selectedFolder);
- }
- }
- }
- foreach (File mf in myMusicFileModels)
- {
- if ((mf.MyPosition.X >= myMusicLowerLimet) && (mf.MyPosition.X <= myMusicUpperLimit))
- {
- mf.Draw(((Game1)Game).camera);
- DrawFileNames(mf);
- }
- }
- foreach (File pf in myPicturesFileModels)
- {
- if ((pf.MyPosition.X >= myPicturesLowerLimit) && (pf.MyPosition.X <= myPicturesUpperLimit))
- {
- pf.Draw(((Game1)Game).camera);
- DrawFileNames(pf);
- }
- }
- base.Draw(gameTime);
- }
- #endregion
- #region Draw Folder and File Names
- private void DrawTitle(string title)
- {
- if (title != null)
- {
- spriteBatch.Begin();
- spriteBatch.DrawString(titleFont, title, new Vector2(GraphicsDevice.DisplayMode.Width / 2 + 1, 51), Color.Black, 0.0f, titleFont.MeasureString(title), 1.0f, SpriteEffects.None, 0.0f);
- spriteBatch.DrawString(titleFont, title, new Vector2(GraphicsDevice.DisplayMode.Width / 2, 50), Color.White, 0.0f, titleFont.MeasureString(title), 1.0f, SpriteEffects.None, 0.0f);
- spriteBatch.End();
- }
- }
- private void DrawModelNames(Folder bm)
- {
- Ray mouseRay = ((Game1)Game).cursor.CalculateCursorRay(((Game1)Game).camera.projection, ((Game1)Game).camera.view);
- if (bm.CheckRayIntersection(mouseRay))
- {
- // begin on the spritebatch, because we're going to be drawing some text.
- spriteBatch.Begin();
- Vector3 screenSpace = GraphicsDevice.Viewport.Project(
- Vector3.Zero, ((Game1)Game).camera.projection, ((Game1)Game).camera.view, bm.GetWorld());
- Vector2 textPosition =
- new Vector2(screenSpace.X, screenSpace.Y - 60);
- Vector2 stringCenter =
- hudFont.MeasureString(bm.FolderName + " " + bm.NumOfFiles) / 2;
- Vector2 shadowOffset = new Vector2(1, 1);
- if (screenSpace.Z > 0)
- {
- spriteBatch.DrawString(hudFont, bm.FolderName + " " + bm.NumOfFiles,
- textPosition + shadowOffset, Color.Black, 0.0f,
- stringCenter, 1.0f, SpriteEffects.None, 0.0f);
- spriteBatch.DrawString(hudFont, bm.FolderName + " " + bm.NumOfFiles,
- textPosition, Color.White, 0.0f,
- stringCenter, 1.0f, SpriteEffects.None, 0.0f);
- }
- spriteBatch.End();
- }
- }
- private void DrawFileNames(File f)
- {
- Ray mouseRay = ((Game1)Game).cursor.CalculateCursorRay(((Game1)Game).camera.projection, ((Game1)Game).camera.view);
- if (f.CheckRayIntersection(mouseRay))
- {
- Vector2 stringCenter = Vector2.Zero;
- String text;
- spriteBatch.Begin();
- Vector3 screenSpace = GraphicsDevice.Viewport.Project(
- Vector3.Zero, ((Game1)Game).camera.projection, ((Game1)Game).camera.view, f.GetWorld());
- Vector2 textPosition =
- new Vector2(screenSpace.X, screenSpace.Y - 60);
- if (f.FileName != null)
- {
- stringCenter =
- hudFont.MeasureString(f.FileName) / 2;
- text = f.FileName;
- }
- else
- {
- stringCenter = hudFont.MeasureString("null") / 2;
- text = "null";
- }
- Vector2 shadowOffset = new Vector2(1, 1);
- spriteBatch.DrawString(hudFont, text,
- textPosition + shadowOffset, Color.Black, 0.0f,
- stringCenter, 1.0f, SpriteEffects.None, 0.0f);
- spriteBatch.DrawString(hudFont, text,
- textPosition, Color.White, 0.0f,
- stringCenter, 1.0f, SpriteEffects.None, 0.0f);
- spriteBatch.End();
- }
- }
- #endregion
- #region Folder & File Data Assigning
- private void AssignFolderData()
- {
- for (int i = 0; i < myDocumentsfolders.Count; i++)
- {
- myDocumentsfolderModels[i].FolderName = myDocumentsfolders[i];
- myDocumentsfolderModels[i].FolderFullPath = myDocumentsfolderFullPath[i];
- }
- for (int i = 0; i < myMusicFolders.Count; i++)
- {
- myMusicFolderModels[i].FolderName = myMusicFolders[i];
- myMusicFolderModels[i].FolderFullPath = myMusicFolderFullPath[i];
- }
- for (int i = 0; i < myPicturesFolders.Count; i++)
- {
- myPicturesFolderModels[i].FolderName = myPicturesFolders[i];
- myPicturesFolderModels[i].FolderFullPath = myPicturesFolderFullPath[i];
- }
- }
- private void AssignFileData()
- {
- for (int i = 0; i < myDocumentsfiles.Count; i++)
- {
- myDocumentsfileModels[i].FileName = myDocumentsfiles[i];
- }
- for (int i = 0; i < myMusicFiles.Count; i++)
- {
- myMusicFileModels[i].FileName = myMusicFiles[i];
- }
- for (int i = 0; i < myPicturesFiles.Count; i++)
- {
- myPicturesFileModels[i].FileName = myPicturesFiles[i];
- }
- }
- private void MyDocumentsAssignFoldersAndFiles(string folder)
- {
- // Assign Files and Folders for My Documents folder
- myDocumentsfolders = FileOperations.showFolders(folder);
- myDocumentsfolderFullPath = FileOperations.showFolderFullPath(folder);
- myDocumentsnumOfFiles = FileOperations.NoOfFiles(folder);
- myDocumentsfiles = FileOperations.showFiles(folder);
- }
- private void MyMusicAssignFoldersAndFiles(string folder)
- {
- // Assign Files and Folders for My Music Folder
- myMusicFolders = FileOperations.showFolders(folder);
- myMusicFolderFullPath = FileOperations.showFolderFullPath(folder);
- myMusicNumOfFiles = FileOperations.NoOfFiles(folder);
- myMusicFiles = FileOperations.showFiles(folder);
- }
- private void MyPicturesAssignFoldersAndFiles(string folder)
- {
- // Assign Files and Folders for My Pictures Folder
- myPicturesFolders = FileOperations.showFolders(folder);
- myPicturesFolderFullPath = FileOperations.showFolderFullPath(folder);
- myPicturesNumOfFiles = FileOperations.NoOfFiles(folder);
- myPicturesFiles = FileOperations.showFiles(folder);
- }
- #endregion
- #region Folder & File Movement
- private void MoveMyDocumentsFileRight()
- {
- if (myDocumentsfileModels[0].MyPosition.X < myDocumnetsUpperLimit)
- {
- for (int i = 0; i < myDocumentsfileModels.Count; i++)
- {
- Vector3 newPosition = myDocumentsfileModels[i].MyPosition;
- newPosition.X += 1;
- myDocumentsfileModels[i].MoveFile(newPosition);
- }
- }
- }
- private void MoveMyMusicFileRight()
- {
- if (myMusicFileModels[0].MyPosition.X < myMusicUpperLimit)
- {
- for (int i = 0; i < myMusicFileModels.Count; i++)
- {
- Vector3 newPosition = myMusicFileModels[i].MyPosition;
- newPosition.X += 1;
- myMusicFileModels[i].MoveFile(newPosition);
- }
- }
- }
- private void MoveMyPicturesFileRight()
- {
- if (myPicturesFileModels[0].MyPosition.X < myPicturesUpperLimit)
- {
- for (int i = 0; i < myPicturesFileModels.Count; i++)
- {
- Vector3 newPosition = myPicturesFileModels[i].MyPosition;
- newPosition.X += 1;
- myPicturesFileModels[i].MoveFile(newPosition);
- }
- }
- }
- private void MoveMyDocumentsFileLeft()
- {
- if (myDocumentsfileModels[myDocumentsfileRowSize - 1].MyPosition.X > myDocumentsLowerLimit)
- {
- for (int i = 0; i < myDocumentsfileModels.Count; i++)
- {
- Vector3 newPosition = myDocumentsfileModels[i].MyPosition;
- newPosition.X -= 1;
- myDocumentsfileModels[i].MoveFile(newPosition);
- }
- }
- }
- private void MoveMyMusicFileLeft()
- {
- if (myMusicFileModels[myMusicFileRowSize - 1].MyPosition.X > myMusicLowerLimet)
- {
- for (int i = 0; i < myMusicFileModels.Count; i++)
- {
- Vector3 newPosition = myMusicFileModels[i].MyPosition;
- newPosition.X -= 1;
- myMusicFileModels[i].MoveFile(newPosition);
- }
- }
- }
- private void MoveMyPicturesFileLeft()
- {
- if (myPicturesFileModels[myPicturesFileRowSize - 1].MyPosition.X > myPicturesLowerLimit)
- {
- for (int i = 0; i < myPicturesFileModels.Count; i++)
- {
- Vector3 newPosition = myPicturesFileModels[i].MyPosition;
- newPosition.X -= 1;
- myPicturesFileModels[i].MoveFile(newPosition);
- }
- }
- }
- private void moveMyDocumentsFoldersRight()
- {
- if (myDocumentsfolderModels[0].MyPosition.X < myDocumnetsUpperLimit)
- {
- for (int i = 0; i < myDocumentsfolders.Count; i++)
- {
- Vector3 newPosition = myDocumentsfolderModels[i].MyPosition;
- newPosition.X += 1;
- myDocumentsfolderModels[i].moveFolder(newPosition);
- }
- }
- }
- private void moveMyMusicFoldersRight()
- {
- if (myMusicFolderModels[0].MyPosition.X < myMusicUpperLimit)
- {
- for (int i = 0; i < myMusicFolderModels.Count; i++)
- {
- Vector3 newPosition = myMusicFolderModels[i].MyPosition;
- newPosition.X += 1;
- myMusicFolderModels[i].moveFolder(newPosition);
- }
- }
- }
- private void moveMyPicturesFoldersRight()
- {
- if (myPicturesFolderModels[0].MyPosition.X < myPicturesUpperLimit)
- {
- for (int i = 0; i < myPicturesFolderModels.Count; i++)
- {
- Vector3 newPosition = myPicturesFolderModels[i].MyPosition;
- newPosition.X += 1;
- myPicturesFolderModels[i].moveFolder(newPosition);
- }
- }
- }
- private void moveMyDocumentFoldersLeft()
- {
- if (myDocumentsfolderModels[myDocumentsfolderRowSise - 1].MyPosition.X > myDocumentsLowerLimit)
- {
- for (int i = 0; i < myDocumentsfolders.Count; i++)
- {
- Vector3 newPosition = myDocumentsfolderModels[i].MyPosition;
- newPosition.X -= 1;
- myDocumentsfolderModels[i].moveFolder(newPosition);
- }
- }
- }
- private void moveMyMusicFoldersLeft()
- {
- if (myMusicFolderModels[myMusicFolderRowSize - 1].MyPosition.X > myMusicLowerLimet)
- {
- for (int i = 0; i < myMusicFolderModels.Count; i++)
- {
- Vector3 newPosition = myMusicFolderModels[i].MyPosition;
- newPosition.X -= 1;
- myMusicFolderModels[i].moveFolder(newPosition);
- }
- }
- }
- private void moveMyPicturesFoldersLeft()
- {
- if (myPicturesFolderModels[myPicturesFolderRowSize - 1].MyPosition.X > myPicturesLowerLimit)
- {
- for (int i = 0; i < myPicturesFolderModels.Count; i++)
- {
- Vector3 newPosition = myPicturesFolderModels[i].MyPosition;
- newPosition.X -= 1;
- myPicturesFolderModels[i].moveFolder(newPosition);
- }
- }
- }
- #endregion
- #region Folder and File Positioning
- private void PositionFolders()
- {
- int myDocumentsModulus = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(myDocumentsfolders.Count) / Convert.ToDecimal(6.0)));
- int myMusicModulus = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(myMusicFolders.Count) / Convert.ToDecimal(6.0)));
- int myPicturesModulus = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(myPicturesFolders.Count) / Convert.ToDecimal(6.0)));
- myDocumentsfolderRowSise = myDocumentsModulus;
- myMusicFolderRowSize = myMusicModulus;
- myPicturesFolderRowSize = myPicturesModulus;
- for (int i = 0; i < myDocumentsfolders.Count; i++)
- {
- myDocumentsfolderModels[i].moveFolder(myDocumentsPosition);
- myDocumentsPosition.X += 5;
- if (((i + 1) % myDocumentsModulus == 0) && (i != 0))
- {
- myDocumentsPosition.Y -= 5;
- myDocumentsPosition.X -= myDocumentsModulus * 5;
- }
- }
- for (int i = 0; i < myMusicFolders.Count; i++)
- {
- myMusicFolderModels[i].moveFolder(myMusicPosition);
- myMusicPosition.X += 5;
- if (((i + 1) % myMusicModulus == 0) && (i != 0))
- {
- myMusicPosition.Y -= 5;
- myMusicPosition.X -= myMusicModulus * 5;
- }
- }
- for (int i = 0; i < myPicturesFolders.Count; i++)
- {
- myPicturesFolderModels[i].moveFolder(myPicturesPosition);
- myPicturesPosition.X += 5;
- if (((i + 1) % myPicturesModulus == 0) && (i != 0))
- {
- myPicturesPosition.Y -= 5;
- myPicturesPosition.X -= myPicturesModulus * 5;
- }
- }
- }
- private void PositionFiles()
- {
- int myDocumentsmodulus = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(myDocumentsfileModels.Count) / Convert.ToDecimal(3)));
- int myMusicmodulus = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(myMusicFileModels.Count) / Convert.ToDecimal(3)));
- int myPicturesmodulus = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(myPicturesFileModels.Count) / Convert.ToDecimal(3)));
- myDocumentsfileRowSize = myDocumentsmodulus;
- myMusicFileRowSize = myMusicmodulus;
- myPicturesFileRowSize = myPicturesmodulus;
- for (int i = 0; i < myDocumentsfiles.Count; i++)
- {
- myDocumentsfileModels[i].MoveFile(myDocumentsfilePosition);
- myDocumentsfileModels[i].RotateFile(MathHelper.ToRadians(-45.0f), myDocumentsfilePosition);
- myDocumentsfilePosition.X += 5;
- if (((i + 1) % myDocumentsmodulus == 0) && (i != 0))
- {
- myDocumentsfilePosition.Y -= 5;
- myDocumentsfilePosition.X -= myDocumentsmodulus * 5;
- myDocumentsfilePosition.Z += 5;
- }
- }
- for (int i = 0; i < myMusicFiles.Count; i++)
- {
- myMusicFileModels[i].MoveFile(myMusicFilePosition);
- myMusicFileModels[i].RotateFile(MathHelper.ToRadians(-45.0f), myMusicFilePosition);
- myMusicFilePosition.X += 5;
- if (((i + 1) % myMusicmodulus == 0) && (i != 0))
- {
- myMusicFilePosition.Y -= 5;
- myMusicFilePosition.X -= myMusicmodulus * 5;
- myMusicFilePosition.Z += 5;
- }
- }
- for (int i = 0; i < myPicturesFiles.Count; i++)
- {
- myPicturesFileModels[i].MoveFile(myPicturesFilePosition);
- myPicturesFileModels[i].RotateFile(MathHelper.ToRadians(-45.0f), myPicturesFilePosition);
- myPicturesFilePosition.X += 5;
- if (((i + 1) % myPicturesmodulus == 0) && (i != 0))
- {
- myPicturesFilePosition.Y -= 5;
- myPicturesFilePosition.X -= myPicturesmodulus * 5;
- myPicturesFilePosition.Z += 5;
- }
- }
- }
- #endregion
- #region Show New Folders & Files & Reset Folder Positions
- private void ShowNewFolders(string folder)
- {
- myDocumentsfolderModels.Clear();
- myDocumentsfileModels.Clear();
- MyDocumentsAssignFoldersAndFiles(folder);
- ResetPositions();
- this.LoadContent();
- }
- private void MusicShowNewFolders(string folder)
- {
- myMusicFolderModels.Clear();
- myMusicFileModels.Clear();
- MyMusicAssignFoldersAndFiles(folder);
- ResetPositions();
- this.LoadContent();
- }
- private void PicturesShowNewFolders(string folder)
- {
- myPicturesFolderModels.Clear();
- myPicturesFileModels.Clear();
- MyPicturesAssignFoldersAndFiles(folder);
- ResetPositions();
- this.LoadContent();
- }
- private void ResetPositions()
- {
- myDocumentsPosition = new Vector3(-35, 50, 25);
- myDocumentsfilePosition = new Vector3(-35, 15, 45);
- myMusicPosition = new Vector3(-180, 50, 25);
- myMusicFilePosition = new Vector3(-180, 15, 45);
- myPicturesPosition = new Vector3(100, 50, 25);
- myPicturesFilePosition = new Vector3(100, 15, 45);
- }
- #endregion
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- namespace _3D_Game
- {
- class Folder : BasicModel
- {
- private string folderName;
- private string folderFullPath;
- private int noOfFiles;
- private bool isSelected;
- private Vector3 myPosition = Vector3.Zero;
- private float myScale = 1.0f;
- private Matrix myWorld = Matrix.Identity;
- private int number;
- private List<BoundingBox> box = new List<BoundingBox>();
- private BasicEffect boxEffect;
- private GraphicsDevice graphics;
- public Vector3 MyPosition
- {
- get { return myPosition; }
- set { myPosition = value; }
- }
- public Matrix MyWorld
- {
- get { return myWorld; }
- set { myWorld = value; }
- }
- public float MyScale
- {
- get { return myScale; }
- set { myScale = value; }
- }
- public bool IsSelected
- {
- get { return isSelected; }
- set { isSelected = value; }
- }
- public int NumOfFiles
- {
- get { return noOfFiles; }
- }
- public String FolderName
- {
- get { return folderName; }
- set
- {
- folderName = value;
- }
- }
- public string FolderFullPath
- {
- get { return folderFullPath; }
- set
- {
- folderFullPath = value;
- NoOfFiles(value);
- }
- }
- public Folder(Model m, int folderNumber, GraphicsDevice g, Vector3 pos)
- : base(m,g)
- {
- graphics = g;
- number = folderNumber;
- myPosition = pos;
- boxEffect = new BasicEffect(g);
- }
- public override void Update()
- {
- base.Update();
- }
- public override Matrix GetWorld()
- {
- return myWorld;
- }
- public void moveFolder(Vector3 pos)
- {
- myPosition = pos;
- myWorld = Matrix.CreateScale(myScale) * Matrix.CreateTranslation(pos);
- }
- private void NoOfFiles(string folder)
- {
- noOfFiles = FileOperations.NoOfFiles(folderFullPath);
- }
- public void ScaleFolder(float scale)
- {
- myScale = scale;
- myWorld = Matrix.CreateScale(scale) * Matrix.CreateTranslation(myPosition);
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- namespace _3D_Game
- {
- class BasicModel
- {
- public Model model { get; protected set; }
- protected Matrix world = Matrix.Identity;
- public List<BoundingBox> boundingBoxes = new List<BoundingBox>();
- short[] bBoxIndices =
- {
- 0, 1, 1, 2, 2, 3, 3, 0, // Front edges
- 4, 5, 5, 6, 6, 7, 7, 4, // Back edges
- 0, 4, 1, 5, 2, 6, 3, 7 // Side edges connecting front and back
- };
- BasicEffect boxEffect;
- GraphicsDevice graphics;
- public BasicModel(Model m, GraphicsDevice g)
- {
- model = m;
- graphics = g;
- MeshModel();
- boxEffect = new BasicEffect(g);
- }
- public virtual void Update()
- {
- }
- public virtual void Draw(Camera camera)
- {
- Matrix[] transforms = new Matrix[model.Bones.Count];
- model.CopyAbsoluteBoneTransformsTo(transforms);
- foreach (ModelMesh mesh in model.Meshes)
- {
- foreach (BasicEffect be in mesh.Effects)
- {
- be.EnableDefaultLighting();
- be.Projection = camera.projection;
- be.View = camera.view;
- be.World = mesh.ParentBone.Transform * GetWorld();
- }
- mesh.Draw();
- // ... and then transform the BoundingSphere using that matrix.
- BoundingSphere sphere = TransformBoundingSphere(mesh.BoundingSphere, world);
- foreach (BoundingBox box in boundingBoxes)
- {
- Vector3[] corners = box.GetCorners();
- VertexPositionColor[] primitiveList = new VertexPositionColor[corners.Length];
- // Assign the 8 box vertices
- for (int i = 0; i < corners.Length; i++)
- {
- primitiveList[i] = new VertexPositionColor(corners[i], Color.White);
- }
- /* Set your own effect parameters here */
- boxEffect.World = GetWorld();
- boxEffect.View = camera.view;
- boxEffect.Projection = camera.projection;
- boxEffect.TextureEnabled = false;
- // Draw the box with a LineList
- foreach (EffectPass pass in boxEffect.CurrentTechnique.Passes)
- {
- pass.Apply();
- graphics.DrawUserIndexedPrimitives(PrimitiveType.LineList, primitiveList, 0, 8, bBoxIndices, 0, 12);
- }
- }
- // now draw the sphere with our renderer
- BoundingSphereRenderer.Draw(sphere, camera.view, camera.projection);
- }
- }
- public void RotateFile(float rotation, Vector3 position)
- {
- world = Matrix.CreateRotationX(rotation) * Matrix.CreateTranslation(position);
- }
- public virtual Matrix GetWorld()
- {
- return world;
- }
- //public bool CollidesWith(BoundingBox otherbox, Matrix otherWorld)
- //{
- // foreach (ModelMesh myModelMeshes in model.Meshes)
- // {
- // if (myModelMeshes.BoundingSphere.Transform(
- // GetWorld()).Intersects(
- // otherbox.Transform(otherWorld)))
- // {
- // return true;
- // }
- // }
- // return false;
- //}
- public bool CheckRayIntersection(Ray ray)
- {
- foreach (BoundingBox bb in boundingBoxes)
- {
- if (bb.Intersects(ray) != null)
- {
- return true;
- }
- }
- return false;
- }
- /// <summary>
- /// This helper function takes a BoundingSphere and a transform matrix, and
- /// returns a transformed version of that BoundingSphere.
- /// </summary>
- /// <param name="sphere">the BoundingSphere to transform</param>
- /// <param name="world">how to transform the BoundingSphere.</param>
- /// <returns>the transformed BoundingSphere/</returns>
- private static BoundingSphere TransformBoundingSphere(BoundingSphere sphere, Matrix transform)
- {
- BoundingSphere transformedSphere;
- // the transform can contain different scales on the x, y, and z components.
- // this has the effect of stretching and squishing our bounding sphere along
- // different axes. Obviously, this is no good: a bounding sphere has to be a
- // SPHERE. so, the transformed sphere's radius must be the maximum of the
- // scaled x, y, and z radii.
- // to calculate how the transform matrix will affect the x, y, and z
- // components of the sphere, we'll create a vector3 with x y and z equal
- // to the sphere's radius...
- Vector3 scale3 = new Vector3(sphere.Radius, sphere.Radius, sphere.Radius);
- // then transform that vector using the transform matrix. we use
- // TransformNormal because we don't want to take translation into account.
- scale3 = Vector3.TransformNormal(scale3, transform);
- // scale3 contains the x, y, and z radii of a squished and stretched sphere.
- // we'll set the finished sphere's radius to the maximum of the x y and z
- // radii, creating a sphere that is large enough to contain the original
- // squished sphere.
- transformedSphere.Radius = Math.Max(scale3.X, Math.Max(scale3.Y, scale3.Z));
- // transforming the center of the sphere is much easier. we can just use
- // Vector3.Transform to transform the center vector. notice that we're using
- // Transform instead of TransformNormal because in this case we DO want to
- // take translation into account.
- transformedSphere.Center = Vector3.Transform(sphere.Center, transform);
- return transformedSphere;
- }
- protected virtual void MeshModel()
- {
- Matrix[] transforms = new Matrix[model.Bones.Count];
- model.CopyAbsoluteBoneTransformsTo(transforms);
- foreach (ModelMesh mesh in model.Meshes)
- {
- Matrix meshTransform = transforms[mesh.ParentBone.Index];
- boundingBoxes.Add(BuildBoundingBox(mesh, meshTransform));
- }
- }
- private BoundingBox BuildBoundingBox(ModelMesh mesh, Matrix meshTransform)
- {
- // Create initial variables to hold min and max xyz values for the mesh
- Vector3 meshMax = new Vector3(float.MinValue);
- Vector3 meshMin = new Vector3(float.MaxValue);
- foreach (ModelMeshPart part in mesh.MeshParts)
- {
- // The stride is how big, in bytes, one vertex is in the vertex buffer
- // We have to use this as we do not know the make up of the vertex
- int stride = part.VertexBuffer.VertexDeclaration.VertexStride;
- VertexPositionNormalTexture[] vertexData = new VertexPositionNormalTexture[part.NumVertices];
- part.VertexBuffer.GetData(part.VertexOffset * stride, vertexData, 0, part.NumVertices, stride);
- // Find minimum and maximum xyz values for this mesh part
- Vector3 vertPosition = new Vector3();
- for (int i = 0; i < vertexData.Length; i++)
- {
- vertPosition = vertexData[i].Position;
- // update our values from this vertex
- meshMin = Vector3.Min(meshMin, vertPosition);
- meshMax = Vector3.Max(meshMax, vertPosition);
- }
- }
- // transform by mesh bone matrix
- meshMin = Vector3.Transform(meshMin, meshTransform);
- meshMax = Vector3.Transform(meshMax, meshTransform);
- // Create the bounding box
- BoundingBox box = new BoundingBox(meshMin, meshMax);
- return box;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement