Skip to content
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

Document why Basis axis vectors are exposed transposed #26432

Open
TyTYct opened this issue Mar 1, 2019 · 13 comments
Open

Document why Basis axis vectors are exposed transposed #26432

TyTYct opened this issue Mar 1, 2019 · 13 comments

Comments

@TyTYct
Copy link

TyTYct commented Mar 1, 2019

Godot version:

3.1 beta 9

OS/device including version:

Windows 10

Issue description:

print spatial.transform.basis is wrong

image

image

I tested some case and this happen when spartial angle between 0 and 180 degree. it is ok at angle 180 degree or 0 degree

image

Steps to reproduce:

Minimal reproduction project:

test transform.zip

@TyTYct TyTYct changed the title print basis print spatial.transform.basis is wrong Mar 1, 2019
@StraToN StraToN added this to the 3.1 milestone Mar 1, 2019
@PapaFl
Copy link
Contributor

PapaFl commented Mar 1, 2019

Basis is not transposed when converted to String. (or the other way around maybe?)
This results in different output. Not sure if this is an issue/bug.

@akien-mga
Copy link
Member

It's not a bug a priori, Basis exposes its axis vectors transposed indeed. This should be better documented.

@akien-mga akien-mga changed the title print spatial.transform.basis is wrong Document why Basis axis vectors are exposed transposed Mar 1, 2019
@Zylann
Copy link
Contributor

Zylann commented Mar 1, 2019

Wait, so with this into account, is -z forward, x right and y up? If not, that's yet another piece of info coders have to know to get them, and another reason to support shortcuts #26371

@Calinou
Copy link
Member

Calinou commented Mar 1, 2019

Wait, so with this into account, is -z forward, x right and y up?

According to Vector3.FORWARD, Vector3.RIGHT and Vector3.UP, yes 😃

@Zylann
Copy link
Contributor

Zylann commented Mar 1, 2019

@Calinou those are constants, I mean taking any basis, rotated randomly, are x, y and z vectors still going to represent the same axes we see in the editor?
Edit: they do, ignore me :p

@PapaFl
Copy link
Contributor

PapaFl commented Mar 1, 2019

Just to clear any confusion:
Transform.basis basically is a 3x3 matrix used for rotation (and scale). Multiplying Basis * Vector3 rotates the Vector3, So multiplying the forward axis vector with a Transform.basis results in a vector pointing "forward" for that transformation.
If we look at how Matrix * Vector multiplication works:

[a  b  c]   [ j ]   [j*a + k*b + l*c]
[d  e  f] * [ k ] = [j*d + k*e + l*f]
[g  h  i]   [ l ]   [j*g + k*h + l*i]

we can see that if the Vector is Vector3(0, 0, -1) This basically results in:

[ -c ]
[ -f ]
[ -i ]

which is equal to -Basis.z exactly because Basis is exposed transposed.

@TyTYct
Copy link
Author

TyTYct commented Mar 2, 2019

I confuse why transform.basis is different from transform.basis.x, transform.basis.y, transform.basis.z.
I think that transform.basis.x is a part of transform.basis.

@PapaFl
Copy link
Contributor

PapaFl commented Mar 2, 2019

You're right that Basis.X (and Y, Z) represent a part of Basis. As i mentioned above, Basis is a 3x3 Matrix.
Basis.X basically gives you one column of the matrix:

        [a  b  c] 
Basis = [d  e  f], Basis.X = [a, d, g]
        [g  h  i]

However print(Basis) prints the Basis row by row.
I've tried to make this clear in this image:
trp

@TyTYct
Copy link
Author

TyTYct commented Mar 2, 2019

thanks, @PapaFl . I understood that. It is not a bug.

@TyTYct TyTYct closed this as completed Mar 2, 2019
@akien-mga
Copy link
Member

I still think it needs better documentation though.

@akien-mga akien-mga reopened this Mar 2, 2019
@Calinou
Copy link
Member

Calinou commented Apr 17, 2020

Should we leave the "full" Basis print handler as-is? I haven't followed the issue closely.

@Chlorobyte-but-real
Copy link

For whoever got notified for that message, I am dumb. GLSL works with columns in the matrix as well, but accessing the individual elements is done by supplying the column then the row first, and I got confused (I do my coordinates in x, y usually). There is no inconsistency between GDScript and C#.

@Mickeon
Copy link
Contributor

Mickeon commented Jan 13, 2024

Just for a bit of clarification and revival of this issue.

In Godot 4 the way both Transform3D and Basis are converted to String (and by extension printed out) has changed:

var my_basis = Basis(Vector3(1, 2, 3), Vector3(4, 5, 6), Vector3(7, 8, 9))
print(my_basis)  # [X: (1, 2, 3), Y: (4, 5, 6), Z: (7, 8, 9)]
	
var transform = Transform3D(my_basis, Vector3.ZERO)
print(transform) # [X: (1, 2, 3), Y: (4, 5, 6), Z: (7, 8, 9), O: (0, 0, 0)]

This should mean that the original issue no longer exists. What could be documented now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants