コード例 #1
0
        /// <summary>
        /// should take delegate for OnCommandEntered
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();
            camera = new gxtCamera(Vector2.Zero, 0.0f, 0.0f, true);
            sceneGraph = new gxtSceneGraph();
            sceneGraph.Initialize();
            gxtKeyboard kb = gxtKeyboardManager.Singleton.GetKeyboard();
            characterProcessor = new gxtKeyboardCharacterProcessor(true, kb);
            SpriteFont consoleFont;
            if (gxtResourceManager.Singleton.Load<SpriteFont>("Fonts\\calibri", out consoleFont))
            {
                inGameConsole = new gxtInGameConsole();
                inGameConsole.Initialize(sceneGraph, 150.0f, true, gxtVerbosityLevel.INFORMATIONAL, true, false, consoleFont, true, "console: ", 0.0f, 1.0f, 6);
                gxtLog.Singleton.AddListener(inGameConsole);
                characterProcessor.OnCharacterEntered += inGameConsole.AppendCharacter;
                consoleController = new gxtInGameConsoleController();
                consoleController.Initialize(true, inGameConsole);

                commandProcessor = new gxtCommandProcessor(true);
                commandProcessor.AddConsoleCommand("fps", "Gets the current frames per second", FPSCommand);
                commandProcessor.AddConsoleCommand("exit", "Shuts down the entire application", ExitCommand);
                commandProcessor.AddConsoleCommand("memory", "Gets the memory usage \nin bytes or mb", MemoryUsageCommand);
                commandProcessor.AddConsoleCommand("resolution", "Sets the display resolution, width height", ResolutionCommand);
                inGameConsole.OnCommandEntered += commandProcessor.Process;
            }
        }
コード例 #2
0
ファイル: SAPTestGame.cs プロジェクト: Loko/GXT
 /// <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;
     nodes = new List<gxtISceneNode>();
     camera = new gxtCamera(Vector2.Zero, 0.0f, 0.0f, false);
     gxtDisplayManager.Singleton.RegisterCamera(camera);
     gxtDisplayManager.Singleton.SetResolution(800, 600, false);
     Root.DisplayManager.WindowTitle = "Sweep and Prune TestBed";
     sceneGraph = new gxtSceneGraph();
     sceneGraph.Initialize();
     //drawManager.Initialize();
     if (gxtDebugDrawer.SingletonIsInitialized)
     {
         debugDrawerId = gxtDebugDrawer.Singleton.GetNewId();
         gxtDebugDrawer.Singleton.AddSceneGraph(debugDrawerId, sceneGraph);
         gxtDebugDrawer.Singleton.DebugFont = Content.Load<SpriteFont>("Fonts\\debug_font");
         gxtDebugDrawer.Singleton.FillGeometry = false;
     }
     drawableCollider = new gxtSortAndSweepCollider<gxtISceneNode>();
     drawableCollider.Initialize();
     InitializeRectangles();
 }
コード例 #3
0
ファイル: AudioTestGame.cs プロジェクト: Loko/GXT
        /// <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();
            Root.DisplayManager.WindowTitle = "Audio Test";
            sceneGraph = new gxtSceneGraph();
            Content.RootDirectory = "Content";
            audioEngine = new AudioEngine("Content\\Audio\\gxt_test_sounds.xgs");
            soundBank = new SoundBank(audioEngine, "Content\\Audio\\gxt_test_sound_bank.xsb");
            waveBank = new WaveBank(audioEngine, "Content\\Audio\\gxt_test_wave_bank.xwb");

            audioEngine.Update();

            Cue cue = soundBank.GetCue("park_1");
            cue.Play();
            if (gxtDebugDrawer.SingletonIsInitialized)
            {
                debugDrawerId = gxtDebugDrawer.Singleton.GetNewId();
                gxtDebugDrawer.Singleton.AddSceneGraph(debugDrawerId, sceneGraph);
                gxtDebugDrawer.Singleton.CurrentSceneId = debugDrawerId;
                //gxtDebugDrawer.Singleton.SetTargetDrawManager(world.DrawManager);
                gxtDebugDrawer.Singleton.DebugFont = Content.Load<SpriteFont>("Fonts\\debug_font");
                //gxtDebugDrawer.Singleton.SetDebugFont(Root);
            }
        }
コード例 #4
0
ファイル: gxtInGameConsole.cs プロジェクト: Loko/GXT
        /// <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();
        }
コード例 #5
0
ファイル: TextureMappingTestGame.cs プロジェクト: Loko/GXT
        /// <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();
            camera = new gxtCamera(Vector2.Zero, 0.0f, 0.0f, gxtDisplayManager.Singleton);
            gxtDisplayManager.Singleton.RegisterCamera(camera);
            gxtRoot.Singleton.DisplayManager.SetResolution(800, 600, false);
            vertices = new VertexPositionColorTexture[3];

            /*
            vertices[0] = new VertexPositionColorTexture(new Vector3(-0.1f, 0.0f, 1.0f), new Color(255, 255, 255, 255), new Vector2(0.0f, 1.0f));
            vertices[2] = new VertexPositionColorTexture(new Vector3(0.35f, 0.1f, 1.0f), new Color(255, 255, 255, 255), new Vector2(1.0f, 0.0f));
            vertices[1] = new VertexPositionColorTexture(new Vector3(0.0f, 0.45f, 1.0f), new Color(255, 255, 255, 255), new Vector2(0.0f, 0.0f));
            */
            /*
            vertices[0] = new VertexPositionColorTexture(new Vector3(-10.0f, 0.0f, 1.0f), new Color(255, 255, 255, 255), new Vector2(0.0f, 1.0f));
            vertices[2] = new VertexPositionColorTexture(new Vector3(3.5f, -2.5f, 1.0f), new Color(255, 255, 255, 255), new Vector2(1.0f, 0.0f));
            vertices[1] = new VertexPositionColorTexture(new Vector3(0.0f, 4.5f, 1.0f), new Color(255, 255, 255, 255), new Vector2(0.0f, 0.0f));
            */
            vertices[0] = new VertexPositionColorTexture(new Vector3(0.0f, 0.0f, 0.0f), new Color(255, 255, 255, 255), new Vector2(0.0f, 1.0f));
            vertices[1] = new VertexPositionColorTexture(new Vector3(250.0f, 300.0f, 0.0f), new Color(255, 255, 255, 255), new Vector2(1.0f, 0.0f));
            vertices[2] = new VertexPositionColorTexture(new Vector3(25.0f, -300.0f, 0.0f), new Color(255, 255, 255, 255), new Vector2(0.0f, 0.0f));

            vertexBuffer = new VertexBuffer(gxtRoot.Singleton.Graphics, typeof(VertexPositionColorTexture), vertices.Length, BufferUsage.WriteOnly);
            vertexBuffer.SetData<VertexPositionColorTexture>(vertices);

            // effect.world is object centroid
            // view up is negated, position is -1, target is camX, camY, 0.0f

            effect = new BasicEffect(gxtRoot.Singleton.Graphics);
            effect.TextureEnabled = true;
            effect.Texture = grassTexture;
            effect.LightingEnabled = false;

            effect.World = Matrix.CreateWorld(new Vector3(275.0f / 3.0f, 250.0f / 3.0f, 0.0f), -Vector3.UnitZ, Vector3.Up);
            gxtLog.WriteLineV(VerbosityLevel.INFORMATIONAL, "World: {0}", effect.World.ToString());
            effect.View = Matrix.CreateLookAt(new Vector3(0, 0, -1.0f), new Vector3(0.0f, 0.0f, 0.0f), -Vector3.Up);
            //effect.View *= Matrix.CreateTranslation(0.0f, -40.0f, 0.0f);
            gxtLog.WriteLineV(VerbosityLevel.INFORMATIONAL, "View: {0}", effect.View.ToString());

            effect.Projection = Matrix.CreateOrthographic(800.0f, 600.0f, 0.0f, 1.0f);
            //effect.Projection = Matrix.CreateTranslation(0.0f, 0.0f, 1.0f);
            //effect.Projection = Matrix.CreatePerspectiveFieldOfView(gxtMath.PI * 0.25f, 4.0f / 3.0f, 0.2f, 100.0f);
            //gxtRoot.Singleton.SpriteBatch.GraphicsDevice.SetVertexBuffer(vertexBuffer);
            gxtLog.WriteLineV(VerbosityLevel.INFORMATIONAL, "Projection: {0}", effect.Projection.ToString());
            gxtLog.WriteLineV(VerbosityLevel.INFORMATIONAL, "Camera: {0}", camera.GetTransformation().ToString());
            gxtRoot.Singleton.Graphics.RasterizerState = RasterizerState.CullNone;

            sceneGraph = new gxtSceneGraph();
            //manager.Initialize();
            if (gxtDebugDrawer.SingletonIsInitialized)
            {
                int debugDrawId = gxtDebugDrawer.Singleton.GetNewId();
                gxtDebugDrawer.Singleton.AddSceneGraph(debugDrawId, sceneGraph);
            }
        }
