I have a room with 4 walls along the x and z axis respectively. My player, who is in first person (therefore the camera), should have collision detection with these walls. I'm relatively new to this so please bare with me. I believe the way to do this is to calculate the direction and distance to the wall from the camera and then normalize the directions. However, I can only get this far before I don't know what to do. I think you should work out the angle and direction your facing?
Here _dx
and _dz
is the small buffer in front of the camera.
float CalcDirection(float Cam_x, float Cam_z, float Wall_x, float Wall_z)
{
//Calculate direction and distance to obstacle.
float ob_dirx = Cam_x + _dx - Wall_x;
float ob_dirz = Cam_z + _dz - Wall_z;
float ob_dist = sqrt(ob_dirx*ob_dirx + ob_dirz*ob_dirz);
//Normalise directions
float ob_norm = sqrt(ob_dirx*ob_dirx + ob_dirz*ob_dirz);
ob_dirx = (ob_dirx)/ob_norm;
ob_dirz = (ob_dirz)/ob_norm;
Can anyone explain in layman's terms how I work out the angle?