Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Wanted: Very Simple 3D system
#11
Right hand rules (as I know it):
On your right hand (where the name comes from):
1. thumb is x axis and is pointing in positive direction
2. index finger is y axis pointing in positive direction
3. middle finger is z axis pointing in positive direction

In physics and math, the right hand is naturally aligned so that the z axis points to your eye as you make on "L" with thumb and index finger, 3 o'clock with thumb the clock's small hand and index the large hand. clock.

BUT in BASIC the Y axis points down! still using your right hand, still making an "L" with thumb and index finger, point the y axis down to floor as y goes positive in index finger. Your elbow goes up, you have to swing your arm way over to left AND lo and behold the middle index finger, the positive direction points away for your eye. The z axis did a 180 just like the y axis. And hurts like hell to get the thumb to pointing right as it does in BASIC screen when y is ascending pointed down, it naturally wants to point left when the index finger is pointing down on the desk.

Wait.... now do we also have to remove our eye ball and swing it over to the other side, to restore again z pointing positively to it!

Wow that's new for me, I always forgot to swing the camera over when I flip the y axis, so z is still headed positively at the camera = my eyeball. It should still be 3 O'clock, time didn't do a 180.

Maybe not as easy as WINDOW screen but it builds character! ;-))

Picture this:


Attached Files Image(s)
   
b = b + ...
Reply
#12
I guess the xy projection plane could be anywhere in relation to "real" model in Euclidian 3D.

You would need offsets for all x, y and z to move camera over to project onto BASIC screen where x and y are always >= 0.
b = b + ...
Reply
#13
Oh hey @bert22306

Let me show you my 3D Printer!
Code: (Select All)
_Title "Fake 3D demo" 'b+ 2020- 01-30

Const xmax = 700, ymax = 300, xc = 300, yc = 300
Screen _NewImage(xmax, ymax, 32)
_Delay .25 'need time for screen to load before attempting to move it.
_ScreenMove _Middle
ReDim colr As _Unsigned Long
For i = 1 To 50
    colr = _RGB32(0 + 5 * i, 0, 0)
    Text 60 + i, 20 + i, 256, colr, "Bert"
Next
Sleep

Sub Text (x, y, textHeight, K As _Unsigned Long, txt$)
    Dim fg As _Unsigned Long, cur&, I&, multi, xlen
    fg = _DefaultColor
    'screen snapshot
    cur& = _Dest
    I& = _NewImage(8 * Len(txt$), 16, 32)
    _Dest I&
    Color K, _RGBA32(0, 0, 0, 0)
    _PrintString (0, 0), txt$
    multi = textHeight / 16
    xlen = Len(txt$) * 8 * multi
    _PutImage (x, y)-Step(xlen, textHeight), I&, cur&
    Color fg
    _FreeImage I&
End Sub
b = b + ...
Reply
#14
OK Bert convinced me to try Parallelism first, KISS. Here is my first test with a Pryramid the 3D model's height is the same as the side of a square base. You can press <, or >. for increasing and decreasing the PC = Parallel Constant

Code: (Select All)
_Title "3D per Parallelism test 1 Pyramid" 'b+ 2024-02-20
'  "parallelism suggests a connection of meaning through an echo of form"

Dim Shared As Long SW, SH: SW = 800: SH = 600
Screen _NewImage(SW, SH, 32)
_Delay .25 'need time for screen to load before attempting to move it.
_ScreenMove _Middle

Type XYZ
    As Double x, y, z
End Type
Type XY
    As Double x, y
End Type
Dim Shared As Double PC ': PC = .7 ' or something  PC = Parallel Constant

Window (-2, -1)-(2, 3)

' pyramid with square base and 4 iso-tri's to apex
Dim p3(1 To 5) As XYZ
Dim p2(1 To 5) As XY

p3(1).x = 0: p3(1).y = 2: p3(1).z = 0 ' apex

p3(2).x = -1: p3(2).y = 0: p3(2).z = -1 ' base
p3(3).x = 1: p3(3).y = 0: p3(3).z = -1
p3(4).x = 1: p3(4).y = 0: p3(4).z = 1
p3(5).x = -1: p3(5).y = 0: p3(5).z = 1