コード例 #6
0
ファイル: gxtWorld.cs プロジェクト: Loko/GXT
        // some log method here that checks the state of everything
        // see if major components are null and initialized
        // maybe some other things can be printed
        /// <summary>
        /// Initializes the world and all of its components
        /// Should be called first (before load)
        /// </summary>
        public virtual void Initialize(bool initEnabled = true, string name = "GXT World")
        {
            gxtDebug.Assert(!IsInitialized(), "World has already been initialized!");
            enabled = initEnabled;
            worldName = name;
            gameSpeed = 1.0f;

            // init lists
            actors = new List<gxtIActor>();
            animations = new List<gxtAnimation>();
            controllers = new List<gxtIController>();

            // construct components
            sceneGraph = new gxtSceneGraph();
            processManager = new gxtProcessManager();
            physicsWorld = new gxtPhysicsWorld();
            pathGraph = new gxtPathGraph();
            audioScene = new gxtAudioScene();

            // init components
            sceneGraph.Initialize();
            camera = new gxtCamera(Vector2.Zero, 0, 0, true);
            //gxtDisplayManager.Singleton.RegisterCamera(camera);
            processManager.Initialize();
            physicsWorld.Initialize();
            //audioScene.Initialize("soundBankFile", "waveBankFile");

            // fire on init event
            if (OnWorldInit != null)
                OnWorldInit(this);
        }
コード例 #7
0
ファイル: SceneGraphTestGame.cs プロジェクト: Loko/GXT
        /// <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);
            
        }
コード例 #8
0
ファイル: SpriteBatchTestGame.cs プロジェクト: Loko/GXT
        /// <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();
            camera = new gxtCamera(Vector2.Zero, 0.0f, 0.0f, false);
            gxtDisplayManager.Singleton.RegisterCamera(camera);
            gxtDisplayManager.Singleton.SetResolution(800, 600, false);
            gxtDisplayManager.Singleton.WindowTitle = "Custom SpriteBatch Test";
            base.IsMouseVisible = true;

            grassTexture = Content.Load<Texture2D>("Textures\\grass");
            scrapTexture = Content.Load<Texture2D>("Textures\\scratched_metal");
            brickTexture = Content.Load<Texture2D>("Textures\\seamless_brick");
            font = Content.Load<SpriteFont>("Fonts\\debug_font");

            sceneGraph = new gxtSceneGraph();
            sceneGraph.Initialize();

            spriteBatch = new gxtSpriteBatch();
            spriteBatch.Initialize(gxtRoot.Singleton.XNASpriteBatch, gxtRoot.Singleton.Graphics);

            gxtPolygon poly = gxtGeometry.CreateCirclePolygon(200, 11);
            vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColorTexture), poly.NumVertices, BufferUsage.WriteOnly);
            indexBuffer = new IndexBuffer(GraphicsDevice, typeof(int), 3 + ((poly.NumVertices - 3) * 3), BufferUsage.WriteOnly);
            Triangulate(poly);
            CalculateUVCoords(poly);

            if (gxtDebugDrawer.SingletonIsInitialized)
            {
                int debugDrawId = gxtDebugDrawer.Singleton.GetNewId();
                gxtDebugDrawer.Singleton.AddSceneGraph(debugDrawId, sceneGraph);
            }
        }
