Fix PutShipOnRoute function#5250
Conversation
After placing the ship on the route, the possibility of a collision is checked. In case of a possible collision, its position is changed to avoid this. It turns out that this calculation worked incorrectly, because the FromVectors function creates a matrix using vectors as columns, and in the further calculation it is assumed that vectors are rows. Also removed unnecessary Frame object retrieval by FrameId
fluffyfreak
left a comment
There was a problem hiding this comment.
Nice work, and I love a good debug visualisation video!
|
Will merge within 24 h if no one objects |
src/lua/LuaSpace.cpp
Outdated
| if (shipFrame->GetNonRotFrame() != targFrame->GetNonRotFrame() && targpos.Length() > erad) { | ||
| // the ship is not in the target's frame or target is above the effective radius of obstructor - rotate the ship's position | ||
| // around the target position, so that the obstructor's "effective radius" does not cross the path | ||
| // direction obstructor -> target |
There was a problem hiding this comment.
Interesting dillemma here, the code checks that we are both not in the same frame and further than the effective radius, however the comment is saying that this is an 'or' condition - what happens if we are in the same frame but beyond effective radius?
There was a problem hiding this comment.
@Web-eWorks Really weird. After paradoxically long deliberation, it seems to me that we need to change the comment to "and", because we want to enter the sphere of effective radius of obstructor only perpendicular to it, even if for some reason the target is not in the obstructor frame. (perhaps it could be an orbital station, in a very very low orbit?)
There was a problem hiding this comment.
@Web-eWorks if we are in the same frame but the target is beyond effective radius, like in any other case, when the target is beyond the effective radius, we can calculate the tangent, so option 1 can be used. I think I should remove the frame check at all.
There was a problem hiding this comment.
Feel free - I'm not particularly familiar with this algorithm, but that inconsistency stood out.
The choice of trajectory correction method depends only on whether we can calculate the tangent to the sphere of the effective radius of the obstructor from the target. We cannot do this if the target is within this sphere. All other conditions are unnecessary.
After placing the ship on the route, the possibility of a collision is checked. In case of a possible collision, its position is changed to avoid this. It turns out that this calculation worked incorrectly, because the
FromVectorsfunction creates a matrix using vectors ascolumns, and in the further calculation it is assumed that vectors are rows.
Also removed unnecessary
Frameobject retrieval byFrameId.This video shows that now everything is working as it should (at least in the video). The dangerous trajectory that was originally shown in red, the new safe trajectory is shown in blue, and the alternative trajectory (also safe, but on the other side of the obstructor) in gray.
coll.mp4
Two cases are shown - when the ship is out of the target frame, and when it is in the same frame with the target. In the first case, the trajectory turns so as not to fall into a dangerous proximity, and in the second case, the ship moves to the normal to the planet's surface.