-
Notifications
You must be signed in to change notification settings - Fork 88
better segment hovering when mouse is on node #615
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
better segment hovering when mouse is on node #615
Conversation
| } | ||
|
|
||
| return HoveredNodeId != 0 || HoveredSegmentId != 0; | ||
| if (HoveredNodeId != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argument can be made that his should be done at line 877 after we determine HoveredNodeID. That approach works for all cases except for level crossings. I found no way to get the following function to find level crossing nodes:
RayCast(segmentInput, out RaycastOutput segmentOutput)
Therefore I decided to call GetHoveredSegmentFromNode() here.
The code can take multiple paths. the most complicated one is this:
- We determine the
HoveredSegmentID. - We determine
HoveredNodeIDby calculating shortest distance to the segment start or end node. - We fix
HoveredSegmentIDagain by finding the segment which makes the minimum angle with the mouse-to-node vector.
it may sound confusing but thats the only way to support level crossings.
TLM/TLM/UI/TrafficManagerTool.cs
Outdated
| /// returns the node segment that is closest to the mouse pointer based on angle. | ||
| /// </summary> | ||
| internal ushort GetHoveredSegmentFromNode() { | ||
| bool considerSegmentLenght = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better place for this hard coded configuration option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a constant somewhere in the same class, or Constants.cs module (we have one or a few)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
|
I tested this with bridges, tunnels, metro, level crossings, and of course normal junctions. |
|
|
||
| protected override ushort HoveredNodeId { | ||
| get { | ||
| bool ctrlDown = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes #616
TLM/TLM/UI/TrafficManagerTool.cs
Outdated
| /// input order does not matter. | ||
| /// The return value is between 0 to 180. | ||
| /// </summary> | ||
| private static float GetAgnele(Vector3 v1, Vector3 v2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming: GetAngle
kvakvs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good
fixes #538
I have explained the math behind my approach in #576 (comment) . Please read it.
as suggested by @aubergine10 in #576 (comment) I provided option to "buff the clickability of segments based on their length". The option can be configured at compile time.
fixes #594
To fix this: when mouse ray is not valid I set
HoveredSegmentIdandHoveredSegmentIdto zeroEDIT: fixes #616
I added an exception for when control key is down.