c# - How to get an angle between a direction faced and a point in 3D space -
the information have vertical angle of player's vision, horizontal angle point in question, distance point , point's vertical height.
i've figured out how angle if player isn't looking or down (vertical angle) using following.
float getvisionangle(float anglehoriz, float anglevert, float distance, float height) { double = math.cos(anglehoriz * (math.pi / 180)) * distance); double hypotenuse = math.sqrt(distance * distance + height * height); return (float)(math.acos(a / hypotenuse) * (180 / math.pi)); } 
what can't figure out how angle if player's vision direction modified vertical angle (looking or down). i've been mulling on in head few days , can't figure out way it.
what i'm using generate vision cone cutoff. when object checked visibility, information have work angle of object player, distance object, , height. initial range check return angle player's direction of vision , determine whether object visible or not.

here shot of code in debug using solution provided @habo unfortunately, results in nan error.

converting angles radians before using them seems fix lot of numerical errors. don't understand formula @ end converts previous numbers final angle though. 
ah = angle in horizontal plane between line of sight (los) , object. (anglehoriz) av = angle in vertical plane of los. (anglevert) d = distance object in horizontal plane. (distance) h = height of object above horizontal plane. (height) = distance origin object. = sqrt( d * d + h * h ) oh = horizontal offset los object @ base of wall. = sin( ah ) * d dh = horizontal distance origin wall. = cos( ah ) * d hlos = height @ los intersects wall. = tan( av ) * dh dlos = distance observer los @ wall. = sqrt( dh * dh + hlos * hlos ) dw = distance along wall between line of sight , object. = sqrt( oh * oh + ( h - hlos ) * ( h - hlos ) ) answer = acos( ( dlos * dlos + * - dw * dw ) / ( 2 * dlos * ) )
Comments
Post a Comment