What math libs are you talking about anyway? Do you even know what your
talking about? What source code have you examined to base your comments off
of? I’ve looked over Wolfenstein, Doom, and a few other (true 3d) engines
and the math fits the algorithms pretty tightly… obviously you never
written an application that umm has to redraw 60 times per second. Its still
about speed, and clever design.
Programming is an exercise of caching, who said that? You use the ANSI C
math library to create all your lookup tables, and you use standard C or C++
operators like ‘*’ or ‘+’ to actually do the math. Sure people write
routines to do matrix operations, or vector calculations, or point in
polygon tests or whatever, but again your missing the big picture – those
routines are specific for the data structure at hand. There are so many ways
to approach a problem a math lib would only get in the way. At least the one
your describing, or think your describing, because your not writing it
anyway. The routines to do math fit closely with the data structure at hand,
it has to be if your writing a software rasterizer. And if your doing
hardware based, then no math library helps with the math because most of
that is handled with OpenGL!! So are you talking about a math library
specifically for the data structures that would be optimal for pairing
OpenGL and a software rasterizer? Of course not, because it has to be
"slashdot" perfection it must work with everything and every approach and be
GNU at the same time! what??
So what are you talking about? Are you talking about writing games, because
that is what SDL is for, at least until or if it has windowing support or a
competely functional GUI. Or are you just talking for the sake of talking?
Why dont we here from the person who actually is going to program it. He
doesn’t need a defense attorney, you might be saying stuff that totally is
opposite of his intentions. Just because people on this list cant keep their
mouth shut.
769 messages in less than a month…grr…
I guess you need some code
;-------------------
;
; xpartialbyystep
;
; multiplies long [ystep] (possibly negative), by word [xpartial] (in BX)
;
; returns dx:ax
; trashes bx,cx,di
;
;-------------------
PROC xpartialbyystep NEAR
;
; setup
;
mov ax,[WORD ystep]
mov cx,[WORD ystep+2]
or cx,cx ; is ystep negatice?
jns @@multpos
;
; multiply negative cx:ax by bx
;
neg cx
neg ax
sbb cx,0
mul bx ; fractionfraction
mov di,dx ; di is low word of result
mov ax,cx ;
mul bx ; unitsfraction
add ax,di
adc dx,0
neg dx
neg ax
sbb dx,0
ret
;
; multiply positive cx:ax by bx
;
EVEN
@@multpos:
mul bx ; fractionfraction
mov di,dx ; di is low word of result
mov ax,cx ;
mul bx ; unitsfraction
add ax,di
adc dx,0
ret
ENDP
Alright… here is a piece of code from Wolfenstein from (WL_DR_A.asm).
Granted this is old code not updated for 386+ processors here, but i’m
trying to make a point… Notice how he only uses four multiplies to
calculate the initial starting (x, y) position on the grid for vertical
intersection testing? Now, notice what he does here, that the math portion,
the fixed point is highly optimized for the algorithm. Obviously only
Carmack is aware of how the fixed point relates to this. A library wouldn’t
know where the possibilities of overflow could occur… if it (a library)
stored the decimal offset as memory then it would have to reference and
compare it in order to
determine how to shift, or use self-modifying code. Both makes assumptions
that only the person implementing the code should make. In an related
example, if world coordinates of a tile-based world take up 16-bits, or
65536 x 65536, an algorithm must accomodate that. More specifically, you
couldn’t use a 16.16 tangent table and divide a world coordinate by a
tangent entry, because the resulting shift necessary on the world coordinate
would cause an overflow. I’m really rusty on my x86 asm, I promise I’ll try
to give a better explanation in the future.
Anyway, He has to know about the 16.16 fixed point and work around the
limitations.
Heh, not using 32-bit registers back then (circa 1992). You think he’s
resorting to asm because of deadlines? No, obviously the math is used for
speed. And the stuff he is getting is from lookup tables, more specifically
precalculated tangent lookup tables. Stuff that a math library couldnt hope
to do, because lookup tables must be accomodating to algorithms.
And back to modern times… even if it is purely floating point, then there
are other problems… like caching issues (fitting certain portions of code
in L1 cache) . In games, math that needs the optimization is the same
math that is tied in closely with the algorithms used, usually inside
rendering
routines. The ANSI C math library generates great lookup point tables.
Yippe.
I only say all this because you really are annoying me. I’m sure a math
library would be useful for CAD and other stuff, or maybe even for a game. I
gave an opinion and the specific reasons why, for the hope he could overcome
those OR perhaps think about some practical limitations while designing it.
It isnt necessary to argue for the sake of arguing, for this list has
already spirled out of control. Next time when I make a suggestion I will
attach code to specify what i’m trying to say. Perhaps then it will have
more weight, or else make me look more foolish. Whatever
Matt
Of course. I’m talking about low level 1D array operations, rather than 3D
and 4D matrix operations. 3D matrix operations isn’t all there is to math
libs, even for 3D. (Well, maybe it is in some 3D maths libs, but then
they’re> really a very specialized kind of array based math libs.)
//David