コード例 #1
0
ファイル: SceneGraphTestGame.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);
            /*
            gxtGamepad gp = gxtGamepadManager.Singleton.GetGamepad(PlayerIndex.One);
            float speed = 5.0f;
            grassNode.RelativePosition += gp.AdjLStick() * speed;
            if (gp.GetState(Buttons.B) == gxtControlState.FIRST_PRESSED)
                scrapMetalNode.RelativeVisibility = !scrapMetalNode.RelativeVisibility;
            float rz = (gp.RTrigger() - gp.LTrigger()) * 0.1f;
            if (rz != 0.0f)
                grassNode.RelativeRotation += rz;
                //grassNode.RelativeVisibility = !grassNode.RelativeVisibility;
            */
            gxtKeyboard kb = gxtKeyboardManager.Singleton.GetKeyboard();
            float speed = 5.0f;
            if (kb.IsDown(Keys.A))
                baseNode.Translate(new Vector2(-speed, 0.0f), gxtTransformSpace.WORLD);
            if (kb.IsDown(Keys.D))
                baseNode.Translate(new Vector2(speed, 0.0f), gxtTransformSpace.WORLD);
            if (kb.IsDown(Keys.S))
                baseNode.Translate(new Vector2(0.0f, speed), gxtTransformSpace.WORLD);
            if (kb.IsDown(Keys.W))
                baseNode.Translate(new Vector2(0.0f, -speed), gxtTransformSpace.WORLD);
            if (kb.IsDown(Keys.E))
                baseNode.Rotate(0.005f, gxtTransformSpace.LOCAL);
                //grassNode.RelativeRotation += 0.005f;
                //baseNode.RelativeRotation += 0.005f;
            if (kb.IsDown(Keys.Q))
                baseNode.Rotate(-0.005f, gxtTransformSpace.LOCAL);
                //grassNode.RelativeRotation -= 0.005f;
                //baseNode.RelativeRotation -= 0.005f;
            if (kb.IsDown(Keys.Z))
                baseNode.ScaleAxes(0.995f);

            if (kb.IsDown(Keys.C))
                baseNode.ScaleAxes(1.005f);

            if (kb.GetState(Keys.Enter) == gxtControlState.FIRST_PRESSED)
            {
                childTransformSpace = (gxtTransformSpace)(((int)childTransformSpace + 1) % 3);
            }

            //gxtLog.WriteLineV(gxtVerbosityLevel.INFORMATIONAL, childTransformSpace.ToString());


            if (kb.IsDown(Keys.Left))
                childNode.Translate(new Vector2(-speed, 0.0f), childTransformSpace);
            if (kb.IsDown(Keys.Right))
                childNode.Translate(new Vector2(speed, 0.0f), childTransformSpace);
            if (kb.IsDown(Keys.Down))
                childNode.Translate(new Vector2(0.0f, speed), childTransformSpace);
            if (kb.IsDown(Keys.Up))
                childNode.Translate(new Vector2(0.0f, -speed), childTransformSpace);
            if (kb.IsDown(Keys.OemOpenBrackets))
                childNode.Rotate(-0.005f, childTransformSpace);
            //grassNode.RelativeRotation += 0.005f;
            //baseNode.RelativeRotation += 0.005f;
            if (kb.IsDown(Keys.OemCloseBrackets))
                childNode.Rotate(0.005f, childTransformSpace);
            //grassNode.RelativeRotation -= 0.005f;
            //baseNode.RelativeRotation -= 0.005f;
            if (kb.IsDown(Keys.OemComma))
                childNode.ScaleAxes(0.995f);

                //baseNode.Scale = new Vector2(baseNode.Scale.X - 0.005f, baseNode.Scale.Y - 0.005f);
                //baseNode.ScaleAll(0.985f);
                //grassNode.RelativeScale = new Vector2(grassNode.RelativeScale.X - 0.005f, grassNode.RelativeScale.Y - 0.005f);
                //baseNode.Scale = new Vector2(baseNode.Scale.X - 0.005f, baseNode.Scale.Y - 0.005f);
            if (kb.IsDown(Keys.OemPeriod))
                childNode.ScaleAxes(1.005f);
                //baseNode.Scale = new Vector2(baseNode.Scale.X + 0.005f, baseNode.Scale.Y - 0.005f);
                //baseNode.ScaleAll(1.015f);
                //grassNode.RelativeScale = new Vector2(grassNode.RelativeScale.X + 0.005f, grassNode.RelativeScale.Y + 0.005f);
                //baseNode.Scale = new Vector2(baseNode.Scale.X + 0.005f, baseNode.Scale.Y + 0.005f);
            if (kb.GetState(Keys.N) == gxtControlState.FIRST_PRESSED)
                baseNode.ScaleAxes(new Vector2(-1.0f, 1.0f));
            //if (kb.GetState(Keys.P) == gxtControlState.FIRST_PRESSED)
            //    childNode.InheritPosition = !childNode.InheritPosition;
            if (kb.GetState(Keys.V) == gxtControlState.FIRST_PRESSED)
            {
                baseNodeVisible = !baseNodeVisible;
                baseNode.SetVisibility(baseNodeVisible, false);
            }
            if (kb.GetState(Keys.Space) == gxtControlState.FIRST_PRESSED)
            {
                //baseNode.ScaleAxes(-1.0f, 1.0f);
                //baseNode.FlipHorizontal();
                //baseNode.SetColor(Color.Red);
                baseNode.FlipVertical();
            }
            if (kb.GetState(Keys.T) == gxtControlState.FIRST_PRESSED)
                gxtLog.WriteLineV(gxtVerbosityLevel.INFORMATIONAL, sceneGraph.DebugTrace());

            if (kb.IsDown(Keys.F2))
                camera.Rotation += 0.005f;
            if (kb.IsDown(Keys.F1))
                camera.Rotation -= 0.005f;
            if (kb.IsDown(Keys.F3))
                camera.Translate(-0.3f, 0.0f);
            if (kb.IsDown(Keys.F4))
                camera.Translate(0.3f, 0.0f);
            if (kb.IsDown(Keys.F5))
                camera.Translate(0.0f, -0.3f);
            if (kb.IsDown(Keys.F6))
                camera.Translate(0.0f, 0.3f);
            if (kb.IsDown(Keys.F7))
                camera.Zoom -= 0.005f;
            if (kb.IsDown(Keys.F8))
                camera.Zoom += 0.005f;
            
                //transformNode.ColorOverlay = Color.Red;
            /*
            if (kb.GetState(Keys.U) == gxtControlState.FIRST_PRESSED)
                childNode.InheritScale = !childNode.InheritScale;
            if (kb.IsDown(Keys.Left))
                sceneRotation -= 0.005f;
            if (kb.IsDown(Keys.Right))
                sceneRotation += 0.005f;
            if (kb.IsDown(Keys.Up))
                scenePos -= new Vector2(0.0f, 10.0f);
            */
            //sceneGraph.Update();
            //gxtLog.WriteLineV(gxtVerbosityLevel.INFORMATIONAL, baseNode.Scale.ToString());

            gxtMouse m = gxtMouseManager.Singleton.GetMouse();
            Vector2 mousePos = camera.GetVirtualMousePosition(m.GetPosition());
            if (m.GetState(gxtMouseButton.LEFT) == gxtControlState.FIRST_PRESSED)
            {

                baseNode.SetDerivedPosition(mousePos);
            }

            if (m.GetState(gxtMouseButton.RIGHT) == gxtControlState.FIRST_PRESSED)
            {
                Vector2 mouseN = Vector2.Normalize(mousePos - baseNode.GetDerivedPosition());
                if (mouseN != Vector2.Zero)
                {
                    float ang = gxtMath.Atan2(mouseN.Y, mouseN.X);
                    //worldRotation += 0.00005f; //gxtMath.WrapAngle(worldRotation + 0.00005f);
                    baseNode.SetDerivedRotation(gxtMath.PI_OVER_TWO + baseNode.GetDerivedRotation());
                }
            }
            prevVirtualMousePos = mousePos;
            gxtDebugDrawer.Singleton.AddPt(mousePos, Color.Yellow, 0.0f);

            /*
            IEnumerator<gxtISceneNode> treeIterator = sceneGraph.Root.GetChildEnumerator();
            while (treeIterator.MoveNext())
            {
                gxtISceneNode cur = treeIterator.Current;
                IEnumerator<gxtISceneNode> curChildren = cur.GetChildEnumerator();
                while (curChildren.MoveNext())
                {
                    aabbsToAdd.Add(curChildren.Current.GetAABB());
                }
            }
            */

            sceneGraph.Update(gameTime);

            List<gxtAABB> aabbsToAdd = new List<gxtAABB>();
            aabbsToAdd.Add(baseNode.GetAABB());
            aabbsToAdd.Add(childNode.GetAABB());
            aabbsToAdd.Add(childNode2.GetAABB());

            /*
            IEnumerator<gxtISceneNode> treeIterator = sceneGraph.Root.GetChildEnumerator();
            while (treeIterator.MoveNext())
            {
                gxtISceneNode cur = treeIterator.Current;
                IEnumerator<gxtISceneNode> curChildren = cur.GetChildEnumerator();
                while (curChildren.MoveNext())
                {
                    aabbsToAdd.Add(curChildren.Current.GetAABB());
                }
            }
            */

            for (int i = 0; i < aabbsToAdd.Count; ++i)
            {
                gxtDebugDrawer.Singleton.AddAABB(aabbsToAdd[i], Color.Blue, 0.0f);
            }

            sceneGraph.Update(gameTime);
        }
