I'm mapping/modding mostly in old game named Doom 2, but in port, while scripting i encountered a problem with angles in 3D world. screenshot of model with this problem. Note: Red points are the real and correct normal angles, and the Arrows are my attempt to convert these real 3D angles to doom's angle and pitch but failed and only facing up or down but not right or left... For example i have here a MD3/Model/3D Model of some object and i wanted to show his mesh's vertices normals to point where exactly they facing (normal's real correct angle). But i've only managed (probably) to get only a Pitch Angle (or Z angle), by "Angle" i meant when it rotates 360 degrees to left or right, There is also "Roll" Angle in game but i don't think its important.
What i was trying to do is to convert from Real 3D Angle to Doom's Angle and Pitch, but i don't know anything mostly in trigonometry and it's formulas... I think its very easy for who knows in these things.
NOTE: real 3D angle values are from -1 to 1 float. doom's angle are from 0 to 360 float, and pitch from -90 to 90 float.
Here is my code of converting to doom's angle and pitch (up and down, left or right angles):
vector3 ConvertAngletoDoomAngle(vector3 ang) {
return (
0, //angle (this one i have problem with, i want to make arrows turn correctly left and right)
0, //roll (this is not important and i bet it's harder to get...)
90 * ang.z //pitch (where arrows points down and up was looking kinda correct...)
);
}
i think there are "cos" and "sin" needed to convert angle to 2D angle... i dont know :( goal: these arrows must be facing to red points.
I think what you are given is the surface normal vector n, the components of describe the direction of the vector in terms of a cartesian coordinate system xyz.
and you want to find the azimuth angle φ about the xz plane, and the inclination ψ above the xz plane.
These are described first as a rotation about the y axis and then a rotation about the rotated z' axis
This sequence results in
nx = cos(φ)
ny = sin(φ)*sin(ψ)
nz =-sin(φ)*cos(ψ)
The way to reverse the process and find the angles is as follows
φ = atan2(-nz, sqrt(nx^2+ny^2))
ψ = atan(ny/nx)
where atan2(dy,dx)
is the full quadrant arc tangent function, and atan(r)
is standard arc tangent function.