Sprite3DReal Userlibrary

Developed or developing a new product in PureBasic? Tell the world about it.
S.M.
Enthusiast
Enthusiast
Posts: 118
Joined: Sat Apr 24, 2004 1:11 pm
Contact:

Sprite3DReal Userlibrary

Post by S.M. »

Hi

I wrote a small 3D-Engine.It is called Sprite3DReal.

Download:
http://hometown.aol.de/Gastmailing/S3DR_1_0.zip (92 kb)
I hope it is useful for somebody. :D

Sorry for my bad english. :oops:

regards
Stefan
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post by Blade »

Very nice, considering that it doesn't need large DLLs to work, so a 20K exe can do all! I like it! :)

I tried to enable textures interpolation with Sprite3DQuality (your libary uses the original Sprite3D) but it doesn't work.
Can be done?
S.M.
Enthusiast
Enthusiast
Posts: 118
Joined: Sat Apr 24, 2004 1:11 pm
Contact:

Post by S.M. »

You're right it wasn't possible. :roll:

I updated the library now.Just download it again.

Download:
http://hometown.aol.de/Gastmailing/S3DR_1_0.zip

Now it should work. :wink:

regards
Stefan
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Thank you!
This is great.
I have a question: Is it possible to add a collision check function?

And Rotate and Zoom ones?
Here is this example:

Code: Select all

InitSprite()
InitSprite3D()
InitKeyboard()

OpenScreen(800,600,16,"Example 3")

S3DR_CreateZBuffer();must be called before Start3D() and S3DR_BeginReal3D()

LoadSprite(1,"box.bmp",#PB_Sprite_Texture)
Procedure S3DR_RotateAndZoom(radians.f,zoom.f)
  x.f=Cos(radians)
  y.f=Sin(radians)
  S3DR_Draw3D(-y,x,zoom,x,y,zoom,-x,-y,zoom,y,-x,zoom)
EndProcedure
zoom.f=1
Repeat
  
  Start3D()
  S3DR_BeginReal3D()
  S3DR_ClearScreenAndZBuffer(#black)
  
  S3DR_UseTransparency(#S3DR_TRUE)
  
  S3DR_SelectTexture(1)

  radians.f+0.01:If radians>=2*3.14159265:radians=0:EndIf
  If zoom>=50:zi.b=0:ElseIf zoom<=1:zi.b=1:EndIf
  If zi.b:zoom+0.1:Else:zoom-0.1:EndIf
  
  S3DR_RotateAndZoom(radians,zoom)
  
  S3DR_EndReal3D()
  Stop3D()
  
  FlipBuffers():Delay(15)
  
  ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)

S3DR_FreeZBuffer()
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

Got a way to individually change the colors of the four corners of a 3dsprite?

I know the code is on these forums (thanks to a fellow forum member), though having it integrated into this library would rule :)
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

I need a serious library like could be this.
I am developing a scientific physichs simulation, and to do so there's not needed 3D, but 2D is enough and needed. This is the reason why i asked about a collision detection function for sprites, and zoom and rotate. No camera is needed here. :arrow:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Re: Sprite3DReal Userlibrary

Post by traumatic »

I already told you in the german forum but I'll do it again:

I like it !! :)
Good programmers don't comment their code. It was hard to write, should be hard to read.
S.M.
Enthusiast
Enthusiast
Posts: 118
Joined: Sat Apr 24, 2004 1:11 pm
Contact:

Post by S.M. »

Hi

@Psychophanta
Is it possible to add a collision check function?
It is possible but i think it is not very useful.
And Rotate and Zoom ones?
Good idea, I will add a few commands for rotate/scale/translate
the World-Matrix. :D

@Shannara
I added it to my TODO-List (shouldn't be hard to integrate :wink: )

regards
Stefan
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

S.M. wrote: It is possible but i think it is not very useful.
If it is possible, then please do it. It is useful to me. And never would be a surplus for any one.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
S.M.
Enthusiast
Enthusiast
Posts: 118
Joined: Sat Apr 24, 2004 1:11 pm
Contact:

Post by S.M. »

Hi
@Psychophanta

Now I added a Box-Collision function to the Library (Not documented at the moment):

Code: Select all

S3DR_TestCollision(O1X1.f,O1Y1.f,O1Z1.f,O1X2.f,O1Y2.f,O1Z2.f,O1X3.f,O1Y3.f,O1Z3.f,O1X4.f,O1Y4

,O1Z4.f,O2X1.f,O2Y1.f,O2Z1.f,O2X2.f,O2Y2.f,O2Z2.f,O2X3.f,O2Y3.f,O2Z3.f,O2X4.f,O2Y4,O2Z4.f)
Download:
http://hometown.aol.de/Gastmailing/S3DR_1_0.zip (115 KB)

Here is a short example:

Code: Select all

InitSprite()
InitSprite3D()
InitKeyboard()

OpenScreen(800,600,16,"TestCollision")

S3DR_CreateZBuffer()

LoadSprite(1,"Texture2.bmp",#PB_Sprite_Texture)
LoadSprite(2,"house.bmp",#PB_Sprite_Texture)

Start3D()
S3DR_BeginReal3D()
S3DR_SetCullMode(#S3DR_NONE)
S3DR_MoveCamera(-20,3,0)
S3DR_RotateCamera(ACos(-1)/2,0,0)
S3DR_UseFog(1,0,100,RGB(220,220,255))
S3DR_EndReal3D()
Stop3D()

Repeat
  
  ExamineKeyboard()
  
  Start3D()
  
  S3DR_BeginReal3D()
  S3DR_ClearScreenAndZBuffer(RGB(220,220,255))
  
  If KeyboardPushed(#PB_Key_Left):S3DR_RotateCamera(-0.025,0,0):EndIf
  If KeyboardPushed(#PB_Key_Right):S3DR_RotateCamera(0.025,0,0):EndIf 
  
  If KeyboardPushed(#PB_Key_Up):S3DR_MoveCamera(0,0,0.5):EndIf  
  If KeyboardPushed(#PB_Key_Down):S3DR_MoveCamera(0,0,-0.5):EndIf
  
  DX.f+0.01
  
  ;Untergrung zeichen:
  S3DR_SelectTexture(1)    
  S3DR_Draw3D(-20,0,20,20,0,20,-20,0,-20,20,0,-20)
  
  S3DR_SelectTexture(2)
  S3DR_Draw3D(5,5*Sin(DX),5,-5,5*Sin(DX),5,5,5,-5,-5,5,-5)  
  
  

Result=S3DR_TestCollision(-20,0,20,20,0,20,-20,0,-20,20,0,-20,5,5*Sin(DX),5,-5,5*Sin(DX),5,5,5,-5,-

5,5,-5)
  
  S3DR_EndReal3D()
  
  Stop3D()
  
  
  StartDrawing(ScreenOutput())
  DrawingMode(1)
  DrawingFont(GetStockObject_(#ANSI_FIXED_FONT))
  If Result
    DrawText("Collision: YES")
  Else
    DrawText("Collision: NO")
  EndIf
  StopDrawing()
  
  FlipBuffers()
  
  
Until KeyboardPushed(#PB_Key_Escape)
CloseScreen()
If you want an example code for an pixel-exact collision-detection for 3D Sprites, then just ask me. :wink:

regards
Stefan
benny
Enthusiast
Enthusiast
Posts: 465
Joined: Fri Apr 25, 2003 7:44 pm
Location: end of www
Contact:

Post by benny »

@S.M.:

Pretty nice, indeed :!: Well done, Stefan ...

What else is on your To-Do-List :?: (I am just curious ;-) )
regards,
benny!
-
pe0ple ar3 str4nge!!!
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

I just needed it :!:

I know, you are the author of SpriteEx lib too.

I use your libs, because it are really fast, and seem well done.

Please add useful functions to this lib. I think in fact it is really useful and interesting, not only for games 8O

Thanks :!:

S.M. wrote:If you want an example code for an pixel-exact collision-detection for 3D Sprites, then just ask me. :wink:
Yes, i do.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
S.M.
Enthusiast
Enthusiast
Posts: 118
Joined: Sat Apr 24, 2004 1:11 pm
Contact:

Post by S.M. »

@benny

My To-Do-List: :D

Code: Select all

- Commands for rotate/scale and translate the World-Matrix
- diffuse-color support
- Commands for changing FOV near- and far plane 
- more Camera-functions
- extended fog-functions (EXP,EXP2,Intensity)
- VertexBuffer support (for faster rendering)
- A command for render triangles
- optimize commands (the commands S3DR_DrawBillboard(),S3DR_RotateCamera() and S3DR_MoveCamera() are slow)
- Antialiasing ?
- Lights ?
@Psychophanta
I know, you are the author of SpriteEx lib too.

I use your libs, because it are really fast, and seem well done.
Nice to hear, Thanks.

Ok, here is the code:

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 PB_Sprite
  Sprite.l
  Width.w
  Height.w
  Depth.w
  Mode.w
  FileName.l
  RealWidth.w
  RealHeight.w
  ClipX.w
  ClipY.w
EndStructure

#DDSD_WIDTH=4
#DDSD_HEIGHT=2
#DDSD_CAPS=1
#DDSCAPS_3DDEVICE=8192
#DDSCAPS_OFFSCREENPLAIN=64

Global *D3DDevice.IDirect3DDevice7
Global *BackBuffer.IDirectDrawSurface7

Procedure CreateRenderSprite(Sprite,Width,Height)
  Result=CreateSprite(Sprite,Width,Height)
  If Result=0:ProcedureReturn 0:EndIf
  *PBSprite.PB_Sprite=IsSprite(Sprite)
  *DDS.IDirectDrawSurface7=*PBSprite\Sprite
  *DDS\GetDDInterface(@*DD.IDirectDraw7)
  *DDS\Release()
  DDSD.DDSURFACEDESC2
  DDSD\dwSize=SizeOf(DDSURFACEDESC2)
  DDSD\dwFlags=#DDSD_WIDTH|#DDSD_HEIGHT|#DDSD_CAPS 
  DDSD\dwWidth=Width
  DDSD\dwHeight=Height
  DDSD\ddsCaps\dwCaps=#DDSCAPS_3DDEVICE|#DDSCAPS_OFFSCREENPLAIN
  Result=*DD\CreateSurface(DDSD,*PBSprite,0)
  If Result:ProcedureReturn 0:EndIf
  ProcedureReturn *PBSprite\Sprite
EndProcedure

Procedure SelectRenderSprite(Sprite)
  !extrn _PB_Direct3D_Device
  !MOV Eax,[_PB_Direct3D_Device]
  !MOV [p_D3DDevice],Eax
  !extrn _PB_DirectX_BackBuffer
  !MOV Eax,[_PB_DirectX_BackBuffer]
  !MOV [p_BackBuffer],Eax
  *D3DDevice\EndScene()
  Select Sprite
    Case -1
      *D3DDevice\SetRenderTarget(*BackBuffer,2)
    Default
      *D3DDevice\SetRenderTarget(PeekL(IsSprite(Sprite)),2)
  EndSelect
  *D3DDevice\BeginScene()
EndProcedure






;Example:

InitSprite()
InitSprite3D()


InitKeyboard()
InitMouse()
OpenScreen(640,480,16,"Collision detection with 3D-Sprites")

CreateRenderSprite(0,181,181)
CreateRenderSprite(1,181,181)

TransparentSpriteColor(0,255,0,255)
TransparentSpriteColor(1,255,0,255)

LoadSprite(5,"C:\PureBASIC2\Examples\Sources\Data\GeeBee2.bmp",#PB_Sprite_Texture)
CreateSprite3D(5,5)


Repeat
  ExamineKeyboard()
  ExamineMouse()
  
  ClearScreen(0,0,0)
  
  UseBuffer(0)
  ClearScreen(255,0,255);Clear Sprite 0
  UseBuffer(1)
  ClearScreen(255,0,255);Clear Sprite 1
  UseBuffer(-1)
  
  
  Start3D()
  
  SelectRenderSprite(0);Draw the 3D-Sprite on Sprite 0
  Angle1+2
  RotateSprite3D(5,Angle1,0)
  DisplaySprite3D(5,27,27)
  
  
  SelectRenderSprite(1);Draw the 3D-Sprite on Sprite 1
  Angle2-2
  RotateSprite3D(5,Angle2,0)
  DisplaySprite3D(5,27,27)
  
  SelectRenderSprite(-1);Draw on Backbuffer
  Stop3D()
  
  
  DisplayTransparentSprite(0,MouseX(),MouseY())
  DisplayTransparentSprite(1,200,100)
  
  If SpritePixelCollision(0,MouseX(),MouseY(),1,200,100)
    StartDrawing(ScreenOutput())
    FrontColor(255,255,0)
    DrawingMode(1)
    DrawingFont(GetStockObject_(#ANSI_FIXED_FONT))
    DrawText("Collision !")
    StopDrawing()
  EndIf
  
  FlipBuffers()
  
Until KeyboardPushed(#PB_Key_Escape)

I hope you understand how it works. :wink:

regards
Stefan
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

It is a DirectX example.
Pity that DirectX is too slow doing that task :(
Thanks anyway.
I hope you implement S3DR_TestCollision() function for your next S3DR lib version, or at least for your next of next. :)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
benny
Enthusiast
Enthusiast
Posts: 465
Joined: Fri Apr 25, 2003 7:44 pm
Location: end of www
Contact:

Post by benny »

S.M. wrote:@benny

My To-Do-List: :D

Code: Select all

- Commands for rotate/scale and translate the World-Matrix
- diffuse-color support
- Commands for changing FOV near- and far plane 
- more Camera-functions
- extended fog-functions (EXP,EXP2,Intensity)
- VertexBuffer support (for faster rendering)
- A command for render triangles
- optimize commands (the commands S3DR_DrawBillboard(),S3DR_RotateCamera() and S3DR_MoveCamera() are slow)
- Antialiasing ?
- Lights ?
Wow ... 8O ... that sounds quite cool - good luck and I am looking forward
to see the upcoming versions ....
regards,
benny!
-
pe0ple ar3 str4nge!!!
Post Reply