Exemplo n.º 1
0
        private void InitializeRectangles()
        {
            float spacing = 100.0f;
            //float sign = 1.0f;
            int verticalVariation = 35;

            gxtRandom rng = new gxtRandom();

            gxtISceneNode node;
            gxtRectangle rect = new gxtRectangle(65, 35);
            
            for (int i = 0; i < NUM_RECTANGLES; i++)
            {
                //gxtIDrawable drawable = new gxtDrawable(Color.Blue);
                //drawable.Entity = rect;

                float x = (float)(spacing * i);
                float y = rng.Next(-verticalVariation, verticalVariation);
                float rot = (float)rng.NextFloat() * gxtMath.TWO_PI;

                node = new gxtSceneNode();
                node.Position = new Vector2(x, y);
                node.Rotation = rot;
                
                //node.ColorOverlay = Color.Blue;
                //node.AttachDrawable(drawable);
                sceneGraph.AddNode(node);
                gxtAABB aabb = node.GetAABB();
                nodes.Add(node);
                drawableCollider.AddObject(node, ref aabb);
                //gxtRectangle rect = new gxtRectangle(new Vector2(x, y), new Vector2(65, 35), Color.Blue, 0.5f);
                //rect.Rotation = rot;
                //drawables.Add(rect);
                //drawManager.Add(rect);
                //gxtAABB rectAABB = rect.GetAABB();
                //drawableCollider.AddObject(rect, ref rectAABB);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Note: consider making a struct that packages all these settings, or one or two structs
        /// At this rate, the number of variables for this function is growing to the point that it 
        /// deteroriates readability
        /// </summary>
        /// <param name="scene"></param>
        /// <param name="consoleHeight"></param>
        /// <param name="initEnabled"></param>
        /// <param name="verbosity"></param>
        /// <param name="useGlobalVerbosity"></param>
        /// <param name="useTimeStamps"></param>
        /// <param name="consoleFont"></param>
        /// <param name="initOpen"></param>
        /// <param name="consolePrefix"></param>
        /// <param name="consoleTextRenderDepth"></param>
        /// <param name="consoleBackgroundRenderDepth"></param>
        /// <param name="logBufferSize"></param>
        public void Initialize(gxtSceneGraph scene, float consoleHeight, bool initEnabled = true, gxtVerbosityLevel verbosity = gxtVerbosityLevel.INFORMATIONAL, bool useGlobalVerbosity = true, bool useTimeStamps = false, SpriteFont consoleFont = null, 
            bool initOpen = true, string consolePrefix = "console: ", float consoleTextRenderDepth = 0.0f, float consoleBackgroundRenderDepth = 1.0f, int logBufferSize = 6)
        {
            gxtDebug.Assert(logBufferSize >= 0);
            gxtDebug.Assert(gxtDisplayManager.SingletonIsInitialized);

            this.enabled = initEnabled;
            this.useGlobalVerbosity = useGlobalVerbosity;
            this.verbosityLevel = verbosity;
            this.useTimeStamps = useTimeStamps;
            this.isOpen = initOpen;
            this.text = string.Empty;

            // all these colors and depths should be taken as parameters
            this.consoleSpriteFont = consoleFont;
            this.informationalMaterial = new gxtMaterial(isOpen, Color.White, consoleTextRenderDepth);
            this.successMaterial = new gxtMaterial(isOpen, Color.Green, consoleTextRenderDepth);
            this.warningMaterial = new gxtMaterial(isOpen, Color.Yellow, consoleTextRenderDepth);
            this.criticalMaterial = new gxtMaterial(isOpen, Color.Red, consoleTextRenderDepth);
            this.inputMaterial = new gxtMaterial(isOpen, Color.Black, consoleTextRenderDepth);
            this.backgroundMaterial = new gxtMaterial(isOpen, new Color(255, 255, 255, 65), consoleBackgroundRenderDepth);

            this.resolutionWidth = gxtDisplayManager.Singleton.ResolutionWidth;
            this.resolutionHeight = gxtDisplayManager.Singleton.ResolutionHeight;
            this.consoleWidth = resolutionWidth;
            this.consoleHeight = gxtMath.Clamp(consoleHeight, 0.0f, resolutionHeight);
            gxtDisplayManager.Singleton.resolutionChanged += OnResolutionChange;
            // these should be taken as parameters
            this.horizontalPadding = 15.0f;
            this.verticalPadding = 0.0f;
            this.verticalTextSpacing = 5.0f;

            // background rectangle and container node
            backgroundRectangle = new gxtRectangle(consoleWidth, consoleHeight, backgroundMaterial);
            consoleNode = new gxtSceneNode();
            consoleNode.Position = new Vector2(0.0f, (-resolutionHeight * 0.5f) + (consoleHeight * 0.5f));
            consoleNode.AttachDrawable(backgroundRectangle);

            // textnode
            this.consolePrefix = consolePrefix;
            consoleTextField = new gxtTextField(consoleFont, consolePrefix + "_", inputMaterial);
            consoleTextNode = new gxtSceneNode();
            consoleTextNode.AttachDrawable(consoleTextField);

            consoleNode.AddChild(consoleTextNode);

            this.logBufferSize = logBufferSize;
            this.logWriteIndex = 0;

            logBufferNodes = new gxtSceneNode[logBufferSize];
            logBufferEntries = new gxtTextField[logBufferSize];

            // consider using a fixed size queue instead
            gxtISceneNode topAnchor = new gxtSceneNode();
            topAnchor.Position = new Vector2((consoleWidth * 0.5f) - horizontalPadding, (-consoleHeight * 0.5f) + verticalPadding);
            logBufferNodes[0] = topAnchor;
            logBufferEntries[0] = new gxtTextField(consoleFont);
            logBufferEntries[0].Material = new gxtMaterial();
            logBufferNodes[0].AttachDrawable(logBufferEntries[0]);

            gxtISceneNode current = topAnchor;
            for (int i = 1; i < logBufferSize; ++i)
            {
                gxtISceneNode node = new gxtSceneNode();
                logBufferNodes[i] = node;
                current.AddChild(node);
                node.Position = new Vector2(0.0f, verticalTextSpacing);
                current = node;

                gxtTextField tf = new gxtTextField(consoleFont);
                logBufferEntries[i] = tf;
                tf.Material = new gxtMaterial();
                current.AttachDrawable(tf);
            }

            consoleNode.AddChild(topAnchor);
            scene.AddNode(consoleNode);

            AdjustConsoleTextPos();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
            IsMouseVisible = true;
            camera = new gxtCamera(Vector2.Zero, 0.0f, 0.0f, false);
            gxtDisplayManager.Singleton.WindowTitle = "Scene Graph Test";
            //gxtDisplayManager.Singleton.SetResolution(800, 600, false);
            sceneGraph = new gxtSceneGraph();
            sceneGraph.Initialize();

            childNode2 = new gxtSceneNode();
            baseNode = new gxtSceneNode();
            childNode = new gxtSceneNode();

            /*
            gxtIDrawable blueRectDrawable = new gxtDrawable(Color.Blue);
            gxtRectangle blueRect = new gxtRectangle(200.0f, 100.0f);
            blueRectDrawable.Entity = blueRect;

            gxtIDrawable yellowRectDrawable = new gxtDrawable(Color.Yellow, true, 0.45f);
            gxtRectangle yellowRect = new gxtRectangle(85.0f, 45.0f);
            yellowRectDrawable.Entity = yellowRect;


            gxtIDrawable grassDrawable = new gxtDrawable(new Color(255, 255, 255, 255), true, 0.0f);
            gxtPolygon grassPoly = gxtGeometry.CreateRectanglePolygon(150, 150);
            gxtDrawablePolygon grassPolygon = new gxtDrawablePolygon(grassPoly.v);
            Texture2D grassTexture = Content.Load<Texture2D>("Textures\\grass");
            grassPolygon.SetupTexture(grassTexture, gxtTextureCoordinateType.CLAMP);
            grassDrawable.Entity = grassPolygon;

            gxtIDrawable gridDrawable = new gxtDrawable(new Color(30, 100, 255, 255), true, 0.5f);
            Texture2D gridTexture = Content.Load<Texture2D>("Textures\\grid");
            gxtPolygon gridPoly = gxtGeometry.CreateRectanglePolygon(247, 250);
            gxtDrawablePolygon gridPolygon = new gxtDrawablePolygon(gridPoly.v);
            gridPolygon.SetupTexture(gridTexture, gxtTextureCoordinateType.CLAMP);
            gridDrawable.Entity = gridPolygon;

            gxtIDrawable textDrawable = new gxtDrawable(Color.White, true, 0.0f);
            SpriteFont font = Content.Load<SpriteFont>("Fonts\\debug_font");
            gxtTextField textEntity = new gxtTextField(font, "1.0f");
            textDrawable.Entity = textEntity;
            */
            //Vector2[] grassVertices2 = gxtGeometry.CreateCircleVertices(225, 7);
            Vector2[] grassVertices2 = gxtGeometry.CreateRectangleVertices(350, 350);
            //gxtMesh grassMesh = new gxtMesh(grassVertices);
            gxtMesh grassMesh = new gxtMesh();
            //grassMesh.SetVertices(grassVertices);
            Texture2D grassTexture = Content.Load<Texture2D>("Textures\\grass");
            grassMesh.SetVertices(grassVertices2);
            grassMesh.ApplyTexture(grassTexture, gxtTextureCoordinateType.WRAP);
            gxtIMaterial material = new gxtMaterial();
            grassMesh.Material = material;
            material.RenderDepth = 0.0f;
            material.ColorOverlay = new Color(255, 255, 255, 255);

            gxtIMaterial fontMaterial = new gxtMaterial();
            fontMaterial.ColorOverlay = Color.Red;
            //fontMaterial.RenderDepth = 0.75f;
            SpriteFont font = gxtResourceManager.Singleton.Load<SpriteFont>("Fonts\\debug_font");
            gxtTextField tf = new gxtTextField();
            tf.Text = "LOLOL";
            tf.SpriteFont = font;
            tf.Material = fontMaterial;
            tf.Material.Visible = true;
            //gxtSprite sprite = new gxtSprite(Content.Load<Texture2D>("Textures\\grass"));
            //grassDrawable.Entity = sprite;

            //transformNode.AttachDrawable(blueRect);
            //transformNode.AttachDrawable(yellowRect);
            baseNode.Scale = new Vector2(1.0f, 1.0f);

            baseNode.AttachDrawable(grassMesh);
            baseNode.AttachDrawable(tf);

            //Vector2[] lines = gxtGeometry.CreateRectangleVertices(150, 150);

            gxtIMaterial lineMaterial = new gxtMaterial();
            lineMaterial.ColorOverlay = Color.White;
            lineMaterial.RenderDepth = 0.0f;
            //gxtDynamicIndexedPrimitive dynamicLine = new gxtDynamicIndexedPrimitive(lines, PrimitiveType.LineList);
            gxtLine line = new gxtLine();
            line.Start = new Vector2(-75, -75);
            line.End = new Vector2(75, 75);
            line.Material = lineMaterial;
            //dynamicLine.Texture = grassTexture;
            //baseNode.AttachDrawable(dynamicLine);

            Texture2D metalTexture = gxtResourceManager.Singleton.LoadTexture("Textures\\scratched_metal");
            gxtIMaterial metalMaterial = new gxtMaterial();
            metalMaterial.SetDefaults();
            gxtSprite metalSprite = new gxtSprite(metalTexture, metalMaterial);
            //childNode2.AttachDrawable(metalSprite);

            gxtIMaterial circMaterial = new gxtMaterial();
            circMaterial.RenderDepth = 0.1f;
            circMaterial.ColorOverlay = new Color(255, 0, 0, 100);

            gxtCircle circ = new gxtCircle(75.0f, gxtCircleDrawMode.CIRCLE);
            circ.Material = circMaterial;

            gxtCircle circShell = new gxtCircle(75.0f, gxtCircleDrawMode.SHELL);
            circShell.Material = lineMaterial;

            childNode.Position = new Vector2(150, 300);
            childNode.ScaleAxes(1.35f);
            //childNode.Rotation = gxtMath.PI_OVER_FOUR;
            childNode.AttachDrawable(line);
            baseNode.AddChild(childNode);
            //childNode.AttachDrawable(grassMesh);
            childNode.AttachDrawable(circ);
            childNode.AttachDrawable(circShell);
            //baseNode.AttachDrawable(circ);

            if (gxtDebugDrawer.SingletonIsInitialized)
            {
                int id = gxtDebugDrawer.Singleton.GetNewId();
                gxtDebugDrawer.Singleton.DebugFont = gxtResourceManager.Singleton.Load<SpriteFont>("Fonts\\debug_font");
                gxtDebugDrawer.Singleton.AddSceneGraph(id, sceneGraph);
                gxtDebugDrawer.Singleton.CurrentSceneId = id;
            }

            childNode2.Position = new Vector2(125, 200);
            //childNode2.Rotation = -0.085f;
            gxtRectangle r = new gxtRectangle(100, 150);
            r.Material = new gxtMaterial();
            r.Material.ColorOverlay = new Color(0, 0, 255, 100);

            Vector2[] rectVerts = gxtGeometry.CreateRectangleVertices(100, 150);
            gxtLineLoop lloop = new gxtLineLoop(rectVerts, lineMaterial, true);
            childNode2.AttachDrawable(r);
            childNode2.AttachDrawable(lloop);
            childNode2.Scale = new Vector2(1.0f, 1.0f);
            childNode.AddChild(childNode2);
            /*
            baseNode.AttachDrawable(grassDrawable);
            baseNode.AttachDrawable(textDrawable);
            baseNode.AttachDrawable(gridDrawable);

            //transformNode.AddChild(baseNode);
            sceneGraph.AddNode(baseNode);

            gxtIDrawable lineLoopDrawable = new gxtDrawable(Color.Red, true, 0.3f);
            gxtLineLoop ll = new gxtLineLoop(2.0f);
            gxtAABB aabb = baseNode.GetAABB();
            gxtPolygon aabbPoly = gxtGeometry.ComputePolygonFromAABB(aabb);
            ll.SetVertices(aabbPoly.v);
            lineLoopDrawable.Entity = ll;

            gxtIDrawable circleDrawable = new gxtDrawable(true, 0.65f);
            gxtSprite circle = new gxtSprite(grassTexture);
            //gxtCircle circle = new gxtCircle(100.0f);
            circleDrawable.Entity = circle;
            childNode.Position = new Vector2(100.0f, 200.0f);
            childNode.Rotation = 0.0f;
            childNode.Scale = new Vector2(1.0f, 1.0f);
            childNode.AttachDrawable(circleDrawable);

            gxtIDrawable circleLoopDrawable = new gxtDrawable(Color.Yellow, true, 0.35f);
            gxtLineLoop circleLoop = new gxtLineLoop(2.0f);
            gxtAABB circAABB = circle.GetAABB(Vector2.Zero, 0.0f, Vector2.One);
            gxtPolygon circAABBPoly = gxtGeometry.ComputePolygonFromAABB(circAABB);
            circleLoop.SetVertices(circAABBPoly.v);
            circleLoopDrawable.Entity = circleLoop;

            baseNode.AttachDrawable(lineLoopDrawable);
            childNode.AttachDrawable(circleLoopDrawable);

            baseNode.AddChild(childNode);

            gxtIDrawable blueRectDrawable2 = new gxtDrawable(Color.Blue, true, 0.5f);
            gxtRectangle rect = new gxtRectangle(100, 65);
            blueRectDrawable2.Entity = rect;
            childNode2.Position = new Vector2(-150, 85);
            childNode2.Rotation = 0.3f;
            childNode2.AttachDrawable(blueRectDrawable2);
            childNode.AddChild(childNode2);

            if (gxtDebugDrawer.SingletonIsInitialized)
            {
                int id = gxtDebugDrawer.Singleton.GetNewId();
                gxtDebugDrawer.Singleton.AddSceneGraph(id, sceneGraph);
                gxtDebugDrawer.Singleton.CurrentSceneId = id;
            }
            /*
            //Texture2D grassTexture = Content.Load<Texture2D>("Textures\\grass");
            //gxtIDrawable grass = new gxtDrawableSprite(grassTexture);
            gxtRectangle rect = new gxtRectangle(200, 100);
            rect.RenderDepth = 1.0f;
            //gxtDrawableLine line = new gxtDrawableLine(new Vector2(-100, 50), new Vector2(100, -50));
            //gxtPolygon boxPoly = gxtGeometry.CreateRectanglePolygon(200, 100);
            //gxtDrawableLineLoop lineLoop = new gxtDrawableLineLoop();
            //lineLoop.SetVertices(boxPoly.v);

            gxtLineBatch lineBatch = new gxtLineBatch();
            lineBatch.Add(new Vector2(0.0f, 100.0f), new Vector2(100.0f, -150.0f));


            gxtCircle circle = new gxtCircle(100.0f);
            circle.RenderDepth = 1.0f;

            grassNode = new gxtSceneNode();
            //grassNode.AttachDrawable(lineLoop);
            //grassNode.AttachDrawable(rect);
            //grassNode.AttachDrawable(line);
            grassNode.AttachDrawable(lineBatch);
            //grassNode.Drawable = grass;

            //Texture2D scrapMetalTexture = Content.Load<Texture2D>("Textures\\grid");
            //gxtIDrawable scrapMetal = new gxtDrawableSprite(scrapMetalTexture);

            scrapMetalNode = new gxtSceneNode();
            //scrapMetalNode.AttachDrawable(scrapMetal);
            //scrapMetalNode.AttachDrawable(lineLoop);
            scrapMetalNode.AttachDrawable(circle);
            //scrapMetalNode.Drawable = scrapMetal;
            scrapMetalNode.Position = new Vector2(100.0f, 100.0f);
            //scrapMetalNode.InheritRotation = false;
            //scrapMetalNode.InheritPosition = false;

            grassNode.AddChild(scrapMetalNode);

            transformNode = new gxtSceneNode();
            //transformNode.Drawable = scrapMetal;
            transformNode.AddChild(grassNode);
            //transformNode.AttachDrawable(circle);

            sceneGraph.AddNode(transformNode);
            gxtLog.WriteLineV(gxtVerbosityLevel.INFORMATIONAL, sceneGraph.NodeCount);
            manager = new gxtDrawManager();
            manager.Initialize();
            */
            sceneGraph.AddNode(baseNode);
            gxtLog.WriteLineV(gxtVerbosityLevel.INFORMATIONAL, "Window Width: {0}", gxtDisplayManager.Singleton.ResolutionWidth);
            gxtLog.WriteLineV(gxtVerbosityLevel.INFORMATIONAL, "Window Height: {0}", gxtDisplayManager.Singleton.ResolutionHeight);
            //gxtSprite sprite = new gxtSprite(texture);
            //sprite.Depth = 0.0f;
            //sprite.Alpha = 100;
            //manager.Add(sprite);
            
        }