Page 1 of 2

TransformImage3D()

Posted: Tue Nov 27, 2012 7:49 pm
by Michael Vogel
I would like to have a TransformImage3D function which does the same like TransformSprite3D but for images.

Re: TransformImage3D()

Posted: Tue Nov 27, 2012 10:53 pm
by STARGÅTE
Why you need it? Example?
Why you can't use Sprite3D?

Re: TransformImage3D()

Posted: Wed Nov 28, 2012 4:13 pm
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

Re: TransformImage3D()

Posted: Wed Nov 28, 2012 4:54 pm
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.

Re: TransformImage3D()

Posted: Wed Nov 28, 2012 6:40 pm
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?!

Re: TransformImage3D()

Posted: Wed Nov 28, 2012 7:55 pm
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.

Re: TransformImage3D()

Posted: Thu Nov 29, 2012 7:05 am
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.

Re: TransformImage3D()

Posted: Mon Dec 03, 2012 5:10 am
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.

Re: TransformImage3D()

Posted: Tue Dec 04, 2012 12:31 am
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:

Re: TransformImage3D()

Posted: Sat Dec 15, 2012 2:05 pm
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

Re: TransformImage3D()

Posted: Fri Dec 28, 2012 10:21 am
by Michael Vogel
Another (small) reason, why TransformImage3D would be a cool function: it would support PrinterOutput :wink:

Re: TransformImage3D()

Posted: Mon Dec 31, 2012 2:42 pm
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

Re: TransformImage3D()

Posted: Tue Jan 01, 2013 12:48 pm
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?!

Re: TransformImage3D()

Posted: Fri Jan 04, 2013 12:09 pm
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.

Re: TransformImage3D()

Posted: Fri Jan 04, 2013 6:10 pm
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.