#Rotate Camera over a point
17 messages · Page 1 of 1 (latest)
I need something more correct for the vertical rotation. Rotating around Y happens to work because the orientation is more consistent, but it all falls apart the moment I rotate raound X, which I know is not what I want
Didn't read the code, but you could use nested entities
Put the camera entity into another entity. Offset the position of the camera, rotate the parent
The parent rotates in place, moving the camera around it's location point
let mut transform = q_camera.single_mut();
transform.rotate_around(Vec3::ZERO, Quat::from_rotation_y(delta.x));
transform.rotate_around(Vec3::ZERO, Quat::from_rotation_x(delta.y));
This essentially the math I'm trying but the translation is wrong. The horizontal rotation is correct but not vertical. The orientations in the screenshots are what I'm hoping to get.
However, if I rotate horizontally and then vertically, I get
What's the math for having the camera rotate around the point but relative to the look-at direction?
This is essentially why quarternions exist
Because the axis are local to the object and rotate with it, making this difficult
I'd again recommend you put the camera into an empty object, center empty object to where you want the pivot to be and rotate that with Euler angles
I think the camera is in it's own object. Could you point out how the center entity affects the math?
I'm mostly trying to learn the math here
I'm not the person to teach you the math and I'd argue the help forum is not the place to do that.
How I would practically do this with minimum math is you can spawn entities within other entities. In this case their transforms are relative to the parents
So if you spawn the camera within a SpatialBundle, you could give it an offset and the offset will be relative to the parent
So if you offset the position somewhat and rotate the parent, the child will orbit the parent at that offset, while retaining the same relative rotation. If the child was rotated to point at the parent, rotating the parent retains the rotation, so the child will always face the parent