CitiesSkylinesMods / TMPE

Cities: Skylines Traffic Manager: President Edition
https://steamcommunity.com/sharedfiles/filedetails/?id=1637663252
MIT License
571 stars 85 forks source link

lane connector should raycast the whole lane #625

Closed kianzarrin closed 4 years ago

kianzarrin commented 4 years ago

see #543

in https://github.com/krzychu124/Cities-Skylines-Traffic-Manager-President-Edition/issues/543#issuecomment-549069179 @krzychu124 fixing the rendering problem.

EDIT: the current ray-casting would work just fine. meanwhile this issue is for making it easier to hover over lane node markers by making the whole lane hover-able.

~~This issue is for fixing the ray-casting problem. I intend to use GetClosestLane(). should be a piece of cake! ~~

kianzarrin commented 4 years ago

I gave up on trying to measure the HitPos and instead decided to use full lane markers from the old Traffic++ code.

The freaking HitPos has +-2meter error which is good enough for hovering over segments but way too poor for lane detection. I wrote a code to hover on the exact place of the circle of the lane marker but it intermittently fails because of the inaccuracy in all x y z directions (it seems that the position is on the mouse-ray but it penetrates the segment a bit before it gets a hit.

It might be able to fix the problem by measuring height of the lane bezier. after measuring the vertical penetration of the mouse ray we can also calculate the x and y penetration too.

in https://github.com/krzychu124/Cities-Skylines-Traffic-Manager-President-Edition/issues/543#issuecomment-549069179 @krzychu124 said he will fix the way things are rendered at which point it would not be necessary to use the hitpos anymore.

So i decided to abort this issue. EDIT:So I decided to abort measuring the hitpos and focus only on hovering the whole lane.

kianzarrin commented 4 years ago

even thought fixing hitpos is necessary temporarily I could not resist the urge to fix it lol! I have made partial progress.

EDIT: scrap that! I fixed it satisfactory!

Debug 672.8506581: KIAN DEBUG FIXH:
112.864:CorrectH
114.002:hitH
113.988:h1
113.689:h2 << best approximation

Debug 764.8867964: KIAN DEBUG FIXH:
112.864:CorrectH
111.653:hitH
114.682:h1
114.383:h2 << best approximation

Debug 799.0462602: KIAN DEBUG FIXH:
112.864:CorrectH
111.312:hitH
114.376:h1
114.077:h2 << best approximation

the code is:

        static float FixH() {
            NetSegment segment = Shortcuts.GetSeg(HoveredSegmentId);
            Vector3 pos1 = segment.GetClosestPosition(HitPos);
            segment.GetClosestLanePosition(
                HitPos, NetInfo.LaneType.All, VehicleInfo.VehicleType.All,
                out Vector3 pos2, out uint laneID, out int laneIndex, out float laneOffset);
            float hitH = HitPos.y;
            float h1 = pos1.y;
            float h2 = pos2.y;
            float nodeH = Shortcuts.GetNode(segment.m_startNode).m_position.y; // not useful if road has slope.

            Log._Debug($"KIAN DEBUG FIXH:\n" +
                $"{nodeH.ToString("000.000")}:nodeH\n" +
                $"{hitH.ToString("000.000")}:hitH\n"+
                $"{h1.ToString("000.000")}:h1\n" +
                $"{h2.ToString("000.000")}:h2\n"
                );
            return h2;
        }

we want hitH to be slightly (not too much) higher than nodeH. It just works better that way :).

kianzarrin commented 4 years ago

Its working! Screenshot (370)

kvakvs commented 4 years ago

Can the highlighted lane gain same color as the connector node?

originalfoo commented 4 years ago

At a guess the lane highlight is just there as visual aid during dev testing?

kvakvs commented 4 years ago

More visual feedback is nice when a connector origin circle is obstructed by traffic. But maybe some won't like it. Maybe show it only when something liek Shift is held for now, later when i work on the tool UI maybe there will be some space for a toggle switch.

kianzarrin commented 4 years ago

@aubergine10 No the white line is not a dev thing. Its final product. I did not show all segment lane markers because i did not wanted it to look like xmass.

@kvakvs More visual feedback is nice when a connector origin circle is obstructed by traffic. But maybe some won't like it. Maybe show it only when something liek Shift is held for now,

The segment lane marker does not appear when the user is hovering over the lane marker circle. It only appears if the lane marker is hovered as a result of user hovering over the rest of the lane and not the circle. This approach in my opinion is better than the shift thing you mentioned. I can make it same color as node marker.