示例#1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="node"></param>
 /// <param name="mesh"></param>
 public gxtAnimationClip(gxtISceneNode node, gxtIMesh mesh)
 {
     gxtDebug.Assert(mesh.Material != null, "Meshes used in animation must have an attached material!");
     this.node = node;
     this.keyframes = new List<gxtKeyframe>();
     this.mesh = mesh;
     uvCoords = new Vector2[mesh.NumVertices];
     currentFrame = 0;
 }
示例#2
0
文件: gxtSceneGraph.cs 项目: Loko/GXT
 /// <summary>
 /// Adds the node to the collection if it isn't in the update queue already
 /// Returns boolean indicating it has been added and the subtree should be 
 /// recursively marked as dirty.  If a node is already in the queue it will 
 /// not be added twice
 /// </summary>
 /// <param name="node">Scene Node</param>
 /// <returns>If added to the queue</returns>
 public static bool AddNodeToUpdateQueue(gxtISceneNode node)
 {
     gxtDebug.Assert(nodeUpdateQueue != null, "Node Update Queue Hasn't Been Initialized Yet!");
     if (!nodeUpdateQueue.Contains(node))
     {
         nodeUpdateQueue.Enqueue(node);
         return true;
     }
     return false;
 }
示例#3
0
文件: gxtSceneGraph.cs 项目: Loko/GXT
 /// <summary>
 /// Adds a node as a child of the root scene node
 /// </summary>
 /// <param name="node">Node</param>
 public virtual void AddNode(gxtISceneNode node)
 {
     gxtDebug.Assert(IsInitialized(), "Scene graph hasn't been initialized!");
     root.AddChild(node);
 }
示例#4
0
文件: gxtSceneGraph.cs 项目: Loko/GXT
 /// <summary>
 /// Removes the node from the scene, regardless of its parent
 /// </summary>
 /// <param name="node">Node</param>
 public virtual bool RemoveNode(gxtISceneNode node)
 {
     if (node.Parent != null)
         return node.Parent.RemoveChild(node);
     return false;
 }
示例#5
0
文件: gxtSceneGraph.cs 项目: Loko/GXT
 /// <summary>
 /// Initializes the scene graph
 /// </summary>
 /// <param name="sceneVisible">Flag enabling/disabling rendering of the scene</param>
 /// <param name="updateQueueCapacity">Initial capacity of the update queue, it will grow if needed</param>
 public virtual void Initialize(bool sceneVisible = true, int updateQueueCapacity = 8)
 {
     gxtDebug.Assert(!IsInitialized(), "Instance of scene graph has already been initialized");
     gxtDebug.Assert(updateQueueCapacity >= 0, "Can't have a negative capacity update queue!");
     nodeUpdateQueue = new Queue<gxtISceneNode>(updateQueueCapacity);
     Visible = sceneVisible;
     root = new gxtSceneNode();
 }
示例#6
0
文件: gxtSceneGraph.cs 项目: Loko/GXT
 /// <summary>
 /// Determines if the node exists as a child of the root, or, if deepSearch is set to true,
 /// is in the tree at all
 /// </summary>
 /// <param name="node">Node</param>
 /// <param name="deepSearch">Recursive Search</param>
 /// <returns>If found</returns>
 public virtual bool ContainsNode(gxtISceneNode node, bool deepSearch = true)
 {
     return root.ContainsChild(node, deepSearch);
 }
示例#7
0
文件: gxtDebugNode.cs 项目: Loko/GXT
 /// <summary>
 /// Constructor initializing debugdrawable with given
 /// drawable and duration
 /// </summary>
 /// <param name="node">Scene Node</param>
 /// <param name="duration">Time Until Removal</param>
 /// <param name="id">Scene Graph id this drawable belongs to</param>
 public gxtDebugNode(gxtISceneNode node, TimeSpan duration, int id)
 {
     Node = node;
     TimeRemaining = duration;
     SceneId = id;
 }
示例#8
0
文件: gxtSceneNode.cs 项目: Loko/GXT
        /// <summary>
        /// Adds a child node
        /// </summary>
        /// <param name="node">Node</param>
        public virtual void AddChild(gxtISceneNode node)
        {
            gxtDebug.Assert(node != null, "Can't add a null reference as a child node!");
            gxtDebug.Assert(!this.Equals(node), "Can't add a node as a child of itself");

            // changing parents without detaching is allowed, but not reccomended
            if (node.Parent != null)
                gxtLog.WriteLineV(gxtVerbosityLevel.WARNING, "Scene Node With Non Null Parent Is Being Changed");
            children.Add(node);
            node.Parent = this;
            node.QueueForUpdate();
        }
