Skip to content

Commit

Permalink
save eulerAngles instead of quaternion for node (cocos#4383)
Browse files Browse the repository at this point in the history
* save eulerAngles insteadof quat

* refine code
  • Loading branch information
2youyou2 authored and jareguo committed May 13, 2019
1 parent 75b6627 commit 1023715
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cocos2d/core/3d/polyfill-3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ cc.js.getset(proto, 'eulerAngles', function () {
return this._eulerAngles;
}
else {
return this._quat.toEuler(cc.v3());
return this._quat.toEuler(this._eulerAngles);
}
}, function (v) {
if (CC_EDITOR) {
Expand Down
17 changes: 9 additions & 8 deletions cocos2d/core/CCNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ let NodeDefines = {
_anchorPoint: cc.v2(0.5, 0.5),
_position: cc.Vec3,
_scale: cc.Vec3,
_quat: cc.Quat,
_eulerAngles: cc.Vec3,
_skewX: 0.0,
_skewY: 0.0,
_zIndex: {
Expand Down Expand Up @@ -1175,7 +1175,7 @@ let NodeDefines = {
this._cullingMask = 1;
this._childArrivalOrder = 1;

this._eulerAngles = cc.v3();
this._quat = cc.quat();
},

statics: {
Expand Down Expand Up @@ -1324,21 +1324,22 @@ let NodeDefines = {
}

// TODO: remove _rotationX & _rotationY in future version, 3.0 ?
// Update quaternion from rotation, when upgrade from 1.x to 2.0
// Update eulerAngles from rotation, when upgrade from 1.x to 2.0
// If rotation x & y is 0 in old version, then update rotation from default quaternion is ok too
let quat = this._quat;
let eulerAngles = this._eulerAngles;
if ((this._rotationX || this._rotationY) &&
(quat.x === 0 && quat.y === 0 && quat.z === 0 && quat.w === 1)) {
(eulerAngles.x === 0 && eulerAngles.y === 0 && eulerAngles.z === 0)) {
if (this._rotationX === this._rotationY) {
quat.fromEuler(quat, 0, 0, -this._rotationX);
eulerAngles.z = -this._rotationX;
}
else {
quat.fromEuler(quat, this._rotationX, this._rotationY, 0);
eulerAngles.x = this._rotationX;
eulerAngles.y = this._rotationY;
}
this._rotationX = this._rotationY = undefined;
}

this._toEuler();
this._fromEuler();

// Upgrade from 2.0.0 preview 4 & earlier versions
// TODO: Remove after final version
Expand Down

0 comments on commit 1023715

Please sign in to comment.