コード例 #9
0
ファイル: TextureMappingTestGame2.cs プロジェクト: Loko/GXT
        /// <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();

            polygon = gxtGeometry.CreateCirclePolygon(100.0f, 3); //gxtGeometry.CreateCirclePolygon(75.0f, 5);

            texturedPolygon = new TexturedPolygon(polygon, gxtRoot.Singleton.Graphics, -0.5f);
            texturedPolygon.ColorOverlay = new Color(255, 0, 0, 100);
            grassTexture = Content.Load<Texture2D>("Textures\\grass");
            texturedPolygon.Texture = grassTexture;
            texturedPolygon.TextureEnabled = false;
            texturedPolygon.CalculateUVCoords();

            polygon2 = gxtGeometry.CreateCirclePolygon(100.0f, 7);

            texturedPolygon2 = new TexturedPolygon(polygon2, gxtRoot.Singleton.Graphics);
            texturedPolygon2.Texture = grassTexture;
            texturedPolygon2.TextureEnabled = false;
            texturedPolygon2.CalculateUVCoords();
            texturedPolygon2.Position = new Vector2(-50, -50);

            //texturedPolygon.Scale(1.5f, 1.5f);

            //referenceCircle = new gxtCircle(Vector2.Zero, 200.0f, Color.Blue, 0.0f);

            sceneGraph = new gxtSceneGraph();
            sceneGraph.Initialize();

            if (gxtDebugDrawer.SingletonIsInitialized)
            {
                debugDrawId = gxtDebugDrawer.Singleton.GetNewId();
                gxtDebugDrawer.Singleton.AddSceneGraph(debugDrawId, sceneGraph);
                gxtDebugDrawer.Singleton.SetId(debugDrawId);
            }
            //manager.Add(referenceCircle);
            camera = new gxtCamera(Vector2.Zero, 0.0f, 0.0f, gxtDisplayManager.Singleton);
        }
