Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple overflow error!
#1
Hi!
I'm learning 3D rotating, but I have a litle trouble with my code! I get Overflow all the time, but I can't seem to understand why!! Here is the code:
Code:
SCREEN 12
DIM c!(360), s!(360)
points = 7
theta = 1
phi = 1
DIM x(points), y(points), z(points), new.x(points), new.y(points), z2(points), x2(points), y2(points)

FOR angle = 1 TO 360
c!(angle) = COS(angle * 3.14 / 180)
s!(angle) = SIN(angle * 3.14 / 180)
NEXT

x.center = 150
y.center = 150
z.center = 265

FOR i = 0 TO points
   READ x(i)
   READ y(i)
   READ z(i)
NEXT

   DO
        FOR i = 0 TO points
x2(i) = -x(i) * s!(theta) + y(i) * c!(theta)
y2(i) = -x(i) * c!(theta) * s!(phi) - y(i) * s!(theta) * s!(phi) - z(i) * c!(phi)
z2(i) = -x(i) * c!(theta) * c!(phi) - y(i) * s!(theta) * c!(phi) + z(i) * s!(phi)
new.x(i) = 256 * (x2(i) / (z2(i) + zcenter)) + xcenter
new.y(i) = 256 * (y2(i) / (z2(i) + zcenter)) + ycenter

     theta = theta + 1
     phi = phi + 1
     IF theta = 360 THEN theta = 0
     IF phi = 360 THEN phi = 0
        NEXT
   LOOP UNTIL INKEY$ = CHR$(27)

DATA 50,50,-50
DATA -50,-50,-50
DATA -50,50,-50
DATA 50,-50,-50

DATA 50,50,50
DATA -50,-50,50
DATA -50,50,50
DATA 50,-50,50
Please help me! Thank you!
Reply
#2
Don't know much about 3D, but what line are you getting the error on? That would help me answer your question better..
quote="na_th_an"]
Greenday, Spice Girls... Can you tell the difference?
[/quote]
Reply
#3
You dimmed your c! and s! with '360'. That means those arrays goes from 0 to 359. But in the for loop below the iterator goes from 1 to 360.
So I think you should do this:
Code:
DIM c!(1 TO 360), s!(1 TO 360)
B 4 EVER
Reply
#4
Quote:You dimmed your c! and s! with '360'. That means those arrays goes from 0 to 359. But in the for loop below the iterator goes from 1 to 360.
So I think you should do this:
Code:
DIM c!(1 TO 360), s!(1 TO 360)

Nope, dimming to 360 makes its range from 0 to 360. Not well coded, but that's not the problem.

Where do you EXACTLY get the overflow?
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#5
oups...forgot that,..., but anyway...I tested your code and got it.
It's just a typo.
Here's the right code:
Code:
SCREEN 12
DIM c!(360), s!(360)
points = 7
theta = 1
phi = 1
DIM x(points), y(points), z(points), new.x(points), new.y(points), z2(points), x2(points), y2(points)

FOR angle = 1 TO 360
c!(angle) = COS(angle * 3.14 / 180)
s!(angle) = SIN(angle * 3.14 / 180)
NEXT

x.center = 150
y.center = 150
z.center = 265

FOR i = 0 TO points
READ x(i)
READ y(i)
READ z(i)
NEXT

DO
FOR i = 0 TO points
  x2(i) = -x(i) * s!(theta) + y(i) * c!(theta)
  y2(i) = -x(i) * c!(theta) * s!(phi) - y(i) * s!(theta) * s!(phi) - z(i) * c!(phi)
  z2(i) = -x(i) * c!(theta) * c!(phi) - y(i) * s!(theta) * c!(phi) + z(i) * s!(phi)
  new.x(i) = 256 * (x2(i) / (z2(i) + z.center)) + x.center
  new.y(i) = 256 * (y2(i) / (z2(i) + z.center)) + y.center

  theta = theta + 1
  phi = phi + 1
  IF theta = 360 THEN theta = 0
  IF phi = 360 THEN phi = 0
NEXT
LOOP UNTIL INKEY$ = CHR$(27)

DATA 50,50,-50
DATA -50,-50,-50
DATA -50,50,-50
DATA 50,-50,-50

DATA 50,50,50
DATA -50,-50,50
DATA -50,50,50
DATA 50,-50,50

You forgot the dots in x,y,z center so that there was a division by zero...
B 4 EVER
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)