Wow, no one? No other alternative to get a true angle other than ACos? Ugh...
I'm not sure if I'm posting this in the right place (this is my first post) but I figured I'd give it a shot.
I'm working on a project in a 3d engine involving a tank running around a landscape and shooting. The turret of the tank can rotated 360 degrees and the barrel can have its elevation angle set anywhere from 0 to 90 degrees.
What I needed to do was ensure that the elevation of barrel took into account the angle of the tank itself, as it would be travelling up and down hills.
In the end, here's what I did to figure out the actual elevation angle of the barrel (taking into consideration what the user had set for the barrel elevation as well as the angle of the tank itself).
BarrelVector = VNormalize(VSubtract(BaseOfBarrel, EndOfBarrel))
PlaneVector = VNormalize(VSbutract(BaseOfBarrel, EndOfBarrelWithYSetToBase))
DotProd = VDotProduct(BarrelVector,PlaneVector)
TrueElevation = ACos(DotProd)
Now, this returns an angle from 0 to 90 and therein lies my problem. If the barrel is pointed parrell to the Y plane, the angle is 0, no problem there. But if the barrel is pointed 10 degrees below the Y plane, the angle returned is 10, the same as it is when the barrel is 10 degrres above the Y plane. What I really need is the to return as -10. The same issue happens at the 90 degree angle, where an 80 degree and a 100 degree both return 80.
I know this is a result of the ACos function but I have no idea how to get around this. Any advice would be appreciated.