I have been working on a 3d rendering project as code. I am a bit stumped on the math though. I know how to render points using arctangent on an HTML canvas using JavaScript, like this:
function Gen(x,y,z){
xs = Math.sin(Math.atan(z/x)) * pix_rate; /*x, y and z are inputs;
xs and ys are screen coords;
pix_rate: coefficient to scale up xs or ys
to fit on screen from screen.width/Math.sin(fov)*/
ys = Math.sin(Math.atan(y/x)) * pix_rate;
return {"x":xs, "y":ys}; //What is given back to the function call
}
I also have figured out how to account for the eye position, which I just subtract from each coordinate before I do those calculations.
What I cannot figure out is how to factor in the two different planes of directions the eye can be facing (azimuth and elevation). I have used a number of different methods that all have the same result. Also, is my math redundant? Thanks. This is not homework by the way, and I am in 8th grade, so apologies if I got something wrong.