Permalink
Browse files

Merge pull request #819 from SickheadGames/PlaneIntersectFix

Ray-Plane intersect/WinRT ScreenSizeChange viewport fix
  • Loading branch information...
2 parents 39a485a + fe5e385 commit 66e6ee963942818d24776911cf53c909d6844224 @dellis1972 dellis1972 committed Oct 3, 2012
Showing with 21 additions and 5 deletions.
  1. +13 −2 MonoGame.Framework/Ray.cs
  2. +8 −3 MonoGame.Framework/Windows8/MetroGameWindow.cs
View
@@ -193,13 +193,24 @@ public void Intersects(ref BoundingBox box, out float? result)
public void Intersects(ref Plane plane, out float? result)
{
var den = Vector3.Dot(Direction, plane.Normal);
- if (Math.Abs(den) < 0.0001f)
+ if (Math.Abs(den) < 0.00001f)
{
result = null;
return;
}
- result = -Vector3.Dot(plane.Normal, Position) / den;
+ result = (-plane.D - Vector3.Dot(plane.Normal, Position)) / den;
+
+ if (result < 0.0f)
+ {
+ if (result < -0.00001f)
+ {
+ result = null;
+ return;
+ }
+
+ result = 0.0f;
+ }
}
public void Intersects(ref BoundingSphere sphere, out float? result)
@@ -197,10 +197,15 @@ private void Window_SizeChanged(CoreWindow sender, WindowSizeChangedEventArgs ar
// Set the new client bounds.
SetClientBounds(args.Size.Width, args.Size.Height);
- // Set the default new back buffer size, but this
+ // Set the default new back buffer size and viewport, but this
// can be overloaded by the two events below.
- manager.PreferredBackBufferWidth = (int)((_backBufferScale.X * _clientBounds.Width) + 0.5f);
- manager.PreferredBackBufferHeight = (int)((_backBufferScale.Y * _clientBounds.Height) + 0.5f);
+
+ var newWidth = (int)((_backBufferScale.X * _clientBounds.Width) + 0.5f);
+ var newHeight = (int)((_backBufferScale.Y * _clientBounds.Height) + 0.5f);
+ manager.PreferredBackBufferWidth = newWidth;
+ manager.PreferredBackBufferHeight = newHeight;
+
+ manager.GraphicsDevice.Viewport = new Viewport(0, 0, newWidth, newHeight);
// Set the new view state which will trigger the
// Game.ApplicationViewChanged event and signal

0 comments on commit 66e6ee9

Please sign in to comment.