Qbasicnews.com
December 03, 2021, 01:55:22 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: 3d programming  (Read 9518 times)
red_Marvin
Na_th_an
*****
Posts: 1509



WWW
« on: January 16, 2004, 07:49:21 PM »

I've been trying to understand the 3d stuff I try to learn and
for example I use the formula for 3d->2d coords from the
qbasicnews 3d tutorial:
Code:
X3 = 256 * (x2 / (Z2 + zCenter)) + xCenter
Y3 = 256 * (y2 / (Z2 + zCenter)) + yCenter


Now I wonder:

1) Is the x/y/zcenter supposed to be camera position or center
of perspective

2)I implemented it as cam coords (ie: keys up/down: inc/dec ycenter etc.)
but I didn't get any perspective based changes of the coords
ie: In gta2 the rooftops move more than the ground when you walk
because they are higher up...
Logged

/post]
wildcard
*.*
Administrator
__/--\__
*****
Posts: 2370



« Reply #1 on: January 16, 2004, 10:30:57 PM »

The xCenter/yCenter is for the camera, it makes the view centered in screen; although its not required if you have a moving camera. So you can use it as a camera, but will require other transformations to move the camera at any angle.

What kind of model are you using to test with? I'm not quite sure why you wouldn't get the perspective difference, unless you don't have a differring x/z or y/z value.
Logged
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #2 on: January 17, 2004, 03:56:46 AM »

And adding the z to zcenter makes your projection a left-handed system. ;*)

Most books uses the right-handed system. ie. Looking at negative z.

when increased:

x = right
y = up
z = into you from screen

Don't worry 2 months from now, QBCM will feature a 3d series from the basics to the advanced. Including a PSx algo in sorting which Blitz just taught me. ;*)
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
Oz
I hold this place together
*****
Posts: 923



« Reply #3 on: January 27, 2004, 02:20:11 PM »

i can get you a better 2d to 3d conversion method using elipses.......i thought of this all by myself (which is y its kinda crazy to understand......

this isn't done, but it gives you the general idea
Code:
TYPE AxisType
  x  AS SINGLE
  y  AS SINGLE
  z  AS SINGLE
END TYPE

TYPE CoordType
 axis AS AxisType ' X,Y,Z coordinates
  rx  AS SINGLE   ' X radius
  ry  AS SINGLE   ' Y radius
  a   AS SINGLE   ' last recorded angle
END TYPE

TYPE ObjectType
  centerL  AS AxisType   'Left
  centerR  AS AxisType   'Right
  centerC  AS AxisType   'Center
END TYPE

DIM CObject AS ObjectType
DIM Coord(1 TO 2, 1 TO 20) AS CoordType

DECLARE FUNCTION x2d! (x AS SINGLE, z AS SINGLE)
DECLARE FUNCTION y2d! (y AS SINGLE, z AS SINGLE)


SCREEN 12

DIM Sine(360) AS SINGLE, Cosine(360) AS SINGLE

a = 0
FOR i! = 0 TO 6.28 STEP 6.28 / 360
Sine(a) = SIN(i!)
Cosine(a) = COS(i!)
a = a + 1
NEXT

DIM Shape AS INTEGER
DIM Speed AS AxisType
DIM angle(1 TO 2) AS SINGLE
DIM hilight AS INTEGER
DIM keys AS STRING

'Clear screen
CLS
'Create Interface
LINE (3, 3)-(640, 290), 15, BF
LINE (10, 10)-(630, 280), 0, BF
LOCATE 1, 5: PRINT "ŬOutput ShapeŜ"

LINE (3, 307)-(640, 450), 15, BF
LINE (10, 317)-(630, 440), 0, BF
LOCATE 20, 5: PRINT "ŬInput DataŜ"

'Initialize Center
' The Center
CObject.centerC.x = 640 \ 2
CObject.centerC.y = 480 \ 4
CObject.centerC.z = 10 \ 2
' The Left Side
CObject.centerL.x = CObject.centerC.x + 160 * Sine(270)
CObject.centerL.y = CObject.centerC.y + 80 * Cosine(270)
CObject.centerL.z = 10 \ 2
' The Right Side
CObject.centerR.x = CObject.centerC.x + 160 * Sine(90)
CObject.centerR.y = CObject.centerC.y + 80 * Cosine(90)
CObject.centerR.z = 10 \ 2 - 2

'Initialize Shape
Shape = 5

'Initialize Radius
FOR nn = 1 TO 2
 FOR n = 1 TO Shape
  Coord(nn, n).rx = 30
  Coord(nn, n).ry = 30
 NEXT
NEXT
angle = 90

DO
keys = INKEY$

'Erase Previous
CIRCLE (CObject.centerL.x, CObject.centerL.y), 2, 0
LINE (CObject.centerC.x, CObject.centerC.y)-(CObject.centerR.x, CObject.centerR.y), 0
CIRCLE (CObject.centerR.x, CObject.centerR.y), 2, 0
LINE (CObject.centerC.x, CObject.centerC.y)-(CObject.centerL.x, CObject.centerL.y), 0
CIRCLE (CObject.centerL.x, CObject.centerL.y), 2, 0

angle(1) = angle(1) + .01
IF angle(1) > 360 THEN angle(1) = 0

'Center Correction
' The Right Side
CObject.centerR.z = 10 \ 2
CObject.centerL.x = x2d(CObject.centerR.x, CObject.centerR.z)
CObject.centerL.y = x2d(CObject.centerR.y, CObject.centerR.z)
CObject.centerR.x = CObject.centerC.x + 160 * Sine(angle(1))
CObject.centerR.y = CObject.centerC.y + 80 * Cosine(angle(1))
' The Left Side
angle(2) = angle(1) + 180
IF angle(2) > 360 THEN angle(2) = angle(2) - 360
CObject.centerL.z = 10 \ 2
CObject.centerL.x = x2d(CObject.centerL.x, CObject.centerL.z)
CObject.centerL.y = x2d(CObject.centerL.y, CObject.centerL.z)
CObject.centerL.x = CObject.centerC.x + 160 * Sine(angle(2))
CObject.centerL.y = CObject.centerC.y + 80 * Cosine(angle(2))

'Draw Center
CIRCLE (CObject.centerC.x, CObject.centerC.y), 2, 15
CIRCLE (CObject.centerL.x, CObject.centerL.y), 2, 15
LINE (CObject.centerC.x, CObject.centerC.y)-(CObject.centerR.x, CObject.centerR.y), 1
CIRCLE (CObject.centerR.x, CObject.centerR.y), 2, 15
LINE (CObject.centerC.x, CObject.centerC.y)-(CObject.centerL.x, CObject.centerL.y), 1
CIRCLE (CObject.centerL.x, CObject.centerL.y), 2, 15

'Erase Previous PSETs
FOR sp = 1 TO Shape
 PSET (Coord(1, sp).axis.x, Coord(1, sp).axis.y), 0
NEXT
FOR sp = 1 TO Shape
 PSET (Coord(2, sp).axis.x, Coord(2, sp).axis.y), 0
NEXT

'Erase Connection lines
FOR sp = 1 TO Shape
 init = sp
 endd = sp + 1
 IF endd > Shape THEN endd = endd - Shape
 LINE (x2d(Coord(1, init).axis.x, Coord(1, init).axis.z), y2d(Coord(1, init).axis.y, Coord(1, init).axis.z))-(x2d(Coord(1, endd).axis.x, Coord(1, endd).axis.z), y2d(Coord(1, endd).axis.y, Coord(1, endd).axis.z)), 0
NEXT



'Calculate voxel
'Left Side
FOR sp = 1 TO Shape
 Coord(1, sp).a = sp * (360 \ Shape) - 1
 Coord(1, sp).axis.x = CObject.centerL.x + Coord(1, sp).rx * Sine(Coord(1, sp).a)
 Coord(1, sp).axis.y = CObject.centerL.y + Coord(1, sp).ry * Cosine(Coord(1, sp).a)
 Coord(1, sp).axis.z = ((CObject.centerC.y - Coord(1, sp).axis.x) / 30) * 10
 Coord(1, sp).axis.x = x2d(Coord(1, sp).axis.x, Coord(1, sp).axis.z)
 Coord(1, sp).axis.y = y2d(Coord(1, sp).axis.y, Coord(1, sp).axis.z)
NEXT sp
'Right Side
FOR sp = 1 TO Shape
 Coord(2, sp).a = sp * (360 \ Shape) - 1
 Coord(2, sp).axis.x = CObject.centerR.x + Coord(2, sp).rx * Sine(Coord(2, sp).a)
 Coord(2, sp).axis.y = CObject.centerR.y + Coord(2, sp).ry * Cosine(Coord(2, sp).a)
 Coord(2, sp).axis.z = ((CObject.centerC.y - Coord(2, sp).axis.x) / 30) * 10
 Coord(2, sp).axis.x = x2d(Coord(2, sp).axis.x, Coord(2, sp).axis.z)
 Coord(2, sp).axis.y = y2d(Coord(2, sp).axis.y, Coord(2, sp).axis.z)
NEXT sp

'Lines Connecting
FOR sp = 1 TO Shape
 init = sp
 endd = sp + 1
 IF endd > Shape THEN endd = endd - Shape
 LINE (Coord(1, init).axis.x, Coord(1, init).axis.y)-(Coord(1, endd).axis.x, Coord(1, endd).axis.y), 2
NEXT

FOR sp = 1 TO Shape
 PSET (Coord(1, sp).axis.x, Coord(1, sp).axis.y), 2
NEXT
FOR sp = 1 TO Shape
 PSET (Coord(2, sp).axis.x, Coord(2, sp).axis.y), 2
NEXT

LOOP UNTIL keys = CHR$(27)
'CLS
'SCREEN 9
'LOCATE 1, 1: PRINT "End of 3D example (v1.0)"
'SYSTEM

FUNCTION x2d! (x AS SINGLE, z AS SINGLE)
IF x = 0 OR z = 0 THEN
 x = -1
 EXIT FUNCTION
END IF
x2d = (((x) / z) + (640 \ 2)) - 320
END FUNCTION

FUNCTION y2d! (y AS SINGLE, z AS SINGLE)
IF y = 0 OR z = 0 THEN
 y = -1
 EXIT FUNCTION
END IF
y2d = (((y) / z) + (480 \ 2)) - 240
END FUNCTION

Simple, eh?
Logged
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #4 on: January 28, 2004, 04:59:53 AM »

eh?

Code:
FUNCTION x2d! (x AS SINGLE, z AS SINGLE)
IF x = 0 OR z = 0 THEN
 x = -1
 EXIT FUNCTION
END IF
x2d = (((x) / z) + (640 \ 2)) - 320
END FUNCTION

FUNCTION y2d! (y AS SINGLE, z AS SINGLE)
IF y = 0 OR z = 0 THEN
 y = -1
 EXIT FUNCTION
END IF
y2d = (((y) / z) + (480 \ 2)) - 240
END FUNCTION


Where's the ellipse?
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
Oz
I hold this place together
*****
Posts: 923



« Reply #5 on: January 28, 2004, 01:17:34 PM »

the elipse is in the code.......
Code:
FOR sp = 1 TO Shape
 Coord(1, sp).a = sp * (360 \ Shape) - 1
 Coord(1, sp).axis.x = CObject.centerL.x + Coord(1, sp).rx * Sine(Coord(1, sp).a)
 Coord(1, sp).axis.y = CObject.centerL.y + Coord(1, sp).ry * Cosine(Coord(1, sp).a)
 Coord(1, sp).axis.z = ((CObject.centerC.y - Coord(1, sp).axis.x) / 30) * 10
 Coord(1, sp).axis.x = x2d(Coord(1, sp).axis.x, Coord(1, sp).axis.z)
 Coord(1, sp).axis.y = y2d(Coord(1, sp).axis.y, Coord(1, sp).axis.z)
NEXT sp

this calculates all the points on the elipse
the drawing is just a bit furture in the code (this is in the main module)

Oz
Logged
Oz
I hold this place together
*****
Posts: 923



« Reply #6 on: January 28, 2004, 01:27:03 PM »

as a seperate note, I flipped my axis like this

           z     y
           |   /
           |  /
           | /
 --------|---------- x
         / |
        /  |

This way, the main axis are x and y still........a little easier to work with....i dunno

Oz
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #7 on: January 28, 2004, 01:45:00 PM »

Quote from: "Alex_at_EverNever"
Code:
as a seperate note, I flipped my axis like this

           z     y
           |   /
           |  /
           | /
 ----------|---------- x
         / |
        /  |

This way, the main axis are x and y still........a little easier to work with....i dunno

Oz
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Oz
I hold this place together
*****
Posts: 923



« Reply #8 on: January 28, 2004, 02:43:58 PM »

thnx for the correction

Oz
Logged
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #9 on: January 29, 2004, 04:46:52 AM »

Quote from: "Alex_at_EverNever"
i can get you a better 2d to 3d conversion method using elipses.......i thought of this all by myself (which is y its kinda crazy to understand......



You said 2d to 3d.   And your ellipse code does not convert.  And the right term for that is "Polar to cartesian"

x=cos(theta)
y=sin(theta)

for real 3d, you use the "spherical" coordinate system

x=r sin(phi) cos(theta)
y=r sin(phi) sin(theta)
z=r cos(phi)
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
Oz
I hold this place together
*****
Posts: 923



« Reply #10 on: January 29, 2004, 11:47:22 AM »

i use both methods........2d-3d conversion (the FUNCTIONs)
and the polar equations to add the rotation methods

Oz
Logged
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #11 on: January 30, 2004, 03:31:19 AM »

Polar=2d not 3d
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
andy
Senior Member
**
Posts: 175



WWW
« Reply #12 on: February 06, 2004, 10:23:21 AM »

I recently wrote a 3d to 2d conversion programme myself, it is very simple and consists of a bout 5 to 10 lines, I will post it when I go home. It just uses the idea of similar triangles.
Logged

eminiscing about trapezoids in conjunction with stratospherical parabolas:

No questions asked.

www.stickskate.com
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #13 on: February 07, 2004, 03:41:47 AM »

What's simpler than this?

Code:
x=xcenter+(xr!*256/distance)
y=ycenter- (yr!*256/distance)
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
andy
Senior Member
**
Posts: 175



WWW
« Reply #14 on: February 14, 2004, 12:45:55 PM »

ok here is my code it is not amazingly easy to understand so If you would like a bit more help either PM me or just post here.

Code:
DECLARE SUB zrotate (y!, x!, rho!, centerx, centery)
DECLARE SUB xrotate (y!, z!, alpha!, centery, centerz)
DECLARE SUB yrotate (x!, z!, theta!, centerx, centerz)
DECLARE SUB zoom (inout!, x, p, z!, zoomfactor!, side, length)
DECLARE SUB getx (zeye!, xp!, z!, xcord!)
DECLARE SUB gety (zeye!, yp!, z!, ycord!)

INPUT file$
IF file$ = "" THEN file$ = "cube"
file$ = "data\" + file$ + ".txt"
PRINT file$

OPEN file$ FOR INPUT AS #1

INPUT #1, lines    'total lines in the file
INPUT #1, points   'total points
INPUT #1, numlines 'total lines to draw

numlines2 = numlines

DIM xp(points), yp(points), z(points), xcord(points), ycord(points), linesfrom(numlines), linesto(numlines)
DIM xp2(points), yp2(points), z2(points)

INPUT #1, blank 'absorb the blank line
lines = lines - 4  'count down the amount of lines to avoid input
'past end of file error
DO

i = i + 1
PRINT i
INPUT #1, linesfrom(i), linesto(i)  'take co-ords to draw lines from-to
numlines = numlines - 1
lines = lines - 1
LOOP UNTIL numlines = 0

INPUT #1, blank
lines = lines - 1

i = 0
DO

i = i + 1
PRINT i

INPUT #1, xp(i), yp(i), z(i)  ' input x,y,z co-ords
xp2(i) = xp(i)
yp2(i) = yp(i)
z2(i) = z(i)
lines = lines - 1
 
LOOP UNTIL i = points
CLOSE #1




GOSUB setinitial
GOSUB setvariables
GOSUB getcords
GOSUB drawline

DO
DO
khb$ = INKEY$
IF khb$ <> "" THEN

IF khb$ = "=" OR khb$ = "+" THEN EXIT DO 'zoom in
IF khb$ = "-" THEN EXIT DO 'zoom out

IF khb$ = CHR$(0) + "K" THEN EXIT DO 'left rotate
IF khb$ = CHR$(0) + "M" THEN EXIT DO 'right rotate
IF khb$ = CHR$(0) + "H" THEN EXIT DO 'up rotate
IF khb$ = CHR$(0) + "P" THEN EXIT DO 'down rotate
IF khb$ = CHR$(0) + "I" THEN EXIT DO 'anti-clockwise rotate
IF khb$ = CHR$(0) + "Q" THEN EXIT DO 'clockwise rotate

IF khb$ = "a" THEN EXIT DO 'left move
IF khb$ = "A" THEN EXIT DO 'left move

IF khb$ = "w" THEN EXIT DO 'up move
IF khb$ = "W" THEN EXIT DO 'up move

IF khb$ = "d" THEN EXIT DO 'right move
IF khb$ = "D" THEN EXIT DO 'right move

IF khb$ = "s" THEN EXIT DO 'down move
IF khb$ = "S" THEN EXIT DO 'down move

IF khb$ = "c" THEN EXIT DO 'debug
IF khb$ = "C" THEN EXIT DO 'debug
IF khb$ = " " THEN EXIT DO ' debug
IF khb$ = CHR$(13) THEN EXIT DO 'debug

IF khb$ = "r" OR khb$ = "R" THEN EXIT DO 'reset

IF khb$ = CHR$(27) THEN END 'exit
END IF
LOOP

'**************** ZOOM IN ************************
 
IF khb$ = "+" OR khb$ = "=" THEN
FOR i = 1 TO points
IF z(i) < -150 + zoomin THEN tag = 1
NEXT

IF tag <> 1 THEN
FOR i = 1 TO points
z(i) = z(i) - zoomin
NEXT
IF spin = 1 THEN centerz = centerz - zoomin
END IF
tag = 0
END IF

'***************** ZOOM OUT *********************

IF khb$ = "-" THEN
FOR i = 1 TO points
IF z(i) > 3000 THEN tag = 1
NEXT

IF tag <> 1 THEN
FOR i = 1 TO points
z(i) = z(i) + zoomout
NEXT
IF spin = 1 THEN centerz = centerz + zoomout
END IF
tag = 0
END IF



'*********************** Y rotate ********************

IF khb$ = CHR$(0) + "K" THEN
FOR i = 1 TO points
yrotate xp(i), z(i), -theta, centerx, centerz
NEXT
END IF

'*****************************************************

IF khb$ = CHR$(0) + "M" THEN
FOR i = 1 TO points
yrotate xp(i), z(i), theta, centerx, centerz
NEXT
END IF

' ************************* X ROTATE ************************
IF khb$ = CHR$(0) + "H" THEN
FOR i = 1 TO points
xrotate yp(i), z(i), alpha, centery, centerz
NEXT
END IF

'**********************************************************

IF khb$ = CHR$(0) + "P" THEN
FOR i = 1 TO points
xrotate yp(i), z(i), -alpha, centery, centerz
NEXT
END IF

'********************** Z ROTATE *******************

IF khb$ = CHR$(0) + "I" THEN
FOR i = 1 TO points
zrotate yp(i), xp(i), rho, centerx, centery
NEXT
END IF

'**********************************************

IF khb$ = CHR$(0) + "Q" THEN
FOR i = 1 TO points
zrotate yp(i), xp(i), -rho, centerx, centery
NEXT
END IF


'***************** MOVE LEFT *********************
IF khb$ = "a" OR khb$ = "A" THEN
FOR i = 1 TO points
xp(i) = xp(i) - leftmove
NEXT
IF spin = 1 THEN centerx = centerx - leftmove
END IF

'***************** MOVE UP *********************
IF khb$ = "w" OR khb$ = "W" THEN
FOR i = 1 TO points
yp(i) = yp(i) - upmove
NEXT
IF spin = 1 THEN centery = centery - upmove
END IF

'***************** MOVE RIGHT *********************
IF khb$ = "d" OR khb$ = "D" THEN
FOR i = 1 TO points
xp(i) = xp(i) + rightmove
NEXT
IF spin = 1 THEN centerx = centerx + rightmove
END IF

'***************** MOVE down *********************
IF khb$ = "s" OR khb$ = "S" THEN
FOR i = 1 TO points
yp(i) = yp(i) + downmove
NEXT
IF spin = 1 THEN centery = centery + downmove
END IF


'******************* DEBUG **********************

IF khb$ = "c" OR khb$ = "C" THEN
IF debug = 0 THEN debug = 1 ELSE debug = 0
IF debug = 1 THEN debugl = 1 ELSE debugl = 0
END IF

IF khb$ = " " THEN
IF debug = 1 THEN
debugl = debugl + 1
IF debugl > numlines2 THEN debugl = 1
END IF
END IF

IF khb$ = CHR$(13) THEN
IF debug = 1 THEN
LOCATE 1, 1
COLOR 15
PRINT "this line goes between points"; linesfrom(debugl); "and"; linesto(debugl)
PRINT "Point"; linesfrom(debugl); "currently: x"; xp(linesfrom(debugl)); "y"; yp(linesfrom(debugl)); "z"; z(linesfrom(debugl))
PRINT "Point"; linesto(debugl); "currently: x"; xp(linesto(debugl)); "y"; yp(linesto(debugl)); "z"; z(linesto(debugl))
PRINT "Point"; linesfrom(debugl); "originally: x"; xp2(linesfrom(debugl)); "y"; yp2(linesfrom(debugl)); "z"; z2(linesfrom(debugl))
PRINT "Point"; linesto(debugl); "originally: x"; xp2(linesto(debugl)); "y"; yp2(linesto(debugl)); "z"; z2(linesto(debugl))

PCOPY 1, 0
'DO: khb$ = INKEY$: LOOP UNTIL khb$ = CHR$(27)
SLEEP
END IF
END IF

'***************** RESET *************************


IF khb$ = "r" OR khb$ = "R" THEN
LINE (0, 0)-(320, 200), 0, BF
GOSUB setvariables
GOSUB refresh
END IF


'********************* DRAW SHAPE ****************

GOSUB getcords

'CLEAR SCREEN
LINE (0, 0)-(320, 200), 0, BF

FOR check = 1 TO points
IF z(check) < 0 THEN dont = dont + 1
'PRINT z(check), dont
'PCOPY 1, 0
NEXT

IF dont <> points THEN
GOSUB drawline
END IF
dont = 0
PCOPY 1, 0
 
LOOP
END

drawline:
SCREEN 7, 0, 1, 0

FOR i = 1 TO numlines2

IF debugl = i THEN
LINE (xcord(linesfrom(i)), ycord(linesfrom(i)))-(xcord(linesto(i)), ycord(linesto(i))), 1
ELSE
LINE (xcord(linesfrom(i)), ycord(linesfrom(i)))-(xcord(linesto(i)), ycord(linesto(i)))
END IF

NEXT i

PCOPY 1, 0
RETURN

getcords:
FOR i = 1 TO points
getx zeye, xp(i), z(i), xcord(i)
gety zeye, yp(i), z(i), ycord(i)
NEXT
RETURN

setvariables:

'z variables
zeye = 320
startz = 50
depth = 100

'zoom variables
zoomfactor = 1.4
RETURN


setinitial:
SCREEN 7, 0, 0, 0
CLS

'math variabkes
DIM SHARED pi AS SINGLE
pi = 3.141593

theta = 5     'Y ROTATE
alpha = 5     'X ROTATE
rho = 5       'Z ROTATE

leftmove = 5  'MOVE
rightmove = 5 'MOVE
upmove = 5    'MOVE
downmove = 5  'MOVE

zoomin = 10    'ZOOM
zoomout = 10   'ZOOM

'centers
centerx = 160
centery = 100
centerz = 100

IF start = 0 THEN
DO
INPUT "Spin about center of the object(1) or center of the screen(2)?", spin
LOOP UNTIL spin = 1 OR spin = 2
END IF
start = 1
RETURN

refresh:
FOR i = 1 TO points
xp(i) = xp2(i)
yp(i) = yp2(i)
z(i) = z2(i)
NEXT
GOSUB setinitial

RETURN

SUB getx (zeye, xp, z, xcord)
x = (zeye * (160 - xp)) / (zeye + z)
xcord = 160 - x
xcord = INT(xcord)
END SUB

SUB gety (zeye, yp, z, ycord)
y = (zeye * (100 - yp)) / (zeye + z)
ycord = 100 - y
ycord = INT(ycord)
END SUB

SUB xrotate (y, z, alpha, centery, centerz)
radalpha = alpha * pi / 180

ynew = ((y - centery) * COS(radalpha)) + ((z - centerz) * SIN(radalpha)) + centery
znew = -((y - centery) * SIN(radalpha)) + ((z - centerz) * COS(radalpha)) + centerz

y = ynew
z = znew

END SUB

SUB yrotate (x, z, theta, centerx, centerz)
radtheta = theta * pi / 180

xnew = ((x - centerx) * COS(radtheta)) - ((z - centerz) * SIN(radtheta)) + centerx
znew = ((x - centerx) * SIN(radtheta)) + ((z - centerz) * COS(radtheta)) + centerz

x = xnew
z = znew

END SUB

SUB zrotate (y, x, rho, centerx, centery)
radrho = rho * pi / 180

xnew = ((x - centerx) * COS(radrho)) + ((y - centery) * SIN(radrho)) + centerx
ynew = -((x - centerx) * SIN(radrho)) + ((y - centery) * COS(radrho)) + centery

x = xnew
y = ynew

END SUB



My program reads .txt files which tells the prog the co-ords of the points and which points to draw line between.

here is the general method:

Code:
number of lines in this file
number of points
number of lines to be drawn
empty line
number,number2   ' the numbers are  the points to draw the lines between, only 2 numbers per line
number.number2   ' etc as before
empty line
x,y,z  'x y z cordinates of the points
x,y,z  'same as above


note the txt files can not contain notes.

Here is an example, it is a cube

Code:
25
8
12

1,2
2,3
3,4
4,1
1,5
2,6
3,7
4,8
5,6
6,7
7,8
8,5

110,150,50
210,150,50
210,50,50
110,50,50
110,150,150
210,150,150
210,50,150
110,50,150


note code files should be in a folder called data in the same directory as qb.

note the buttons for my file are as follows:

yrotate - left, right arrows
xrotate - up, down arrows
zrotate - pgup pgdown

zoomin - +
zoom out - minus sighn (-)

left right up down - w a s d

reset - r

When you are asked what file to open you don't need to enter the .txt or the path of the txt file as it does it automatically

If you make any good images with this file please send them to me.
Logged

eminiscing about trapezoids in conjunction with stratospherical parabolas:

No questions asked.

www.stickskate.com
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!