Exemplo n.º 1
0
            void _IButton.Translate(Vector2 d)
            {
                mAABB.Translate(d);
                Vector3 d3 = new Vector3(d, 0);

                mCorner2 += d3;
                mCorner3 += d3;
                mButtonCore.Translate(d);
            }
Exemplo n.º 2
0
        void XICamera.Update(GameTime game_time)
        {
            if (mListener_WorldRegenerated.GetMaxOne() != null)
            {
                InitFromWorld();
            }

            XTouch.MultiDragData multi_drag_msg = mListener_MultiDrag.GetMaxOne();

            if (multi_drag_msg != null)
            {
                if (multi_drag_msg.mFrameCount == 0)
                {
                    mMultiDragPrev = multi_drag_msg;
                }

                // figure out zoom.  damp so that human powered drag zoom is not jittery.
                // it's not that there is anything wrong with the measurement or the calculation, it's
                // that people don't seem to keep their fingers at constant separation when they mean to.
                const float k_zoom_damping   = 0.8f;
                float       ideal_zoom_ratio = (float)(mMultiDragPrev.mMaxScreenSeparation / multi_drag_msg.mMaxScreenSeparation);

                float zoom_ratio = (mDampedMaxScreenSeparation > -1f)                                                                                                                  ?
                                   (k_zoom_damping * mDampedMaxScreenSeparation + (1f - k_zoom_damping) * ideal_zoom_ratio)        :
                                   ideal_zoom_ratio;

                mDampedMaxScreenSeparation = zoom_ratio;

                // place new world view so that the zoom point in world space is at the same place on the screen.
                Vector2 size_0         = mWorldView.GetSize();
                Vector2 size_1         = zoom_ratio * size_0;
                Vector2 avg_world_pos  = CalcWorldPos(multi_drag_msg.mAvgScreenPos);
                float   pos_x_fraction = multi_drag_msg.mAvgScreenPos.X / mScreenDim.x;
                float   pos_y_fraction = multi_drag_msg.mAvgScreenPos.Y / mScreenDim.y;
                float   dx_world       = pos_x_fraction * size_1.X;
                float   dy_world       = pos_y_fraction * size_1.Y;
                Vector2 p0             = new Vector2(avg_world_pos.X - dx_world, avg_world_pos.Y - dy_world);
                Vector2 p1             = p0 + size_1;
                xAABB2  world_view     = new xAABB2(p0, p1);

                // figure out translation
                // this calculation assumes fullscreen, viewport not taken into consideration
                Vector2 pixel_move      = multi_drag_msg.mAvgScreenPos - mMultiDragPrev.mAvgScreenPos;
                Vector2 screen_fraction = new Vector2(pixel_move.X / mScreenDim.x, pixel_move.Y / mScreenDim.y);
                Vector2 world_view_size = world_view.GetSize();
                Vector2 world_move      = new Vector2(screen_fraction.X * world_view_size.X, screen_fraction.Y * world_view_size.Y);
                world_view.Translate(-world_move);
                mMultiDragPrev = multi_drag_msg;

                // clamp and calc projection matrix
                mWorldView = ClampWorldView(world_view);
                CalcProjectionMatrix();
            }
        }
Exemplo n.º 3
0
            private void Translate(Vector2 t)
            {
                mAABB.Translate(t);
                mPos = mAABB.GetMin();

                // translate each button the same amount, and account for title
                for (int i = 0; i < mSelections.Length; ++i)
                {
                    mSelections[i].Translate(t);
                }

                mTitleButton.Translate(t);
            }
Exemplo n.º 4
0
 public xAABB2 GetScreenAABB()
 {
     if (mParent != null)
     {
         xAABB2 parent_screen_aabb = mParent.GetPosition().GetScreenAABB();
         xAABB2 aabb = mRelativeAABB;
         aabb.Translate(parent_screen_aabb.GetMin());
         return(aabb);
     }
     else
     {
         return(mRelativeAABB);
     }
 }
Exemplo n.º 5
0
 public void Translate(Vector2 v)
 {
     mRelativeAABB.Translate(v);
     ValidateAABB();
 }
Exemplo n.º 6
0
        public static void UnitTest()
        {
            xAABB2 aabb1 = new xAABB2();

            XUtils.Assert(aabb1.mIsValid == false);

            xAABB2 aabb2 = new xAABB2(Vector2.Zero);
            xAABB2 aabb3 = new xAABB2(Vector2.Zero, 1f);
            xAABB2 aabb4 = new xAABB2(Vector2.Zero, Vector2.Zero);

            XUtils.Assert(aabb2.IsValid() && aabb3.IsValid() && aabb4.IsValid());

            aabb2.Reset();
            XUtils.Assert(!aabb2.IsValid());

            Vector2     oneTwo     = new Vector2(1f, 2f);
            Vector2     negTwoFour = -2f * oneTwo;
            Vector2     TwentyTen  = new Vector2(20f, 10f);
            const float kTol       = 0.001f;

            aabb2.Set(oneTwo);
            XUtils.AssertVal(aabb2.mMin, oneTwo, kTol);
            XUtils.AssertVal(aabb2.mMax, oneTwo, kTol);
            XUtils.Assert(aabb2.IsValid());

            //aabb2.Set( oneTwo, negTwoFour ); inside out, asserts, good
            aabb2.Set(negTwoFour, oneTwo);
            XUtils.Assert(aabb2.Contains(Vector2.Zero));
            XUtils.Assert(!aabb2.Contains(TwentyTen));
            XUtils.Assert(aabb2.Contains(negTwoFour));
            XUtils.Assert(aabb2.Contains(oneTwo));
            XUtils.Assert(!aabb2.Contains(-TwentyTen));

            //aabb2.Set( oneTwo, -3f ); asserts on negative radius, good
            Vector2 fiveFive     = new Vector2(5f, 5f);
            Vector2 sixSeven     = oneTwo + fiveFive;
            Vector2 negFourThree = new Vector2(-4f, -3f);
            Vector2 epsilon      = new Vector2(kTol, kTol);

            aabb2.Set(oneTwo, 5f);
            XUtils.Assert(aabb2.Contains(oneTwo));
            XUtils.Assert(aabb2.Contains(fiveFive));
            XUtils.Assert(aabb2.Contains(negFourThree));
            XUtils.Assert(!aabb2.Contains(TwentyTen));
            XUtils.Assert(!aabb2.Contains(-TwentyTen));
            XUtils.Assert(aabb2.Contains(Vector2.Zero));
            XUtils.Assert(aabb2.Contains(negFourThree + epsilon));
            XUtils.Assert(!aabb2.Contains(negFourThree - epsilon));
            XUtils.Assert(aabb2.Contains(sixSeven - epsilon));
            XUtils.Assert(!aabb2.Contains(sixSeven + epsilon));

            aabb2.Set(Vector2.Zero);
            XUtils.Assert(!aabb2.IsNonDegenerate());

            aabb2.Add(Vector2.UnitX);
            XUtils.Assert(!aabb2.IsNonDegenerate());
            XUtils.Assert(aabb2.Contains(new Vector2(0.5f, 0f)));

            aabb2.Add(oneTwo);
            XUtils.Assert(aabb2.IsNonDegenerate());
            XUtils.Assert(aabb2.Contains(new Vector2(0.5f, 1f)));

            aabb2.Reset();
            aabb2.Add(Vector2.Zero);
            XUtils.Assert(aabb2.IsValid());

            aabb2.Reset();
            aabb2.Add(-fiveFive);
            aabb2.Add(TwentyTen);
            XUtils.AssertVal(aabb2.GetMin(), -fiveFive, kTol);
            XUtils.AssertVal(aabb2.GetMax(), TwentyTen, kTol);
            XUtils.AssertVal(aabb2.GetCenter(), new Vector2(7.5f, 2.5f), kTol);
            XUtils.AssertVal(aabb2.GetRadius(), new Vector2(12.5f, 7.5f), kTol);
            XUtils.AssertVal(aabb2.GetSize(), new Vector2(25f, 15f), kTol);
            XUtils.AssertVal(aabb2.GetArea(), 375f, kTol);

            aabb2.Reset();
            aabb2.Add(Vector2.Zero);
            aabb2.Add(oneTwo);
            aabb2.ScaleWorld(4f);
            XUtils.AssertVal(aabb2.GetArea(), 32f, kTol);

            aabb2.Translate(fiveFive);
            Vector2 center2 = new Vector2(7f, 9f);

            XUtils.AssertVal(aabb2.GetArea(), 32f, kTol);
            XUtils.AssertVal(aabb2.GetCenter(), center2, kTol);
            XUtils.Assert(!aabb2.Contains(oneTwo));
            XUtils.Assert(aabb2.Contains(new Vector2(6f, 8f)));

            //aabb2.ScaleWorld( -1f ); asserts negative scalar, good
            //aabb2.ScaleLocal( -50f ); asserts negative scalar, good
            aabb2.ScaleLocal(0.25f);
            XUtils.AssertVal(aabb2.GetCenter(), center2, kTol);
            XUtils.AssertVal(aabb2.GetArea(), 2f, kTol);
            XUtils.Assert(!aabb2.Contains(new Vector2(6f, 8f)));
            XUtils.Assert(aabb2.Contains(center2));

            aabb2.Reset();
            aabb2.Add(Vector2.Zero);
            aabb2.Add(oneTwo);
            aabb2.Resize(new Vector2(0.1f, -0.3f));
            XUtils.AssertVal(aabb2.GetArea(), 1.68f, kTol);
            XUtils.Assert(!aabb2.Contains(Vector2.Zero));
            XUtils.Assert(aabb2.Contains(new Vector2(-0.05f, 1.4f)));
        }