Skip to content

Allow rotating entity selectionboxes #12379

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

Merged
merged 22 commits into from
Oct 30, 2022

Conversation

appgurueu
Copy link
Contributor

@appgurueu appgurueu commented May 27, 2022

Ready for review. Closes #12372. Written with @runsy's petz in mind.

Screenshot 2022-05-27 18-29-06

How to test

  1. /spawnentity testentities:selectionbox
  2. Point at it, punch & rightclick it a few times
  3. Point at other (rotating) objects (items in particular) and observe that their boxes are unaffected
  4. Other raycast testing (normals etc. should still work)

@appgurueu appgurueu force-pushed the rot-selection-box branch 2 times, most recently from ee90272 to ddbb9df Compare May 27, 2022 15:53
@MisterE123
Copy link
Contributor

oh, this is so good. I hope it gets merged for 5.6. How does it affect walking on collisionboxes?

@appgurueu
Copy link
Contributor Author

oh, this is so good. I hope it gets merged for 5.6. How does it affect walking on collisionboxes?

It doesn't affect collisionboxes because that's way more complex, only selectionboxes.

@appgurueu appgurueu force-pushed the rot-selection-box branch from ddbb9df to 8193935 Compare May 27, 2022 16:33
@sfan5 sfan5 added the Feature ✨ PRs that add or enhance a feature label May 27, 2022
@appgurueu appgurueu force-pushed the rot-selection-box branch from 8193935 to 9afabb0 Compare May 27, 2022 16:47
@Zughy Zughy added @ Client / Audiovisuals Roadmap: Needs approval The change is not part of the current roadmap and needs to be approved by coredevs beforehand UI/UX labels May 27, 2022
@appgurueu appgurueu force-pushed the rot-selection-box branch from 9afabb0 to 4f1c9b3 Compare May 28, 2022 09:40
@appgurueu appgurueu force-pushed the rot-selection-box branch from 4f1c9b3 to daf3057 Compare May 28, 2022 09:57
@appgurueu appgurueu force-pushed the rot-selection-box branch from daf3057 to 7e25b2c Compare May 28, 2022 09:58
@sfan5 sfan5 added Concept approved Approved by a core dev: PRs welcomed! and removed Roadmap: Needs approval The change is not part of the current roadmap and needs to be approved by coredevs beforehand labels May 29, 2022
@appgurueu
Copy link
Contributor Author

Carts may benefit from this as well: They are nonphysical either way and may be rotated by 45° when going uphill.

@ghost
Copy link

ghost commented Jun 1, 2022

Yeah, this could be cool for entity selection.

@Andrey2470T
Copy link
Contributor

Generally works fine. 👍 However, I noticed at high (even middle) rotation speed the selection boxes may a bit lag from their entities' rotation. Visually this appears in the following way:
Снимок экрана от 2022-05-31 12-11-12
Снимок экрана от 2022-05-31 12-11-35

@appgurueu
Copy link
Contributor Author

appgurueu commented Jun 4, 2022

I noticed at high (even middle) rotation speed the selection boxes may a bit lag from their entities' rotation.

Presumably the same issue as #11905 and thus somewhat out of scope for this PR to fix... There are two issues:

  1. The broken rotation interpolation is only applied when drawing (after the pointed thing has been determined) - this does not seem to matter though and is mostly negligible;
  2. For some reason gcao->getSceneNode()->getAbsoluteTransformation().getRotationDegrees() yields an outdated rotation despite being called after the Generic CAO's step has been called, which is definitely not how it's supposed to behave.

The fix for 2. is to simply call updateAbsolutePosition(). Latest commit fixes it.

@appgurueu
Copy link
Contributor Author

automatic_rotate probably won't work serverside...

@appgurueu appgurueu force-pushed the rot-selection-box branch from 144a5c0 to 7e1d307 Compare June 5, 2022 18:11
@appgurueu
Copy link
Contributor Author

appgurueu commented Jun 5, 2022

What about intersection normals: Should the Lua API return the rotated normal or the face normal as pointed_thing.intersection_normal? Up until this PR the two have been equal.

@x2048
Copy link
Contributor

x2048 commented Sep 27, 2022

I've noticed that server-side rotation is slightly different from client-side rotation, even for a static entitiy (automatic_rotation = 0). Compare the cross shapes at the screenshots below:
image
image

@appgurueu

@appgurueu
Copy link
Contributor Author

appgurueu commented Sep 28, 2022

I've noticed that server-side rotation is slightly different from client-side rotation, even for a static entity (automatic_rotate = 0).

Was the entity static from the get go (in this case this would be a clear bug) or did you stop its automatic rotation after a while (then this would be expected to some extent)?

Edit: I've been able to reproduce this for edge cases (thin boxes, significantly rotated) even after setting the rotation by punching. This might be related to float precision issues. I suspect this is related to me not resetting the variable keeping track of the total automatic rotate properly.

