Multiple times in the past, I've tried to make a 3D engine for the heck of it because my 3D skills are nonexistent, and with every engine I make, my knowledge increases. Well, I've come quite far with this one but I'm puzzled on how to fix this bug I've been having with rotation.
This is part of my function TurnCamera, and is the portion which handles pitch. X is the angle it needs to turn, and v.x, v.y, and v.z are the coordinates of each vertex.
I'm having two problems. First, when using ATan(v.y/v.z), v.z is often zero, leaving me with NaN. That is why it does a check for if v.z is zero and determines the angle based on y if so. But the algorithm doesn't work anyway. What is wrong with my equation?
'pitch If x<>0 If v.z=0 If v.y>0 angle=90 Else angle=270 EndIf If v.z<>0 angle=ATan(v.y/v.z)+x dist=Distance2D(v.z,v.y,0,0) v.z=Cos(angle)*dist v.y=Sin(angle)*dist End If
This is part of my function TurnCamera, and is the portion which handles pitch. X is the angle it needs to turn, and v.x, v.y, and v.z are the coordinates of each vertex.
I'm having two problems. First, when using ATan(v.y/v.z), v.z is often zero, leaving me with NaN. That is why it does a check for if v.z is zero and determines the angle based on y if so. But the algorithm doesn't work anyway. What is wrong with my equation?