world.setQuaternion seems to set the local rotation.
To reproduce:
- Create 2 objects.
- Create a parent for one of the objects and set a rotation on the parent
- Use world.setQuaternion to set the same quaternion on both objects
Observe that their rotations are different.
Maybe this is intended, but it seems like a bug.
Is there some way to set the rotation in world space? I’m trying to match the rotation of 2 objects, but so far I’ve been unable to do so.
Transforms in general seem unnecessarily confusing/messy. Why do we have functions in world, and in world.transform? Why can’t I get the rotation of an object? Why does setQuaternion not accept a quaternion, instead requiring the individual x,y,z,w values?
Hi Jens,
Apologies for the confusion.
The Position
/Scale
/Quaternion
components represent the local transform relative to the parent. They expose the same get/set/reset/etc API as all other components.
world.setQuaternion
is a convenience method for Quaternion.set(world, ...)
(not very useful at this point admittedly).
world.transform
builds on top of the APIs exposed directly by world
, handling the more complex logic, but we may simplify this in a major update when we get the opportunity.
Our initial set of functions implemented in world.transform
were based on what we had specific use cases already in mind for, but sounds like a world.transform.get/setWorldQuaternion
would be a welcome addition.
In the meantime, world.transform.get/setWorldTransform
are already available which enable any sort of modifications necessary to the world transform, like:
// Reusing objects to avoid runtime allocations (optional)
const TEMP_MATRIX = mat4.i()
const TEMP_TRS = {
t: vec3.zero(),
r: quat.zero(),
s: vec3.zero(),
}
const setWorldQuaternion = (world: World, eid: Eid, quaternion: Quat) => {
world.transform.getWorldTransform(eid, TEMP_MATRIX)
TEMP_MATRIX.decomposeTrs(TEMP_TRS)
TEMP_MATRIX.makeTrs(TEMP_TRS.t, quaternion, TEMP_TRS.s)
world.transform.setWorldTransform(eid, TEMP_MATRIX)
}
1 Like