public MaterialsView(BohemianArtifact bbshelf, Vector3 position, Vector3 size)
        {
            bookshelf = bbshelf;
            bookshelf.Library.SelectedArtifactChanged += new ArtifactLibrary.SelectedArtifactHandler(library_SelectedArtifactChanged);
            this.position = position;
            this.size = size;

            titleText = new SelectableText(XNA.Font, "Materials", new Vector3(0.4f, 0, 0), bookshelf.GlobalTextColor, Color.White);
            titleText.InverseScale(0.8f, size.X, size.Y);

            // the border circle that encases the centre and separates the tiers
            borderCircle = new SelectableBlob(circleCenter, (float)Math.PI, BORDER_RADIUS * 0.01f, BORDER_RADIUS, 0, Color.Black, Color.Black, Color.Black, null);

            // create the steam paths
            steamPaths = new SteamPath[numSteam];
            steamSpeed = 5;
            Color steamColor = new Color(0.95f, 0.95f, 0.95f);
            float steamWidth = 0.03f;
            float steamFade = 0.025f;
            // start from the center and work outwards
            steamPaths[0] = new SteamPath(new Vector2(0.5f, circleCenter.Y), new Vector2(0.58f, 0.0f), -0.015f, steamWidth, steamFade, steamColor, steamColor, Color.White);
            steamPaths[1] = new SteamPath(new Vector2(0.6f, circleCenter.Y), new Vector2(0.75f, 0.025f), -0.03f, steamWidth, steamFade, steamColor, steamColor, Color.White);
            steamPaths[2] = new SteamPath(new Vector2(0.4f, circleCenter.Y), new Vector2(0.3f, 0.025f), 0.04f, steamWidth, steamFade, steamColor, steamColor, Color.White);
            steamPaths[3] = new SteamPath(new Vector2(0.3f, circleCenter.Y), new Vector2(0.1f, 0.1f), 0.07f, steamWidth, steamFade, steamColor, steamColor, Color.White);
            steamPaths[4] = new SteamPath(new Vector2(0.7f, circleCenter.Y), new Vector2(0.95f, 0.1f), -0.06f, steamWidth, steamFade, steamColor, steamColor, Color.White);
            steamPaths[5] = new SteamPath(new Vector2(0.8f, circleCenter.Y), new Vector2(1.0f, 0.35f), -0.05f, steamWidth, steamFade, steamColor, steamColor, Color.White);
            steamPaths[6] = new SteamPath(new Vector2(0.2f, circleCenter.Y), new Vector2(0.0f, 0.3f), 0.05f, steamWidth, steamFade, steamColor, steamColor, Color.White);

            animationTimer = new Timer(0.4f);
            animationTimer.FinishEvent += new TimerFinished(AnimationTimerFinished);

            //materialTexts = new Dictionary<string, SelectableText>();
            //LoadMaterialTexts();
            //materialTextures = new Dictionary<string, Texture2D>();
            //LoadMaterialTextures();
            materialColors = new Dictionary<Material, Color>();
            LoadMaterialColors();

            // a list of materials that are selected
            materialConstraints = new List<Material>();

            artifactList = new List<ArtifactContainer>();
            CreateArtifactList();
            UpdateArtifactsFromConstraints();

            RepositionArtifacts();

            // create the list of materials
            materialList = new List<MaterialContainer>();
            CreateMaterialBlobs();
            RepositionBlobs();

            animationTimer.Start();
        }
 private MaterialContainer FindMaterialContainerFromBlob(SelectableBlob blob, out int tier)
 {
     tier = 0;
     foreach (ArrayList list in materialTiers)
     {
         int index;
         if ((index = list.IndexOf(blob)) != -1) // change the arraylist into a hashtable to make the list searchable by the SelectableBlobs
         {
             return (MaterialContainer)list[index];
         }
         tier++;
     }
     tier = -1;
     return null;
 }
 private MaterialContainer FindMaterialContainerFromBlob(SelectableBlob blob)
 {
     foreach (MaterialContainer container in materialList)
     {
         if (container.Blob == blob)
         {
             return container;
         }
     }
     return null;
 }
 public SteamPath(Vector2 start, Vector2 end, float curveDistance, float circleRadius, float edgeThickness, Color color, Color insideEdgeColor, Color outsideEdgeColor)
 {
     Padding = 1.1f;
     Blob = new SelectableBlob(start, end, curveDistance, circleRadius, edgeThickness, color, insideEdgeColor, outsideEdgeColor, ref Angle);
     Length = Blob.MiddleRadius * Blob.SpanAngle; // 2*pi*r * span/(2*pi) = r * span
     MaxArtifacts = (int)(Length / (ARTIFACT_CIRCLE_RADIUS * Padding)); // 10% padding
     Artifacts = new List<ArtifactContainer>();
     Visible = false;
 }
