Reputation: 693
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?
Upvotes: 0
Views: 77
Reputation: 7994
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.
Upvotes: 1