Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lane connector should raycast the whole lane #625

Closed
kianzarrin opened this issue Jan 26, 2020 · 7 comments · Fixed by #635
Closed

lane connector should raycast the whole lane #625

kianzarrin opened this issue Jan 26, 2020 · 7 comments · Fixed by #635
Labels
feature A new distinct feature
Milestone

Comments

@kianzarrin
Copy link
Collaborator

kianzarrin commented Jan 26, 2020

see #543

in #543 (comment) @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 kianzarrin added feature A new distinct feature triage Awaiting issue categorisation labels Jan 26, 2020
@originalfoo originalfoo changed the title lane connector should raycast the hole lane lane connector should raycast the whole lane Jan 26, 2020
@originalfoo originalfoo added this to the 11.1 milestone Jan 26, 2020
@kianzarrin
Copy link
Collaborator Author

kianzarrin commented Jan 31, 2020

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 #543 (comment) @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
Copy link
Collaborator Author

kianzarrin commented Jan 31, 2020

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
Copy link
Collaborator Author

Its working!
Screenshot (370)

@kvakvs
Copy link
Collaborator

kvakvs commented Jan 31, 2020

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

@originalfoo
Copy link
Member

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

@kvakvs
Copy link
Collaborator

kvakvs commented Jan 31, 2020

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
Copy link
Collaborator Author

@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.

kianzarrin added a commit that referenced this issue Feb 10, 2020
#625:
revived the lane hovering code from Traffic ++
Lane Connector now highlights lanes with Lane Sheath overlay.
Train markers use right color.
embolden lane curves for selected lane.
fixed drawing lane curves underground
made performance optimization by caching mouse pointer and lane bounds. They are recalculated only if user moves the mouse ray.
#543: I fixed the vertical mismatch by intersecting the mouse ray at the place where it hits the road.
@originalfoo originalfoo removed the triage Awaiting issue categorisation label Apr 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new distinct feature
Projects
None yet
3 participants