示例#9
0
文件: gxtWorld.cs 项目: Loko/GXT
 public void RemoveSceneNode(gxtISceneNode sceneNode)
 {
     sceneGraph.RemoveNode(sceneNode);
 }
示例#10
0
文件: gxtWorld.cs 项目: Loko/GXT
 public void AddSceneNode(gxtISceneNode sceneNode)
 {
     sceneGraph.AddNode(sceneNode);
 }
示例#11
0
文件: SAPTestGame.cs 项目: Loko/GXT
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            gxtDebugDrawer.Singleton.CurrentSceneId = debugDrawerId;

            foreach (gxtISceneNode r in nodes)
            {
                r.SetColor(Color.Blue);
            }

            gxtKeyboard kb = gxtKeyboardManager.Singleton.GetKeyboard();
            float tx = 0.0f, ty = 0.0f;
            float cameraSpeed = 3.0f;
            if (kb.IsDown(Keys.A))
                tx -= cameraSpeed;
            if (kb.IsDown(Keys.W))
                ty -= cameraSpeed;
            if (kb.IsDown(Keys.D))
                tx += cameraSpeed;
            if (kb.IsDown(Keys.S))
                ty += cameraSpeed;
            if (kb.IsDown(Keys.Q))
                camera.Rotation -= 0.005f;
            if (kb.IsDown(Keys.E))
                camera.Rotation += 0.005f;
            if (kb.IsDown(Keys.Z))
                camera.Zoom += 0.01f;
            if (kb.IsDown(Keys.C))
                camera.Zoom = gxtMath.Min(gxtCamera.MIN_CAMERA_SCALE, camera.Zoom - 0.01f);
            if (kb.GetState(Keys.Tab) == gxtControlState.FIRST_PRESSED)
                gxtDisplayManager.Singleton.SetResolution(1280, 720, false);
            if (kb.GetState(Keys.CapsLock) == gxtControlState.FIRST_PRESSED)
                gxtDisplayManager.Singleton.SetResolution(800, 600, false);
                
            if (kb.GetState(Keys.T) == gxtControlState.FIRST_PRESSED)
                gxtLog.WriteLineV(gxtVerbosityLevel.INFORMATIONAL, drawableCollider.DebugTrace());
            if (kb.GetState(Keys.I) == gxtControlState.FIRST_PRESSED)
                drawIntervals = !drawIntervals;
            if (kb.GetState(Keys.B) == gxtControlState.FIRST_PRESSED)
                drawBoundingBoxes = !drawBoundingBoxes;
            if (kb.GetState(Keys.P) == gxtControlState.FIRST_PRESSED)
                gxtLog.WriteLineV(gxtVerbosityLevel.INFORMATIONAL, drawableCollider.DebugTracePairs());

            camera.TranslateLocal(tx, ty);

            gxtOBB camOBB = camera.GetViewOBB();
            camOBB.Extents *= 0.95f;

            gxtAABB camAABB = camera.GetViewAABB();
            camAABB.Extents *= 0.95f;

            gxtLog.WriteLineV(gxtVerbosityLevel.WARNING, "Zoom: {0}", camera.Zoom); 
            gxtDebugDrawer.Singleton.AddOBB(camOBB, Color.Yellow, 0.0f);
            gxtDebugDrawer.Singleton.AddAABB(camAABB, Color.Red, 0.0f);
            gxtDebugDrawer.Singleton.AddAxes(camera.Position, camera.Rotation, Color.Red, Color.Green, 0.0f);
            //gxtLog.WriteLineV(gxtVerbosityLevel.CRITICAL, "Camera Rotation: {0}", camera.Rotation.ToString());
            gxtAABB cameraAABB = camera.GetViewAABB();
            float cameraYBoundary = cameraAABB.Max.Y;
            float cameraXBoundary = cameraAABB.Max.X;

            gxtMouse mouse = gxtMouseManager.Singleton.GetMouse();
            Vector2 virtualMousePos = camera.GetVirtualMousePosition(mouse.GetPosition());
            gxtDebugDrawer.Singleton.AddPt(virtualMousePos, Color.Yellow, 0.0f);
            if (mouse.GetState(gxtMouseButton.LEFT) == gxtControlState.FIRST_PRESSED)
            {
                foreach (gxtISceneNode drawable in nodes)
                {
                    gxtAABB aabb = drawable.GetAABB();
                    if (aabb.Contains(virtualMousePos))
                    {
                        currentSelection = drawable;
                        currentSelection.SetColor(Color.Green);
                        //currentSelection.ColorOverlay = Color.Green;
                        //currentSelection = drawable as gxtRectangle;
                        //currentSelection.ColorOverlay = Color.Green;
                    }
                }
            }
            else if (mouse.GetState(gxtMouseButton.LEFT) == gxtControlState.DOWN)
            {
                if (currentSelection != null)
                {
                    if (kb.GetState(Keys.Delete) == gxtControlState.FIRST_PRESSED)
                    {
                        drawableCollider.RemoveObject(currentSelection);
                        sceneGraph.RemoveNode(currentSelection);
                        nodes.Remove(currentSelection);
                        currentSelection = null;
                        //drawManager.Remove(currentSelection);
                        //drawables.Remove(currentSelection);
                        //currentSelection = null;
                    }
                    else
                    {
                        Vector2 prevVirtualMousePos = camera.GetVirtualMousePosition(new Vector2(mouse.PrevState.X, mouse.PrevState.Y));
                        Vector2 d = virtualMousePos - prevVirtualMousePos;
                        currentSelection.Position += d;
                        gxtAABB aabb = currentSelection.GetAABB();
                        drawableCollider.UpdateObject(currentSelection, ref aabb);
                        currentSelection.SetColor(Color.Green);
                        //currentSelection.ColorOverlay = Color.Green;
                    }
                }

            }
            else if (mouse.IsUp(gxtMouseButton.LEFT))
            {
                if (currentSelection != null)
                {
                    currentSelection.SetColor(Color.Blue);
                    currentSelection = null;
                }
            }


            
            foreach (gxtISceneNode drawable in nodes)
            {
                if (drawBoundingBoxes)
                    gxtDebugDrawer.Singleton.AddAABB(drawable.GetAABB(), new Color(255, 0, 0, 100), 1.0f);
            }

            if (drawIntervals)
                drawableCollider.DebugDraw(Color.White, Color.Red, cameraYBoundary, cameraXBoundary);

            #if RAY_CAST_TEST
            Vector2 rayOrigin = new Vector2(-100.0f, 0.0f);
            Vector2 direction = virtualMousePos - rayOrigin;
            direction.Normalize();

            gxtRay ray = new gxtRay(rayOrigin, direction);
            List<gxtISceneNode> rayHits = drawableCollider.RayCastAll(ray);
            if (rayHits.Count != 0)
            {
                for (int i = 0; i < rayHits.Count; i++)
                {
                    rayHits[i].SetColor(Color.Orange, false);
                    gxtLog.WriteLineV(gxtVerbosityLevel.WARNING, "Num Ray Hits: {0}", rayHits.Count);
                    //gxtRectangle rect = rayHits[i] as gxtRectangle;
                    //rect.ColorOverlay = Color.Orange;
                }
                gxtDebugDrawer.Singleton.AddRay(ray, float.MaxValue, Color.Green, 0.0f);
            }
            else
            {
                gxtDebugDrawer.Singleton.AddRay(ray, Color.Green, 0.0f);
            }
            #else
            gxtBroadphaseCollisionPair<gxtISceneNode>[] rectPairs = drawableCollider.GetCollisionPairs();
            foreach (gxtBroadphaseCollisionPair<gxtISceneNode> rectPair in rectPairs)
            {
                rectPair.objA.ColorOverlay = Color.Orange;
                rectPair.objB.ColorOverlay = Color.Orange;
                gxtDebugDrawer.Singleton.AddPt(rectPair.objA.GetAABB().Position, Color.Yellow, 0.0f);
            }
            #endif


            //drawManager.Update();
            // fps at top left
            /*
            string fpsString = "FPS: " + gxtDebug.GetFPS().ToString();
            Vector2 strSize = gxtDebugDrawer.Singleton.DebugFont.MeasureString(fpsString);
            strSize *= 0.5f;
            Vector2 topLeftCorner = new Vector2(-gxtDisplayManager.Singleton.WindowWidth * 0.5f, -gxtDisplayManager.Singleton.WindowHeight * 0.5f);
            topLeftCorner += camera.Position;
            gxtDebugDrawer.Singleton.AddString("FPS: " + gxtDebug.GetFPS(), topLeftCorner + strSize, Color.White, 0.0f);
            */
            sceneGraph.Update(gameTime);
        }
