TransformImage3D()
- Michael Vogel
- Addict
- Posts: 2797
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
TransformImage3D()
I would like to have a TransformImage3D function which does the same like TransformSprite3D but for images.
Re: TransformImage3D()
Why you need it? Example?
Why you can't use Sprite3D?
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 more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
- Michael Vogel
- Addict
- Posts: 2797
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: TransformImage3D()
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).STARGÅTE wrote:Why you need it? Example?
Why you can't use Sprite3D?
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.

Re: TransformImage3D()
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.
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 more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
- Michael Vogel
- Addict
- Posts: 2797
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: TransformImage3D()
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.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.
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?!
Re: TransformImage3D()
No.I'm not sure, but could a DrawImage3D be written to work also that fast?!
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 more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
- Michael Vogel
- Addict
- Posts: 2797
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: TransformImage3D()
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.
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.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: TransformImage3D()
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.I would need a fast (and working) possibility to transform an image to a given rectangle like it could be done with sprites.
BERESHEIT
- Michael Vogel
- Addict
- Posts: 2797
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: TransformImage3D()
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 effortsnetmaestro wrote: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.I would need a fast (and working) possibility to transform an image to a given rectangle like it could be done with sprites.

Re: TransformImage3D()
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
- Michael Vogel
- Addict
- Posts: 2797
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: TransformImage3D()
Another (small) reason, why TransformImage3D would be a cool function: it would support PrinterOutput 

Re: TransformImage3D()
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
- Michael Vogel
- Addict
- Posts: 2797
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: TransformImage3D()
Thanks for that, codeprof, seems to work in general.codeprof wrote:For Windows, this code could help you: [...]
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?!
Re: TransformImage3D()
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.
There also seems no soluton to correct the perspective distorting.
- Michael Vogel
- Addict
- Posts: 2797
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: TransformImage3D()
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.