Author Topic: Bug with GetCameraScale()!  (Read 7426 times)

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Bug with GetCameraScale()!
« on: February 03, 2011, 02:50:47 AM »
Hello,

The value of "GetCameraScale()" seems to update too slowly compared the actual timing of the player zooming in/out.

This becomes a serious issue when the position of drawn objects is calculated using the value returned by this function.  For example the new 3D Starfield Engine.

For about half a second, the stars move to the position they would be in if they were being drawn on a flat plane.
Then, they "jump" to their correct positions like it was 3D.

I have studied this behaviour extensively and done my best to isolate what causes it.  The thing I keep coming back to is the GetCameraScale() command.  It's not a FPS issue - this bug occurs even with 1 star and 100fps.  The effect is especially pronounced when you are zoomed all the way in.



Here is why I think it's GetCameraScale() that causes the issue.

In the Parallax engine, in which the bug was NOT present, the position of stars was calculated like this:

Code: [Select]
starX[i] = (GetCameraX() / zdepth[layer]) + SetStarX[i]
starY[i] = (GetCameraY() / zdepth[layer]) + SetStarY[i]

Where i is the ID of the star, starX is the drawn position of that star, zdepth is the "parallax factor" of the layer that star happens to be on, and SetStarX is the initial, assigned position of the star.
Notice that GetCameraScale() is never invoked here.  So the delay is not present.


In the new 3D Starfield Engine, the values are calculated, in part, based on the current camera scale.

Specifically, the line below takes the camera's scale and modifies it to a value that represents the Z-coordinate of the camera.

Code: [Select]
local CameraZ = (-1 / GetCameraScale()) * zscalefactor
The variable CameraZ is later used to calculate the X and Y positions of stars.

The inclusion of Camera Scale induces this drawing update latency.





I have delayed reporting this for several days until I was satisfied none of my own code could be causing this.
Alex, PM me or reply here if you would like a copy of a prototype of the engine, so you can see the erroneous behaviour (and the stars!) for yourself.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Bug with GetCameraScale()!
« Reply #1 on: February 03, 2011, 03:33:32 AM »
Update.

It seems like this only happens in LevelDraw.
Screendraw doesn't have that problem.  Unfortunately doing this in screendraw is rather different...

I will have a think and see if I can come up with a way to convert between the two.

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 24
  • Posts: 932
  • Eufloria: Yes
Re: Bug with GetCameraScale()!
« Reply #2 on: February 03, 2011, 03:39:06 AM »
Which may well slow it down even more...

Have a look at rally v1.2 - IIRC, that converted from world to screen, perhaps with a bit of cannibalisation you could work backwards from there.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 4
  • Posts: 1,809
Re: Bug with GetCameraScale()!
« Reply #3 on: February 04, 2011, 04:41:34 AM »
With a little help from Aino I have managed to get this working in ScreenDraw now.  So it's no longer an issue for me personally.