# 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.

## 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.

1. 1
2. 2
Rutin
19
3. 3
khawk
19
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633771
• Total Posts
3013761
×

## Important Information

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!