TransformSprite3D() anyone got an example?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

TransformSprite3D() anyone got an example?

Post by Rook Zimbabwe »

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? :D
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: TransformSprite3D() anyone got an example?

Post by STARGÅTE »

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

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
Image

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 moreTypeface - Sprite-based font include/module
User avatar
Innesoft
Enthusiast
Enthusiast
Posts: 105
Joined: Mon Jan 18, 2010 10:30 am
Location: UK
Contact:

Re: TransformSprite3D() anyone got an example?

Post by Innesoft »

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...

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
..of course you need to disable backface culling in dx9 with the following (taken from some other thread)....

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()
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.
Innesoft - The Software Marketplace - Innesoft Blog
» Applications, Educational Software, Casual Games
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Re: TransformSprite3D() anyone got an example?

Post by Rook Zimbabwe »

Interesstig work each of you! :D

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...
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
Innesoft
Enthusiast
Enthusiast
Posts: 105
Joined: Mon Jan 18, 2010 10:30 am
Location: UK
Contact:

Re: TransformSprite3D() anyone got an example?

Post by Innesoft »

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...
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.
---

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)
..but for isometric drawing, as long as you draw in top-->bottom order you shouldn't need it.
Innesoft - The Software Marketplace - Innesoft Blog
» Applications, Educational Software, Casual Games
Huitbit
User
User
Posts: 12
Joined: Thu Jun 11, 2009 4:56 am
Location: GUADELOUPE(F.W.I)

Re: TransformSprite3D() anyone got an example?

Post by Huitbit »

@STARGÅTE
z is important for the correct pulling the triangles of the texture
Very good job :P , it's the first time I read that z is usefull !!!

Thanks

Hasta la vista !
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Re: TransformSprite3D() anyone got an example?

Post by Rook Zimbabwe »

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!
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: TransformSprite3D() anyone got an example?

Post by Olliv »

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!
Hello Rook,

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
jamirokwai
Enthusiast
Enthusiast
Posts: 796
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: TransformSprite3D() anyone got an example?

Post by jamirokwai »

Olliv wrote:Could somebody check if OPENGL is okay or not okay on Linux with the code of STARGÅTE ?
I tested on Mac OX X 10.6.5. At least, it works, so should work on Linux, too...
STARGÅTE wrote:Image
On Max OS X, your example displays the same image with or without z-parameter. Maybe a bug??

Image
Regards,
JamiroKwai
Post Reply