private void CalcProjectionMatrix() { Vector2 min = mWorldView.GetMin(); Vector2 max = mWorldView.GetMax(); // left, right, bottom, top, near, far float left = min.X; float right = max.X; float top = min.Y; float bottom = max.Y; const float near = 1; const float far = -1; mProjectionMatrix = Matrix.CreateOrthographicOffCenter(left, right, bottom, top, near, far); }
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)); }
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); }
void _IButton.Draw(XSimpleDraw simple_draw) { // draw border and background, then draw core Vector3 lo = new Vector3(mAABB.GetMin(), 2); // zero might not be right z Vector3 hi = new Vector3(mAABB.GetMax(), 2); Color body_color = mButtonCore.mPressed ? mButtonCore.mPressedColor : mButtonCore.mStyle.mBackgroundColor; Color border_color = mButtonCore.mStyle.mBorderColor; simple_draw.DrawQuad(lo, hi, body_color); simple_draw.DrawLine(lo, mCorner2, border_color); simple_draw.DrawLine(mCorner2, hi, border_color); simple_draw.DrawLine(hi, mCorner3, border_color); simple_draw.DrawLine(mCorner3, lo, border_color); mButtonCore.Draw(simple_draw); }
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); } }
void _ISelector.Draw(XSimpleDraw simple_draw) { if (mRenderEnabled) { // draw the title and background, buttons will draw themselves Style style = XUI.Instance().GetStyle(mStyle); Color widget_color = style.mBackgroundColor; Color border_color = style.mBorderColor; Vector3 lo_x_lo_y = new Vector3(mAABB.GetMin(), 1); Vector3 hi_x_hi_y = new Vector3(mAABB.GetMax(), 1); Vector2 size = mAABB.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, widget_color); simple_draw.DrawLine(lo_x_lo_y, hi_x_lo_y, border_color); simple_draw.DrawLine(hi_x_lo_y, hi_x_hi_y, border_color); simple_draw.DrawLine(hi_x_hi_y, lo_x_hi_y, border_color); simple_draw.DrawLine(lo_x_hi_y, lo_x_lo_y, border_color); } }
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())); } }
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))); }