'Check if rotation of model has changed?
How would you check if the rotation of a model has changed? tried:
var oldRotate = this._target.quaternion;
console.log('works returns vector3 quaternion: ', oldRotate);
var newRotate = oldRotate;
if (oldRotate != newRotate) {
console.log('this isnt triggering');
}
this doesn't work and yes it's in a 'loop'
also tried:
var oldRotation = new THREE.Vector3();
oldRotation.copy(controlObject.quaternion);
controlObject.position.copy(pos);
this._position.copy(pos);
this._parent.SetPosition(this._position);
this._parent.SetQuaternion(this._target.quaternion);
var newRotation = new THREE.Vector3();
newRotation.copy(controlObject.quaternion);
console.log(oldRotation.equals(newRotation));
any ideas?
Solution 1:[1]
You can't compare objects for equality using the ==
/!=
operator. This will merely compare the references to the objects, not their values. You will need to compare using the .equals
method.
Also, in your example, you're assigning oldR
to newRotate
directly. I'm not sure if you've not included some intervening code. Either way, you should also be using .clone
otherwise the !=
will never happen.
See: https://threejs.org/docs/#api/en/math/Quaternion for information about the clone
and equals
methods.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |