jeyoder / StuffInSpace

A real-time interactive WebGL visualisation of objects in Earth orbit
http://stuffin.space
816 stars 153 forks source link

Camera rotation erratic with certain searches #35

Open eldorel opened 4 years ago

eldorel commented 4 years ago

I'm not sure exactly what may be influencing this, but the camera rotation goes ballistic on certain zoom levels and searches.

It almost looks like the camera is shifting the globe to focus on an object, and this causes uncontrolled rotation in searches where there are a lot of evenly spaced objects.

I recorded it and uploaded a Gif here: https://i.imgur.com/Up3Q423.gifv

thkruz commented 3 years ago

Its related to the raycasting code that runs in the rendering pipeline. When you click on the earth it uses a readpixels call to access the GPU and determine if you clicked on the earth - that eats up 6ms of a 16ms rendering loop on my high end gaming computer. My guess is that when you add that to the position update call that runs every draw frame and any code related to the group of satellites it is all just too much for your computer to keep up.

The reason it HAS to keep up is that the code has the camera chase the last position of the mouse (simplified explanation). If you get behind then it keeps over compensating and you get that camera shake effect.

If you are forking the code, I'd recommend disabling the raycasting code and just use the code that gets called when you don't hit the earth all the time. I originally did that for my mobile app and then realized it was worth just doing all the time and using the extra rendering time for other things.

Also verify that you limit the number of on mouse move calls to no more than one every 16ms. Otherwise you will have jquery eat into your rendering.