02-20-2024, 03:28 PM (This post was last modified: 02-20-2024, 03:52 PM by bplus.)
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! ;-))
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
02-20-2024, 10:22 PM (This post was last modified: 02-20-2024, 11:50 PM by bplus.)
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
' 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 simple Oh nutz now I see I have my numbered label points commented as ' apex nope! only the first is... BRB, OK fixed.
02-21-2024, 02:58 PM (This post was last modified: 02-21-2024, 07:18 PM by bplus.)
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...
02-21-2024, 09:51 PM (This post was last modified: 02-21-2024, 09:58 PM by bplus.)
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
' 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
02-22-2024, 02:49 AM (This post was last modified: 02-22-2024, 02:50 AM by PhilOfPerth.)
I was a bit amused with yor heading "very simple 3D system! Sounds a bit like "Brain Surgery 101" to newbys like me!
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.)
Please visit my Website at: http://oldendayskids.blogspot.com/
(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
' 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 simple 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.)
Please visit my Website at: http://oldendayskids.blogspot.com/
(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.