Math: vertical viewing angle - Printable Version + open.mp forum (https://forum.open.mp) -- Forum: General (https://forum.open.mp/forumdisplay.php?fid=19) --- Forum: Programming (https://forum.open.mp/forumdisplay.php?fid=56) --- Thread: Math: vertical viewing angle (/showthread.php?tid=721) |
Math: vertical viewing angle - Freaksken - 2019-07-15 I have a system in which I've worked out the code for giving an NPC a horizontal viewing angle (left image). How would I achieve a similar result, but now for the vertical direction (right image)? Below is the code for the left image, for reference. This is a math question, thus the code isn't really necessary, but might help you understand the problem. Just ignore that the angles start from the NPC's center instead of his eyes, that's easy enough to fix. As you can see, the z-position is irrelevant for the horizontal viewing angle, but probably not for the vertical viewing angle (not sure). PHP Code: static bool:FAI_IsPlayerInAggroViewingAngle(playerid, npcid) { Here's another visualisation of what the result should look like: RE: Math: vertical viewing angle - hiddos - 2019-07-15 An alternative way of doing both of these together is through some vector calculations. You want to essentially do step 3 of the image below: Some rough code (that I didn't test for accuracy) would look like: PHP Code: new?Float:xn,?Float:yn,?Float:zn; RE: Math: vertical viewing angle - Freaksken - 2019-07-15 An idea I had myself, was to (imagining) a rotation of the coordinate system around the y-axis, so that the same code I gave could work with now x = z and y = y. However, that doesn't seem to work when the NPC has any other rotation than 0.0 degrees. RE: Math: vertical viewing angle - hiddos - 2019-07-16 Something I overlooked in my answer: getting the absolute value of the angle is not necessary as the range out arccos is [0-180] (or [0-pi]). As such I've edited the post RE: Math: vertical viewing angle - Freaksken - 2019-08-15 I brushed up on my maths knowledge and now understand your solution (and how simple it actually is). Thnx again! |