TransformSprite3D() anyone got an example?
Posted: Sun Sep 05, 2010 1:53 am
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? 

http://www.purebasic.com
https://www.purebasic.fr/english/
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
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()
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...
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)
Very good jobz is important for the correct pulling the triangles of the texture
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!
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: