Posts: 3,288
Threads: 167
Joined: Nov 2001
Add 120 to your original coords not the transformed coords.
Code: for i = 0 to numpoints
x(i) = x(i) + 120
y(i) = y(i) + 120
z(i) = z(i) + 120
next i
Its called translation.
You could also translate before rotation to acheive the same effect.
The problem is you are translating after rotating. Do the reverse.
Posts: 29
Threads: 9
Joined: Oct 2004
Thank you! I know that it will make he cube rotate around me, but I'm still getting that stupid overflow error! What is wrong? I did everything you say!
Code: SCREEN 12
DIM c!(360), s!(360)
pts = 7
theta = 1
phi = 1
interv = 100000
DIM x(pts), y(pts), z(pts), new.x(pts), new.y(pts), z2(pts), x2(pts), y2(pts)
FOR angle = 0 TO 360
c!(angle) = COS(angle * 3.14 / 180)
s!(angle) = SIN(angle * 3.14 / 180)
NEXT
x.center = 200
y.center = 156
z.center = 0
FOR i = 0 TO pts
READ x(i)
x(i) = x(i) + 120
READ y(i)
y(i) = y(i) + 120
READ z(i)
z(i) = z(i) + 120
NEXT
DO
CLS
theta = theta + 1
'phi = phi + 1
FOR i = 0 TO pts
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
IF new.x(i) <= 32767 OR new.y(i) <= 32767 THEN
LINE (new.x(i) - 3, new.y(i) - 3)-(new.x(i) + 3, new.y(i) + 3), 10, BF
LINE (new.x(0), new.y(0))-(new.x(1), new.y(1)), 15
LINE (new.x(2), new.y(2))-(new.x(0), new.y(0)), 15
LINE (new.x(3), new.y(3))-(new.x(1), new.y(1)), 15
LINE (new.x(2), new.y(2))-(new.x(3), new.y(3)), 15
LINE (new.x(4), new.y(4))-(new.x(5), new.y(5)), 15
LINE (new.x(6), new.y(6))-(new.x(4), new.y(4)), 15
LINE (new.x(7), new.y(7))-(new.x(5), new.y(5)), 15
LINE (new.x(6), new.y(6))-(new.x(7), new.y(7)), 15
LINE (new.x(5), new.y(5))-(new.x(1), new.y(1)), 15
LINE (new.x(6), new.y(6))-(new.x(2), new.y(2)), 15
LINE (new.x(7), new.y(7))-(new.x(3), new.y(3)), 15
LINE (new.x(4), new.y(4))-(new.x(0), new.y(0)), 15
END IF
IF theta = 360 THEN theta = 0
IF phi = 360 THEN phi = 0
NEXT
FOR q = 0 TO interv
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
Posts: 480
Threads: 24
Joined: Mar 2003
read my post above. move the entire LINEs block out of the for...next loop. You don't need to draw the lines 8 times:
Code: SCREEN 12
DIM c!(360), s!(360)
pts = 7
theta = 1
phi = 1
interv = 100000
DIM x(pts), y(pts), z(pts), new.x(pts), new.y(pts), z2(pts), x2(pts), y2(pts)
FOR angle = 0 TO 360
c!(angle) = COS(angle * 3.14 / 180)
s!(angle) = SIN(angle * 3.14 / 180)
NEXT
x.center = 200
y.center = 156
z.center = 0
FOR i = 0 TO pts
READ x(i)
x(i) = x(i) + 120
READ y(i)
y(i) = y(i) + 120
READ z(i)
z(i) = z(i) + 120
NEXT
DO
CLS
theta = theta + 1
'phi = phi + 1
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'I TOOK THESE TWO LINES OUT OF YOUR FOR...NEXT LOOP. THEY ONLY
'NEED TO BE PROCESSED WHEN THE VALUES FOR PHI AND THETA CHANGE.
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IF theta = 360 THEN theta = 0
IF phi = 360 THEN phi = 0
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
FOR i = 0 TO pts
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
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'I ADDED THESE LINES TO YOUR PROGRAM. MAKE SURE X AND Y ARE ON SCREEN
'AND THAT Z < 0 (i.e. not behind the screen)
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IF new.x(i) >= 0 AND new.x(i) <= 639 AND new.y(i) >= 0 AND new.y(i) <= 479 AND z2(i) < 0 THEN
CIRCLE (new.x(i), new.y(i)), 3, 15
END IF
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
NEXT
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'I TOOK THESE OUT OF YOUR FOR...NEXT LOOP
'THEY CAUSE OVERFLOW ERROR BECAUSE OF THE LIMITS YOU
'CAN GIVE QB FOR LINE COORDINATES.
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'LINE (new.x(i) - 3, new.y(i) - 3)-(new.x(i) + 3, new.y(i) + 3), 10, BF
'LINE (new.x(0), new.y(0))-(new.x(1), new.y(1)), 15
'LINE (new.x(2), new.y(2))-(new.x(0), new.y(0)), 15
'LINE (new.x(3), new.y(3))-(new.x(1), new.y(1)), 15
'LINE (new.x(2), new.y(2))-(new.x(3), new.y(3)), 15
'LINE (new.x(4), new.y(4))-(new.x(5), new.y(5)), 15
'LINE (new.x(6), new.y(6))-(new.x(4), new.y(4)), 15
'LINE (new.x(7), new.y(7))-(new.x(5), new.y(5)), 15
'LINE (new.x(6), new.y(6))-(new.x(7), new.y(7)), 15
'LINE (new.x(5), new.y(5))-(new.x(1), new.y(1)), 15
'LINE (new.x(6), new.y(6))-(new.x(2), new.y(2)), 15
'LINE (new.x(7), new.y(7))-(new.x(3), new.y(3)), 15
'LINE (new.x(4), new.y(4))-(new.x(0), new.y(0)), 15
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
FOR q = 0 TO interv
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
Posts: 29
Threads: 9
Joined: Oct 2004
Thank you very much!
Sorry about thous lines, but I didn't think thay will change anything.
Now everything works! Exept 2 squares missing, but I'll fix it.
Quote: 'I TOOK THESE OUT OF YOUR FOR...NEXT LOOP
'THEY CAUSE OVERFLOW ERROR BECAUSE OF THE LIMITS YOU
'CAN GIVE QB FOR LINE COORDINATES.
So that means I can't use lines? What else can I use instead of lines?
And now when I'm rotating theta, it only rotates around me, but If I wan't to rotate it in the middle of me, I fould need to create two for.. loops, one will be responsible for rotating cube around me and the second loop will be responsible for rotating cube in the middle of me for example right? Thank you!
Posts: 480
Threads: 24
Joined: Mar 2003
You *can* use lines, but if you are connecting two points with a line, you need to make sure that both coordinate pairs for the two points are within the valid range that can be passed to the LINE statement before you draw it.
Posts: 3,288
Threads: 167
Joined: Nov 2001
Overflow prolly is due to numerrical limits of qb. Try to add this opn the top of your proggie.
defsng a - z
Posts: 29
Threads: 9
Joined: Oct 2004
If I put the defsng a - z I still get the overflow error, I allso try define a - z, but nothing!
Posts: 3,288
Threads: 167
Joined: Nov 2001
You could make your scale a lil smaller if that's the case.
Posts: 480
Threads: 24
Joined: Mar 2003
What line exactly is giving you the overflow error?
Posts: 29
Threads: 9
Joined: Oct 2004
Hi!
Well, nevermind about that overdlow! Something is starting to work! Now I can like walk into my 3D "world", but I'm not sure everything works right! When I turn right/left it doesn't look realy natural! for example there is a square, when I turn left, about when theta gets 100, it looks like it will git the camera! Allso try to go around the square! There is definetly something wrong with turning right/left! Please take a look at it
left/right - a/d; forword, backword - w/s:
Code: SCREEN 13
DIM c!(360), s!(360)
pts = 7
theta = 1
phi = 1
interv = 100000
DIM x(pts), y(pts), z(pts), new.x(pts), new.y(pts), z2(pts), x2(pts), y2(pts)
FOR angle = 0 TO 360
c!(angle) = COS(angle * 3.14 / 180)
s!(angle) = SIN(angle * 3.14 / 180)
NEXT
x.center = 160
y.center = 0
z.center = -200
FOR i = 0 TO pts
READ x(i)
x(i) = x(i) + 120
READ y(i)
y(i) = y(i) + 120
READ z(i)
z(i) = z(i) + 120
NEXT
DO
K$ = INKEY$
IF theta >= 361 THEN theta = 1
IF theta <= 0 THEN theta = 360
FOR i = 0 TO pts
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
IF new.x(i) >= 0 AND new.x(i) <= 639 AND new.y(i) >= 0 AND new.y(i) <= 479 AND z2(i) < 0 THEN
CIRCLE (new.x(i), new.y(i)), 2, 15
END IF
NEXT
SELECT CASE UCASE$(K$)
CASE "A"
CLS
PRINT theta
theta = theta + 4
CASE "D"
CLS
PRINT theta
theta = theta - 4
CASE "S"
CLS
PRINT theta
z.center = z.center - 4
CASE "W"
CLS
PRINT theta
z.center = z.center + 4
END SELECT
LOOP UNTIL K$ = CHR$(27)
DATA -50,-50,0
DATA 50,-50,0
DATA -50,50,0
DATA 50,50,0
DATA -50,-50,-100
DATA 50,-50,-100
DATA -50,50,-100
DATA 50,50,-100
Well, I allmost know how to turn right/left into 3D world! The second problem is what if I wan't some object to rotate when camera stands still? I got a simple idea in 2D rotation, but I'm not sure if its the best way to do it with 3D:
Code: SCREEN 12
Cam = 180
Obj = 90
PSET (SIN(Cam / 57) * 150 + 300, COS(Cam / 57) * 150 + 200), 15
PSET (SIN(Obj / 57) * 10 + (SIN(Cam / 57) * 150 + 300), COS(Obj / 57) * 10 + (COS(Cam / 57) * 150 + 200)), 10
Camera has rotated 180 angle and Obj is rotated 90 angle! Can I use the same idea in 3D rotation?
I know 2D rotation perfectly! It is so simple! I understand in 3D rotation what is x, y, z, but I don't understand exactly how do thous formulas work! Does any of you have the same problems? Do I need to understand thous formulas like I understand 2D!?
Allso, have any of you have created 3D game? Thank you!
|