-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
GDNative linear indexing of Basis returns rows, expected columns (axis) #14553
Comments
CC @neikeq @Hinsbart |
After some more testings I realized that GetGlobalTransform acts ok, but the problem is in Vector3.cs If I am right the problem is in godot/modules/mono/glue/cs_files/Vector3.cs I think this must be removed. |
I don't know, in my tests it works as it should:
outputs:
|
Yes looks like I am wrong again. I get very strange results. |
@akien-mga I just made the same test by using Godot-Nim and I got the same strange output. |
I don't think so as Mono doesn't use GDNative. CC @endragor who may have a clue about what could be wrong in Godot-Nim. |
Are you sure about that? Seems too strange to have the same problem in Nim and C#, that's why I thought that Mono is using parts of GDNative. Here is the example project (like the first example project) for Nim. |
Try using |
I think what GDScript used is how it's defined in |
I'm not sure what are the established conventions for this, but in the context of Basis I think it makes sense for It seems to be consistent with linear indexing of matrices in Matlab at least: https://de.mathworks.com/help/matlab/math/matrix-indexing.html?requestedDomain=www.mathworks.com#f1-85511 |
Perfect. Just for future reference. |
Quoting @reduz from IRC:
|
That needs to be fixed before RC1 ideally. |
This looks like it is more problematic from what it seems. Of course you can alternatively use GetAxis (e.g. for basis.z basis.GetAxis(2) ) but this must be corrected. I tested this only in Mono. basis_problems.zip Be careful with this cause if you do not rotate the objects to another angle from the initial one you will not see the problem. The objects in the example are rotated. |
Bound scripting langs should not imitate the C++ API, which is made the current way for faster vector-matrix multiplication. GDScript already exposes the vectors as transposed. |
Mono part is fixed by #16326, only GDNative left. |
As I explained in #16937
you should be expecting rows if M[i][j] should refer to M_{ij} on paper. The first index is row, the second is column. Basis implementation got it right. It is Transform2D which is transposed and awkward, which has M[j][i] corresponding to M_{ij} on paper. get_axis returns a column, not a row (because, to get the local x-axis of the transformation, you do M.(1,0,0) for example which gives you the first column, not row) so you shouldn't expect to be able to access it like M[i], just use the accessor function. |
They are regarding to how GLSL and OpenGL uses them, which is also how
most people expect them to be.
…On Thu, Mar 22, 2018 at 8:35 AM, tagcup ***@***.***> wrote:
Columns/rows *are* swapped in Transform2D though
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14553 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF-Z29tj8xYsw4BC5n-d3wVc9OhsFNQSks5tg8S3gaJpZM4Q9VmP>
.
|
No they aren't. The old version was like that, if you remember, and led to many bugs, and I fixed them |
Oh wait, you mean the OpenGL itself. Sorry. Yeah, could be. |
@reduz you're totally right about it, OpenGL is for whatever reason column major: https://www.opengl.org/archives/resources/faq/technical/transformations.htm I see where you're coming from now. Actually you did mention this back then I totally forgot. But they also admit this choice in OpenGL caused endless confusion among programmers, so I think it is best to avoid and stick with the current sensible row major implementation |
The confusion comes from DirectX being row major. I prefer we stick to
column major simply for the fact we already are adopting all other OpenGL
conventions, such as coordinate system, clip space range, shading language,
etc.
…On Thu, Mar 22, 2018 at 9:00 AM, tagcup ***@***.***> wrote:
@reduz <https://github.com/reduz> you're totally right about it, OpenGL
is for whatever reason column major: https://www.opengl.org/
archives/resources/faq/technical/transformations.htm
I see where you're coming from now. Actually you did mention this back
then I totally forgot. But they also admit this choice in OpenGL caused
endless confusion among programmers, so I think it is best to avoid and
stick with the current sensible row major implementation
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14553 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF-Z2xcjH9r1naxPVuO5xEabzY0wepg3ks5tg8q3gaJpZM4Q9VmP>
.
|
I'm guessing their reasoning for this awkward choice is because it made get_axis simpler, which they probably use a lot internally, and they're trying to rationalize that by saying if you transposed all the maths in the world it'll work OK so it's the same, just a matter of convention, you just need to flip the entire math literature upside down! ("Column-major versus row-major is purely a notational convention. Note that post-multiplying with column-major matrices produces the same result as pre-multiplying with row-major matrices.") |
When they made this choice, vector instruction sets were not common, so I
can understand it. DirectX swapped it because it could take better
advantage of SSE. On the hardware level (GPUs) it doesn't really matter.
In any case, will prefer to stay true to the OpenGL convetion, so bound
languages will be column major.
…On Thu, Mar 22, 2018 at 9:09 AM, tagcup ***@***.***> wrote:
I'm guessing their reasoning for this awkward choice is because it made
get_axis simpler, which they probably use a lot internally, and they're
trying to rationalize that by saying if you transposed all the maths in the
world it'll work OK so it's the same, just a matter of convention, you just
need to flip the entire math literature upside down! ("Column-major versus
row-major is purely a notational convention. Note that post-multiplying
with column-major matrices produces the same result as pre-multiplying with
row-major matrices.")
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14553 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF-Z28Re0YLZ03Msv-cc32D-Ap5iuNpCks5tg8yigaJpZM4Q9VmP>
.
|
Actually I found that OpenGL do both column major and row major. There's apparently a transpose flag just for that https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glUniform.xhtml |
So I don't see any single argument for column major. Not to mention bound languages don't interact with OpenGL |
Yes, this is OpenGL4 though, which we don't use and pretty much no one
uses.
Again, this will not change.
…On Thu, Mar 22, 2018 at 9:14 AM, tagcup ***@***.***> wrote:
So I don't see any single argument for column major.
Not to mention bound languages don't interact with OpenGL
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#14553 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF-Z2-7HivBw3KO6Alh3oxT0g2fYE67vks5tg83ugaJpZM4Q9VmP>
.
|
No it's not OpenGL4. and in fact, you're using that function already in Godot and explicitly settings the transpose flag to false here. Also the fact that you don't use something doesn't mean the entire world isn't using it |
Whatever suit yourself then |
This should be fully fixed (= behaves like GDScript) in Mono after #23833, but I don't know the status for GDNative. |
This was incorrectly marked as fixed for C#. #26203 fixes it. |
Thanks @neikeq. @karroffel What was the conclusion in the end? This needs to be fixed in C++ bindings and not GDNative? |
@akien-mga exactly, the GDNative C API doesn't actually expose the indexing, so it's only a binding issue |
Alright, moved to godotengine/godot-cpp#241. |
Per godotengine/godot#14553: Godot stores Basis in row-major layout for more change for efficiently taking advantage of SIMD instructions, but in scripts Basis looks like and is accessible in a column-major format. This change modifies the C++ binding so that from the script's perspective Basis does look like if it was column-major while retaining a row-major in-memory representation. This is achieved using a set of helper template classes which allow accessing individual columns whose components are non-continues in memory as if it was a Vector3 type. This ensures script interface compatibility without needing to transpose the Basis every time it is passed over the script-engine boundary. Also made most of the Vector3 class interfaces inlined in the process for increased performance. While unrelated (but didn't want to file a separate PR for it), this change adds the necessary flags to have debug symbol information under MSVC. Fixes godotengine#241.
Per godotengine/godot#14553: Godot stores Basis in row-major layout for more change for efficiently taking advantage of SIMD instructions, but in scripts Basis looks like and is accessible in a column-major format. This change modifies the C++ binding so that from the script's perspective Basis does look like if it was column-major while retaining a row-major in-memory representation. This is achieved using a set of helper template classes which allow accessing individual columns whose components are non-continues in memory as if it was a Vector3 type. This ensures script interface compatibility without needing to transpose the Basis every time it is passed over the script-engine boundary. Also made most of the Vector3 class interfaces inlined in the process for increased performance. While unrelated (but didn't want to file a separate PR for it), this change adds the necessary flags to have debug symbol information under MSVC. Fixes godotengine#241.
Per godotengine/godot#14553: Godot stores Basis in row-major layout for more change for efficiently taking advantage of SIMD instructions, but in scripts Basis looks like and is accessible in a column-major format. This change modifies the C++ binding so that from the script's perspective Basis does look like if it was column-major while retaining a row-major in-memory representation. This is achieved using a set of helper template classes which allow accessing individual columns whose components are non-continues in memory as if it was a Vector3 type. This ensures script interface compatibility without needing to transpose the Basis every time it is passed over the script-engine boundary. Also made most of the Vector2 and Vector3 class interfaces inlined in the process for increased performance. While unrelated (but didn't want to file a separate PR for it), this change adds the necessary flags to have debug symbol information under MSVC. Fixes godotengine#241.
Per godotengine/godot#14553: Godot stores Basis in row-major layout for more change for efficiently taking advantage of SIMD instructions, but in scripts Basis looks like and is accessible in a column-major format. This change modifies the C++ binding so that from the script's perspective Basis does look like if it was column-major while retaining a row-major in-memory representation. This is achieved using a set of helper template classes which allow accessing individual columns whose components are non-continues in memory as if it was a Vector3 type. This ensures script interface compatibility without needing to transpose the Basis every time it is passed over the script-engine boundary. Also made most of the Vector2 and Vector3 class interfaces inlined in the process for increased performance. While unrelated (but didn't want to file a separate PR for it), this change adds the necessary flags to have debug symbol information under MSVC. Fixes godotengine#241.
Operating system or device, Godot version, GPU Model and driver (if graphics related):
Manjaro 64bit, Godot Beta1
Issue description:
Seems that the values from GetGlobalTransform to be wrong. (Not sure thought)
Steps to reproduce:
Run the example project. It uses the Mono script for the player.
Clasic fps controls WASD and mouse to move.
Switch the script of the Player to Player.gd to see how it was used to work in Godot.
Link to minimal example project:
GlobalTransform.zip
P.S. I am not sure that the problem is in GetGlobalTransform but seem to me that only this method can ruin the movement.
The text was updated successfully, but these errors were encountered: