TransformImage3D()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

TransformImage3D()

Post by Michael Vogel »

I would like to have a TransformImage3D function which does the same like TransformSprite3D but for images.
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: TransformImage3D()

Post by STARGÅTE »

Why you need it? Example?
Why you can't use Sprite3D?
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: TransformImage3D()

Post by Michael Vogel »

STARGÅTE wrote:Why you need it? Example?
Why you can't use Sprite3D?
I have written a program to displaying GPX tracks in 3D and there are only two problems (some drawtext quality issues and sprite library incompatibilities with certain graphic cards).

The screenshots below may give you an indication about such trifling issues, like the bold button text in the top window. The main point is the 3D map (seen in the background window) which works fine on maybe 95% of all PC's but leads to a crash on all others. I fear, the only way to get a reliable program showing the 3D map, is a TransformImage3D command.

Image
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: TransformImage3D()

Post by STARGÅTE »

ok, so you want a software 3D engine (based on cpu).
In this case, I have already written an include: http://www.purebasic.fr/german/viewtopi ... 89#p305189
to use functions like: Plot3D(), Line3D() and so on, for drawing in 3D olny with Start/Stop Drawing.
I can add a funktion like: DrawImage3D(), than the image pixels used, not the color.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: TransformImage3D()

Post by Michael Vogel »

STARGÅTE wrote:ok, so you want a software 3D engine (based on cpu).
In this case, I have already written an include: http://www.purebasic.fr/german/viewtopi ... 89#p305189
to use functions like: Plot3D(), Line3D() and so on, for drawing in 3D olny with Start/Stop Drawing.
I can add a funktion like: DrawImage3D(), than the image pixels used, not the color.
The image for your library looks really fine, I will have a look, maybe your include file could be helpful for me as well. A DrawImage3D function would also allow me to send the image to the printer, which would be another point for such a command.

Actually, the whole 3D stuff has been solved by using matrix manipulations which are fast enough to rotate the GPS track very quickly and the rotation of the map (which could be as large as 1280 x 1280 pixels) is also relatively fast, so a complete redraw (track, text information, map) is done in less than 50 milliseconds even on slower machines.

I'm not sure, but could a DrawImage3D be written to work also that fast?!
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: TransformImage3D()

Post by STARGÅTE »

I'm not sure, but could a DrawImage3D be written to work also that fast?!
No.
If i will Plot 1280x1280 pixel with Plot() my system needs 62ms, without any calculations.
(my) Drawing3D functions not for runtime display, only for single draw or small drawing areas.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: TransformImage3D()

Post by Michael Vogel »

Stargate, I have downloaded your brilliant example for drawing 3D elements, definitely looks great.

On the other hand, I would need a fast (and working) possibility to transform an image to a given rectangle like it could be done with sprites. So I only can hope, that the used sprite library function could be easily adapted to be usable for images as well.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: TransformImage3D()

Post by netmaestro »

I would need a fast (and working) possibility to transform an image to a given rectangle like it could be done with sprites.
If you're on Windows, transforming an image similar to TransformSprite3D() can be accomplished with the SetWorldTransform_() API. I am halfway through making an example for you but I can't finish it until tomorrow.
BERESHEIT
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: TransformImage3D()

Post by Michael Vogel »

netmaestro wrote:
I would need a fast (and working) possibility to transform an image to a given rectangle like it could be done with sprites.
If you're on Windows, transforming an image similar to TransformSprite3D() can be accomplished with the SetWorldTransform_() API. I am halfway through making an example for you but I can't finish it until tomorrow.
Don't rush, I'm trying to optimize my code since weeks to get a working version for all platforms, but failed. Your posting gives me new hope, thanks for all your efforts :wink:
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: TransformImage3D()

Post by applePi »

STARGÅTE, this is a great examples, also the Alphablending demonstrations, and yes in a future version the addition of DrawImage3D() will be great. thanks
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: TransformImage3D()

Post by Michael Vogel »

Another (small) reason, why TransformImage3D would be a cool function: it would support PrinterOutput :wink:
codeprof
User
User
Posts: 65
Joined: Sun Sep 16, 2012 12:13 pm

Re: TransformImage3D()

Post by codeprof »

For Windows, this code could help you:

Code: Select all

Structure QUADBLT_VERTEX
x.l
y.l
EndStructure

Structure QUADBLT_QUAD
v.QUADBLT_VERTEX[4]
EndStructure

Structure QUADBLT_TRIANGLE
v.QUADBLT_VERTEX[3]
EndStructure