Example #5
0
        protected override void LoadContent()
        {
            string filename = System.Windows.Forms.Application.ExecutablePath;
            string path = System.IO.Path.GetDirectoryName(filename) + "\\Resources\\";

            // setup the render target for picking objects
            PresentationParameters presentation = GraphicsDevice.PresentationParameters;
            colorPickerTarget = new RenderTarget2D(GraphicsDevice, presentation.BackBufferWidth, presentation.BackBufferHeight, false, presentation.BackBufferFormat, presentation.DepthStencilFormat);
            colorPickerData = new Color[presentation.BackBufferWidth * presentation.BackBufferHeight];

            RasterizerState rasterizerState = new RasterizerState();
            rasterizerState.CullMode = CullMode.None;
            rasterizerState.MultiSampleAntiAlias = true;
            XNA.GraphicsDevice.RasterizerState = rasterizerState;
            BlendState bs = BlendState.NonPremultiplied;
            //BlendState bs1 = BlendState.Additive;
            blendState = new BlendState();
            blendState.AlphaBlendFunction = BlendFunction.Add;
            blendState.ColorBlendFunction = BlendFunction.Add;
            blendState.AlphaDestinationBlend = Blend.InverseSourceAlpha;
            blendState.AlphaSourceBlend = Blend.SourceAlpha;
            blendState.ColorDestinationBlend = Blend.InverseSourceAlpha;
            blendState.ColorSourceBlend = Blend.SourceAlpha;
            blendState = BlendState.AlphaBlend;

            // this creates an origin at screen coordinates 0, 0 and makes the Y axis increase as you move down the screen
            Matrix world = Matrix.CreateTranslation(-presentation.BackBufferWidth / 2, -presentation.BackBufferHeight / 2, 0) * Matrix.CreateScale(1, -1, 1);
            Matrix view = Matrix.CreateLookAt(new Vector3(0, 0, 30), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
            //projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 480f, 0.01f, 100f);//graphics.GraphicsDevice.DrawPrimitives(PrimitiveType.LineList, 0, 1);
            Matrix projection = Matrix.CreateOrthographic(Program.WindowSize.Width, Program.WindowSize.Height, 0.01f, 100.0f);

            // initialize the global effect with the world, view, and projection matricies and several drawing flags
            XNA.Effect.World = world;
            XNA.Effect.View = view;
            XNA.Effect.Projection = projection;
            XNA.VertexColor = true;
            XNA.Texturing = false;
            XNA.ApplyEffect();

            // this creates two lines that form a crosshair to show where the user is touching. this crosshair should be scaled to the size of the touchpoint
            touchCrosshair = new VertexPositionColorTexture[4];
            touchCrosshair[0] = new VertexPositionColorTexture(new Vector3(-2, 0, 0), Color.Red, Vector2.Zero);
            touchCrosshair[1] = new VertexPositionColorTexture(new Vector3(2, 0, 0), Color.Green, Vector2.Zero);
            touchCrosshair[2] = new VertexPositionColorTexture(new Vector3(0, -2, 0), Color.Blue, Vector2.Zero);
            touchCrosshair[3] = new VertexPositionColorTexture(new Vector3(0, 2, 0), Color.Yellow, Vector2.Zero);

            // initialize the graphics device for all selectable objects
            SelectableObject.SetGraphicsDevice(GraphicsDevice);
            // initialize the graphics device for SelectableText elements
            SelectableText.Initialize();
            // and load our fonts
            spriteFont = Content.Load<SpriteFont>("Arial");
            XNA.Font = spriteFont;

            globalTextColor = new Color(0.7f, 0.7f, 0.7f, 1);

            // create the selectable object manager which will issue colors to all objects that need hit testing
            selectableObjects = new SelectableObjectManager();

            // load the book library
            //library = new ArtifactLibrary("small_sample.xml");
            library = new ArtifactLibrary("large_sample_sorted_colors.xml");
            Console.WriteLine("loaded library");

            // create the visualization objects
            // we are using the screen width for the x and y calculation, so the max y value is 9/16 (0.5625f)
            float viewPadding = 0.025f;

            float languageSize = 0.04f;
            float languageLeft = 0.002f;
            float languageTop = 0.002f;

            float materialSize = 0.3f;
            float materialLeft = viewPadding;
            float materialTop = viewPadding;

            float colorSize = materialSize;
            float colorLeft = materialLeft + materialSize + viewPadding;
            float colorTop = viewPadding;

            float keywordSize = materialSize;
            float keywordLeft = colorLeft + materialSize + viewPadding;
            float keywordTop = viewPadding;
            float infoSize = materialSize;
            float infoLeft = viewPadding;
            float infoTop = materialTop + materialSize + viewPadding;
            float timelineSize = 0.6f; // timeline is only 0.3 * size in height (e.g. 0.15)
            float timelineLeft = infoLeft + infoSize + viewPadding;
            float timelineTop = keywordTop + keywordSize + viewPadding;

            float detailsWidth = 0.3f;
            float detailsHeight = 0.2f;
            float detailsLeft = viewPadding;
            float detailsTop = keywordTop + keywordSize + viewPadding;

            //float timelineTop = 1 - timelineSize * 0.3f - viewPadding;
            languageView = new LanguageView(this, new Vector3(languageLeft * presentation.BackBufferWidth, languageTop * presentation.BackBufferWidth, 0), new Vector3(languageSize * presentation.BackBufferWidth, languageSize * presentation.BackBufferWidth, 1));
            materialView = new MaterialsView(this, new Vector3(materialLeft * presentation.BackBufferWidth, materialTop * presentation.BackBufferWidth, 0), new Vector3(materialSize * presentation.BackBufferWidth, materialSize * presentation.BackBufferWidth, 1));
            colorView = new ColorView(this, new Vector3(colorLeft * presentation.BackBufferWidth, colorTop * presentation.BackBufferWidth, 0), new Vector3(colorSize * presentation.BackBufferWidth, colorSize * presentation.BackBufferWidth, 1));
            keywordView = new KeywordView(this, new Vector3(keywordLeft * presentation.BackBufferWidth, keywordTop * presentation.BackBufferWidth, 0), new Vector3(keywordSize * presentation.BackBufferWidth, keywordSize * presentation.BackBufferWidth, 1));
            timelineView = new TimelineView(this, new Vector3(timelineLeft * presentation.BackBufferWidth, timelineTop * presentation.BackBufferWidth, 0), new Vector3(timelineSize * presentation.BackBufferWidth, timelineSize * presentation.BackBufferWidth, 1));
            detailsView = new DetailsView(this, new Vector3(detailsLeft * presentation.BackBufferWidth, detailsTop * presentation.BackBufferWidth, 0), new Vector3(detailsWidth * presentation.BackBufferWidth, detailsHeight * presentation.BackBufferWidth, 1));
            //timelineView = new TimelineView(this, new Vector3(400, 400, 0), new Vector3(1500, 1500, 1));

            // select a random artifact
            int numArtifacts = library.Artifacts.Count;
            int artifactIndex = random.Next(numArtifacts);
            artifactIndex = 0;
            library.SelectArtifact(library.Artifacts[artifactIndex]);

            FileStream file = new FileStream("texture\\material\\metal_2.jpg", FileMode.Open);
            Texture2D texture = Texture2D.FromStream(GraphicsDevice, file);
            file.Close();
            blobTest1 = new SelectableBlob(new Vector2(100, 1000), new Vector2(300, 1200), -10, 20, 10, Color.LightGray, Color.LightGray, Color.White, ref blob1Angle);
            //blobTest2 = new SelectableBlob(new Vector2(1000, 500), 80, Color.White, texture);
            blobTest2 = new SelectableBlob(new Vector2(1000, 500), 0*(float)Math.PI / 4, 0, 0, 10, Color.Red, Color.Blue, Color.Green, texture);
            blobTest2.CircleRadius = 40;
            blobTest2.MiddleRadius = 0;
            timer = new Timer(1);
            selectableObjects.AddObject(blobTest2);

            Color c1 = Color.Navy;
            //c1.A = 127;
            Color c2 = new Color(0.0f, 1.0f, 0.0f, 1.0f);
            //c2.A = 127;
            rectTest1 = new SelectableQuad(new Vector3(100, 100, -10), new Vector3(400, 100, -10), new Vector3(400, 800, -10), new Vector3(100, 800, -10), c1);
            rectTest2 = new SelectableQuad(new Vector3(200, 200, 0), new Vector3(600, 200, 0), new Vector3(600, 600, 0), new Vector3(200, 600, 0), c2);
            rectTest2.Points[0].Color = Color.Transparent;
            rectTest2.Points[3].Color.A = 0;
            /* test the Selectable objects
            lineTest = new SelectableLine(new Vector3(50, 50, 0), new Vector3(2000, 1000, 0), Color.Red, 20);
            rectTest1 = new SelectableQuad(new Vector3(100, 100, 0), new Vector3(400, 100, 0), new Vector3(400, 800, 0), new Vector3(100, 800, 0), Color.Navy);
            rectTest2 = new SelectableQuad(new Vector3(700, 100, 0), new Vector3(1000, 100, 0), new Vector3(1000, 800, 0), new Vector3(700, 800, 0), Color.Green);
            textTest = new SelectableText(kootenayFont, "Kootenay", new Vector3(980, 780, 0), Color.Red, Color.Orange);

            //textTest.SetQuadColor(new Color(1, 0.7f, 0, 0.1f));
            //textTest.Rotation = 1;
            //textTest.Recompute();

            selectableObjects.AddObject(lineTest);
            selectableObjects.AddObject(rectTest1);
            selectableObjects.AddObject(rectTest2);
            selectableObjects.AddObject(textTest);
            //*/

            /* this is to test rendering triangles and lines with user defined primary objects
            verts = new VertexPositionColor[5];
            verts[0] = new VertexPositionColor(new Vector3(0, 0, 0), Color.Red);
            verts[1] = new VertexPositionColor(new Vector3(2000, 0, 0), Color.Green);
            verts[2] = new VertexPositionColor(new Vector3(1000, 2000, 0), Color.Blue);

            verts[3] = new VertexPositionColor(new Vector3(0, 0, 0), Color.Yellow);
            verts[4] = new VertexPositionColor(new Vector3(500, 100, 0), Color.Yellow);

            // this is to test loading of the screen with a grid of many many vertical and horizontal lines
            int pixelsPerLine = 2;
            hLines = new VertexPositionColor[2 * GraphicsDevice.DisplayMode.Width / pixelsPerLine];
            vLines = new VertexPositionColor[2 * GraphicsDevice.DisplayMode.Height / pixelsPerLine];
            for (int i = 0; i < 2 * GraphicsDevice.DisplayMode.Width / pixelsPerLine; i += 2)
            {
                hLines[i] = new VertexPositionColor(new Vector3(i * pixelsPerLine / 2, 0, 0), Color.White);
                hLines[i + 1] = new VertexPositionColor(new Vector3(i * pixelsPerLine / 2, GraphicsDevice.DisplayMode.Height, 0), Color.Gray);
            }
            for (int i = 0; i < 2 * GraphicsDevice.DisplayMode.Height / pixelsPerLine; i += 2)
            {
                vLines[i] = new VertexPositionColor(new Vector3(0, i * pixelsPerLine / 2, 0), Color.White);
                vLines[i + 1] = new VertexPositionColor(new Vector3(GraphicsDevice.DisplayMode.Width, i * pixelsPerLine / 2, 0), Color.Gray);
            }
            //*/

            // test drawing text to the screen, including a background color behind the text (eventually for hit testing)
            //spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
            //Vector2 textSize = spriteFont.MeasureString("Testing");
            //spriteTexture = new Texture2D(GraphicsDevice, (int)textSize.X, (int)textSize.Y);
            //Color[] textureColor = new Color[(int)textSize.X * (int)textSize.Y];
            //for (int i = 0; i < textureColor.Length; i++)
            //{
            //    textureColor[i] = Color.Salmon;
            //    textureColor[i].A = 200;
            //}
            //spriteTexture.SetData<Color>(textureColor);

            // test the backbuffer renderer
            /*
            GraphicsDevice.SetRenderTarget(colorPickerTarget);
            Draw(new GameTime());
            GraphicsDevice.SetRenderTarget(null);
            FileStream pngFile = new FileStream("pickerTarget.png", FileMode.Create);
            colorPickerTarget.SaveAsPng(pngFile, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
            //*/
        }