コード例 #10
0
ファイル: MyAnimationTestGame.cs プロジェクト: Loko/GXT
        /// <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 = "Animation Scene Graph Test";
            sceneGraph = new gxtSceneGraph();
            sceneGraph.Initialize();

            Texture2D grassTexture, metalTexture;
            bool textureLoaded = gxtResourceManager.Singleton.LoadTexture("Textures\\grass", out grassTexture);
            gxtDebug.Assert(textureLoaded, "Texture load failed!");
            textureLoaded = gxtResourceManager.Singleton.LoadTexture("Textures\\scratched_metal", out metalTexture);
            gxtDebug.Assert(textureLoaded, "Texture load failed!");

            parent = new gxtSceneNode();
            Vector2[] rectangleVertices = gxtGeometry.CreateRectangleVertices(150, 100);
            gxtDynamicMesh rectangle = new gxtDynamicMesh(rectangleVertices);
            gxtIMaterial rectangleMaterial = new gxtMaterial(true, Color.Yellow, 0.5f);
            rectangle.Material = rectangleMaterial;
            rectangle.ApplyTexture(grassTexture, gxtTextureCoordinateType.WRAP);
            parent.AttachDrawable(rectangle);

            child = new gxtSceneNode();
            child.Position = new Vector2(37.5f, 55.5f);
            Vector2[] rectangleVertices2 = gxtGeometry.CreateRectangleVertices(75, 175);
            gxtIMaterial rectangleMaterial2 = new gxtMaterial(true, Color.Blue, 1.0f);
            gxtDynamicMesh rectangle2 = new gxtDynamicMesh(rectangleVertices2);
            rectangle2.Material = rectangleMaterial2;
            rectangle2.ApplyTexture(metalTexture, gxtTextureCoordinateType.WRAP);
            child.AttachDrawable(rectangle2);
            parent.AddChild(child);

            sceneGraph.AddNode(parent);

            gxtAnimationPose a0 = new gxtAnimationPose();
            a0.InterpolateUVCoords = true;
            a0.InterpolateColorOverlay = true;
            a0.UVCoordinates = rectangle.GetTextureCoordinates();

            gxtAnimationPose a1 = new gxtAnimationPose();
            a1.InterpolateUVCoords = false;
            a1.InterpolateColorOverlay = true;
            a1.ColorOverlay = Color.Red;
            a1.Translation = new Vector2(-150, -200);

            Vector2[] uvCoordsCopy = rectangle.GetTextureCoordinates();
            for (int i = 0; i < uvCoordsCopy.Length; ++i)
            {
                uvCoordsCopy[i] += new Vector2(-0.75f);
            }
            a1.UVCoordinates = uvCoordsCopy;

            gxtAnimationPose a2 = new gxtAnimationPose();
            a2.Translation = new Vector2(200, -225);
            a2.Rotation = gxtMath.PI_OVER_FOUR;
            a2.InterpolateUVCoords = false;
            Vector2[] uvCoordsCopy2 = rectangle.GetTextureCoordinates();
            for (int i = 0; i < uvCoordsCopy2.Length; ++i)
            {
                uvCoordsCopy2[i] *= (1.0f / 1.5f);
                //uvCoordsCopy2[i] += new Vector2(-3.75f, 0.0f);
            }
            a2.UVCoordinates = uvCoordsCopy2;


            gxtAnimationPose a3 = new gxtAnimationPose();
            a3.Translation = new Vector2(50, 200);
            a3.Rotation = gxtMath.DegreesToRadians(-235);
            a3.Scale = new Vector2(1.85f, 1.75f);

            gxtKeyframe k0 = new gxtKeyframe(a0, 0.0f);
            gxtKeyframe k1 = new gxtKeyframe(a1, 0.4f);
            gxtKeyframe k2 = new gxtKeyframe(a2, 0.65f);
            gxtKeyframe k3 = new gxtKeyframe(a3, 1.0f);


            gxtAnimationClip clip = new gxtAnimationClip(parent, rectangle);
            clip.AddKeyframe(k0);
            clip.AddKeyframe(k1);
            clip.AddKeyframe(k2);
            clip.AddKeyframe(k3);

            animClip = new gxtAnimation(TimeSpan.FromSeconds(5.0), true, true, 1.0f);
            animClip.AddClip(clip);

            animController = new gxtAnimationController();
            animController.AddAnimation("default", animClip);
            //animClip.AddTween();
            /*
            gxtAnimationKeyFrame k3 = new gxtAnimationKeyFrame();
            */

            /*
            parent = new gxtSceneNode();
            //gxtIDrawable rectangleDrawable = new gxtDrawable(Color.Yellow, true, 0.5f);
            gxtRectangle rectangle = new gxtRectangle(150, 100);
            gxtIMaterial rectangleMaterial = new gxtMaterial(true, Color.Yellow, 0.2f);
            rectangle.Material = rectangleMaterial;
            parent.AttachDrawable(rectangle);

            child = new gxtSceneNode();
            //gxtIDrawable childRectDrawable = new gxtDrawable(Color.Blue, true, 0.0f);
            gxtRectangle childRect = new gxtRectangle(75, 175);
            gxtIMaterial childRectangleMaterial = new gxtMaterial(true, new Color(0, 0, 255, 100), 0.0f);
            childRect.Material = childRectangleMaterial;
            child.AttachDrawable(childRect);
            child.Position = new Vector2(37.5f, 55.5f);

            parent.AddChild(child);

            sceneGraph.AddNode(parent);

            initKeyframe = new gxtKeyframe(gxtNodeTransform.Identity, 0.0f);

            gxtNodeTransform midTransform = new gxtNodeTransform();
            midTransform.Translation = new Vector2(-185, -100);
            midTransform.Scale = new Vector2(-1.5f, 1.5f);
            midTransform.Rotation = gxtMath.DegreesToRadians(-25.0f);
            gxtKeyframe midKeyFrame = new gxtKeyframe(midTransform, 0.235f);

            gxtNodeTransform finalPose = new gxtNodeTransform();
            finalPose.Translation = new Vector2(100.0f, -200.0f);
            finalPose.Rotation = gxtMath.DegreesToRadians(90.0f);
            finalKeyframe = new gxtKeyframe(finalPose, 0.6f);

            gxtNodeTransform lastXform = new gxtNodeTransform();
            lastXform.Translation = new Vector2(100.0f, -200.0f);
            lastXform.Rotation = -6.0f * gxtMath.PI;
            lastXform.Scale = new Vector2(0.25f, 1.45f);
            gxtKeyframe lastKeyframe = new gxtKeyframe(lastXform, 0.85f);


            gxtTween tween = new gxtTween(parent);
            tween.AddKeyframe(initKeyframe);
            tween.AddKeyframe(finalKeyframe);
            tween.AddKeyframe(midKeyFrame);
            tween.AddKeyframe(lastKeyframe);


            animClip = new gxtAnimationClip(TimeSpan.FromSeconds(10.0));
            animClip.AddTween(tween);
            animClip.Loop = false;
            animClip.PlaybackRate = 1.0f;

            animController = new gxtAnimationController();
            animController.AddClip("default", animClip);
            animController.Stop("default");
            */

            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);
        }