' now draw the thing! and find ideal PC = Parallel Constant
PC = .2
While _KeyDown(27) = 0
    kh& = _KeyHit
    If kh& = 44 Then PC = PC - .01
    If kh& = 46 Then PC = PC + .01
    ' recalc new array
    For i = 1 To 5
        M2SPP p3(i), p2(i) ' that was easy now draw the thing!
    Next

    Cls
    Locate 2, 20: Print "Here, the 3D Model height at apex is same as a side at the base."
    Locate 4, 18: Print "Press  <, = less, >. = more    When does the base look square?  PC ="; PC
    Locate 6, 21: Print "Oh! PC is the Parallel Constant for this very simple 3D system."
    ' base
    Line (p2(2).x, p2(2).y)-(p2(3).x, p2(3).y), &HFFFFFFFF ' front line base
    Line (p2(3).x, p2(3).y)-(p2(4).x, p2(4).y), &HFFFFFFFF ' right side
    Line (p2(4).x, p2(4).y)-(p2(5).x, p2(5).y), &HFFFF0000 ' back front
    Line (p2(5).x, p2(5).y)-(p2(2).x, p2(2).y), &HFFFF0000 ' left side


    Line (p2(1).x, p2(1).y)-(p2(2).x, p2(2).y), &HFFFFFFFF ' Front L
    Line (p2(1).x, p2(1).y)-(p2(3).x, p2(3).y), &HFFFFFFFF ' Front R
    Line (p2(1).x, p2(1).y)-(p2(4).x, p2(4).y), &HFFFFFFFF ' Back R
    Line (p2(1).x, p2(1).y)-(p2(5).x, p2(5).y), &HFFFF0000 ' Back L

    _PrintString (PMap(p2(1).x, 0) - 4, PMap(p2(1).y, 1) - 17), "1" ' apex
    _PrintString (PMap(p2(2).x, 0) - 10, PMap(p2(2).y, 1) + 4), "2" ' Front L
    _PrintString (PMap(p2(3).x, 0) + 4, PMap(p2(3).y, 1) + 4), "3" ' Front R
    _PrintString (PMap(p2(4).x, 0) - 4, PMap(p2(4).y, 1) + 8), "4" ' Back R
    _PrintString (PMap(p2(5).x, 0) - 4, PMap(p2(5).y, 1) + 8), "5" ' Back L

    Locate 35, 10
    Print "I thought -z would be the back part and +z the front but it seems to work visa versa."
    Locate 36, 25
    Print "Mainly because the white face is bigger, I think.";
    _Display

Wend

' thankyou vince '2024-02
Sub M2SPP (pIN As XYZ, pOut As XY) 'M2SPP = Model (3D) 2 Screen Per Parallelism
    pOut.x = pIN.x + PC * pIN.z
    pOut.y = pIN.y + PC * pIN.z
End Sub

Update: thanks to my new spellchecker, "somple" is now simpleSmile Oh nutz now I see I have my numbered label points commented as ' apex nope! only the first is... BRB, OK fixed.
b = b + ...
Reply
#15
OK I revised the conversion forumlas for projecting onto the screen so that as depth distance decreases ie the x-y plane approaches the eye/camera the bigger the image gets in the x-y plane. I am of opinion that as distance is increased the image expands more rapidly than just linearly controlled by the PC constant to aid in making the model look right. New PC looks like around .5 for pyramid with base below origin and apex just above it by same amount:
Code: (Select All)
_Title "3D per Parallelism test 2 Pyramid" 'b+ 2024-02-20
'  "parallelism suggests a connection of meaning through an echo of form"
' 2024-02-21 screew around with pyramid numbers

Dim Shared As Long SW, SH: SW = 800: SH = 600
Screen _NewImage(SW, SH, 32)
_Delay .25 'need time for screen to load before attempting to move it.
_ScreenMove _Middle

Type XYZ
    As Double x, y, z
End Type
Type XY
    As Double x, y
End Type
Dim Shared As Double PC ': PC = .7 ' or something  PC = Parallel Constant

Window (-2, -2)-(2, 2)

' pyramid with square base and 4 iso-tri's to apex
Dim p3(1 To 5) As XYZ
Dim p2(1 To 5) As XY

' use all positive x, y, z in 3D Model
p3(1).x = 0: p3(1).y = 1: p3(1).z = 0 ' apex

