Sprite3D functions to accept floats

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
chris_b
Enthusiast
Enthusiast
Posts: 103
Joined: Sun Apr 27, 2003 1:54 am

Sprite3D functions to accept floats

Post by chris_b »

Presumably with both DirectX and OpenGL the various parameters for positioning, rotating and transforming Sprite3Ds will be converted to floating point values anyway - so there's no reason for Sprite3D functions not to accept floats for these parameters.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Can we see some code please? I thought they already accepted floats.
--Kale

Image
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

I have used floats with Sprite3d...
I like logic, hence I dislike humans but love computers.
chris_b
Enthusiast
Enthusiast
Posts: 103
Joined: Sun Apr 27, 2003 1:54 am

Post by chris_b »

Here's an example to show what I mean (the 64x64 PNG I used can be downloaded here)

Code: Select all

UsePNGImageDecoder()

Structure vertex
    sx.f
    sy.f
    sz.f
    rhw.f
    color.l
    specular.l
    tu.f
    tv.f
EndStructure 

  Structure PB_Sprite3D
     Texture.l              ; DirectX7 surface
     Vertice.vertex[4] ; The 4 vertices for the rectangle sprite
     Width.w
     Height.w
  EndStructure 

InitSprite()
InitSprite3D()

OpenScreen(640,480,32,"example")

CatchSprite(0,?bitmap,#PB_Sprite_Texture | #PB_Sprite_AlphaBlending)
CreateSprite3D(0,0)
ZoomSprite3D(0,64,64)
CreateSprite3D(1,0)
ZoomSprite3D(1,64,64)

*sprite.PB_Sprite3D=IsSprite3D(1)

Sprite3DQuality(1)

x.f=0

Repeat
  
  x=x+0.05
  If x>576
    x=0
  EndIf
  
  f.f=x-Round(x,0)
  
  *sprite\Vertice[0]\sx=f
  *sprite\Vertice[1]\sx=64+f
  *sprite\Vertice[2]\sx=f
  *sprite\Vertice[3]\sx=64+f
    
  ClearScreen(RGB(0,0,64))
  Start3D()
    DisplaySprite3D(0,x,0,255)      
    DisplaySprite3D(1,Round(x,0),64,255)
  Stop3D()

  FlipBuffers()

Until GetAsyncKeyState_($1B)

CloseScreen()

End

DataSection

bitmap:
IncludeBinary("test.png")

EndDataSection
The top sprite jumps a whole pixel every 20 frames - the x position is rounded to the nearest pixel. The bottom sprite show how it would look with my proposed feature request - the sprite moves smoothly.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

I've never noticed that before. :?
--Kale

Image
Steve Elliott
Enthusiast
Enthusiast
Posts: 109
Joined: Sun Jan 01, 2006 9:34 pm
Location: Wales, UK

Post by Steve Elliott »

Floats and doubles are ignored for positioning? I'm about to convert some code into a PureBASIC engine I'm developing, and if this is as bad as it seems I might need to re-think my use of PureBASIC.

This has serious implications for smooth movement in games - a major priority Fred. :(
Project S: loading...
Intel Core2 Duo E7200 @ 2.53Ghz, 3Gb RAM Intel G45 Express
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Steve Elliott wrote:This has serious implications for smooth movement in games - a major priority Fred. :(
Only when movements are slower than (DisplayedFramesPerSecond)*pixel/second.
Usually, when movements are slower than 30 pixel/second.

But i second this request, of course!
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

third, i wondered why my scrolling maps seemed to move kind of jerky...
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Any news on this issue Fred?
--Kale

Image
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Sprite3D functions to accept floats

Post by nco2k »

chris_b wrote:Presumably with both DirectX and OpenGL the various parameters for positioning, rotating and transforming Sprite3Ds will be converted to floating point values anyway - so there's no reason for Sprite3D functions not to accept floats for these parameters.
i second the request, but what about 2d sprites?? are they meant to accept floats for positioning aswell?? would be cool. :D

c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

2D sprites only consist of complete pixel.
there is no smoothing between the pixels.
according to this, 2D sprites only can positioned on full pixels,
so there is no use for float-parameters.


concerning float parameters for Sprite3D-commands:

would not only be a good idea, but its essetially.
maybe it was easier that way before PB supported Doubles,
but not it does, so the Sprite3D-Lib should be changed soon.

I think the 3D-features on Linux and on Mac support floats, too, don't they?
oh... and have a nice day.
skape
User
User
Posts: 17
Joined: Mon Nov 18, 2013 7:24 am

Re: Sprite3D functions to accept floats

Post by skape »

Very sorry to resurrect such an old thread (I couldn't find a newer one addressing this), but has this been added / changed as of PB 5.2x? It doesn't appear to be possible in the 5.20 demo. It's something that is somewhat important to me, to be able to draw sprites at non-whole number positions for smooth slow speed movement. Is there a good workaround if not? (Something mutiplatform...)

Thanks! :)
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Sprite3D functions to accept floats

Post by Fred »

You can't draw sprite at a non-whole number position as in PB the base unit is the pixel and you can't have an half pixel. Just you float if you need slow motion and it will display it slower, on pixel basis.
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Sprite3D functions to accept floats

Post by STARGÅTE »

Fred wrote:You can't draw sprite at a non-whole number position as in PB the base unit is the pixel and you can't have an half pixel. Just you float if you need slow motion and it will display it slower, on pixel basis.
You can.
TransformSprite() accept floats, so you can make move on sub pixel base, like in this example.
On top the normal DisplaySprite, on bottom the sub pixel move with TransformSprite().

Code: Select all

InitSprite()

UsePNGImageDecoder()

Enumeration
	#Window
	#Sprite
EndEnumeration

OpenWindow(#Window, 0, 0, 300, 300, "Sprite", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Window), 0, 0, WindowWidth(#Window), WindowHeight(#Window), 0, 0, 0)
SpriteQuality(#PB_Sprite_BilinearFiltering)

CreateSprite(#Sprite, 32, 32)
StartDrawing(SpriteOutput(#Sprite))
	Box(10, 1, 2, 30, $FF8080)
	Box(16, 1, 2, 30, $80FF80)
	Box(22, 1, 2, 30, $8080FF)
	Line(1, 16, 30, 1, $FFFFFF)
StopDrawing()

Define Start = ElapsedMilliseconds()
Define X.f

Repeat
	
	Repeat
		
		Select WindowEvent()
			Case #PB_Event_CloseWindow
				End
			Case #Null
				Break
		EndSelect
		
	ForEver
	
	ClearScreen(0)
	
	X = 50+(ElapsedMilliseconds()-Start)/1000
	
	ZoomSprite(#Sprite, 32, 32)
	DisplaySprite(#Sprite, X, X)
	
	TransformSprite(#Sprite, X, X+50, X+SpriteWidth(#Sprite), X+50, X+SpriteWidth(#Sprite), X+50+SpriteHeight(#Sprite), X, X+50+SpriteHeight(#Sprite))
	DisplaySprite(#Sprite, 0, 0)
	
	FlipBuffers()
	
ForEver
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
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Sprite3D functions to accept floats

Post by Fred »

Now that's interesting, always something new to learn :).

ps: on my screen it looks a bit wierd, like a bit of intensity change when being between pixels (I guess it's GFX card interpolations to emulate this)
Post Reply