I'm doing 3d maze in opengl, 2d like collisions
Map is defined like 2dim array
---------x axis
|0 0 0
|0 1 0
|0 0 0
|
|z axis
that 1 is a cube
I divide that cube to 4 cubes
.
_ _
|_|_|
|_|_|
dot is my camera point with x, z coords now I go down to my cube. posX,Z is calculated like this but its not important, but so you know how it works, here
posZ -= (float) ((Math.cos(azimut * Math.PI / 180) * Math.cos(zenit * Math.PI / 180))) / 50;
posX += (float) ((Math.sin(azimut * Math.PI / 180) * Math.cos(zenit * Math.PI / 180))) / 50;
Its calculated every milisec or sth in display() method.. I cast it to int so i have the right coord for my array and save it to newX,Z
newposZ = (int) posZ;
newposX = (int) posX;
if (maze[newposZ][newposX] == 1) {
I check by azimuth where from I'm coming.. like this (this is the dot position in pic above going in top left cube azimuth is 180 if facing wall straight but i wanna check from 90 to 270..)
if (posX - newposX < 0.5 && posZ - newposZ < 0.5 && (azimut > 90 && azimut < 270) {
posZ = newposZ;
}
And yea I change posZ which is lets say 1.1 to casted newposZ which is say 1 so everything is all right Camera hits the wall, but that azimuth checking is a bad idea, because in next step where I check coming to same minicube, but from left like this
if (posX - newposX < 0.5 && posZ - newposZ < 0.5 && (azimut > 0 && azimut > 180) {
posX = newposX;
}
It's bad because at some angle (angle 90 to 180 because its same for both..) it sets both posX and posZ in the same time to newposX, newposZ.. one of that variables is fixed right but other shouldn't be if you know what I mean
It works ok if I check only from -45 to 45degree but i wanna from -90 do +90 anyone can help?