views:

96

answers:

2

Here is my issue. I'm rendering axis alligned cubes that are all the same size. I created an algorithm that rendered around the player like this:

******
******
***p**
******
******

While this does work, the player does not see this whole radius. I know the player's rotation angle on the Y, so I was hoping to modify my algorithm based on this so that it would only render about, what the player can see more or less.

SetPlayerPosition();
float yrotrad;
yrotrad = (Camera.roty / 180 * 3.141592654f);




PlayerPosition.x += 70 * float(sin(yrotrad));
PlayerPosition.y -= 20;
PlayerPosition.z += 70 * -(float(cos(yrotrad)));

collids.clear();
for(int i = 0; i < 135; ++i)
{
 for(int j = 0; j < 50; ++j)
 {
  for(int k = 0; k < 135; ++k)
  {
   if(!CubeIsEmpty(PlayerPosition.x + i, PlayerPosition.y + j, PlayerPosition.z + k))
   {
    collids.push_back(GetCube(PlayerPosition.x + i, PlayerPosition.y + j, PlayerPosition.z + k));
   }
  }
 }
}

Basically, my original algorithm would just subtract 70 from the players location, and render the square that is 70 in size. So I tried to multiply these by the sin and cos os the Y rotation but it did not work. I'm sure this is possible, I just think i'm missing something. How could I achieve my goal of only rendering ~what the player sees.

Thanks

Just as a note, I tried frustrum culling and this got too slow, I'd rather this which works no matter how many cubes I have

instead of rendering the above id like it to only, ex if the player is facing ->

...... ****
...... ****
......P****
...... ****
A: 

After looking at your code again, maybe this is your problem:

PlayerPosition.x += 70.0f * float(sin(yrotrad));
PlayerPosition.y -= 20;
PlayerPosition.z += 70.0f * -(float(cos(yrotrad)));

and what types are the coordinates?

DominicMcDonnell
the coordinates are in Cubes, not camera coords, that might be the issue, a cube is 3.5 units in size
Milo
@Milo: So ints, which will be fine, but notice that I changed the 70 to 70.0f, which will force the multiplication to happen as a float, and therefore not throw away the sin and cos, which will be < 1
DominicMcDonnell
still though its not doing what i intended, it renders only what the player sees at angle 0 but if I for example rotate the player 180 degrees, I see nothing
Milo
@Milo: put a break point in and check the value of Camera.roty. PS, if you put @DominicMcDonnell I'll get informed of your comment
DominicMcDonnell
A: 

I don't quite understand your code ( 70 ? CubeIsEmpty ?) but if Cube-frustum is too slow, you could try sphere-frustum.

http://www.chadvernon.com/blog/resources/directx9/frustum-culling/

Calvin1602