Sprite3D engine with FX [cross-platform]

Share your advanced PureBasic knowledge/code with the community.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Sprite3D engine with FX [cross-platform]

Post by eddy »

v0.94
- view
- layer : zorder, FX
- sprite : color, gradient, transparency, handle, flipsprite, image frames, deformation, FX, attach or detach sprite child
- predefined FX : animation, rotation, scale, transparency, color, shake, blink, jiggle, oscillation, follow object, face object, vortex object, orbit object, move, mouse control, SineScale, SineRotate, SineMove, attach object
- predefined deformation FX : SineSkew, Stretch, Perspective
- predefined easing FX : EasingMove, EasingRotate, EasingScale (with 31 easing modes)

:arrow: how to test
- unzip the downloaded file (this package contains the lastest Orgre3D engine DLL for windows / for linux and mac you'll need to copy engine.so)

:arrow: download : http://www.datafilehost.com/download-a1f2edf8.html
- requirement : PB 4.40+

:arrow: old version
6 5 4 3 2 1
Last edited by eddy on Wed Oct 14, 2009 12:17 am, edited 47 times in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Post by cas »

Hi, is this code compatible with PB 4.31 ?
I get some errors, first one in example snippet: InitEngine3D() should be before InitSprite(). When i swap these two lines, there are still some errors...
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

Code: Select all

; ====================================== 
; EXAMPLE 
; ====================================== 
DisableExplicit 
InitMouse() 
InitKeyboard() 
InitEngine3D() 
InitSprite() 
Add3DArchive(".", #PB_3DArchive_FileSystem) 

#w=800 
#h=600 
OpenWindow(0, 0, 0, #w, #h, "Sprite") 
OpenWindowedScreen(WindowID(0), 0, 0, #w, #h, 0, 0, 0) 

If CreateView(0, 0, 0, #w, #h) 
   If AddLayer(1, "bub.png") 
      AddSprite(10, 50, 50, 100, 100) 
      SetSpriteColor(10, RGB(255, 0, 0)) 
   EndIf 
   If AddLayer(2, "bub.png") 
      AddSprite(11, 100, 100, 100, 100) 
      AddSprite(12, 150, 150, 100, 100) 
      SetSpriteOrder(11, 1) 
      SetSpriteGradient(12, 1, RGB(255, 0, 0), RGB(0, 255, 0), 255, 200) 
   EndIf 
   If AddLayer(3, "bub.png") 
      s1=AddSprite(#PB_Any, 160, 160, 50, 50) 
      s2=AddSprite(#PB_Any, 160, 160, 50, 50) 
      SetSpriteHandle(s2, 0, 25) 
      ScaleSprite(s2, 2, 1) 
      SetSpriteTransparency(s2, 200) 
   EndIf 
EndIf 

Repeat 
   dt=ElapsedMilliseconds()-t0 
   t0=ElapsedMilliseconds() 
   t+dt 
   co.f=Cos(2*#PI*t/5000.0) 
   ScaleLayer(2, 1.0+0.1*co, 1) 
   PositionLayer(2, 400+20*co, 300) 
   SetLayerTransparency(3, 255*(0.6+0.4*co)) 
   TurnSprite(s2, 0.1) 
    
   RenderViews() 
   RenderWorld() 
   FlipBuffers() 
    
   ExamineKeyboard() 
Until KeyboardPushed(#PB_Key_Escape) Or WaitWindowEvent(0)=#PB_Event_CloseWindow
cas wrote:Hi, is this code compatible with PB 4.31 ?
I get some errors, first one in example snippet: InitEngine3D() should be before InitSprite().
I made my test with the DX9 subsystem : there's a difference between DX7 and DX9.
You can swap these two lines.
When i swap these two lines, there are still some errors...
You need to specify the path of your own texture file.
:

If AddLayer(1, "MySpriteTexture.png")
If AddLayer(2, "MySpriteTexture.png")
If AddLayer(3, "MySpriteTexture.png")
Last edited by eddy on Thu Aug 13, 2009 2:21 am, edited 1 time in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
jamirokwai
Enthusiast
Enthusiast
Posts: 796
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: Sprite3D engine [open source]

Post by jamirokwai »

eddy wrote:v0.8
- view
- layer : zorder
- sprite : color, gradient, transparency, handle

W.I.P:
- renderviews function is not fully functionnal. I've some problems to code the sprite rotation
Hi eddy,

keep up the good work. This one actually runs without any changes on PB 4.31, Intel, Mac OS X 8)
Regards,
JamiroKwai
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: Sprite3D engine [open source]

Post by eddy »

:arrow: Function List
  • Procedure.i AddView(View, x, y, Width, Height, Color=$000000, RenderMode=#PB_Camera_Textured)
  • Procedure DeleteView(View)
  • Procedure ClearViews()
  • Procedure SetViewCameraRendering(View, RenderMode)
  • Procedure SetViewBackColor(View, Color)
  • Procedure.b IsView(View)
  • Procedure.i UseView(View=#PB_Ignore)
  • Procedure.i CountViews()
  • Procedure.i ViewID(View)
  • Procedure.i ViewCameraRendering(View)
  • Procedure.i ViewBackColor(View)
  • Procedure.i ViewX(View)
  • Procedure.i ViewY(View)
  • Procedure.i ViewWidth(View)
  • Procedure.i ViewHeight(View)
  • Procedure.i AddLayer(Layer, TextureFile$, BlendMode=#Layer_Blend_Alpha, FilterMode=#Layer_Filter_Bilinear)
  • Procedure DeleteLayer(Layer)
  • Procedure ClearLayers(parentView)
  • Procedure SetLayerOrder(Layer, Order)
  • Procedure SetLayerFrameCount(Layer, FrameCount)
  • Procedure SetLayerFrame(Layer, Frame, x, y, Width, Height)
  • Procedure SetLayerFrameGrid(Layer, Columns, Rows)
  • Procedure SetLayerBlend(Layer, BlendMode)
  • Procedure SetLayerFilter(Layer, FilterMode)
  • Procedure SetLayerTransparency(Layer, Transparency)
  • Procedure SetLayerHandle(Layer, HandleX.f, HandleY.f)
  • Procedure ScaleLayer(Layer, ScaleX.f, ScaleY.f)
  • Procedure PositionLayer(Layer, x.f, y.f)
  • Procedure MoveLayer(Layer, x.f, y.f)
  • Procedure RotateLayer(Layer, angle.f)
  • Procedure TurnLayer(Layer, angle.f)
  • Procedure HideLayer(Layer, Hide.b)
  • Procedure.b IsLayer(Layer)
  • Procedure.i UseLayer(Layer=#PB_Ignore)
  • Procedure.i CountLayers(parentView=#PB_Ignore)
  • Procedure.i LayerID(Layer)
  • Procedure.i LayerOrder(Layer)
  • Procedure.i LayerFrameCount(Layer)
  • Procedure.i LayerBlend(Layer)
  • Procedure.i LayerFilter(Layer)
  • Procedure.i LayerTransparency(Layer)
  • Procedure.f LayerTextureWidth(Layer)
  • Procedure.f LayerTextureHeight(Layer)
  • Procedure.f LayerScaleX(Layer)
  • Procedure.f LayerScaleY(Layer)
  • Procedure.f LayerHandleX(Layer)
  • Procedure.f LayerHandleY(Layer)
  • Procedure.f LayerAngle(Layer)
  • Procedure.f LayerX(Layer)
  • Procedure.f LayerY(Layer)
  • Procedure.b LayerHidden(Layer)
  • Procedure.i AddSprite(Sprite, x, y, Width=#PB_Ignore, Height=#PB_Ignore)
  • Procedure DeleteSprite(Sprite)
  • Procedure ClearSprites(parentLayer)
  • Procedure.i SetSpriteFX(Sprite, FX)
  • Procedure SetSpriteOrder(Sprite, Order)
  • Procedure SetSpriteColor(Sprite, Color)
  • Procedure SetSpriteFrame(Sprite, Frame)
  • Procedure SetSpriteTransparency(Sprite, Transparency)
  • Procedure SetSpriteGradient(Sprite, Vertical, Color1, Color2, Transparency1=255, Transparency2=255)
  • Procedure SetSpriteHandle(Sprite, HandleX.f, HandleY.f)
  • Procedure ScaleSprite(Sprite, ScaleX.f, ScaleY.f)
  • Procedure PositionSprite(Sprite, x.f, y.f)
  • Procedure MoveSprite(Sprite, x.f, y.f)
  • Procedure RotateSprite(Sprite, angle.f)
  • Procedure TurnSprite(Sprite, angle.f)
  • Procedure HideSprite(Sprite, Hide.b)
  • Procedure FlipSprite(Sprite, FlipX.b, FlipY.b)
  • Procedure.b IsSprite(Sprite)
  • Procedure.i CountSprites(parentLayer=#PB_Ignore)
  • Procedure.i LayerSpriteID(Sprite)
  • Procedure.i SpriteOrder(Sprite)
  • Procedure.i SpriteColor(Sprite)
  • Procedure.i SpriteFrame(Sprite)
  • Procedure.i SpriteTransparency(Sprite)
  • Procedure.f SpriteScaleX(Sprite)
  • Procedure.f SpriteScaleY(Sprite)
  • Procedure.f SpriteHandleX(Sprite)
  • Procedure.f SpriteHandleY(Sprite)
  • Procedure.f SpriteAngle(Sprite)
  • Procedure.f SpriteX(Sprite)
  • Procedure.f SpriteY(Sprite)
  • Procedure.i SpriteWidth(Sprite)
  • Procedure.i SpriteHeight(Sprite)
  • Procedure.b SpriteFlipX(Sprite)
  • Procedure.b SpriteFlipY(Sprite)
  • Procedure.b SpriteHidden(Sprite)
  • Procedure.i CreateScaleFX(FX, ScaleList.s, Transition, LoopCount=#PB_Ignore, Duration=#PB_Ignore, Delay=#PB_Ignore)
  • Procedure.i CreateAnimationFX(FX, FrameList.s, FramePerSecond=#PB_Ignore, LoopCount=#PB_Ignore, Duration=#PB_Ignore, Delay=#PB_Ignore)
  • Procedure.i CreateRotationFX(FX, DegreePerSecond=#PB_Ignore, LoopCount=#PB_Ignore, Duration=#PB_Ignore, Delay=#PB_Ignore)
  • Procedure.i CopyFX(FX, NewFX)
  • Procedure FreeFX(FX)
  • Procedure ClearFXs(parentSprite)
  • Procedure SetFXDelay(FX, Delay)
  • Procedure SetFXDuration(FX, Duration)
  • Procedure SetFXSpeed(FX, Speed)
  • Procedure SetFXLoopCount(FX, LoopCount)
  • Procedure PauseFX(FX)
  • Procedure ResumeFX(FX)
  • Procedure.b IsFX(FX)
  • Procedure.i CountFXs(parentSprite=#PB_Ignore)
  • Procedure.i FXDelay(FX)
  • Procedure.i FXDuration(FX)
  • Procedure.i FXSpeed(FX)
  • Procedure.i FXLoopCount(FX)
  • Procedure.b FXPaused(FX)
  • Procedure RenderViews()
jamirokwai wrote: keep up the good work. This one actually runs without any changes on PB 4.31, Intel, Mac OS X 8)
great.

I fixed the renderViews.
Last edited by eddy on Sun Sep 06, 2009 5:16 am, edited 1 time in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

image bub.png
Image

Code: Select all

; ======================================
; EXAMPLE 2
; ======================================
DisableExplicit
InitMouse()
InitKeyboard()
InitEngine3D()
InitSprite()
Add3DArchive(".", #PB_3DArchive_FileSystem)

#w=800
#h=600
OpenWindow(0, 0, 0, #w, #h, "Sprite")
OpenWindowedScreen(WindowID(0), 0, 0, #w, #h, 0, 0, 0)

If CreateView(0, 0, 0, #w, #h)
   If AddLayer(1, "bub.png")
      AddSprite(10, 50, 50, 100, 100)
      SetSpriteColor(10, RGB(255, 0, 0))
   EndIf
   If AddLayer(2, "bub.png")
      For i=0 To 100
         sk=AddSprite(#PB_Any, Random(400)+200, Random(400)+100, 10, 10)
         SetSpriteGradient(sk, 1, RGB(255, 0, 255), RGB(255, 255, 0), 255, 200)
      Next
   EndIf
   If AddLayer(3, "bub.png")
      For i=0 To 100
         sk=AddSprite(#PB_Any, Random(400)+200, Random(400)+100, 20, 20)
         SetSpriteGradient(sk, 1, RGB(255, 0, 0), RGB(0, 255, 0), 255, 200)
      Next
   EndIf
   If AddLayer(4, "bub.png")
      For i=0 To 200
         sk=AddSprite(#PB_Any, Random(800), Random(600), 20, 20)
         SetSpriteTransparency(sk,100+Random(155))
         kx.f=(100+Random(50))/100
         ScaleSprite(sk,kx,kx)
         SetSpriteColor(sk,RGB(100,200,255))
      Next
   EndIf
EndIf

Repeat
   dt=ElapsedMilliseconds()-t0
   t0=ElapsedMilliseconds()
   t+dt
   co.f=Cos(2*#PI*t/5000.0)
   ScaleLayer(2, 1.0+0.1*co, 1)
   ScaleLayer(3, 1.0+0.1*co, 1.0+0.1*co)
   TurnLayer(3,0.05)
   ScaleLayer(4, 1.0+0.2*co, 1.0+0.2*co)
   TurnLayer(4,0.1)
   
   RenderViews()
   RenderWorld()
   FlipBuffers()
   
   ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape) Or WaitWindowEvent(0)=#PB_Event_CloseWindow
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post by dige »

CreateView() crashes with IMA at
AttachNodeObject(\node, CameraID(\camera), #PB_Node_Camera)
Tried with Dx7&9

WinXP SP3, Dx9.0c
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Post by yrreti »

? maybe something with service pack 3.
XP with service pack 2 works fine and looks really neat, especially
example 2.
I stayed away from service pack 3 because I heard it had a lot of
issues. I don't know if those issue have been all resolved, but I
wouldn't be surprised if it was causing the problem.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

Which PB version are you using ?
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post by dige »

PB 4.31x86 (german)
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

;// define frames manually
SetLayerFrameCount(Layer, FrameCount)
SetLayerFrame(Layer, Frame, x, y, Width, Height)

;// generate frames automaticly
SetLayerFrameGrid(Layer, Columns, Rows)

;// new sprite functions
FlipSprite(Sprite, FlipX.b, FlipY.b)
SetSpriteFrame(Sprite, Frame)


Image

Code: Select all

; ======================================
; EXAMPLE 3
; ======================================
DisableExplicit
InitMouse()
InitKeyboard()
InitEngine3D()
InitSprite()
Add3DArchive(".", #PB_3DArchive_FileSystem)

#w=800
#h=600
OpenScreen(#w, #h, 32, "")

Dim KABOOM(400)
If CreateView(0, 0, 0, #w, #h)
   If AddLayer(1, "ex.png")
      SetLayerFrameGrid(1, 4, 4)
      For i=0 To ArraySize(KABOOM())
         KABOOM(i)=AddSprite(#PB_Any, Random(800), Random(600), 64, 64)
         sc.f=0.5+Random(100)/100
         ac.f=i/400
         color=RGB(255,255-ac*165,255-ac*255)
         ScaleSprite(KABOOM(i), sc, sc)
         SetSpriteColor(KABOOM(i), color)
         TurnSprite(KABOOM(i),Random(360))
         FlipSprite(KABOOM(i),Random(1),Random(1))
      Next
   EndIf
EndIf

Repeat
   dt=ElapsedMilliseconds()-t0
   t0=ElapsedMilliseconds()
   frame.f+dt*16/1000
   If Int(frame)>15 : frame=0 : EndIf
   
   For i=0 To ArraySize(KABOOM())
      SetSpriteFrame(KABOOM(i), Int(frame))
   Next
   
   RenderViews()
   RenderWorld()
   FlipBuffers()
   
   ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post by dige »

I've found the problem - works fine now. Maybe you should mention that the file Engine3d.dll is available in the current directory, or in the Windows directory.
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Post by idle »

looks like a bit of work went in to this, hope I can get the time to have look later in the week, thanks.
jamirokwai
Enthusiast
Enthusiast
Posts: 796
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Post by jamirokwai »

eddy wrote:;// define frames manually
SetLayerFrameCount(Layer, FrameCount)
SetLayerFrame(Layer, Frame, x, y, Width, Height)

;// generate frames automaticly
SetLayerFrameGrid(Layer, Columns, Rows)

;// new sprite functions
FlipSprite(Sprite, FlipX.b, FlipY.b)
SetSpriteFrame(Sprite, Frame)


Image
H Eddy,

this one also works fine on Mac OS X x86 PB 4.31 but the colors get mangeld up. They display in blue instead of yellow. I can't judge if it's a problem with your png-image or the engine (Ogre?) itself. The png converted to bmp also display in blue. The blue parts of this screenshot should display in yellow.

Image

I appreciate your great work. The last example runs really smooth fullscreen and inside a window!
Regards,
JamiroKwai
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

dige wrote:I've found the problem - works fine now. Maybe you should mention that the file Engine3d.dll is available in the current directory, or in the Windows directory.
Right, I completely forgot to mention this point. :D
jamirokwai wrote:The png converted to bmp also display in blue. The blue parts of this screenshot should display in yellow.
You mean the colors are inverted. :?

Did you try this code with your own texture ?
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Post Reply