コード例 #1
0
ファイル: World.cs プロジェクト: barronds/XNARTS
        public void RenderWorld(GameTime game_time, xAABB2 view_aabb)
        {
            if (!mRendered)
            {
                XSimpleDraw   simple_draw = XSimpleDraw.Instance(xeSimpleDrawType.WorldSpace_Persistent_Map);
                System.Random rand        = new Random();

                mMap.Iterate((grid, x, y) =>
                {
                    Vector3 low  = new Vector3(x, y, 0f);
                    Vector3 high = new Vector3(x + 1, y + 1, 0f);
                    Color color  = grid.mData[x, y].mColor;

                    simple_draw.DrawQuad(low, high, color);
                });

                // render world lines in here if they are static
                // RenderWorldLines_Static();

                mRendered = true;
            }

            // render world lines here if they are dynamic
            RenderWorldLines_Dynamic(view_aabb);
        }
コード例 #2
0
ファイル: Camera.cs プロジェクト: barronds/XNARTS
        private xAABB2 ClampWorldView(xAABB2 world_view)
        {
            // make it true to aspect ratio and can't exceed width or height of map.
            Vector2 min = world_view.GetMin();
            Vector2 max = world_view.GetMax();

            // clamp edges
            min.X = Math.Max(0, min.X);
            min.Y = Math.Max(0, min.Y);
            max.X = Math.Min(mWorldSize.x, max.X);
            max.Y = Math.Min(mWorldSize.y, max.Y);

            // restore aspect ratio by bringing in x or y
            Vector2 span     = max - min;
            float   ideal_dy = span.X * mAspect;

            if (span.Y > ideal_dy)
            {
                max.Y = min.Y + span.X * mAspect;
            }
            else
            {
                max.X = min.X + span.Y / mAspect;
            }

            return(new xAABB2(min, max));
        }
コード例 #3
0
ファイル: UITypes.cs プロジェクト: barronds/XNARTS
 private void ValidateAABB()
 {
     if (mParent != null)
     {
         xAABB2 parent_aabb = new xAABB2(Vector2.Zero, mParent.GetPosition().GetRelatveAABB().GetSize());
         XUtils.Assert(parent_aabb.Contains(mRelativeAABB.GetMin()) && parent_aabb.Contains(mRelativeAABB.GetMax()));
     }
 }
コード例 #4
0
ファイル: Label.cs プロジェクト: barronds/XNARTS
            // use static GetSizeOfText() if size is needed before construction

            public Label(Widget parent, String text, Style style, Vector2 pos)
            {
                // parent can query aabb afterwards and translate if necessary.  start at prescribed position.
                Vector2 label_size    = Init(text, style);
                xAABB2  relative_aabb = new xAABB2(pos, pos + label_size);

                InitWidget(parent, style, relative_aabb);
            }
コード例 #5
0
ファイル: Camera.cs プロジェクト: barronds/XNARTS
        public XScreenCam(xCoord screen_dim)
        {
            Vector2 min = new Vector2(0, 0);
            Vector2 max = new Vector2(screen_dim.x, screen_dim.y);

            mViewAABB   = new xAABB2(min, max);
            mView       = Matrix.CreateLookAt(new Vector3(0f, 0f, 1f), new Vector3(0f, 0f, 0f), new Vector3(0f, 1f, 0f));
            mProjection = Matrix.CreateOrthographicOffCenter(min.X, max.X, max.Y, min.Y, -1f, 1f);
        }
コード例 #6
0
ファイル: Camera.cs プロジェクト: barronds/XNARTS
        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();
            }
        }
コード例 #7
0
ファイル: panel.cs プロジェクト: barronds/XNARTS
            public override void Render(XSimpleDraw simple_draw)
            {
                base.Render(simple_draw);
                xAABB2 aabb = GetPosition().GetScreenAABB();

                XUI.Instance().Util_DrawBox(simple_draw, GetStyle(), aabb);

                for (int i = 0; i < mChildren.Count; ++i)
                {
                    mChildren[i].Render(simple_draw);
                }
            }
コード例 #8
0
ファイル: UITypes.cs プロジェクト: barronds/XNARTS
 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);
     }
 }
コード例 #9
0
ファイル: Button2.cs プロジェクト: barronds/XNARTS
            public Button(Widget parent, Style style, String text, Vector2 pos)
            {
                // optimize later
                Vector2 label_size = Label.GetSizeOfText(text, style);
                eFont   font       = style.mNormalFont;
                Vector2 font_size  = XFontDraw.Instance().GetFontInfo(font).mSize;
                float   padding    = style.mButtonPadding;
                xAABB2  aabb       = new xAABB2(pos, pos + label_size + 2.0f * new Vector2(padding, padding));

                InitPanel(parent, style, aabb);

                Label label = new Label(this, text, style, ePlacement.Centered);

                AddChild(label);
            }
コード例 #10
0
        public void Util_DrawBox(XSimpleDraw simple_draw, Style style, xAABB2 screen_aabb)
        {
            Vector3 lo_x_lo_y = new Vector3(screen_aabb.GetMin(), 0);
            Vector3 hi_x_hi_y = new Vector3(screen_aabb.GetMax(), 0);

            Vector2 size      = screen_aabb.GetSize();
            Vector3 lo_x_hi_y = lo_x_lo_y + new Vector3(0, size.Y, 0);
            Vector3 hi_x_lo_y = lo_x_lo_y + new Vector3(size.X, 0, 0);

            simple_draw.DrawQuad(lo_x_lo_y, hi_x_hi_y, style.mBackgroundColor);

            simple_draw.DrawLine(lo_x_lo_y, hi_x_lo_y, style.mBorderColor);
            simple_draw.DrawLine(hi_x_lo_y, hi_x_hi_y, style.mBorderColor);
            simple_draw.DrawLine(hi_x_hi_y, lo_x_hi_y, style.mBorderColor);
            simple_draw.DrawLine(lo_x_hi_y, lo_x_lo_y, style.mBorderColor);
        }
コード例 #11
0
ファイル: UITypes.cs プロジェクト: barronds/XNARTS
            private void Place(Vector2 size,
                               float parent_start_norm_x,
                               float parent_start_norm_y,
                               float shape_correct_norm_x,
                               float shape_correct_norm_y,
                               float padding_norm_x,
                               float padding_norm_y)
            {
                Vector2 parent_aabb_size   = mParent.GetPosition().GetRelatveAABB().GetSize();
                Vector2 parent_start_point = new Vector2(parent_start_norm_x * parent_aabb_size.X,
                                                         parent_start_norm_y * parent_aabb_size.Y);
                Vector2 padding      = GetStyle().mPlacementPadding *new Vector2(padding_norm_x, padding_norm_y);
                Vector2 size_correct = new Vector2(size.X * shape_correct_norm_x, size.Y * shape_correct_norm_y);
                Vector2 top_left     = parent_start_point + padding + size_correct;
                Vector2 bottom_right = top_left + size;

                mRelativeAABB = new xAABB2(top_left, bottom_right);
            }
コード例 #12
0
ファイル: World.cs プロジェクト: barronds/XNARTS
        public void RenderWorldLines_Dynamic(xAABB2 view_aabb)
        {
            XSimpleDraw simple_draw_world = XSimpleDraw.Instance(xeSimpleDrawType.WorldSpace_Transient);

            // calculate color to use based on how much world is being drawn
            const float k_large_view_size = 200;
            const float k_small_view_size = 5;
            float       view_width        = view_aabb.GetMax().X - view_aabb.GetMin().X;
            float       lightness         = view_width > k_large_view_size ? 1.0f :
                                            view_width < k_small_view_size ? 0.0f :
                                            (view_width - k_small_view_size) / (k_large_view_size - k_small_view_size);

            lightness = XMath.Sqrt(lightness);

            Color k_lightest_color = new Color(0.0f, 0.0f, 0.0f, 0.025f);
            Color k_darkest_color  = new Color(0.0f, 0.0f, 0.0f, 0.33f);
            Color result_color     = Color.Lerp(k_darkest_color, k_lightest_color, lightness);

            // each cell is 1 unit on edge in world space
            Vector3 start = new Vector3();
            Vector3 end   = new Vector3();

            start.Y = 0;
            end.Y   = mMap.mBounds.y;

            for (int x = 0; x <= mMap.mBounds.x; ++x)
            {
                start.X = x;
                end.X   = x;

                simple_draw_world.DrawLine(start, end, result_color);
            }

            start.X = 0;
            end.X   = mMap.mBounds.x;

            for (int y = 0; y <= mMap.mBounds.y; ++y)
            {
                start.Y = y;
                end.Y   = y;

                simple_draw_world.DrawLine(start, end, result_color);
            }
        }
コード例 #13
0
ファイル: Buttons.cs プロジェクト: barronds/XNARTS
            public _RectangularButton(Vector2 pos,
                                      String text,
                                      Style style,
                                      long id,
                                      Vector2 font_size)
            {
                // padding calculated, and button size and offset
                float   k_padding       = style.mButtonPadding;
                Vector2 new_text_offset = new Vector2(k_padding, k_padding);
                float   button_width    = text.Length * font_size.X + 2 * k_padding;
                float   button_height   = font_size.Y + 2 * k_padding;
                Vector2 new_size        = new Vector2(button_width, button_height);

                mAABB    = new xAABB2(pos, pos + new_size);
                mCorner2 = new Vector3(pos.X + new_size.X, pos.Y, 2);
                mCorner3 = new Vector3(pos.X, pos.Y + new_size.Y, 2);

                mButtonCore = new _ButtonCore(pos, text, style, new_text_offset, id);
            }
コード例 #14
0
ファイル: Camera.cs プロジェクト: barronds/XNARTS
        private void InitFromWorld()
        {
            mWorldSize = XWorld.Instance().GetMapSize();

            // initial view of map
            xAABB2 world_view = new xAABB2(new Vector2(0, 0), new Vector2(mWorldSize.x, mWorldSize.y));

            mWorldView = ClampWorldView(world_view);

            // view matrix is unchanging
            Vector3 pos    = new Vector3(0, 0, 1f);
            Vector3 target = pos - 2f * Vector3.UnitZ;

            mViewMatrix = Matrix.CreateLookAt(pos, target, Vector3.UnitY);
            CalcProjectionMatrix();

            mMultiDragPrev             = new XTouch.MultiDragData(Vector2.Zero, 1f, 0);
            mDampedMaxScreenSeparation = -1f;
        }
コード例 #15
0
ファイル: UITypes.cs プロジェクト: barronds/XNARTS
            private Widget mParent;                             // can be null, for screen widget

            // constructor for absolute position relative to widget.  use screen widget for screen space position.
            public Position(Widget parent, xAABB2 relative_aabb)
            {
                mRelativeAABB = relative_aabb;
                Init(parent, ePlacement.Absolute);
                ValidateAABB();
            }
コード例 #16
0
ファイル: BBox2.cs プロジェクト: barronds/XNARTS
        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)));
        }
コード例 #17
0
ファイル: Selector.cs プロジェクト: barronds/XNARTS
            public Selector(_Position pos, String title, eStyle style, eStyle button_style, eStyle title_style,
                            long id, String[] texts)
            {
                mRenderEnabled   = true;
                mID              = id;
                mPos             = pos.GetPosition();
                mPosition        = pos;
                mTitle           = title;
                mStyle           = style;
                mButtonStyle     = button_style;
                mTitleStyle      = title_style;
                this.mSelections = new _IButton[texts.Length];

                // create a default button to see how big it is vertically
                // size and position border accordingly, factoring in width of largest button including title
                // destroy that button
                // create all the proper buttons in the right spot
                // create title 'button' as disabled button
                XUI xui_inst = XUI.Instance();

                _IButton test          = xui_inst._CreateRectangularButton(Vector2.Zero, "Test", style);
                xAABB2   button_size   = test.GetAABB();
                float    button_size_y = button_size.GetSize().Y;

                xui_inst._DestroyButton(test);

                const float k_border_padding_scalar = 0.5f;
                float       border_padding          = k_border_padding_scalar * button_size_y;

                const float k_spacing_scalar = 0.2f;
                float       spacing          = k_spacing_scalar * button_size_y;

                // pad out the text strings so the buttons can be wide if the text is small
                int longest = GetLongestString(texts);

                PadButtonTexts(texts, longest);

                // create buttons
                PositionAndCreateButtons(texts, mSelections, border_padding, spacing, button_size_y, button_style, 0);

                // track largest
                float largest_x = GetWidest(mSelections);

                // create title button (non-functional) and see if it's the largest
                Vector2 title_pos = mPos + new Vector2(border_padding, border_padding);

                mTitleButton = xui_inst._CreateRectangularButton(title_pos, title, title_style);
                mTitleButton.SetActive(false);
                largest_x = Math.Max(largest_x, mTitleButton.GetAABB().GetSize().X);

                // calculate aabb
                const float title_padding_scalar = 4.0f;
                float       title_padding        = border_padding * title_padding_scalar;
                Vector2     title_padding_v      = new Vector2(0, title_padding);
                float       full_width           = largest_x + 2 * border_padding;

                float full_height = button_size_y * (mSelections.Length) +
                                    (mSelections.Length - 1) * spacing +
                                    2 * border_padding +
                                    title_padding;

                mAABB.Set(mPos, mPos + new Vector2(full_width, full_height));

                // translate each button to be centered, and account for title
                CenterButtons(mSelections, largest_x, title_padding);
                CenterButton(mTitleButton, largest_x, 0);

                // if the selector has a non-trivial Position, fix it
                if (mPosition.IsCentered())
                {
                    // see where it is now, figure out where it should be, translate.
                    // apply to aabb for selector plus translate all the buttons
                    xCoord  screen_dim     = XRenderManager.Instance().GetScreenDim();
                    Vector2 span           = mAABB.GetSize();
                    Vector2 screen_dim_vec = new Vector2(screen_dim.x, screen_dim.y);
                    Vector2 edge           = 0.5f * (screen_dim_vec - span);
                    Translate(edge);
                }
            }
コード例 #18
0
 public void InitWidget(Widget parent, Style style, xAABB2 relative_aabb)
 {
     InitWidgetCommon(style);
     mPosition = new Position(parent, relative_aabb);
 }
コード例 #19
0
ファイル: panel.cs プロジェクト: barronds/XNARTS
 public void InitPanel(Widget parent, Style style, xAABB2 relative_aabb)
 {
     Init();
     InitWidget(parent, style, relative_aabb);
 }