wow....good work! this was both fast and easy! but it wasnt the answer to this question
in a 3d box when you look at the corners in the back of it....they seem to be closer to each other than they really are...the further back they are, the closer and smaller they appear to be! how do i calculate this?
hehe...nej då =)
i just want to be able to draw some objects (stored in maps files(i can do the loading function by myself)) and then move around them how i want to....turn the mouse to look around and press the arrow keys to move around......no light, no textures or anything special...
And here's the modified draw function (get rest from first example) - changed parts are red:
Code:
Public Sub Form_MouseMove(b As Integer, s As Integer, x As Single, y As Single)
'Draw the lines
Dim A As Long
'This will be screen coordinates
Dim x1 As Long
Dim x2 As Long
Dim y1 As Long
Dim y2 As Long
'Temporary rotated points
Dim p1 As tPoint3D
Dim p2 As tPoint3D
Dim r1 As tPoint3D
Dim r2 As tPoint3D
'This is the screen middle
Dim tX As Long
Dim tY As Long
'Get screen middle
tX = (ScaleWidth / 2)
tX = (ScaleHeight / 2)
'Since 3d positions are relative we need a size
Dim size As Single
size = 100
'The camera says where to draw the cube
Dim cam As tPoint3D
'Move camera with mouse
cam.x = (200 - tX) / size
cam.y = (150 - tY) / size
cam.z = 5
'We also want a rotation
Dim rot As Single
'Rotate by mouse
rot = x / 100
'FOV (field-of-view) corrects the stretching
Dim fov As Single
fov = 3
Me.Cls
For A = 0 To UBound(l)
'Get points
p1 = p(l(A).p1)
p2 = p(l(A).p2)
'Rotate the points
With p1
r1.x = (.x * Sin(rot)) + (.y * Cos(rot))
r1.y = (.x * Cos(rot)) - (.y * Sin(rot))
r1.z = p1.z
End With
With p2
r2.x = (.x * Sin(rot)) + (.y * Cos(rot))
r2.y = (.x * Cos(rot)) - (.y * Sin(rot))
r2.z = p2.z
End With
'Get screen coordinates of both points
With r1
x1 = (.x + cam.x) / (.z + cam.z) * size * fov
y1 = (.y + cam.y) / (.z + cam.z) * size * fov
End With
With r2
x2 = (.x + cam.x) / (.z + cam.z) * size * fov
y2 = (.y + cam.y) / (.z + cam.z) * size * fov
End With
'Draw line (origin at screen center)
Line (x1 + tX, y1 + tY)-(x2 + tX, y2 + tY)
Next
End Sub
Software languages known: Qbasic - TI-Basic - Liberty Basic - Visual Basic 6
Software API's known: Directx 7 and 8
Internet languages, in the process of learning: HTML - JAVASCRIPT - PHP - CSS - MYSQL - AJAX