Procedure QuadBlt(hdcDest.l,*points.QUADBLT_QUAD,hdcSrc.l,lXSrc.l,lYSrc.l,lWidth.l,lHeight.l)
  
   
If hdcDest=0 Or *points=0 Or hdcSrc=0
ProcedureReturn #False
EndIf

GetClipBox_(hdcSrc,clipbox.rect)
If lXSrc+lWidth>clipbox\right-clipbox\left Or lYSrc+lHeight>clipbox\bottom-clipbox\top Or lXSrc<0 Or lYSrc<0 Or lWidth<=0 Or lHeight<=0
ProcedureReturn #False
EndIf
rectrgn=CreateRectRgn_(clipbox\left,clipbox\top,clipbox\right,clipbox\bottom)
lResult=GetClipRgn_(hdcDest,rectrgn)
If lResult=-1 Or rectrgn=0
ProcedureReturn #False
EndIf

Triangle2.QUADBLT_TRIANGLE
Triangle2\v[0]\x=*points\v[3]\x
Triangle2\v[0]\y=*points\v[3]\y
Triangle2\v[1]\x=*points\v[2]\x
Triangle2\v[1]\y=*points\v[2]\y
Triangle2\v[2]\x=*points\v[1]\x
Triangle2\v[2]\y=*points\v[1]\y

rgntriangle1=CreatePolygonRgn_(*points,3,1)
rgntriangle2=CreatePolygonRgn_(Triangle2,3,1)

If lResult<>0
CombineRgn_(rgntriangle1,rgntriangle1,rectrgn,#RGN_AND)
CombineRgn_(rgntriangle2,rgntriangle2,rectrgn,#RGN_AND)
EndIf

lOldStretchBltMode=SetStretchBltMode_(hdcDest,#COLORONCOLOR)

SelectClipRgn_(hdcDest,rgntriangle1)
PlgBlt_(hdcDest,*points,hdcSrc,lXSrc,lYSrc,lWidth,lHeight,0,0,0) 

SelectClipRgn_(hdcDest,rgntriangle2)
PlgBlt_(hdcDest,Triangle2,hdcSrc,lWidth+lXSrc,lHeight+lYSrc,-lWidth,-lHeight,0,0,0) 

SetStretchBltMode_(hdcDest,lOldStretchBltMode)

;If lResult=0
SelectClipRgn_(hdcDest,0)
;Else
;SelectClipRgn_(hdcDest,rectrgn)
;EndIf

DeleteObject_(rectrgn)
DeleteObject_(rgntriangle1)
DeleteObject_(rgntriangle2)
EndProcedure



Dim pt.point(3)


OpenWindow(1,0,0,900,900,"TEST")
LoadImage(1,"d:\test.bmp")

MemDC=CreateCompatibleDC_(0)
SelectObject_(MemDC,ImageID(1))

DC=StartDrawing(WindowOutput(1))

pt(0)\x=70
pt(0)\y=300

pt(1)\x=400
pt(1)\y=300

pt(2)\x=400
pt(2)\y=580

pt(3)\x=900
pt(3)\y=700

QuadBlt(DC,@pt(),MemDC,0,0,ImageWidth(1),ImageHeight(1))
StopDrawing()
DeleteDC_(MemDC)

Repeat
Until WindowEvent()=#WM_CLOSE
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: TransformImage3D()

Post by Michael Vogel »

codeprof wrote:For Windows, this code could help you: [...]
Thanks for that, codeprof, seems to work in general.
I've observed some perspective distorting which looks similar to TranformSprite3D without 'z' parameters. Anyhow, the code performs very slow on my notebook, maybe I did something wrong (no, no, debugger was off), but rotating maps (as seen in the screenshot above) in realtime is not possible.

[Rhetorical question] - could it be possible, that Fred's routine is more than 10 times faster?!
codeprof
User
User
Posts: 65
Joined: Sun Sep 16, 2012 12:13 pm

Re: TransformImage3D()

Post by codeprof »

Yes the command is really slow, it seems this is cause by the clipping regions. However I do not know how to improve performace.
There also seems no soluton to correct the perspective distorting.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: TransformImage3D()

Post by Michael Vogel »

Yes, seems like that – so maybe these sprite commands are handmade by Fred© or based on the SetWorldTransform_() functionality. As netmaestro gave the hint for using this call to make linear transformations, this could be a solution, however it will be possible to make the outer area transparent then.
Post Reply