I have not used Freebasic for roughly 8 years and recently picked it up again. To my understanding (which could be horribly wrong) the compiler should be able to handle self referencing variables as in: x = (x +1) , x = (x +y) / x.
I wanted to make a doodle ( code sketch for fun) around a very simple CPU based 3D pixel plotter but all my attempts failed horribly each time I wanted to expand it beyond the simplest of basics. After a long search and 3 new versions of the code i came to the conclusion that variables or arrays which reference their own self while altering their own self cause them to contain completely different data than intended.
The code bellow was written to test it on my machine. Every Sub generate a different result on my machine:
Code: Select all
#define D_PI 3.141592654#
#define D_PI180 (D_PI / 2)
#define D_TABLESIZE 359
dim shared as single costable(D_TABLESIZE)
dim shared as single sintable(D_TABLESIZE)
dim as integer anglemod
for i as integer = 0 to 359
sintable(i) = sin( i * D_PI180)
costable(i) = cos( i * D_PI180)
next i
sub TheXA (x as integer, y as integer, z as integer, xangle as integer, yangle as integer, zangle as integer)
DIM AS INTEGER NewX, NewY, NewZ
NewY = y * cos(XAngle * (D_PI / 180)) - z * sin(XAngle * (D_PI / 180))
NewZ = z * cos(XAngle * (D_PI / 180)) + Y * sin(XAngle * (D_PI / 180))
locate 4,1
print "newY : "; NewY
print "NewZ : "; NewZ
end sub
sub TheXB (x as integer, y as integer, z as integer, xangle as integer, yangle as integer, zangle as integer)
y = y * costable(xangle) - z * sintable(xangle)
z = z * costable(xangle) + y * sintable(xangle)
locate 8,1
print "TestY : "; y
print "TestZ : "; z
end sub
sub TheXC (x as integer, y as integer, z as integer, xangle as integer, yangle as integer, zangle as integer)
y = y * cos(XAngle * (D_PI / 180)) - z * sin(XAngle * (D_PI / 180))
z = z * cos(XAngle * (D_PI / 180)) + y * sin(XAngle * (D_PI / 180))
locate 12,1
print "TestY2 : "; y
print "TestZ2 : "; z
end sub
screenres (800,600, 32)
do while not multikey(&h01)
anglemod = (anglemod +1) mod 360
TheXA (50, 50, 50, anglemod, anglemod, anglemod)
TheXB (50, 50, 50, anglemod, anglemod, anglemod)
TheXC (50, 50, 50, anglemod, anglemod, anglemod)
sleep 100
loop