Trig accuracy issues (and a possible solution)

A project log for Arduino Graphics Card

Advanced graphics for anything from homebrew computers to weather reporting boxes and everything that can communicate over 3.3-5v UART.

Dylan BrophyDylan Brophy 02/27/2018 at 06:422 Comments

The cube I had been rendering did not calculate for camera pitch/yaw, so if it was a 3d game you would only be able to look in the +X direction.  I added some math to fix that, but then I got another problem.

I wasn't using floating point numbers, and I was using a homemade arctan table which, sadly, may have been less than accurate.  The cube jumped around the screen and was recognisable only most of the time.

I was using propeller spin language, and used fixed-point arithmatic.  I think its time I used c++.  We shall see how it goes!


Ted Yapo wrote 03/10/2018 at 14:17 point

You don't really need arctan at all.

You can do the whole rendering pipeline with just sin and cos, and those can be computed very efficiently (and simultaneously).  Of course, you also need addition, multiplication, and one division for the perspective projection.  Using homogeneous coordinates really simplifies things, too.

The OpenGL transformation model is good to check out if you haven't seen it, and can look past FORTRAN-style column-major arrays :-)

  Are you sure? yes | no

Dylan Brophy wrote 03/10/2018 at 19:40 point

Thanks!  I actually figured it out.  i used the trig identity for tan(a+b), then I figured out that I could rotate the world around the camera and that made it work :D

  Are you sure? yes | no