-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add Lua methods 'set_rotation()' and 'get_rotation()' #7395
Conversation
…me method names to be more clear. Instead of an f32 being sent over network for yaw, now a v3f is sent for rotation on xyz axes. Perserved Lua method set_yaw/setyaw so that old mods still work, other wise to set yaw they would need to switch to set_rotation(0, yaw, 0).
…https://github.com/CoderForTheBetter/minetest into minetest-entity-rotation
Using degrees would be consistent with attachment rotations and is what Irrlicht uses. It may also help to avoid network conversion errors with small floating-point values. I still think a Of course that should be a separate PR I could even make myself if need be :) |
@stujones11 I plan on adding The reason I have done all this work is that I wanted to make a mod that had flight mechanics but realized that Minetest did not have many resources for that. After this PR is merged then I will work on and push the code for There really is no reason for you do it, yet, I know this part Minetest well now so it should not take me long to do it, but in about a week and a half I start a summer semester and will be swamped with school. Once I am back in school I will not be able to start a whole new PR I don't think. |
@CoderForTheBetter There is really no hurry, your school work should definitely come first. It would be nice to see these features included in 0.5.0 but I think that might still be a little way off. The code itself is very simple, it's all the other boiler-plate and documentation that takes time. I have also always wanted to make a semi-realistic flying mod and have had several attempts at trying to use dummy attachments, animation key-frames and all sorts of other hackery to mimic pitch and roll, none of which have been very successful =) |
I know you guys are busy so I made a GIF for each thing I tested and know works (can't think of anything else to test) and I summarized questions that need answers: Here's what I know works so far:
Questions:
Hopefully, @SmallJoker and/or @nerzhul can answer my above questions. |
FWIW, I think we should move away from the aircraft terminology (yaw, pitch & roll), this is already done in the api by deprecating |
@CoderForTheBetter |
Irrlicht uses degrees for rotation, using radians (IMO) is not only less intuitive for most people, it would require unnecessary conversions which may result in loss of precision, especially with sending complex floats over the network. |
…m/minetest/minetest into minetest-entity-rotation
@stujones11 Didn't see your comment. I can change back my commit if needed, someone needs to decide on degrees or radians. EDIT: @nerzhul, what do you think? Degrees or radians? I like stu's points:
It is ultimately up to you, @rubenwardy, and @SmallJoker since you guys can approve PRs. |
…ithub.com/minetest/minetest into minetest-entity-rotation
Tested everything using radians, seems to be working. I don't don't mind using radians, I just want this approved before 0.5.0 so that the network code is in place. Degrees or radians can be decided on later, the network can't. Also, it has been three years that people have wanted this basic feature: #2251 This is the only chance for the network code to be put into place since 0.5.0 breaks stuff anyways. |
…netest-entity-rotation
@ClobberXD weird. Are you using the spin command from my mod? It spins it fast now that it is using radians. Try lowering the increment amount to something smaller. Seems to be on your side. Here's what I have with the default increment amount from my mod (a little jerky but that's just Minetest when moving things fast): EDIT: Just tried with 0.09 server step and got the same problem as you. The entity is just spinning too fast for the server step. Realistically, no mod will want to spin an object that fast anyway, which in this case is 1 radian (57 degrees) every server step (very fast). |
Oh right, |
the old 0.1 was before MT was optimized from 0.4.15 to 0.4.17. Now you should use 0.05 by default it's a common accepted choice |
Right, so is there any specific issue preventing this PR from being merged? |
Rubenwardy, we don't have to change everything to one or the other, at first i considered that too but later realised there's actually no reason to enforce a hard rule for everything, and very good reason to be flexible and practical and use one or the other unit according to what makes sense for that particular usage. For example decoration rotation being 0 90 180 270 should obviously be in degrees and these values are never used in Lua maths code. Once you remove the obvious degrees items from your list you end up with Lua maths and values heavily used in Lua maths (object rotations), all are radians for good reason. Existing mods using
Nope, it doesn't make sense to have angles in degrees when those angles are being heavily used in calculations, as with rotations. |
Latest commit doesn't change anything major. It is just an improvement to the quality of the code. |
My 👍 still stands. |
Thanks for reviewing! =D |
* Adds Lua methods 'set_rotation()' and 'get_rotation'. Also changed some method names to be more clear. Instead of an f32 being sent over network for yaw, now a v3f is sent for rotation on xyz axes. Perserved Lua method set_yaw/setyaw so that old mods still work, other wise to set yaw they would need to switch to set_rotation(0, yaw, 0).
Nice! Thank you all for your time reviewing and testing! In about two weeks I will start on trying to make a PR that will make rotations more intuitive when it comes to rolling objects. |
I am ecstatic that this has been merged 🎉 |
We discussed this a long time ago (in my first issue on the subject). This is first needed to be able to get the network protocol where it needs to be. Also, if a function such as 'minetest.rotate_on_axis' existed then the rotation of the object can easily be set back to zero (or any other rotation) using the methods this PR provides. Remember, this PR does not provide a roll on-axis method, that is not its purpose, this just behaves like when attaching an entity to an entity and then setting its rotation. Also, you could test and see that this same problem is in the mentioned entity rotation method. Once I have the time, I will work on another PR that will allow more intuitive rotations. Please, look back on the discussions we have had on this matter in this PR and in #7331. However, if you do have any ideas for something that could work better (although I think this fulfills the purpose it was made for) then please share those ideas. EDIT: Here's a good comment in my last issue that is what decided this PR: link |
Ah, thank you for the explanation :) |
* Adds Lua methods 'set_rotation()' and 'get_rotation'. Also changed some method names to be more clear. Instead of an f32 being sent over network for yaw, now a v3f is sent for rotation on xyz axes. Perserved Lua method set_yaw/setyaw so that old mods still work, other wise to set yaw they would need to switch to set_rotation(0, yaw, 0).
* Adds Lua methods 'set_rotation()' and 'get_rotation'. Also changed some method names to be more clear. Instead of an f32 being sent over network for yaw, now a v3f is sent for rotation on xyz axes. Perserved Lua method set_yaw/setyaw so that old mods still work, other wise to set yaw they would need to switch to set_rotation(0, yaw, 0).
Is the rotation actually saved in the world? Line 523 in 1d3f5af
|
@DS-Minetest Lines 614 to 620 in 1d3f5af
F1000 calls are basically just floats converted to integer, multiplied by 1000. Hence precision errors in some places and weird errors due floats being too large. Lines 305 to 310 in 1d3f5af
EDIT: FYI: If you see |
Ah, thanks, |
This PR adds Lua methods called 'set_rotation(rot)' where rot is a vector {x=0, y=0, z=0} and ''get_rotation()' returns a vector. As far as the network code goes; instead of just a float being sent over the network now a v3f is sent for XYZ axes. I preserved setYaw/set_yaw so that old mods still work. This also changes some of the C++ PlayerSAO names to be more clear.
One issue that needs to be dealt with: should the new Lua methods take radians or degrees? Right now it takes degrees (which I think is more intuitive). setYaw already uses radians though but once it has the angle in radians it uses core::RADTODEG right away. (EDIT as of July 11, 2018: decided on using degrees. EDIT2: it's back to radians)
For testing, I wrote a mod that has various commands for making sure this all works: prytest. Starting a world with the mod enabled will display the commands in chat.
If you're curious to see the Lua code that a mod could use: Link
For some good discussion on entity rotation: #7331
Here's what I know works so far: