Page 1 of 4

Sprite3D engine with FX [cross-platform]

Posted: Sun Aug 09, 2009 8:44 pm
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

Posted: Sun Aug 09, 2009 8:52 pm
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...

Posted: Sun Aug 09, 2009 8:57 pm
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")

Re: Sprite3D engine [open source]

Posted: Sun Aug 09, 2009 10:23 pm
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)

Re: Sprite3D engine [open source]

Posted: Mon Aug 10, 2009 1:33 am
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.

Posted: Mon Aug 10, 2009 2:18 am
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

Posted: Mon Aug 10, 2009 9:55 am
by dige
CreateView() crashes with IMA at
AttachNodeObject(\node, CameraID(\camera), #PB_Node_Camera)
Tried with Dx7&9

WinXP SP3, Dx9.0c

Posted: Mon Aug 10, 2009 12:26 pm
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.

Posted: Mon Aug 10, 2009 12:36 pm
by eddy
Which PB version are you using ?

Posted: Mon Aug 10, 2009 2:00 pm
by dige
PB 4.31x86 (german)

Posted: Mon Aug 10, 2009 6:42 pm
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)

Posted: Tue Aug 11, 2009 6:18 am
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.

Posted: Tue Aug 11, 2009 9:54 am
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.

Posted: Tue Aug 11, 2009 11:37 am
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!

Posted: Tue Aug 11, 2009 12:09 pm
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 ?