program made by noob
Posted: Sat Aug 04, 2007 6:03 pm
I just thought this was really funny.
I just started using qbasic, and I'm working with 3-D rotations. So I figured I try to make the program myself before copying the turtorial's example. Look what I came out with:
**********************************************************
DIM c!(360), s!(360)
DIM SHARED x(4), y(4), z(4)
DIM x2(4), y2(4), z2(4)
DIM x3(4), y3(4)
FOR i = 1 TO 360
c!(i) = COS(i * 3.14 / 180)
s!(i) = SIN(i * 3.14 / 180)
NEXT
x(1) = 50
y(1) = 50
z(1) = 25
x(2) = 50
y(2) = 50
z(2) = -25
x(1) = 50
y(1) = 50
z(1) = 25
x(2) = 50
y(2) = 50
z(2) = -25
xcenter = 150
ycenter = 100
zcenter = 256
phi = 1
theta = 1
SCREEN 7, 0, 1, 0
DO
keyed$ = INKEY$
FOR i = 1 TO 4
x2(i) = -x(i) * s!(theta) + y(i) * c!(theta) 'controls horizontal rotation
y2(i) = -x(i) * c!(theta) * s!(phi) - y(i) * s!(theta) * s!(phi) - z(i) * c!(phi) + p 'controls vertical rotation
z2(i) = -x(i) * c!(theta) * c!(phi) - y(i) * s!(theta) * c!(phi) - z(i) 'controls distance from points
NEXT
FOR i = 1 TO 4
x3(i) = 256 * (x2(i) / (z2(i) + zcenter)) + xcenter 'controls horizontal rotation
y3(i) = 256 * (y2(i) / (z2(i) + zcenter)) + ycenter 'controls vertical rotation
NEXT
CLS
FOR i = 1 TO 4
PSET (x3(i), y3(i)), 1
NEXT
FOR i = 1 TO 3
LINE (x3(i), y3(i))-(x3(i + 1), y3(i + 1)), 15
LINE (x3(i), y3(i))-(x3(i - 1), y3(i - 1)), 15
NEXT
PCOPY 1, 0
phi = phi + 1
theta = theta + 1
IF phi > 360 THEN phi = phi - 360
IF theta > 360 THEN theta = theta - 360
LOOP UNTIL keyed$ = CHR$(27)
********************************************************
The funny thing is that it's supposed to be a square revolving around the center!
LOL!
In the end I had to use the example. :S
I just started using qbasic, and I'm working with 3-D rotations. So I figured I try to make the program myself before copying the turtorial's example. Look what I came out with:
**********************************************************
DIM c!(360), s!(360)
DIM SHARED x(4), y(4), z(4)
DIM x2(4), y2(4), z2(4)
DIM x3(4), y3(4)
FOR i = 1 TO 360
c!(i) = COS(i * 3.14 / 180)
s!(i) = SIN(i * 3.14 / 180)
NEXT
x(1) = 50
y(1) = 50
z(1) = 25
x(2) = 50
y(2) = 50
z(2) = -25
x(1) = 50
y(1) = 50
z(1) = 25
x(2) = 50
y(2) = 50
z(2) = -25
xcenter = 150
ycenter = 100
zcenter = 256
phi = 1
theta = 1
SCREEN 7, 0, 1, 0
DO
keyed$ = INKEY$
FOR i = 1 TO 4
x2(i) = -x(i) * s!(theta) + y(i) * c!(theta) 'controls horizontal rotation
y2(i) = -x(i) * c!(theta) * s!(phi) - y(i) * s!(theta) * s!(phi) - z(i) * c!(phi) + p 'controls vertical rotation
z2(i) = -x(i) * c!(theta) * c!(phi) - y(i) * s!(theta) * c!(phi) - z(i) 'controls distance from points
NEXT
FOR i = 1 TO 4
x3(i) = 256 * (x2(i) / (z2(i) + zcenter)) + xcenter 'controls horizontal rotation
y3(i) = 256 * (y2(i) / (z2(i) + zcenter)) + ycenter 'controls vertical rotation
NEXT
CLS
FOR i = 1 TO 4
PSET (x3(i), y3(i)), 1
NEXT
FOR i = 1 TO 3
LINE (x3(i), y3(i))-(x3(i + 1), y3(i + 1)), 15
LINE (x3(i), y3(i))-(x3(i - 1), y3(i - 1)), 15
NEXT
PCOPY 1, 0
phi = phi + 1
theta = theta + 1
IF phi > 360 THEN phi = phi - 360
IF theta > 360 THEN theta = theta - 360
LOOP UNTIL keyed$ = CHR$(27)
********************************************************
The funny thing is that it's supposed to be a square revolving around the center!
LOL!
In the end I had to use the example. :S