Page 2 of 2

Re: TransformImage3D()

Posted: Fri Jan 04, 2013 6:26 pm
by freak
The sprite function uses hardware accelleration. Any image based solution would be very slow compared to that.

Re: TransformImage3D()

Posted: Mon Jan 14, 2013 12:11 pm
by WriteView
I tried to use codeprof routine.
I found something similar here which fits to what I want: http://www.purebasic.fr/english/viewtop ... 13&t=52723.
Maybe I don't know how to use it. I don't think it transform like it should do.

Try this code which is the same from codeprof with some painting included:

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")
CreateImage(1,500,500)
StartDrawing(ImageOutput(1))
Box(0,0,500,500,#Yellow)

For runner = 0 To 49
  Box(10*runner,0,2,500,#Black)
Next

StopDrawing()


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

DC=StartDrawing(WindowOutput(1))

pt(0)\x=100
pt(0)\y=100

pt(1)\x=600
pt(1)\y=100

pt(2)\x=100+50
pt(2)\y=750

pt(3)\x=600-50
pt(3)\y=750

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

Repeat
Until WindowEvent()=#WM_CLOSE
You can see how it is transformed. The lines changes ther angle along the diagonal from the bottom left to the top right. Can somebody provide me a solution where the lines don't change the angle in the middle of the picture...?

I'm urgently interested in transforming an image like I do in my sample above. I even thought about to grab every line and paint it into a new picture (which is definitely not a good solution). It doesn't has to be a fast routine. It should just transform like it should be.

Thanks

Re: TransformImage3D()

Posted: Thu Jan 31, 2013 10:19 pm
by STARGÅTE
@Michael Vogel

here a first example with my Drawing3D-Include with the new function DrawImage3D:
Image

Download-Demo: Drawing3D_4.exe
change the view with pressed left mouse

If the code is optimized, I will also publish the include.

Re: TransformImage3D()

Posted: Fri Feb 01, 2013 6:00 pm
by Michael Vogel
STARGÅTE wrote:@Michael Vogel

here a first example with my Drawing3D-Include with the new function DrawImage3D:
[...]
If the code is optimized, I will also publish the include.
Stargate, this looks quite fine...
...not as fast as the sprite functions, but this could be useful as a workaround for some graphic cards and perfect to allow printing as well.