コード例 #2
0
ファイル: gxtSceneNode.cs プロジェクト: Loko/GXT
 /// <summary>
 /// Translates the node by the given vector in the desired space
 /// </summary>
 /// <param name="t">Translation Vector</param>
 /// <param name="space">Transform Space</param>
 public virtual void Translate(Vector2 t, gxtTransformSpace space = gxtTransformSpace.LOCAL)
 {
     if (space == gxtTransformSpace.LOCAL)
     {
         // project onto the local axes
         float cos = gxtMath.Cos(relativeRotation);
         float sin = gxtMath.Sin(relativeRotation);
         Vector2 xAxis = new Vector2(cos, sin);
         Vector2 yAxis = new Vector2(-sin, cos);
         relativePosition += (xAxis * t.X) + (yAxis * t.Y);
         QueueForUpdate();
     }
     else if (space == gxtTransformSpace.PARENT)
     {
         relativePosition += t;
         QueueForUpdate();
     }
     else  // world space
     {
         if (parent != null)
         {
             // negative rotation == inverse in this case
             Matrix pInvRotation = Matrix.CreateRotationZ(-parent.GetDerivedRotation());
             Vector2 parentScale = parent.GetDerivedScale();
             Vector2 wt = Vector2.Transform(t, pInvRotation);
             relativePosition += new Vector2(wt.X / parentScale.X, wt.Y / parentScale.Y);
             QueueForUpdate();
         }
         else
         {
             relativePosition += t;
             QueueForUpdate();
         }
     }
 }
コード例 #3
0
ファイル: gxtSceneNode.cs プロジェクト: Loko/GXT
 /// <summary>
 /// Translates the node by the given values in the desired space
 /// </summary>
 /// <param name="tx">tx</param>
 /// <param name="ty">ty</param>
 public virtual void Translate(float tx, float ty, gxtTransformSpace space = gxtTransformSpace.LOCAL)
 {
     Translate(new Vector2(tx, ty), space);
 }
コード例 #4
0
ファイル: gxtSceneNode.cs プロジェクト: Loko/GXT
        /// <summary>
        /// Rotates the node by the given value in the desired space
        /// </summary>
        /// <param name="rot">Additional rotation in radians</param>
        /// <param name="space">Transform Space</param>
        public virtual void Rotate(float rot, gxtTransformSpace space = gxtTransformSpace.LOCAL)
        {
            if (space == gxtTransformSpace.LOCAL)
            {
                relativeRotation += rot;
                QueueForUpdate();
            }
            else if (space == gxtTransformSpace.PARENT)
            {
                relativeRotation += rot;
                float cos = gxtMath.Cos(rot);
                float sin = gxtMath.Sin(rot);
                float pX = relativePosition.X * cos - relativePosition.Y * sin;
                float pY = relativePosition.X * sin + relativePosition.Y * cos;
                relativePosition.X = pX;
                relativePosition.Y = pY;
                QueueForUpdate();
            }
            else if (space == gxtTransformSpace.WORLD)
            {
                gxtLog.WriteLineV(gxtVerbosityLevel.WARNING, "Scene Node Rotate Method Not Implemented For World Space Yet!");
                /*
                if (rot != 0.0f)
                {
                    //relativeRotation += rot;
                    float prevDerivedRotation = GetDerivedRotation();
                    float derivedRot = prevDerivedRotation + rot;
                    float cos = gxtMath.Cos(rot);
                    float sin = gxtMath.Sin(rot);

                    Vector2 derivedPos = GetDerivedPosition();
                    float pX = derivedPos.X * cos - derivedPos.Y * sin;
                    float pY = derivedPos.X * sin + derivedPos.Y * cos;
                    SetDerivedPosition(new Vector2(pX, pY));
                }
                */
                //gxtLog.WriteLineV(gxtVerbosityLevel.WARNING, "Scene Node Rotate Method Not Implemented For World Space Yet!");
                /*
                float prevDerivedRot = GetDerivedRotation();
                Rotation += rot;
                float derivedRot = GetDerivedRotation();
                float dr = derivedRot - prevDerivedRot;
                float cos = gxtMath.Cos(dr);
                float sin = gxtMath.Sin(dr);
                Vector2 derivedPos = GetDerivedPosition();
                float pX = derivedPos.X * cos - derivedPos.Y * sin;
                float pY = derivedPos.X * sin + derivedPos.Y * cos;

                SetDerivedPosition(new Vector2(pX, pY));
                */
                //Matrix derivedRotMat = Matrix.CreateRotationZ(GetDerivedRotation());
                //Matrix derivedInverse = Matrix.Invert(derivedRotMat);

            }
        }