Moving an object is not smooth.. why?

Blitz3D Forums/Blitz3D Programming/Moving an object is not smooth.. why?

alain(Posted 2008) [#1]
Hi there,

I have got a problem with Blitz3D. If you try the following small program:

Graphics3D 640,480
SetBuffer BackBuffer()
camera=CreateCamera()
cube=CreateCube()
While not KeyDown(1)
ms% = MilliSecs()
PositionEntity cube,0,0,5.0+Sin(0.01*Float(ms))
RenderWorld
Flip
Wend
End


You will see a cube waving on Z axis on a sinus move.

But the move is not smooth, it seems to move step by step.

I don't understand why.

Where is the error in my code? What did I do wrong?

It seems Blitz uses integer instead of float somewhere but I cannot understand where is my error..

thanks for any help

alain


Floyd(Posted 2008) [#2]
It's because you are using Sin( EnormousAngle ). The bigger the angle the less accurate Sin( angle ).

In your case a change to Sin( ms Mod 360 ) is probably good enough.

In general you might want to record StartTime = Millisecs() near the start of you program. Then use ms = Millisecs() - StartTime. This will keep the values relatively small.


Rob Farley(Posted 2008) [#3]
I think your problem is that millisecs are too fast... If your screen is updating 60htz that means that means your values are increasing by 16.66 each time (1000/60).

Try millisecs() / 100 and you might see a better result as it won't be skipping.


Floyd(Posted 2008) [#4]
Dividing by 100 would probably help. But the underlying problem is still that the angle values are far too big.

That's why it ends up moving in steps. A very big floating point number can't change by a small amount. In this example the smallest possible change is 8:

Graphics3D 640, 480, 0, 1

BIG# = 123123000

For n# = 1 To 30
	Print Int( BIG + n )
Next

WaitKey



alain(Posted 2008) [#5]
Thanks Floyd I understand well your theory: it is a good point, but it does not fix my problem.

Let's try the following program

Graphics3D 640,480,32,2
SetBuffer BackBuffer()
camera=CreateCamera()
cube=CreateCube()
start% = MilliSecs()
While Not KeyDown(1)
ms% = MilliSecs() - start
z# = 13.0+ms/10000.0
PositionEntity cube,0,0,z
RenderWorld
Text 0,0,"Z pos     :"+z
Text 0,15,"Entity pos:"+EntityZ(cube)
Flip
Wend
End


You can see the value of EntityZ on the screen: it is changing smoothly, but the cube on the screen is only moving once per second...

I think it is an optimization of Blitz3D engine, but it is a problem for me because sometimes I have very slow moves and it looks crap.


_33(Posted 2008) [#6]
alain, you're doing an animation at the subpixel level. I can see that because of the antialiasing mode I use. The problem imho will always be there, as further you get away from the objects, since they move too slow.




alain(Posted 2008) [#7]
yep

that's just what I understood.

I feel a bit stupid.

anyway thanks for the help dudes :)


Bobysait(Posted 2008) [#8]
With your equation [z# = 13.0+ms/10000.0] I just realise :

floating values , I'm surprised it return a float...

(1/10) => Integer
Print(1/10.0) => float
Print(1.0/10) => float

I beleived the only way to get float was [a# * b = c#]
( So "a" should always be a float ... ) it seems it's (a# Or b#)