ClipSprite3D()
Posted: Mon Sep 19, 2005 11:26 pm
That would be quite handy for the isometric tile engine i'm making because it would then support sprite3d, and then I could create nice effects like alphablended walls and stuff...
Code: Select all
Structure DDPIXELFORMAT
dwSize.l
dwFlags.l
dwFourCC.l
dwRGBBitCount.l
dwRBitMask.l
dwGBitMask.l
dwBBitMask.l
dwRGBAlphaBitMask.l
EndStructure
Structure DDCOLORKEY
dwColorSpaceLowValue.l
dwColorSpaceHighValue.l
EndStructure
Structure DDSCAPS2
dwCaps.l
dwCaps2.l
dwCaps3.l
dwCaps4.l
EndStructure
Structure DDSURFACEDESC2
dwSize.l
dwFlags.l
dwHeight.l
dwWidth.l
lPitch.l
dwBackBufferCount.l
dwRefreshRate.l
dwAlphaBitDepth.l
dwReserved.l
lpSurface.l
ddckCKDestOverlay.DDCOLORKEY
ddckCKDestBlt.DDCOLORKEY
ddckCKSrcOverlay.DDCOLORKEY
ddckCKSrcBlt.DDCOLORKEY
ddpfPixelFormat.DDPIXELFORMAT
ddsCaps.DDSCAPS2
dwTextureStage.l
EndStructure
Structure D3DTLVERTEX
sx.f
sy.f
sz.f
rhw.f
color.l
specular.l
tu.f
tv.f
EndStructure
Structure PB_Sprite3D
Texture.IDirectDrawSurface7 ; DirectDrawSurface7
Vertice.D3DTLVERTEX[4] ; The 4 vertices for the rectangle sprite
Width.w ; width set with ZoomSprite3D()
Height.w ; height set with ZoomSprite3D()
unknown.l
EndStructure
Procedure ClipSprite3D(Sprite3D,ClipX,ClipY,ClipWidth,ClipHeight)
*Sprite3D.PB_Sprite3D=IsSprite3D(Sprite3D)
If *Sprite3D=0:ProcedureReturn 0:EndIf
*DDS.IDirectDrawSurface7=*Sprite3D\Texture
DDSDESC.DDSURFACEDESC2
DDSDESC\dwSize=SizeOf(DDSURFACEDESC2)
Result=*DDS\GetSurfaceDesc(DDSDESC)
If Result:ProcedureReturn 0:EndIf
*Sprite3D\Vertice[0]\tu=ClipX/DDSDESC\dwWidth
*Sprite3D\Vertice[0]\tv=ClipY/DDSDESC\dwHeight
*Sprite3D\Vertice[1]\tu=(ClipX+ClipWidth)/DDSDESC\dwWidth
*Sprite3D\Vertice[1]\tv=ClipY/DDSDESC\dwHeight
*Sprite3D\Vertice[2]\tu=ClipX/DDSDESC\dwWidth
*Sprite3D\Vertice[2]\tv=(ClipY+ClipHeight)/DDSDESC\dwHeight
*Sprite3D\Vertice[3]\tu=(ClipX+ClipWidth)/DDSDESC\dwWidth
*Sprite3D\Vertice[3]\tv=(ClipY+ClipHeight)/DDSDESC\dwHeight
ProcedureReturn 1 ; return success
EndProcedure
;Example:
InitSprite()
InitSprite3D()
InitKeyboard()
OpenScreen(1024,768,32,"Clip sprite3D")
CreateSprite(1,256,256,#PB_Sprite_Texture)
StartDrawing(SpriteOutput(1))
Box(0,0,256,256,#Blue)
Box(0,0,50,50,#Yellow)
Box(50,50,50,50,#Red)
StopDrawing()
CreateSprite3D(1,1)
ClipSprite3D(1,0,0,100,100)
Repeat
ClearScreen(0,0,0)
Start3D()
RotateSprite3D(1,1,1)
DisplaySprite3D(1,200,200)
Stop3D()
FlipBuffers()
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
I think your you refering to the aspect ratio. The sprite will be clipped with this code but it gets sized to. After you clipped a sprite you need to use zoomSprite3D() using the same dimensions you used when clipping it. At least if you want a pixel-perfect display.Joakim Christiansen wrote:EDIT:
It messed up the graphix... weird...