@appgurueu
Copy link
Contributor Author

appgurueu commented Sep 28, 2022

After further consideration: This is indeed the error incurred through the server guessing automatic rotate without knowing when the client started applying it; an error of automatic rotate times RTT / stepsize is to be expected.

Setting automatic rotate to zero and then setting the rotation does not get rid of the rotation incurred through automatic rotate; automatic rotate only affects the rotation of the child node, which stays and is always additionally applied.

We can not break this behavior due to backwards compatibility.

Another caveat is that presumably this will reset when the entity is unloaded client-side. When the client comes back to the entity after a while, it will start with a fresh automatic rotate Y-axis rotation. In this case, client & server might experience a larger desync. In fact, different clients might see different total rotations incurred by automatic rotate - which one should the server use in its calculations?

It seems with the current protocol, we can not reliably know, but only guess the rotation of an entity with automatic_rotate != 0.

Some options:

  • Keep as-is & document the aforementioned caveats; would work well enough in singleplayer
  • Get rid of automatic_rotate-related code and jus document that using automatic_rotate + rotatable selectionbox won't work well serverside (similar to attachments) - modders can reimplement serverside raycasting including the automatic rotate guessing (which turns out to be a hack) themselves if they really want to
  • Complicate protocol to sync automatic rotate; probably out of scope for this PR

@appgurueu
Copy link
Contributor Author

appgurueu commented Sep 28, 2022

Went with the first option. Note:

  • Client-side, everything is still fine;
  • For free/detached entities without automatic rotate, everything is still fine & consistent both server- and clientside;
  • In singleplayer, the error of the server's "best guess" will usually be acceptable;
  • The only cases where this really fails (excepting attachments) thus are:
    • singleplayer, rotated selectionbox + automatic rotate, resetting automatic rotate to 0 and starting it again later (as the test entities may do) such that the error adds up
    • multiplayer, rotated selectionbox + automatic rotate, automatic rotate desync may happen

@sfan5 sfan5 added the Rebase needed The PR needs to be rebased by its author label Oct 13, 2022
@sfan5
Copy link
Collaborator

sfan5 commented Oct 13, 2022

Needs rebase.

@appgurueu
Copy link
Contributor Author

Rebased.

@Zughy Zughy removed the Rebase needed The PR needs to be rebased by its author label Oct 14, 2022
@ghost
Copy link

ghost commented Oct 24, 2022

This is basic for the mob mods.

https://github.com/runsy/petz/issues/117

@ghost
Copy link

ghost commented Oct 24, 2022

I think this should implement only in singleplayer.

@appgurueu
Copy link
Contributor Author

I think this should implement only in singleplayer.

Please elaborate: Are you referring to rotatable selectionboxes in general (if so: why?) or do you mean taking automatic rotate into account specifically?

@ghost
Copy link

ghost commented Oct 24, 2022

I think this should implement only in singleplayer.

Please elaborate: Are you referring to rotatable selectionboxes in general (if so: why?) or do you mean taking automatic rotate into account specifically?

I mean the preccision errors.

@appgurueu
Copy link
Contributor Author

I think this should implement only in singleplayer.

Please elaborate: Are you referring to rotatable selectionboxes in general (if so: why?) or do you mean taking automatic rotate into account specifically?

I mean the preccision errors.

The precision errors are only relevant for automatic rotate. Disabling the approximation in multiplayer would require additional work and IMO be dirty. Adding the note for modders IMO is enough.

@ghost
Copy link

ghost commented Oct 24, 2022

Can anyone more review this? please

@nerzhul @TurkeyMcMac @rubenwardy @SmallJoker @lhofhansl @savilli @x2048 @Df458

Copy link
Contributor

@TurkeyMcMac TurkeyMcMac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works. Just some minor things.

@ghost
Copy link

ghost commented Oct 30, 2022

With two approvals this should be merged, isn't it?

@appgurueu
Copy link
Contributor Author

With two approvals this should be merged, isn't it?

Sometimes core devs like to let some time pass, but yes, this does now fulfill the requirements to be merged.

@ghost
Copy link

ghost commented Oct 30, 2022

Sometimes core devs like to let some time pass, but yes, this does now fulfill the requirements to be merged.

I prefer a exhaustive review and checking than a faulty release.

Well, I guess this should be ready for 5.7 release.

@SmallJoker SmallJoker merged commit 0776271 into luanti-org:master Oct 30, 2022
appgurueu added a commit to appgurueu/minetest that referenced this pull request May 2, 2023
@appgurueu appgurueu deleted the rot-selection-box branch March 31, 2024 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@ Client / Audiovisuals Concept approved Approved by a core dev: PRs welcomed! Feature ✨ PRs that add or enhance a feature >= Two approvals ✅ ✅ UI/UX
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rotatable entity selectionboxes