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