
TransformSprite3D() anyone got an example?
- Rook Zimbabwe
- Addict
- Posts: 4322
- Joined: Tue Jan 02, 2007 8:16 pm
- Location: Cypress TX
- Contact:
TransformSprite3D() anyone got an example?
I am hoping someone has an example of how to use TransformSprite3D() (with the X,Y, and Z) so I could get a batter hanndle on it... Anyone? 

Re: TransformSprite3D() anyone got an example?
You can use it for a real 3-D rotation without 3D-Lib.
z is important for the correct pulling the triangles of the texture

EDIT: Bug-Fix
z is important for the correct pulling the triangles of the texture
Code: Select all
InitSprite()
InitSprite3D()
OpenWindow(0, 0, 0, 800, 600, "Screen", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0)
CreateSprite(1, 64, 64, #PB_Sprite_Texture)
StartDrawing(SpriteOutput(1))
Box(0, 0, 64, 64, $808080)
For x = 0 To 7
For y = 0 To 7
If (x+y)%2 : Box(x*8, y*8, 8, 8, $FFFFFF) : EndIf
Next
Next
StopDrawing()
CreateSprite3D(1, 1)
Repeat
ClearScreen(0)
#HalfSize = 150
#Distance = 500
Start3D()
a.f = ElapsedMilliseconds()/1000
z1.f = #Distance-Sin(a)*#HalfSize : z4.f=z1
z2.f = #Distance+Sin(a)*#HalfSize : z3.f=z2
x1.f = -Cos(a)*#HalfSize*#Distance/z1 : x4.f=x1
x2.f = Cos(a)*#HalfSize*#Distance/z2 : x3.f=x2
j.f = #HalfSize*#HalfSize
y1.f = -#HalfSize-Sin(a)*j/z1 : y2.f=-#HalfSize+Sin(a)*j/z2
y3.f = #HalfSize-Sin(a)*j/z3 : y4.f= #HalfSize+Sin(a)*j/z4
TransformSprite3D(1, x1,y1, x2,y2, x3,y3, x4,y4)
DisplaySprite3D(1, 200, 300)
TransformSprite3D(1, x2,y2, x1,y1, x4,y4, x3,y3)
DisplaySprite3D(1, 200, 300)
TransformSprite3D(1, x1,y1,z1, x2,y2,z2, x3,y3,z3, x4,y4,z4)
DisplaySprite3D(1, 600, 300)
TransformSprite3D(1, x2,y2,z2, x1,y1,z1, x4,y4,z4, x3,y3,z3)
DisplaySprite3D(1, 600, 300)
Stop3D()
StartDrawing(ScreenOutput())
DrawText(100,50,"3D-rotation without parameter z")
DrawText(500,50,"3D-rotation with parameter z")
StopDrawing()
FlipBuffers()
Until WindowEvent() = #PB_Event_CloseWindow

EDIT: Bug-Fix
Last edited by STARGÅTE on Wed Oct 27, 2010 10:58 pm, edited 2 times in total.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Re: TransformSprite3D() anyone got an example?
Here's a peice of code I use to flip a Sprite3D using transforms, it ignores the z-axis since this is parallel to the screen, and not needed for flipping...
..of course you need to disable backface culling in dx9 with the following (taken from some other thread)....
All you're really doing with TransformSprite3D is changing the vertex positions (in screen-space, relative to the sprite origin)
It's also worth noting that you can't combine the above flipping method with RotateSprite3D or ZoomSprite3D, since they will override the new vertex positions.
Code: Select all
;0=No Flip, 1=Horiz, 2=Vert, 3=Both
Procedure TformSprite3D(SpriteID.l,scale.f=512,flipmode.i=0)
Select flipmode.i
Case 0
TransformSprite3D(SpriteID,0,0,0,scale.f,0,0,scale.f,scale.f,0,0,scale.f,0)
Case 1
TransformSprite3D(SpriteID,scale.f,0,0,0,0,0,0,scale.f,0,scale.f,scale.f,0)
Case 2
TransformSprite3D(SpriteID,0,scale.f,0,scale.f,scale.f,0,scale.f,0,0,0,0,0)
Case 3
TransformSprite3D(SpriteID,scale.f,scale.f,0,0,scale.f,0,0,0,0,scale.f,0,0)
EndSelect
EndProcedure
Code: Select all
;Disable Backface Culling
Define pd3d.IDirect3DDevice9
Start3D()
EnableASM
!extrn _PB_Screen_Direct3DDevice
!MOV dword EAX, [_PB_Screen_Direct3DDevice]
!MOV dword [v_pd3d],EAX
DisableASM
pd3d\SetRenderState(22,1)
Stop3D()
It's also worth noting that you can't combine the above flipping method with RotateSprite3D or ZoomSprite3D, since they will override the new vertex positions.
Innesoft - The Software Marketplace - Innesoft Blog
» Applications, Educational Software, Casual Games
» Applications, Educational Software, Casual Games
- Rook Zimbabwe
- Addict
- Posts: 4322
- Joined: Tue Jan 02, 2007 8:16 pm
- Location: Cypress TX
- Contact:
Re: TransformSprite3D() anyone got an example?
Interesstig work each of you!
I was hoping that the Z order would let me overcome a roadblock Jared and I are having in our Isometric engine... namely layering and (hopefully) collisions...

I was hoping that the Z order would let me overcome a roadblock Jared and I are having in our Isometric engine... namely layering and (hopefully) collisions...
Re: TransformSprite3D() anyone got an example?
Edit: On second thoughts, this wouldn't work for z-order because in PB the z-order is determined by the order you use DisplaySprite3D in, which is always on top of the current drawing buffer.I was hoping that the Z order would let me overcome a roadblock Jared and I are having in our Isometric engine... namely layering and (hopefully) collisions...
---
It should work for z-order (not tested), if you use the vertex z value...
Code: Select all
scale.f=256
SpriteID=background : z.f=-1
TransformSprite3D(SpriteID,0,0,z.f,scale.f,0,z.f,scale.f,scale.f,z.f,0,scale.f,z.f)
SpriteID=foreground : z.f=0
TransformSprite3D(SpriteID,0,0,z.f,scale.f,0,z.f,scale.f,scale.f,z.f,0,scale.f,z.f)
Innesoft - The Software Marketplace - Innesoft Blog
» Applications, Educational Software, Casual Games
» Applications, Educational Software, Casual Games
Re: TransformSprite3D() anyone got an example?
@STARGÅTE
, it's the first time I read that z is usefull !!!
Thanks
Hasta la vista !
Very good jobz is important for the correct pulling the triangles of the texture

Thanks
Hasta la vista !
- Rook Zimbabwe
- Addict
- Posts: 4322
- Joined: Tue Jan 02, 2007 8:16 pm
- Location: Cypress TX
- Contact:
Re: TransformSprite3D() anyone got an example?
Yep that would usually wrk... BUT
We are drawing the animated dude inn center of screen and then attempting to disply the world around him. That way he will go behind some things and in front of others... Layering is necessary but difficult!
We are drawing the animated dude inn center of screen and then attempting to disply the world around him. That way he will go behind some things and in front of others... Layering is necessary but difficult!
Re: TransformSprite3D() anyone got an example?
Hello Rook,Rook wrote:Yep that would usually wrk... BUT
We are drawing the animated dude inn center of screen and then attempting to disply the world around him. That way he will go behind some things and in front of others... Layering is necessary but difficult!
First, I thank you for this interesting subject. This function is a base for lots of representations.
I thank STARGÅTE too for his response, and the code he gave here. It's very insteresting. Thank to him, I look an other problem with the function TransformSprite3D().
I think OPENGL doesn't support z parameter. I work on Windows but I worry about compatibiliy on Linux.
Could somebody check if OPENGL is okay or not okay on Linux with the code of STARGÅTE ?
Ollivier
-
- Enthusiast
- Posts: 796
- Joined: Tue May 20, 2008 2:12 am
- Location: Cologne, Germany
- Contact:
Re: TransformSprite3D() anyone got an example?
I tested on Mac OX X 10.6.5. At least, it works, so should work on Linux, too...Olliv wrote:Could somebody check if OPENGL is okay or not okay on Linux with the code of STARGÅTE ?
On Max OS X, your example displays the same image with or without z-parameter. Maybe a bug??STARGÅTE wrote:

Regards,
JamiroKwai
JamiroKwai