RemoteTechnologiesGroup / RemoteTech

Community developed continuation of Kerbal Space Program's RemoteTech mod.
http://remotetechnologiesgroup.github.io/RemoteTech
GNU General Public License v2.0
233 stars 102 forks source link

Signal line points to the wrong direction when vessel is behind the camera (screen) #711

Closed zhihengq closed 6 years ago

zhihengq commented 7 years ago

O.S: Windows 10 64 bits KSP: 1.2.2.1622 (WindowsPlayer) both 32 and 64 bits Problem: signal lines point to the wrong direction when one of the vessels is behind the camera.

Reproduction steps: Install RemoteTech 1.8.3. Start a new sandbox game. Create a probe with a powerful enough antenna and enough power, set orbit to SMA: 10000000, with the rest of the orbit parameters 0. Go to either map view or the tracking center, focus view on Kerbin, zoom in and out so that the distance between Kerbin and the camera (or viewpoint) is a little bit smaller than the distance between Kerbin and the probe. Drag around to rotate, at sometimes, or more specifically, when the probe should be behind the camera (at this time the probe should be outside the screen), the signal line reverses its direction. This happens frequently, both between vessels and from KSC to vessels. The above is just the fastest way to reproduce it. The same problem applies to cones.

Logs: output_log.txt

Screenshot:

2016-12-26 1 2016-12-26

KSP-TaxiService commented 7 years ago

I tracked the direction flip of this signal line to the ScaledSpace.LocalToScaledSpace(pos) call where pos is the world-space Vector3d of an edge point (a signal line).

As it is well known, the world space (Unity's coord system) is inadequate for KSP's requirements (Jool is far far away from Sun) because physic jitter is visual at an extreme distance. Squad implemented the "Futurma" workaround of moving the universe around a ship to reliably save, refer to or transform a vessel position anywhere in the solar system. This is what the scaled space is referred to.

Somehow, when the camera is close to the vessel (as reproduced by decdl), the LocalToScaledSpace function returns the unexplained sudden shift in the position instead of the consistent position. In other words, the RemoteTech codebase essentially reads in these transformed positions of the signal line when drawing on screen. I can't find any obvious cause for this shift in the ScaledSpace class.

Given that the bug likely originates from the stock KSP and is visual on RemoteTech side, I will leave this issue open for RT bug hunters in future. Also, since the RT 2.0 redevelopment is based on CommNet, this bug will not appear in RT 2.0.

KSP-TaxiService commented 6 years ago

The root cause of sudden shift in the position is Unity 5's camera.WorldToScreenPoint(planetPos) that, I think, provides this result when incorrect/inproper inputs are given. It only happens if a position is behind the "camera plane". I think it is one common problem in Unity game development, not just KSP.

A workaround is placed to flip the line direction when detecting this scenario. But there is a "new" issue below, in which the entire dish cone is shown if the camera is in certain angle/position. 1

I said "new" because it actually and still exists at the beginning. It is cleverly masked by hiding topmost cone and showing as a trapezoid shape. I am unable to fix this issue as I do not have sufficient knowledge on how to fix.