TLDR:
I'm asking for the direction of the up vector of an entity that can rotate in JavaScript that has a x
, y
, and rotation
(in radians).
I'm using a JavaScript game library. It doesn't have a transform.up
like that of Unity. I've been looking around and I ended up with a source code reference of Unity stating the following:
public Quaternion rotation;
public Vector3 up { get { return rotation * Vector3.up; } }
And looking at the multiplication between the Quaternion and Vector3.up:
// Rotates the point /point/ with /rotation/.
public static Vector3 operator*(Quaternion rotation, Vector3 point)
{
float x = rotation.x * 2F;
float y = rotation.y * 2F;
float z = rotation.z * 2F;
float xx = rotation.x * x;
float yy = rotation.y * y;
float zz = rotation.z * z;
float xy = rotation.x * y;
float xz = rotation.x * z;
float yz = rotation.y * z;
float wx = rotation.w * x;
float wy = rotation.w * y;
float wz = rotation.w * z;
Vector3 res;
res.x = (1F - (yy + zz)) * point.x + (xy - wz) * point.y + (xz + wy) * point.z;
res.y = (xy + wz) * point.x + (1F - (xx + zz)) * point.y + (yz - wx) * point.z;
res.z = (xz - wy) * point.x + (yz + wx) * point.y + (1F - (xx + yy)) * point.z;
return res;
}
More importantly, the quaternion x, y, z, & w are not in radians and are values between 0 and 1.
But my issue starts with that I have an object that has a x
, y
, and rotation
(in radians). What math and code will I be needing in order to determine that this direction is indeed the up vector of this object? See photo below:
Pls note that I am not asking "how to rotate around a pivot point"