示例#12
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);
            
        }
示例#13
0
文件: gxtSceneNode.cs 项目: Loko/GXT
 /// <summary>
 /// Removes the child node and unlinks parent reference
 /// </summary>
 /// <param name="node">Node</param>
 /// <returns>True if removed, false if not</returns>
 public virtual bool RemoveChild(gxtISceneNode node)
 {
     for (int i = NumChildrenNodes - 1; i >= 0; --i)
     {
         if (children[i].Equals(node))
         {
             children.RemoveAt(i);
             node.Parent = null;
             // mark as clean?  should we have an in graph variable?
             return true;
         }
     }
     return false;
 }
示例#14
0
文件: gxtSceneNode.cs 项目: Loko/GXT
 /// <summary>
 /// Removes the child and explicitly disposes of all 
 /// of its attached drawable content.  Does not dispose of the 
 /// node itself!
 /// </summary>
 /// <param name="node">Node</param>
 /// <returns>True if removed, false if not</returns>
 public virtual bool RemoveAndDisposeChild(gxtISceneNode node)
 {
     for (int i = NumChildrenNodes - 1; i >= 0; --i)
     {
         if (children[i].Equals(node))
         {
             children.RemoveAt(i);
             node.Parent = null;
             gxtIDrawable drawable;
             for (int j = node.NumDrawables - 1; j >= 0; --j)
             {
                 drawable = drawables[j];
                 drawables.RemoveAt(j);
                 drawable.Dispose();
             }
             return true;
         }
     }
     return false;
 }
