Quote:
See your point about the tables, but still concerned about big value multiplications: if you divide by 128 then you know exactly where the result will end in terms of binary digits after the decimal place. Obviously there's no such guarantee with dividing by 127. Would suggest that an 8.8 scheme for the lookup-table would be appropriate if sufficient memory is available.
The problem will be whether 128 discrete values representing the range of 0.0 to 1.0 inclusive is sufficient. The multiplication routine produces surprisingly accurate results, even for s15 * fixed127:
results accurate to within +/-1.0: 92%
results accurate to within +/-1.5: 99.5%
The lookup table already is 8.8 (i.e. each entry contains (x^2/4)/127, stored as an 8-bit integer part, and an 8-bit fractional part).
Quote:
Found it was much better to multiply 3x3s alone, work out offset as difference in global positions mapped forward once through the camera matrix (rather than, effectively, object position through composed matrix minus camera position through composed matrix).
Yeah, this is more or less what I proposed a little while ago I think... you transform model space coords through a unit 3x3 rotation matrix, and then add a global translation afterwards to get it into 15-bit coordinates. From an old post:
Code:
x' = x . LW . CW^-1
= (x . LWr + LWt) . (CWr + CWt)^-1
= (x . LWr + LWt) . CWr^-1 - CWt . CWr^-1
= x . (LWr . CWr^-1) + [(LWt - CWt) . CWr^-1]
^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
8-bit rotation 16-bit translation
This is in fact what the hardware of the original PlayStation did, and it worked well there! Is this the sort of thing you mean?
Look forward to seeing if this works ok or not... The nice thing about the fixed127s being only one byte in size is that they hugely simplify a matrix multiply, e.g.
Code:
; multiply X component
LDX vec+0:LDY matrix+0:JSR S8_x_Fixed
STA vecresult+0
LDX vec+1:LDY matrix+3:JSR S8_x_Fixed
CLC:ADC vecresult+0:STA vecresult+0
LDX vec+2:LDY matrix+6:JSR S8_x_Fixed
CLC:ADC vecresult+0:STA vecresult+0
; similar for the other two components
In the case where two fixed127s are multiplied, it'd perhaps be necessary to put in some extra checks to clamp the results of the adds to +/-1.0. Also, at a speed cost, it'd be possible to make the S8_x_Fixed multiply routine a little more accurate, which might also be necessary when composing matrices. We'll have to see...
Enjoy your holiday!