Hello everyone!
I am experimenting with camera panning in conjunction with a parent TransformNode
.
When the parent transform rotates, I would expect the camera panning to happen in the local space of the parent TransformNode
, but this is not the case:
I tried defining the panning axis by hand using the up vector of the parent transform, but it looks wrong so I guess I am not understanding something.
Any ideas on what could be wrong here?
Iām guessing thatās where the problem comes from, as far as I know target is local space, but thereās a world-space vector added here
}
if (!this._targetHost) {
if (this.panningDistanceLimit) {
this._transformedDirection.addInPlace(this._target);
const distanceSquared = Vector3.DistanceSquared(this._transformedDirection, this.panningOriginTarget);
if (distanceSquared <= this.panningDistanceLimit * this.panningDistanceLimit) {
this._target.copyFrom(this._transformedDirection);
}
} else {
this._target.addInPlace(this._transformedDirection);
}
}
this.inertialPanningX *= this.panningInertia;
this.inertialPanningY *= this.panningInertia;
if (Math.abs(this.inertialPanningX) < this.speed * Epsilon) {
this.inertialPanningX = 0;
}
if (Math.abs(this.inertialPanningY) < this.speed * Epsilon) {
Changing the source code like this fixes the problem
if (this.parent) {
const m = TmpVectors.Matrix[0];
Vector3.TransformCoordinatesToRef(this._transformedDirection, this.parent.getWorldMatrix().getRotationMatrix().invertToRef(m), this._transformedDirection);
}
this._target.addInPlace(this._transformedDirection);
2 Likes
Nice catch thank you!
I can make it a bit faster by transposing the rotation matrix instead of inverting it. I will make a pull request at once.
Associated PR:
BabylonJS:master
ā BarthPaleologue:camera-panning-parent
opened 12:06PM - 14 Feb 24 UTC
## Current behavior
The camera pans in world space when a parent is assigned.ā¦
## Expected behavior
The camera must pan in the local space of its parent.
see https://forum.babylonjs.com/t/camera-panning-issue-when-using-parenting/48014
This pull request will make this PG work: https://www.babylonjs-playground.com/#C2ZGCJ#23
Once it is merged, this should work:
1 Like
Awkward, I actually sent a pull request right after I replied to you.
BabylonJS:master
ā 2315137135:master
opened 05:57AM - 14 Feb 24 UTC
fix https://forum.babylonjs.com/t/camera-panning-issue-when-using-parenting/4801⦠4
3 Likes
But youāre right, I didnāt think about optimizing performance with transposed matrices.
bruuuh Too fast for me, sorry I didnāt check before making my own!
1 Like