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

Documents the "arc-based" Quaternion constructor #74838

Merged
merged 1 commit into from
Mar 15, 2023

Conversation

dsnopek
Copy link
Contributor

@dsnopek dsnopek commented Mar 12, 2023

This undocumented Quaternion constructor turned out to be exactly what I needed for a VR prototype I'm working on. Documenting it so it's easier for others to find! :-)

@dsnopek dsnopek requested a review from a team as a code owner March 12, 2023 20:55
@YeldhamDev YeldhamDev added this to the 4.x milestone Mar 13, 2023
Copy link
Member

@fire fire left a comment

Choose a reason for hiding this comment

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

This documents the api.

Copy link
Member

@fire fire left a comment

Choose a reason for hiding this comment

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

This works on non unit sphere vectors?

@dsnopek
Copy link
Contributor Author

dsnopek commented Mar 13, 2023

This works on non unit sphere vectors?

My understanding is "no", that you need to use points on the unit sphere, however, I'm not the greatest at math. :-)

@fire
Copy link
Member

fire commented Mar 13, 2023

I remember this working on points not on the surface of the unit sphere but still using the unit sphere model. Like non-normalized. Might have been my own version of it.

@dsnopek
Copy link
Contributor Author

dsnopek commented Mar 13, 2023

I did a quick test:

func _ready():
	# On the unit sphere.
	var quat1 = Quaternion(Vector3.FORWARD, Vector3.RIGHT)
	print ("Quat1 (unit): ", quat1)
	print ("Quat1 - axis: ", quat1.get_axis())
	print ("Quat1 - angle: ", quat1.get_angle())
	print ("Quat1 - is normalized: ", quat1.is_normalized())
	print ("Quat1 - use in rotation: ", quat1 * Vector3.FORWARD)

	# On a sphere with a radius of 50.
	var quat2 = Quaternion(Vector3.FORWARD * 50.0, Vector3.RIGHT * 50.0)
	print ("Quat2 (50.0): ", quat2)
	print ("Quat2 - axis: ", quat2.get_axis())
	print ("Quat2 - angle: ", quat2.get_angle())
	print ("Quat2 - is normalized: ", quat2.is_normalized())
	print ("Quat2 - use in rotation: ", quat2 * (Vector3.FORWARD * 50.0))

... which gives this output:


Quat1 (unit): (0, -0.707107, 0, 0.707107)
Quat1 - axis: (0, -1, 0)
Quat1 - angle: 1.57079637050629
Quat1 - is normalized: true
Quat1 - use in rotation: (1, 0, -0)
Quat2 (50.0): (0, -1767.767, 0, 0.707107)
Quat2 - axis: (0, -2500, 0)
Quat2 - angle: 1.57079637050629
Quat2 - is normalized: false
Quat2 - use in rotation: (0, 0, -50)

On a sphere with a radius of 50, you end up with a non-normalized quaternion that doesn't give right result when used in a rotation.

So, it looks like it does need to be on the unit sphere. However, if you do have points on a non unit sphere, then you just need to normalize both vectors before passing them to the Quaternion() constructor.

@YuriSizov YuriSizov modified the milestones: 4.x, 4.1 Mar 15, 2023
@YuriSizov YuriSizov merged commit d67c1a5 into godotengine:master Mar 15, 2023
@YuriSizov
Copy link
Contributor

Thanks!

@YuriSizov
Copy link
Contributor

Cherry-picked for 4.0.1.

@dsnopek dsnopek deleted the quaternion-constructor-3 branch July 22, 2024 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants