determining if value is in range with 0=360 degree problem.
Posted
by Raven
on Stack Overflow
See other posts from Stack Overflow
or by Raven
Published on 2010-06-13T10:24:54Z
Indexed on
2010/06/13
10:32 UTC
Read the original article
Hit count: 251
Hi, I am making a piece of code for DirectX app. It's meaning is to not show faces that are not visible. Normaly it would be just using Z-buffer, but I'm making many moves and rotations of mesh, so I would like to not do them and save computing power. I will describe this on cube. You are looking from the front so you see just one face and you don't need to rotate the 5 that left. If you would have one side of cube from 100*100 meshes, it would be great to not have to turn around 50k meshes that you really don't need. So I have stored X,Y,Z rotation of camera(the Z rotation I'm not using), and also X,Y,Z rotation of faces. In this cube simplified I would see faces that makes this statement true:
cRot //camera rotation in degrees
oRot //face rotation in degrees
if(oRot.x > cRot.x-90 && oRot.x < cRot.x+90
&& oRot.y > cRot.y-90 && oRot.y < cRot.y+90)
But there comes a problem. If I will rotate arround, the camera can get to value 330 for exapmple. In this state, I would see front and right side of cube. Right side have rotation 270 so that's allright in IF statement. Problem is with 0 rotation of front face, which is also 360 degrees.
So my question is how to make this statement to work, because when I use modulo, it will be failing for that right side and in this way it won't work for 0=360.
© Stack Overflow or respective owner