From 730700cf101a6ac9f80aa026957c081311dcc0c2 Mon Sep 17 00:00:00 2001 From: DelinWorks Date: Wed, 15 Jun 2022 16:10:47 +0300 Subject: [PATCH] Fix rotation override and node base class calls. Make sure Node class calls it's base functions and NOT the ones overridden when changing position, and make sure the rotation set for the camera isn't altered when calling applyCustomProperties(). --- core/2d/CCCamera.cpp | 13 +++++-------- core/2d/CCNode.cpp | 10 +++++----- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/core/2d/CCCamera.cpp b/core/2d/CCCamera.cpp index f3658b4ab3..b440e89f2a 100644 --- a/core/2d/CCCamera.cpp +++ b/core/2d/CCCamera.cpp @@ -207,7 +207,6 @@ bool Camera::initDefault() { initOrthographic(size.width, size.height, -1024, 1024); setPosition3D(Vec3(size.width / 2, size.height / 2, 0.f)); - _originalPosition = {size.width / 2, size.height / 2}; setRotation3D(Vec3(0.f, 0.f, 0.f)); break; } @@ -447,7 +446,6 @@ void Camera::applyCustomProperties() initOrthographic(size.width, size.height, _nearPlane, _farPlane); setPosition3D(Vec3(size.width / 2, size.height / 2, 0.f)); _originalPosition = {size.width / 2, size.height / 2}; - setRotation3D(Vec3(0.f, 0.f, 0.f)); break; } case Director::Projection::_3D: @@ -458,7 +456,6 @@ void Camera::applyCustomProperties() up(0.0f, 1.0f, 0.0f); _eyeZdistance = eye.z; setPosition3D(eye); - lookAt(center, up); break; } } @@ -512,7 +509,7 @@ const Vec2& Camera::getPosition() const void Camera::setPosition(const Vec2& position) { - _originalPosition = position; + _originalPosition = {position.x, position.y}; auto& pos = getPositionCenter(position, _projectionType, getZoom(), getRotation()); Node::setPosition(pos.x, pos.y); } @@ -525,16 +522,16 @@ void Camera::getPosition(float* x, float* y) const void Camera::setPosition(float x, float y) { - _originalPosition = getPositionCenter({x, y}, _projectionType, getZoom(), getRotation()); - Node::setPosition(_originalPosition.x, _originalPosition.y); _originalPosition = {x, y}; + auto& pos = getPositionCenter({x, y}, _projectionType, getZoom(), getRotation()); + Node::setPosition(pos.x, pos.y); } void Camera::setPosition3D(const Vec3& position) { - _originalPosition = getPositionCenter({position.x, position.y}, _projectionType, getZoom(), getRotation()); - Node::setPosition3D({_originalPosition.x, _originalPosition.y, position.z}); _originalPosition = {position.x, position.y}; + auto& pos = getPositionCenter({position.x, position.y}, _projectionType, getZoom(), getRotation()); + Node::setPosition3D({pos.x, pos.y, position.z}); } Vec3 Camera::getPosition3D() const diff --git a/core/2d/CCNode.cpp b/core/2d/CCNode.cpp index 0626859402..4ed9ee2c72 100644 --- a/core/2d/CCNode.cpp +++ b/core/2d/CCNode.cpp @@ -502,7 +502,7 @@ const Vec2& Node::getPosition() const /// position setter void Node::setPosition(const Vec2& position) { - setPosition(position.x, position.y); + Node::setPosition(position.x, position.y); } void Node::getPosition(float* x, float* y) const @@ -525,8 +525,8 @@ void Node::setPosition(float x, float y) void Node::setPosition3D(const Vec3& position) { - setPositionZ(position.z); - setPosition(position.x, position.y); + Node::setPositionZ(position.z); + Node::setPosition(position.x, position.y); } Vec3 Node::getPosition3D() const @@ -541,7 +541,7 @@ float Node::getPositionX() const void Node::setPositionX(float x) { - setPosition(x, _position.y); + Node::setPosition(x, _position.y); } float Node::getPositionY() const @@ -551,7 +551,7 @@ float Node::getPositionY() const void Node::setPositionY(float y) { - setPosition(_position.x, y); + Node::setPosition(_position.x, y); } float Node::getPositionZ() const