Author Topic: Steve's 3D Print  (Read 3753 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Steve's 3D Print
« on: November 17, 2019, 10:03:51 pm »
Inspired by Petr's 3D printing, I sat down and worked up a simple little routine to make pseudo-3d text of my own, and I wrapped it up into a single neat little SUB with 3 zillion parameters...

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1024, 720, 32)
  2. OE20 = _LOADFONT("calibri.ttf", 72)
  3. _FONT OE20
  4.  
  5. Print3D 100, 100, "Hello World", 10, 10, OE20, &HFFFFFF00, 1, 1, 1, 1
  6. Print3D 100, 200, "Steve is Awesome!", 5, -10, OE20, &HFFFF0000, -1, 1, 1, 1.25
  7. Print3D 100, 300, "So, what do you guys think?", 6, 0, OE20, &HFFFFFFFF, 1, .5, .5, .5
  8.  
  9. Print3D 100, 400, "No 3D, just *italic* style text.", 1, 20, OE20, &HFF00FF00, 0, 0, 1, 1
  10.  
  11.  
  12. SUB Print3D (x AS INTEGER, y AS INTEGER, text$, thick AS INTEGER, tilt AS INTEGER,_
  13.              f AS LONG, fg AS _UNSIGNED LONG, xchange as integer, ychange as integer,_
  14.              scalex as _float, scaley as _float)
  15.     DIM copy AS INTEGER
  16.     DIM dx1 AS _FLOAT, dx2 AS _FLOAT, dy1 AS _FLOAT, dy2 AS _FLOAT
  17.  
  18.     d = _DEST: s = _SOURCE: font = _FONT
  19.     copy = _NEWIMAGE(_WIDTH, _HEIGHT, 32)
  20.     _DEST copy: _SOURCE copy
  21.     _FONT f
  22.     sx1 = 0: sy1 = 0
  23.     sx2 = _PRINTWIDTH(text$, copy): sy2 = _FONTHEIGHT(f)
  24.  
  25.     dx1 = x: dy1 = y
  26.     dx2 = x + sx2 * scalex: dy2 = y + sy2 * scaley
  27.  
  28.     FOR i = thick TO 0 STEP -1
  29.         CLS , 0
  30.         COLOR _RGBA32(_RED32(fg), _GREEN32(fg), _BLUE32(fg), 155 + 100 / i), 0
  31.         PRINT text$
  32.         _MAPTRIANGLE (sx1, sy1)-(sx2, sy1)-(sx1, sy2), copy TO(dx1 + tilt, dy1)-(dx2 + tilt, dy1)-(dx1, dy2), d
  33.         _MAPTRIANGLE (sx1, sy2)-(sx2, sy1)-(sx2, sy2), copy TO(dx1, dy2)-(dx2 + tilt, dy1)-(dx2, dy2), d
  34.         dx1 = dx1 + xchange: dx2 = dx2 + xchange: dy1 = dy1 + ychange: dy2 = dy2 + ychange
  35.     NEXT
  36.     _DEST d: _SOURCE s: _FONT font
  37.     _FREEIMAGE copy

Various thickness is supported.  Different tilts are supported.  Text can expand from any direction...  We can use it to italicize our text if we want to... It scales text to different widths and heights...

It's not a true 3D text, as in we can't rotate it on the x/y/z axis, but it makes a nice imitation text which we can use to create a nice title screen, or such, for our programs. 

Play around with it, see what you guys think of it, and I'll be happily awaiting to see how you guys who are much better than me in math will improve/alter this. 

Many thanks go to Petr for providing the inspiration for me to sit down and play around with getting this up and going to the point where it is.  I'm really quite happy with how it performs and what it can do for us, and I think this will end up going into my toolbox for regular use from now on.  ;)
« Last Edit: November 17, 2019, 10:15:43 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Steve's 3D Print
« Reply #1 on: November 17, 2019, 10:14:31 pm »
And a little demo of some of the various styles of 3d text which we can generate with the routine.  Watch and pay attention to which direction the text tilts and turns as the program goes along.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1024, 720, 32)
  2. OE20 = _LOADFONT("calibri.ttf", 72)
  3. _FONT OE20
  4.  
  5. FOR x = -2 TO 2 STEP 0.1
  6.     CLS , 0
  7.     Print3D 100, 200, "Steve is Awesome!", 5, x * 20, OE20, &HFFFF0000, x, x, 1, 1.25
  8.     _LIMIT 3
  9.     _DISPLAY
  10. FOR x = -2 TO 2 STEP 0.1
  11.     CLS , 0
  12.     Print3D 100, 200, "Steve is Awesome!", 5, x * 20, OE20, &HFFFF0000, -x, -x, 1, 1.25
  13.     _LIMIT 3
  14.     _DISPLAY
  15. FOR x = -2 TO 2 STEP 0.1
  16.     CLS , 0
  17.     Print3D 100, 200, "Steve is Awesome!", 5, x * 20, OE20, &HFFFF0000, x, -x, 1, 1.25
  18.     _LIMIT 3
  19.     _DISPLAY
  20. FOR x = -2 TO 2 STEP 0.1
  21.     CLS , 0
  22.     Print3D 100, 200, "Steve is Awesome!", 5, x * 20, OE20, &HFFFF0000, -x, x, 1, 1.25
  23.     _LIMIT 3
  24.     _DISPLAY
  25.  
  26.  
  27.  
  28.  
  29.  
  30. SUB Print3D (x AS INTEGER, y AS INTEGER, text$, thick AS INTEGER, tilt AS INTEGER,_
  31.              f AS LONG, fg AS _UNSIGNED LONG, xchange as integer, ychange as integer,_
  32.              scalex as _float, scaley as _float)
  33.     DIM copy AS INTEGER
  34.     DIM dx1 AS _FLOAT, dx2 AS _FLOAT, dy1 AS _FLOAT, dy2 AS _FLOAT
  35.  
  36.     d = _DEST: s = _SOURCE: font = _FONT
  37.     copy = _NEWIMAGE(_WIDTH, _HEIGHT, 32)
  38.     _DEST copy: _SOURCE copy
  39.     _FONT f
  40.     sx1 = 0: sy1 = 0
  41.     sx2 = _PRINTWIDTH(text$, copy): sy2 = _FONTHEIGHT(f)
  42.  
  43.     dx1 = x: dy1 = y
  44.     dx2 = x + sx2 * scalex: dy2 = y + sy2 * scaley
  45.  
  46.     FOR i = thick TO 0 STEP -1
  47.         CLS , 0
  48.         COLOR _RGBA32(_RED32(fg), _GREEN32(fg), _BLUE32(fg), 155 + 100 / i), 0
  49.         PRINT text$
  50.         _MAPTRIANGLE (sx1, sy1)-(sx2, sy1)-(sx1, sy2), copy TO(dx1 + tilt, dy1)-(dx2 + tilt, dy1)-(dx1, dy2), d
  51.         _MAPTRIANGLE (sx1, sy2)-(sx2, sy1)-(sx2, sy2), copy TO(dx1, dy2)-(dx2 + tilt, dy1)-(dx2, dy2), d
  52.         dx1 = dx1 + xchange: dx2 = dx2 + xchange: dy1 = dy1 + ychange: dy2 = dy2 + ychange
  53.     NEXT
  54.     _DEST d: _SOURCE s: _FONT font
  55.     _FREEIMAGE copy
« Last Edit: November 17, 2019, 10:16:03 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Steve's 3D Print
« Reply #2 on: November 18, 2019, 10:37:19 am »
Nice work, Steve. For a true 3D font, is easiest to choose a box as a pixel. You just make a block (in 3D space) instead of a pixel, as my video shows earlier this year:       


Now I try write my pseudo 3D function, my suggestion is to generate the whole ASCII table (then, the character call will be much faster). Maybe only some deformed monsters will come out of it instead of letters, we'll see. :)