PDA

View Full Version : Problems with drawing percision.



Runner
10-07-2003, 11:03 AM
I have a following problem. Some time ago I made a game with DelphiX. It is a space shooter for two. One on one viewed from top perspective. You can accelerate and break and you can turn left or right (0..360 degrees).

But the problem is here : DelphiX use float for X and Y coordinates of the Sprite. PowerDraw rutine RenderEffect only uses integer for X and Y coordianted. This is a problem because I calculate movement like this:

Ship.X := Ship.X + Round(cos(Ship.Angle) * Ship.Speed)
Ship.Y := Ship.Y + Round(sin(Ship.Angle) * Ship.Speed)

Now speed cannot be to big or the movement would be to fast, but it speed is small 0.05 or 0.1 then there is no accuracy because the result is rounded up.

In DelphiX the movement is accurate and very smooth, but in PowerDraw there is not.

Does anyone has a solution or workaround for this?


Thanks.
Runner

Paulius
10-07-2003, 03:08 PM
Calculate everything as you did before than store rounded x and y in other variables and pass them to RenderEffect.

Runner
10-07-2003, 07:36 PM
Thanks for the tip, but I already tried it and it doesn't work. Why?
I will show an example.

Lets say I am turned 5 degress clockwise (it doesn't matter which way actualy) and that I am moving with speed 0,5.

Ship.X := Ship.X + Sin(5)*0,5 => Ship.X + 0.087*0,5
Ship.Y := Ship.Y + Cos(5)*0,5 => ShipY + 0.996*0,5

So you see that if I round the result up in a new variable and pass is to RenderEffect then X will not change at all. The Ship will be oriented 5 degrees to the right, but stil moved like it is a 0 degress.

I don't know how precise DelphiX was but there it goes smooth.

But maybe I just can't see the problem clearly

Paulius
10-07-2003, 09:17 PM
X will change after 23 frames if the movement continues
look at some code with your parameters:

Var
xf,yf:real;
xi,yi:integer;
?¢_¬¶
xf:=0;
yf:=0;
...
xf := xf + Sin(5)*0,5; //xf:=0,0435
yf := yf + Cos(5)*0,5;//yf:=0,498
xi:=round(xf); //xi:=0
yi:=round(yf); //yi:=0

//on second pass
xf := xf + Sin(5)*0,5 ;//xf:=0,087
yf := yf + Cos(5)*0,5;//yf:=0,0996
xi:=round(xf); //xi:=0
yi:=round(yf); //yi:=1

//on 23 pass
xf := xf + Sin(5)*0,5 ;//xf:= 1,0005
yf := yf + Cos(5)*0,5 //yf:=11,454
xi:=round(xf); //xf:= 1
yi:=round(yf); //yi:=11


This way the movement is of real?¢_~s precision, we don?¢_~t sacrifice precision because we can?¢_~t use real?¢_~s in 2d, there the smallest thing is a pixel and you can?¢_Tt draw something which would have a coordinate of say 1.239. It has nothing to do with precision, DelphiX just didn?¢_Tt show you it?¢_Ts rounding.
The movement wouldn?¢_Tt be smooth only if you had a terrible framerate, a terrible resolution and the speed of movement would be 0.000000000001.

Runner
11-07-2003, 06:17 AM
Hm...yes I see the issue now. I will change the code and see what happens. If it still isn't smooth then the problem must be elsewhere.

Thank you very much for your help. :)


Runner