ClipSprite3D()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
S.M.
Enthusiast
Enthusiast
Posts: 118
Joined: Sat Apr 24, 2004 1:11 pm
Contact:

Post by S.M. »

I wrote such a function, some time ago.

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)
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Thank you S.M! :D
I hope it's very fast, because I have to use it for every tile i display.
EDIT:
It messed up the graphix... weird... :cry:
I like logic, hence I dislike humans but love computers.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

* BUMP *

@S.M.:
Is it safe to clip a Sprite3D to a non-proportional size? E.g. like 120x177 or has to be in 2^N format?
Joakim Christiansen wrote:EDIT:
It messed up the graphix... weird... :cry:
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.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

How much I need to pay to Fantaisie Software to implement this command which 100% compatible with DirectX7 and the DirectX9 subsystem ASAP?

Don't think I'm kidding here, I mean business. This command is so essential to game development like the air to breath and I'm puzzled it's still not implemented after all these years.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

to be honest, I would prefer a natively set for the U/V coordinates.
"Clip" is a very special use of this, only horizontal/vertical sides.
setting of U/V bears much more possibilities.
oh... and have a nice day.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

I don't care how it's called or implemented. I just want this feature to be added natively ASAP and I am willing to pay for it.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: ClipSprite3D()

Post by DoubleDutch »

ClipSprite3D is needed for all formats to make game programming easier (and the drawing faster). It can be done from code on the forum for DirectX - but can it be done for OpenGl (Mac/Linux)?

Also, the DirectX starup needs to be modified so that the back of a texture is displayed - so you can do h and v flips - if possible this should be done on OpenGl too (for Mac/Linux).

Hopefully the ability to set the sprite3D drawing destination buffer will come back (drawing a texture to a texture) - this way we can create some nice effects.

In general the Sprite3D library needs beefing up so you don't have to go to Ogre to get these abilities.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Post Reply