Just in case anyone finds this interesting or would like to make suggestions:
Before trying to implement texture mapping, I decided to try lighting support.
For that I need to calculate each triangle's normal vector, to find out if it is facing towards the light.
This requires a bit of math: inverseLength = 1 / sqrt(x * x + y * y + z * z)
All of the code so far has been using 23.8 fixed-point math, and while the formula above can be implemented without floats, it'd be much slower.
Of course, we can't use math.h in compiledC code, so this is where the fun begins:
(quotes and newlines omitted for clarity. It would've been nice if we could use raw string literals for inline assembly)
Unfortunately that doesn't work either because gcc really doesn't want to work with floats. To get around that, I assembled that function locally and replaced each instruction with the result as data:
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Just in case anyone finds this interesting or would like to make suggestions:
Before trying to implement texture mapping, I decided to try lighting support.
For that I need to calculate each triangle's normal vector, to find out if it is facing towards the light.
This requires a bit of math:
inverseLength = 1 / sqrt(x * x + y * y + z * z)
All of the code so far has been using 23.8 fixed-point math, and while the formula above can be implemented without floats, it'd be much slower.
Of course, we can't use math.h in compiledC code, so this is where the fun begins:
(quotes and newlines omitted for clarity. It would've been nice if we could use raw string literals for inline assembly)
Unfortunately that doesn't work either because gcc really doesn't want to work with floats. To get around that, I assembled that function locally and replaced each instruction with the result as data:
The result of this abomination is attached below.
1 Attachment