Quaternion from two points

Moderators: cry-nic, Community Volunteers

Quaternion from two points

#1
Hi,

Does anyone know how we can get a Quaternion from just two points (origin n destination) in world space?
I'm trying to rotate an object so that it's forward direction is facing a point (destination point).

What's the best way to do this?

Thanks!

Re: Quaternion from two points

#2
You can use the Quat::CreateRotationVDir() function.

Here is an example:

Code: Select all

Vec3 direction = (destination - origin).GetNormalized();

Quat finalRotation = Quat::CreateRotationVDir(direction);

//Depends on what you need but you could also use Quat::CreateNlerp() or similar to lerp the rotation
finalRotation = Quat::CreateNlerp(m_pEntity->GetWorldRotation(), finalRotation, 0.25f);

m_pEntity->SetPosRotScale(m_pEntity->GetWorldPos(), finalRotation, Vec3(1.f));

Re: Quaternion from two points

#3
You can use the Quat::CreateRotationVDir() function.

Here is an example:

Code: Select all

Vec3 direction = (destination - origin).GetNormalized();

Quat finalRotation = Quat::CreateRotationVDir(direction);

//Depends on what you need but you could also use Quat::CreateNlerp() or similar to lerp the rotation
finalRotation = Quat::CreateNlerp(m_pEntity->GetWorldRotation(), finalRotation, 0.25f);

m_pEntity->SetPosRotScale(m_pEntity->GetWorldPos(), finalRotation, Vec3(1.f));
Thanks! Will try this out.

Who is online

Users browsing this forum: mknmknmknjk and 1 guest