It is currently Thu Jul 09, 2020 10:32 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: TransformSprite() Z-Depth Basics
PostPosted: Thu Aug 25, 2016 10:11 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Apr 27, 2003 8:12 am
Posts: 2042
Location: USA
This is just a simple explanation of the Z-Depth parameter for the TransformSprite() function. Hopefully this shall give someone basic understanding of this parameter. If you have more than two sides with different lengths or continuously moving XY values, it will take a higher mathematical skill than explained here.

The Z-Depth values fix irregular displayed sprites from looking distorted. If you remove the optional Z-Depth values from the TransformSprite() examples below, you will understand their purpose.

As you can see. The shortest side is divided by the longer/opposing side. The divided value is then used as the Z-Depth for the short side. The remaining two sides are of the same length and we need not worry about.

Currently Z-Depth only works in DirectX and not in OpenGL. So Windows only for now.

Code:
TransformSprite(0,0,0,   128,32,2,   128,96,2,   0,128,0)

; X = 0, Y = 0, Z = 0  ____
;                      |   ____
;                      |       ____  X = 128, Y = 32, Z = 2
;                   1  |          /|
;                   2  |        /  |  6      ; 128 / 64 = 2
;                   8  |      /    |  4
;                      |    /      |
;                      |  /    ____  X = 128, Y = 96, Z = 2
;                      |/  ____
;                      ____
; X = 0, Y = 128, Z = 0


TransformSprite(0,0,0,   128,16,1.6,   128,96,1.6,   0,128,0)

; X = 0, Y = 0, Z = 0  ______
;                      |     ______  X = 128, Y = 16, Z = 1.6
;                      |           |
;                   1  |         / |
;                   2  |       /   |  8      ; 128 / 80 = 1.6
;                   8  |     /     |  0
;                      |   /       |
;                      | /     ____  X = 128, Y = 96, Z = 1.6
;                      |   ____
;                      ____
; X = 0, Y = 128, Z = 0


TransformSprite(224,0,8,   288,0,8,   512,512,0,   0,512,0)

;                                64         
;        X = 224, Y = 0, Z = 8  ____  X = 288, Y = 0, Z = 8
;                              /   /\
;                             /      \
;                            /  /     \
;                           /          \     ; 512 / 64 = 8
;                          / /          \
;                         /              \   
;                        __________________
; X = 0, Y = 512, Z = 0          512        X = 512, Y = 512, Z = 0

_________________
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.


Top
 Profile  
Reply with quote  
 Post subject: Re: TransformSprite() Z-Depth Basics
PostPosted: Fri Aug 26, 2016 2:30 am 
Offline
Addict
Addict
User avatar

Joined: Mon May 14, 2007 2:13 am
Posts: 979
Location: Darling River
I will put this with my PB Docs, thanks for sharing. :)

_________________
PureBasic Rocks! Even More! And More!
PureBasic 5, Now We're Really Rockin!


Top
 Profile  
Reply with quote  
 Post subject: Re: TransformSprite() Z-Depth Basics
PostPosted: Fri Aug 26, 2016 2:39 am 
Offline
Addict
Addict
User avatar

Joined: Sun Apr 27, 2003 8:12 am
Posts: 2042
Location: USA
electrochrisso wrote:
I will put this with my PB Docs, thanks for sharing. :)

No problem. ;)

_________________
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.


Top
 Profile  
Reply with quote  
 Post subject: Re: TransformSprite() Z-Depth Basics
PostPosted: Fri Aug 26, 2016 6:50 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jan 10, 2008 1:30 pm
Posts: 1282
Location: Germany, Glienicke
I think it's a good place to post an example:
Code:
Procedure HyperTransformSprite(Sprite.i, Width.f, Height.f, Depth.f, Roll.f, Yaw.f, Pitch.f, AlignX.f=0.5, AlignY.f=0.5)
   
   Protected CosZ.f = Cos(Radian(Roll)), CosY.f = Cos(Radian(Yaw)), CosX.f = Cos(Radian(Pitch))
   Protected SinZ.f = Sin(Radian(Roll)), SinY.f = Sin(Radian(Yaw)), SinX.f = Sin(Radian(Pitch))
   
   Protected A11.f =  CosY*CosZ,                A12.f = -CosY*SinZ,                A13.f =  SinY
   Protected A21.f =  SinX*SinY*CosZ+CosX*SinZ, A22.f = -SinX*SinY*SinZ+CosX*CosZ, A23.f = -SinX*CosY
   Protected A31.f = -CosX*SinY*CosZ+SinX*SinZ, A32.f =  CosX*SinY*SinZ+SinX*CosZ, A33.f =  CosX*CosY
   
   Protected U0.f = -AlignX*Width,  U1.f = (1-AlignX)*Width
   Protected V0.f = -AlignY*Height, V1.f = (1-AlignY)*Height
   
   Protected Z1.f = U0*A31 + V0*A32 + Depth
   Protected Y1.f = ( U0*A21 + V0*A22 ) * Depth / Z1
   Protected X1.f = ( U0*A11 + V0*A12 ) * Depth / Z1
   Protected Z2.f = U1*A31 + V0*A32 + Depth
   Protected Y2.f = ( U1*A21 + V0*A22 ) * Depth / Z2
   Protected X2.f = ( U1*A11 + V0*A12 ) * Depth / Z2
   Protected Z3.f = U1*A31 + V1*A32 + Depth
   Protected Y3.f = ( U1*A21 + V1*A22 ) * Depth / Z3
   Protected X3.f = ( U1*A11 + V1*A12 ) * Depth / Z3
   Protected Z4.f = U0*A31 + V1*A32 + Depth
   Protected Y4.f = ( U0*A21 + V1*A22 ) * Depth / Z4
   Protected X4.f = ( U0*A11 + V1*A12 ) * Depth / Z4
   
   TransformSprite(Sprite, X1, Y1, Z1, X2, Y2, Z2, X3, Y3, Z3, X4, Y4, Z4)
   
EndProcedure



InitSprite()
InitNetwork()

UseJPEGImageDecoder()

Enumeration
   #Window
   #Sprite
EndEnumeration

OpenWindow(#Window, 0, 0, 800, 600, "ScreenTitle", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Window), 0, 0, WindowWidth(#Window), WindowHeight(#Window), 0, 0, 0)

SpriteQuality(#PB_Sprite_BilinearFiltering)

CatchSprite(#Sprite, ReceiveHTTPMemory("http://data.unionbytes.de/convergence_by_rahll.jpg"))

Repeat
   
   Repeat
     
      Select WindowEvent()
         Case #PB_Event_CloseWindow
            End
         Case #Null
            Break
      EndSelect
     
   ForEver
   
   ClearScreen(0)
   
   HyperTransformSprite(#Sprite, 160, 100, 300, ElapsedMilliseconds()/10, 0, 0)
   DisplaySprite(#Sprite, 200, 150)
   
   HyperTransformSprite(#Sprite, 160, 100, 300, 0, Sin(ElapsedMilliseconds()/1000)*70, 0)
   DisplaySprite(#Sprite, 600, 150)
   
   HyperTransformSprite(#Sprite, 160, 100, 300, 0, 0, Sin(ElapsedMilliseconds()/1000)*70)
   DisplaySprite(#Sprite, 200, 450)
   
   HyperTransformSprite(#Sprite, 160, 100, 300, ElapsedMilliseconds()/10, 0, -40, 1.0, 0.0)
   DisplaySprite(#Sprite, 600, 450)
   
   FlipBuffers()
   
ForEver
But as you have said, it doesn't work in OpenGL correctly.

_________________
ImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: TransformSprite() Z-Depth Basics
PostPosted: Fri Aug 26, 2016 7:21 am 
Offline
Addict
Addict
User avatar

Joined: Sun Apr 27, 2003 8:12 am
Posts: 2042
Location: USA
STARGÅTE wrote:
I think it's a good place to post an example:

It is. :D

Thanks for your more complex example! ;)

_________________
www.posemotion.com

PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef

Mac: 10.13.6 / 1.4GHz Core 2 Duo / 2GB DDR3 / Nvidia 320M
PC: Win 7 / AMD 64 4000+ / 3GB DDR / Nvidia 720GT


Even the vine knows it surroundings but the man with eyes does not.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye