Boromir wrote:I'd be happy if someone could show me how to get it working.
I wouldn't have a clue how to "get it working" as I think you are going about it the wrong way.
Don't think in terms of lines think in terms of points in 3D space.
Thus in the example below set(x,y) becomes set3D(x,y,z) and line(x1,y1)-(x2,y2) becomes drawLine3D(x1,y1,z1,x2,y2,z2)
These routines are one way to project the 3D points onto a 2D screen.
You will find some examples here on how to do simple 3D graphics,
http://www.petesqbsite.com/sections/tut ... hics.shtml
Below I have modified a rotating cube demo to handle just the three lines of an x,y,z axis.
Code: Select all
'SCREEN VIEW
' -Y +Z
' | /
' | /
' | /
' | /
' | /
' |/
' - X ---------o----------> +X
' /|
' / |
' / |
' / |
' / |
' / |
' -Z |
' +Y
'
'
'some useful defines
Const Pi = 4 * Atn(1)
Dim Shared As Double TwoPi = 8 * Atn(1)
Dim Shared As Double RtoD = 180 / Pi ' radians * RtoD = degrees
Dim Shared As Double DtoR = Pi / 180 ' degrees * DtoR = radians
screenres 500,500,32
sub set3D(x as double,y as double,z as double)
circle (x+z\2+250,y-z\2+250),3,rgb(0,255,0)
draw string (x+z\2+250,y-z\2+250),str(int(x+.5))+","+str(int(y+.5))+","+str(int(z+.5))
end sub
sub drawLine3D(x1 as double,y1 as double,z1 as double,x2 as double,y2 as double,z2 as double)
line (x1+z1\2+250,y1-z1\2+250)-(x2+z2\2+250,y2-z2\2+250),rgb(255,0,0)
set3D(x1,y1,z1)
set3D(x2,y2,z2)
end sub
type LINE3D
as double x1(2) 'two points to a line
as double y1(2)
as double z1(2)
as double rx1(2)
as double ry1(2)
as double rz1(2)
end type
dim shared as LINE3D L3D(3) 'three lines
for i as integer = 0 to 2 'three lines
for j as integer = 0 to 1 'two points each
read L3D(i).x1(j)
read L3D(i).y1(j)
read L3D(i).z1(j)
L3D(i).rx1(j) = L3D(i).x1(j)
L3D(i).ry1(j) = L3D(i).y1(j)
L3D(i).rz1(j) = L3D(i).z1(j)
next j
next i
sub rotatePointsZ(angle as double)
dim as double px1,py1,pz1
for i as integer = 0 to 2 ' three lines
for j as integer = 0 to 1 ' two points each
px1 = L3D(i).x1(j)
py1 = L3D(i).y1(j)
pz1 = L3D(i).z1(j)
L3D(i).rx1(j) = (Cos(angle*DtoR) * px1 - Sin(angle*DtoR) * py1)
L3D(i).ry1(j) = (Sin(angle*DtoR) * px1 + Cos(angle*DtoR) * py1)
next j
next i
set3D(0,0,0) 'center of rotation
end sub
sub rotatePointsX(angle as double)
dim as double px1,py1,pz1
for i as integer = 0 to 2 ' three lines
for j as integer = 0 to 1 ' two points each
pz1 = L3D(i).z1(j)
py1 = L3D(i).y1(j)
px1 = L3D(i).x1(j)
L3D(i).rz1(j) = (Cos(angle*DtoR) * pz1 - Sin(angle*DtoR) * py1)
L3D(i).ry1(j) = (Sin(angle*DtoR) * pz1 + Cos(angle*DtoR) * py1)
next j
next i
set3D(0,0,0)
end sub
sub rotatePointsY(angle as double)
dim as double px1,py1,pz1
for i as integer = 0 to 2 ' three lines
for j as integer = 0 to 1 'two points each
pz1 = L3D(i).z1(j)
px1 = L3D(i).x1(j)
py1 = L3D(i).y1(j)
L3D(i).rz1(j) = (Cos(angle*DtoR) * pz1 - Sin(angle*DtoR) * px1)
L3D(i).rx1(j) = (Sin(angle*DtoR) * pz1 + Cos(angle*DtoR) * px1)
next j
next i
set3D(0,0,0)
end sub
sub drawPolygons()
for i as integer = 0 to 2 'three lines
drawLine3D(L3D(i).rx1(0), L3D(i).ry1(0), L3D(i).rz1(0), L3D(i).rx1(1) ,L3D(i).ry1(1) ,L3D(i).rz1(1) )
next i
end sub
dim as double now1
now1 = timer
'rotate points around x,y axis center point 150,350
dim as double angle
'rotate around Z - AXIS
for angle = 0 to 360 step 10
cls
locate 2,2
print "ANGLE ROTATION AROUND Z-AXIS =";angle
rotatePointsZ(angle)
drawPolygons()
while timer-now1 < 0.1
sleep 2
wend
now1 = timer
next angle
'rotate around X - AXIS
for angle = 0 to 360 step 10
cls
locate 2,2
print "ANGLE ROTATION AROUND X-AXIS =";angle
rotatePointsX(angle)
drawPolygons()
while timer-now1 < 0.1
sleep 2
wend
now1 = timer
next angle
'rotate around Y - AXIS
for angle = 0 to 360 step 10
cls
locate 2,2
print "ANGLE ROTATION AROUND Y-AXIS =";angle
rotatePointsY(angle)
drawPolygons()
while timer-now1 < 0.1
sleep 2
wend
now1 = timer
next angle
sleep
'DATA BASE OF THREE LINES
data 0,100,0 'start point of line
data 0,-100,0 'end point of line
data -100,0,0
data +100,0,0
data 0,0,100
data 0,0,-100