Jump to content
  • Advertisement
Sign in to follow this  
homer_3

XNA BoundingFrustum troubles

This topic is 2640 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a 2 player 2D game and I'm trying to find the distance each player is from their respective edges of the screen. I found out about the BoundingFrustrum object and it looks like it should be able to help me out. So I'm trying



BoundingFrustum bf = new BoundingFrustum(spriteBatchMatrix* Matrix.CreateOrthographic(graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height, -10, 100));
Vector3 dir = new Vector3(0,0,1);
Vector3 pos;
Ray ray;

Player left;
Player right;

int leftDist = 0;
int rightDist = 0;

//find which player is left and right
if (!player1.IsFlipped())
{
right = player2;
left = player1;
}
else
{
right = player1;
left = player2;
}

//find distance left player is from left edge of screen
pos = new Vector3(left.Position.X, left.Position.Y, 0);
ray = new Ray(pos, dir);
while (bf.Intersects(ray) != null)
{
ray.Position.X = ray.Position.X - 1;
leftDist++;
}

//find distance right player is from right edge of screen
pos = new Vector3(right.Position.X, right.Position.Y, 0);
ray = new Ray(pos, dir);
while (bf.Intersects(ray) != null)
{
ray.Position.X = ray.Position.X + 1;
rightDist++;
}


spriteBatchMatrix is the matrix I pass to SpriteBatch.Begin(). I'm not sure if this is the correct matrix. Probably not because leftDist and rightDist always end up as 0, even though my players' positions are in the view. I don't have any other matrices that effect my camera so I'm not sure how else I should generate the BoundingFrustum.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!