示例#15
0
文件: gxtSceneNode.cs 项目: Loko/GXT
 /// <summary>
 /// Contains search, which can optionally be run on all descendent 
 /// nodes.  
 /// </summary>
 /// <param name="node">Node to search for</param>
 /// <param name="deepSearch">If you want to run the search on all descendants</param>
 /// <returns>If found</returns>
 public virtual bool ContainsChild(gxtISceneNode node, bool deepSearch = false)
 {
     if (deepSearch)
     {
         for (int i = 0; i < NumChildrenNodes; ++i)
         {
             if (children[i].Equals(node))
                 return true;
             if (children[i].ContainsChild(node, true))
                 return true;
         }
     }
     else if (node != null && node.Parent != null && node.Parent.Equals(this))
     {
         gxtDebug.Assert(children.Contains(node), "Node is not a child to it's parent reference!");
         return true;
     }
     return false;
 }
示例#16
0
        public void Initialize(Vector2 initPos, float speed = 3.0f, float maxSpeed = 500.0f)
        {
            hashedString = new gxtHashedString("player_actor");
            this.position = initPos;
            this.rotation = 0.0f; // if we were to take a rotation be sure to use gxtMath.WrapAngle(initRot)
            MoveSpeed = speed;
            MaxSpeed = maxSpeed;

            this.clipMode = asgClipMode.NORMAL;
            // in physics world units
            // setup body
            playerBody = new gxtRigidBody();
            playerBody.Mass = 2.0f;
            playerBody.CanSleep = false;    // should NEVER go to sleep
            playerBody.Awake = true;
            playerBody.FixedRotation = true;
            playerBody.IgnoreGravity = false;
            playerBody.Position = position;
            playerBody.Rotation = rotation;
            world.AddRigidBody(playerBody);

            // setup geom
            //playerPolygon = gxtGeometry.CreateRectanglePolygon(2, 3.5f);
            playerPolygon = gxtGeometry.CreateRoundedRectanglePolygon(2.0f, 3.5f, 0.45f, 0.05f);
            //playerPolygon = gxtGeometry.CreateEllipsePolygon(1.0f, 1.75f, 20);
            //playerPolygon = gxtGeometry.CreateCapsulePolygon(3.0f, 1.0f, 8);
            //playerPolygon = gxtGeometry.CreateCirclePolygon(3.0f, 3);
            playerGeom = new gxtGeom(playerPolygon, position, rotation);
            playerGeom.Tag = this;
            playerGeom.CollidesWithGroups = world.PhysicsWorld.GetCollisionGroup("traversable_world_geometry");
            playerGeom.CollisionGroups = world.PhysicsWorld.GetCollisionGroup("player");
            playerGeom.RigidBody = playerBody;
            playerGeom.OnCollision += OnCollision;
            playerGeom.OnSeperation += OnSeperation;
            world.PhysicsWorld.AddGeom(playerGeom);

            // setup scene node
            // for now we'll just use a line loop but programming it
            // this way makes it easy to swap out for something like a skeleton
            // or a texture later down the road
            scenePoly = gxtPolygon.Copy(playerPolygon);
            scenePoly.Scale(gxtPhysicsWorld.PHYSICS_SCALE);
            //playerEntity = new gxtLineLoop(scenePoly.v);

            // setup drawable
            //playerDrawable = new gxtDrawable(playerEntity, Color.Yellow, true, 0.1f);
            playerSceneNode = new gxtSceneNode();
            playerSceneNode.Position = playerBody.Position;
            //playerSceneNode.AttachDrawable(playerDrawable);
            //world.AddSceneNode(playerSceneNode);

            // setup raycatsing logic
            rayCastTimer = new gxtStopWatch(true);
            world.AddProcess(rayCastTimer);
            raycasts = new List<gxtRayHit>();

            clipMode = asgClipMode.NORMAL;
            this.halfHeight = playerGeom.LocalAABB.Height * 0.5f;
        }
示例#17
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();
        }
示例#18
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 = "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);
        }