p3(2).x = -1: p3(2).y = -1: p3(2).z = -1 ' back L
p3(3).x = 1: p3(3).y = -1: p3(3).z = -1 ' back R
p3(4).x = 1: p3(4).y = -1: p3(4).z = 1 ' front R
p3(5).x = -1: p3(5).y = -1: p3(5).z = 1 ' front L


' now draw the thing! and find ideal PC = Parallel Constant
PC = .5
While _KeyDown(27) = 0
    kh& = _KeyHit
    If kh& = 44 Then PC = PC - .001
    If kh& = 46 Then PC = PC + .001
    ' recalc new array
    For i = 1 To 5
        M2SPP p3(i), p2(i) ' that was easy now draw the thing!
    Next

    Cls
    Locate 2, 20: Print "Here, the 3D Model height at apex is same as a side at the base."
    Locate 4, 18: Print "Press  <, = less, >. = more    When does the base look square?  PC ="; PC
    Locate 6, 21: Print "Oh! PC is the Parallel Constant for this very simple 3D system."

    ' base
    Line (p2(2).x, p2(2).y)-(p2(3).x, p2(3).y), &HFFFF0000 ' back line base
    Line (p2(3).x, p2(3).y)-(p2(4).x, p2(4).y), &HFFFFFFFF ' right side
    Line (p2(4).x, p2(4).y)-(p2(5).x, p2(5).y), &HFFFFFFFF ' front front
    Line (p2(5).x, p2(5).y)-(p2(2).x, p2(2).y), &HFFFF0000 ' left side


    Line (p2(1).x, p2(1).y)-(p2(2).x, p2(2).y), &HFFFF0000 ' Back L
    Line (p2(1).x, p2(1).y)-(p2(3).x, p2(3).y), &HFFFFFFFF ' Back R
    Line (p2(1).x, p2(1).y)-(p2(4).x, p2(4).y), &HFFFFFFFF ' Front R
    Line (p2(1).x, p2(1).y)-(p2(5).x, p2(5).y), &HFFFFFFFF ' Front L

    _PrintString (PMap(p2(1).x, 0) - 4, PMap(p2(1).y, 1) - 17), "1" ' apex
    _PrintString (PMap(p2(2).x, 0) - 10, PMap(p2(2).y, 1) + 4), "2" ' Front L
    _PrintString (PMap(p2(3).x, 0) + 4, PMap(p2(3).y, 1) + 4), "3" ' Front R
    _PrintString (PMap(p2(4).x, 0) - 4, PMap(p2(4).y, 1) + 8), "4" ' Back R
    _PrintString (PMap(p2(5).x, 0) - 4, PMap(p2(5).y, 1) + 8), "5" ' Back L

    Locate 35, 10
    Print "Now the lower the z the smaller the image."
    Locate 36, 25
    Print "Mainly because the white face is bigger, I think.";
    _Display

Wend

' here I am working with a Window so Screen obeys right hand rule so as z increases
' the image x, y plane is closer to the eye/camera so is bigger
' but should be distance squared
' thankyou vince '2024-02  the bigger the Z the closer it is to the eye the greater the image
Sub M2SPP (pIN As XYZ, pOut As XY) 'M2SPP = Model (3D) 2 Screen Per Parallelism
    pOut.x = pIN.x - Sgn(pIN.z) * PC * (pIN.z) ^ 2
    pOut.y = pIN.y - Sgn(pIN.z) * PC * (pIN.z) ^ 2
End Sub

Update: something went horribly wrong when I tried that projection Sub to cubes in various positions in space. Back to the howl'n owl in the woods...
b = b + ...
Reply
#16
Here is revised Pyramid 2 test, i went on and got Cubes working and came back and fixd code to be consistent with it.

Note: use square screen so WINDOW statement is easy. Otherwise you have to figure same ratio of screen sides in the Window corners.

Code: (Select All)
_Title "3D per Parallelism test 2 Pyramid" 'b+ 2024-02-20
'  "parallelism suggests a connection of meaning through an echo of form"
' 2024-02-21 screw around with pyramid numbers, did cube 1 and came back
' and fixed this to match.

Dim Shared As Long SW, SH: SW = 600: SH = 600
Screen _NewImage(SW, SH, 32) ' note: square screen make it easier to set Window command
_ScreenMove 340, 60

Type XYZ
    As Double x, y, z
End Type
Type XY
    As Double x, y
End Type
Dim Shared As Double PC: PC = .35 ' or something  PC = Parallel Constant
Window (-2, -2)-(2, 2)

' pyramid with square base and 4 iso-tri's to apex
Dim p3(1 To 5) As XYZ
Dim p2(1 To 5) As XY

' use all positive x, y, z in 3D Model
p3(1).x = 0: p3(1).y = 1: p3(1).z = 0 ' apex

p3(2).x = -1: p3(2).y = -1: p3(2).z = -1 ' back L
p3(3).x = 1: p3(3).y = -1: p3(3).z = -1 ' back R
p3(4).x = 1: p3(4).y = -1: p3(4).z = 1 ' front R
p3(5).x = -1: p3(5).y = -1: p3(5).z = 1 ' front L

' now draw the thing! and find ideal PC = Parallel Constant
While _KeyDown(27) = 0
    kh& = _KeyHit
    If kh& = 44 Then PC = PC - .001
    If kh& = 46 Then PC = PC + .001
    ' recalc new array
    For i = 1 To 5
        Project p3(i), p2(i) ' that was easy now draw the thing!
    Next

    Cls
    Locate 2: Print "   Here, the 3D Model height at apex is same as a side at the base."
    Locate 4: Print " Press  <, = less, >. = more    When does the base look square?  PC ="; PC
    Locate 6: Print "   Oh! PC is the Parallel Constant for this very simple 3D system."

    ' base
    Line (p2(2).x, p2(2).y)-(p2(3).x, p2(3).y), &HFFFF0000 ' back line base
    Line (p2(3).x, p2(3).y)-(p2(4).x, p2(4).y), &HFFFFFFFF ' right side
    Line (p2(4).x, p2(4).y)-(p2(5).x, p2(5).y), &HFFFFFFFF ' front front
    Line (p2(5).x, p2(5).y)-(p2(2).x, p2(2).y), &HFFFF0000 ' left side


    Line (p2(1).x, p2(1).y)-(p2(2).x, p2(2).y), &HFFFF0000 ' Back L
    Line (p2(1).x, p2(1).y)-(p2(3).x, p2(3).y), &HFFFFFFFF ' Back R
    Line (p2(1).x, p2(1).y)-(p2(4).x, p2(4).y), &HFFFFFFFF ' Front R
    Line (p2(1).x, p2(1).y)-(p2(5).x, p2(5).y), &HFFFFFFFF ' Front L

    _PrintString (PMap(p2(1).x, 0) - 4, PMap(p2(1).y, 1) - 17), "1" ' apex
    _PrintString (PMap(p2(2).x, 0) - 10, PMap(p2(2).y, 1) + 4), "2" ' Front L
    _PrintString (PMap(p2(3).x, 0) + 4, PMap(p2(3).y, 1) + 4), "3" ' Front R
    _PrintString (PMap(p2(4).x, 0) - 4, PMap(p2(4).y, 1) + 8), "4" ' Back R
    _PrintString (PMap(p2(5).x, 0) - 4, PMap(p2(5).y, 1) + 8), "5" ' Back L

    Locate 35, 15
    Print "Now the lower the z the farther back in the image."
    _Display
Wend

' thankyou vince '2024-02  mod to always draw right side and upper face
Sub Project (pIN As XYZ, pOut As XY) 'M2SPP = Model (3D) 2 Screen Per Parallelism
    pOut.x = pIN.x - PC * pIN.z
    pOut.y = pIN.y - PC * pIN.z
End Sub

And now here is Cube test 1:
Code: (Select All)
_Title "3D per Parallelism test Cube 1" ' started Parallelism b+ 2024-02-20
'  "parallelism suggests a connection of meaning through an echo of form"
' 2024-02-21 Pyramid 2 screw around with pyramid numbers fix projection formula
' 2024-02-21 now test cubes with DrawCube sub
' 2024-02-21 return to Pyramid 2 and fix that according to how this Project sub works.

Dim Shared As Long SW, SH: SW = 600: SH = 600
Screen _NewImage(SW, SH, 32)
_ScreenMove 340, 60

Type XYZ
    As Single x, y, z
End Type
Type XY
    As Single x, y
End Type
Dim Shared PC: PC = .35 ' or something  PC = Parallel Constant
Window (-5, -5)-(5, 5) ' setup for 3D

drawCube 0, 0, -2, 2, _RGB32(0, 160, 0)

drawCube 0, -2, 0, 2, _RGB32(0, 0, 255)
drawCube -2, 0, 0, 2, _RGB32(255, 0, 0)
'drawCube 0, 0, 0, 2, _RGB32(255, 255, 255) ' dont need
drawCube 2, 0, 0, 2, _RGB32(255, 0, 0)
drawCube 0, 2, 0, 2, _RGB32(0, 0, 255)

drawCube 0, 0, 2, 2, _RGB32(0, 160, 0) ' front most

Sub drawCube (cx, cy, cz, side, colr~&) 'draw a cube on screen from an xyz() 3D array
    Dim As Integer i, r, g, b
    Dim sd2, lx, rx, ty, by, fz, bz
    Dim c2 As _Unsigned Long
    r = _Red32(colr~&): g = _Green32(colr~&): b = _Blue32(colr~&)
    ReDim corners(0 To 7) As XYZ
    sd2 = side / 2
    rx = cx + sd2: lx = cx - sd2
    ty = cy + sd2: by = cy - sd2
    fz = cz + sd2: bz = cz - sd2
    'bck face
    corners(0).x = lx: corners(0).y = ty: corners(0).z = bz
    corners(1).x = rx: corners(1).y = ty: corners(1).z = bz
    corners(2).x = rx: corners(2).y = by: corners(2).z = bz
    corners(3).x = lx: corners(3).y = by: corners(3).z = bz
    'frt face
    corners(4).x = lx: corners(4).y = ty: corners(4).z = fz
    corners(5).x = rx: corners(5).y = ty: corners(5).z = fz
    corners(6).x = rx: corners(6).y = by: corners(6).z = fz
    corners(7).x = lx: corners(7).y = by: corners(7).z = fz

    ReDim xy(0 To 7) As XY
    For i = 0 To 7
        Project corners(i), xy(i) ' take a corner x,y,z and convert to screen coordinates x,y
        ' Print i; corners(i).x; corners(i).y; corners(i).z; " >>>  "; xy(i).x; xy(i).y
    Next
    'Sleep
    'Cls
    'back face
    'Line (xy(0).x, xy(0).y)-(xy(1).x, xy(1).y), &HFFFF0000
    'Line (xy(1).x, xy(1).y)-(xy(2).x, xy(2).y), colr~&
    'Line (xy(2).x, xy(2).y)-(xy(3).x, xy(3).y), colr~&
    'Line (xy(3).x, xy(3).y)-(xy(0).x, xy(0).y), colr~&

    'front face
    'Line (xy(4).x, xy(4).y)-(xy(5).x, xy(5).y), colr~&
    'Line (xy(5).x, xy(5).y)-(xy(6).x, xy(6).y), colr~&
    'Line (xy(6).x, xy(6).y)-(xy(7).x, xy(7).y), colr~&
    'Line (xy(7).x, xy(7).y)-(xy(4).x, xy(4).y), colr~&


    ' left side of face
    'If xy(0).x > 0 Then
    '    c2 = _RGB32(.6 * r, .6 * g, .6 * b)
    '    FillTriangle PMap(xy(0).x, 0), PMap(xy(0).y, 1), PMap(xy(3).x, 0), PMap(xy(3).y, 1), PMap(xy(7).x, 0), PMap(xy(7).y, 1), c2
    '    FillTriangle PMap(xy(4).x, 0), PMap(xy(4).y, 1), PMap(xy(7).x, 0), PMap(xy(7).y, 1), PMap(xy(0).x, 0), PMap(xy(0).y, 1), c2
    'End If

    ' top face
    'If xy(0).y < 0 Then
    c2 = _RGB32(.85 * r, .85 * g, .85 * b)
    FillTriangle PMap(xy(0).x, 0), PMap(xy(0).y, 1), PMap(xy(1).x, 0), PMap(xy(1).y, 1), PMap(xy(4).x, 0), PMap(xy(4).y, 1), c2
    FillTriangle PMap(xy(4).x, 0), PMap(xy(4).y, 1), PMap(xy(5).x, 0), PMap(xy(5).y, 1), PMap(xy(1).x, 0), PMap(xy(1).y, 1), c2
    'End If

    ' right face
    'If xy(1).x < 0 Then
    c2 = _RGB32(.6 * r, .6 * g, .6 * b)
    FillTriangle PMap(xy(1).x, 0), PMap(xy(1).y, 1), PMap(xy(2).x, 0), PMap(xy(2).y, 1), PMap(xy(5).x, 0), PMap(xy(5).y, 1), c2
    FillTriangle PMap(xy(5).x, 0), PMap(xy(5).y, 1), PMap(xy(6).x, 0), PMap(xy(6).y, 1), PMap(xy(2).x, 0), PMap(xy(2).y, 1), c2
    'End If

    ' bottom face
    'If xy(0).y > 0 Then
    '    c2 = _RGB32(45 * r, .45 * g, .45 * b)
    '    FillTriangle PMap(xy(3).x, 0), PMap(xy(3).y, 1), PMap(xy(2).x, 0), PMap(xy(2).y, 1), PMap(xy(7).x, 0), PMap(xy(7).y, 1), c2
    '    FillTriangle PMap(xy(7).x, 0), PMap(xy(7).y, 1), PMap(xy(6).x, 0), PMap(xy(6).y, 1), PMap(xy(2).x, 0), PMap(xy(2).y, 1), c2
    'End If

    ' front face
    FillTriangle PMap(xy(4).x, 0), PMap(xy(4).y, 1), PMap(xy(5).x, 0), PMap(xy(5).y, 1), PMap(xy(6).x, 0), PMap(xy(6).y, 1), colr~&
    FillTriangle PMap(xy(6).x, 0), PMap(xy(6).y, 1), PMap(xy(7).x, 0), PMap(xy(7).y, 1), PMap(xy(4).x, 0), PMap(xy(4).y, 1), colr~&

End Sub

' steves latest version to check out, seems to be working OK
Sub FillTriangle (x1, y1, x2, y2, x3, y3, K As _Unsigned Long)
    $Checking:Off
    Static a&, m As _MEM
    If a& = 0 Then a& = _NewImage(1, 1, 32): m = _MemImage(a&)
    _MemPut m, m.OFFSET, K
    _MapTriangle _Seamless(0, 0)-(0, 0)-(0, 0), a& To(x1, y1)-(x2, y2)-(x3, y3)
    $Checking:On
End Sub

' here I am working with a Window so Screen obeys right hand rule so as z increases
' the image x, y plane is closer to the eye/camera so is bigger
' but should be distance squared
' thankyou vince '2024-02  the bigger the Z the closer it is to the eye the greater the image
Sub Project (pIN As XYZ, pOut As XY) 'M2SPP = Model (3D) 2 Screen Per Parallelism
    pOut.x = pIN.x - PC * pIN.z
    pOut.y = pIN.y - PC * pIN.z
End Sub
b = b + ...
Reply
#17
I was a bit amused with yor heading "very simple 3D system! Sounds a bit like "Brain Surgery 101" to newbys like me!  Big Grin
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#18
(02-20-2024, 10:22 PM)bplus Wrote: OK Bert convinced me to try Parallelism first, KISS. Here is my first test with a Pryramid the 3D model's height is the same as the side of a square base. You can press <, or >. for increasing and decreasing the PC = Parallel Constant

Code: (Select All)
_Title "3D per Parallelism test 1 Pyramid" 'b+ 2024-02-20
'  "parallelism suggests a connection of meaning through an echo of form"

Dim Shared As Long SW, SH: SW = 800: SH = 600
Screen _NewImage(SW, SH, 32)
_Delay .25 'need time for screen to load before attempting to move it.
_ScreenMove _Middle

Type XYZ
    As Double x, y, z
End Type
Type XY
    As Double x, y
End Type
Dim Shared As Double PC ': PC = .7 ' or something  PC = Parallel Constant

Window (-2, -1)-(2, 3)

' pyramid with square base and 4 iso-tri's to apex
Dim p3(1 To 5) As XYZ
Dim p2(1 To 5) As XY

p3(1).x = 0: p3(1).y = 2: p3(1).z = 0 ' apex

p3(2).x = -1: p3(2).y = 0: p3(2).z = -1 ' base
p3(3).x = 1: p3(3).y = 0: p3(3).z = -1
p3(4).x = 1: p3(4).y = 0: p3(4).z = 1
p3(5).x = -1: p3(5).y = 0: p3(5).z = 1


' now draw the thing! and find ideal PC = Parallel Constant
PC = .2
While _KeyDown(27) = 0
    kh& = _KeyHit
    If kh& = 44 Then PC = PC - .01
    If kh& = 46 Then PC = PC + .01
    ' recalc new array
    For i = 1 To 5
        M2SPP p3(i), p2(i) ' that was easy now draw the thing!
    Next

    Cls
    Locate 2, 20: Print "Here, the 3D Model height at apex is same as a side at the base."
    Locate 4, 18: Print "Press  <, = less, >. = more    When does the base look square?  PC ="; PC
    Locate 6, 21: Print "Oh! PC is the Parallel Constant for this very simple 3D system."
    ' base
    Line (p2(2).x, p2(2).y)-(p2(3).x, p2(3).y), &HFFFFFFFF ' front line base
    Line (p2(3).x, p2(3).y)-(p2(4).x, p2(4).y), &HFFFFFFFF ' right side
    Line (p2(4).x, p2(4).y)-(p2(5).x, p2(5).y), &HFFFF0000 ' back front
    Line (p2(5).x, p2(5).y)-(p2(2).x, p2(2).y), &HFFFF0000 ' left side


    Line (p2(1).x, p2(1).y)-(p2(2).x, p2(2).y), &HFFFFFFFF ' Front L
    Line (p2(1).x, p2(1).y)-(p2(3).x, p2(3).y), &HFFFFFFFF ' Front R
    Line (p2(1).x, p2(1).y)-(p2(4).x, p2(4).y), &HFFFFFFFF ' Back R
    Line (p2(1).x, p2(1).y)-(p2(5).x, p2(5).y), &HFFFF0000 ' Back L

    _PrintString (PMap(p2(1).x, 0) - 4, PMap(p2(1).y, 1) - 17), "1" ' apex
    _PrintString (PMap(p2(2).x, 0) - 10, PMap(p2(2).y, 1) + 4), "2" ' Front L
    _PrintString (PMap(p2(3).x, 0) + 4, PMap(p2(3).y, 1) + 4), "3" ' Front R
    _PrintString (PMap(p2(4).x, 0) - 4, PMap(p2(4).y, 1) + 8), "4" ' Back R
    _PrintString (PMap(p2(5).x, 0) - 4, PMap(p2(5).y, 1) + 8), "5" ' Back L

    Locate 35, 10
    Print "I thought -z would be the back part and +z the front but it seems to work visa versa."
    Locate 36, 25
    Print "Mainly because the white face is bigger, I think.";
    _Display

Wend

' thankyou vince '2024-02
Sub M2SPP (pIN As XYZ, pOut As XY) 'M2SPP = Model (3D) 2 Screen Per Parallelism
    pOut.x = pIN.x + PC * pIN.z
    pOut.y = pIN.y + PC * pIN.z
End Sub

Update: thanks to my new spellchecker, "somple" is now simpleSmile  Oh nutz now I see I have my numbered label points commented as ' apex  nope! only the first is... BRB, OK fixed.
All a bit above me, but just curious: is the .7 (in line 15) sqrt(2)/2, by any chance?
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#19
(02-22-2024, 03:53 AM)PhilOfPerth Wrote: ...
All a bit above me, but just curious: is the .7 (in line 15) sqrt(2)/2, by any chance?

.7 came from vince
Quote:hello B+,

there are two options, the easiest is parallel projection and the trickier but more realistic one is perspective projection

say you have 3D coord variables x, y, z and you wish to convert them to 2D coords, lets call them p, q

for parallel:

p = x + 0.7*z
q = y + 0.7*z

where 0.7 is a kind of arbitrary number which you can mod until it looks right

But Phil if you were thinking a parallelogram to represent the square base of a pyramid with one angle at 45 degrees such that the sin 45 = cos 45 = SQR(2)/2 = .7???, I see where you are coming from ie, "isomorphic projections" for isometric drawings.
b = b + ...
Reply
#20
Very interesting topic, I look forward to playing with all this code.

So, anyone up for making a QB64PE version of Crystal Castles or Zaxxon?  Smile
Reply




Users browsing this thread: 1 Guest(s)