diff --git a/cocos/3d/CCLight3D.cpp b/cocos/3d/CCLight3D.cpp index ac77b3a50e..beb6e38cd1 100644 --- a/cocos/3d/CCLight3D.cpp +++ b/cocos/3d/CCLight3D.cpp @@ -76,9 +76,9 @@ const Vec3& DirectionLight3D::getDirection() const dir.set(-mat.m[8], -mat.m[9], -mat.m[10]); return dir; } -Vec3 DirectionLight3D::getDirectionInWorld() const +const Vec3& DirectionLight3D::getDirectionInWorld() const { - Vec3 dir; + static Vec3 dir; Mat4 mat = getNodeToWorldTransform(); dir.set(-mat.m[8], -mat.m[9], -mat.m[10]); return dir; @@ -139,9 +139,9 @@ const Vec3& SpotLight3D::getDirection() const return dir; } -Vec3 SpotLight3D::getDirectionInWorld() const +const Vec3& SpotLight3D::getDirectionInWorld() const { - Vec3 dir; + static Vec3 dir; Mat4 mat = getNodeToWorldTransform(); dir.set(-mat.m[8], -mat.m[9], -mat.m[10]); return dir; diff --git a/cocos/3d/CCLight3D.h b/cocos/3d/CCLight3D.h index 717d17f2af..a964085798 100644 --- a/cocos/3d/CCLight3D.h +++ b/cocos/3d/CCLight3D.h @@ -126,7 +126,7 @@ public: /** * Returns direction in world. */ - Vec3 getDirectionInWorld() const; + const Vec3& getDirectionInWorld() const; CC_CONSTRUCTOR_ACCESS: DirectionLight3D(); @@ -196,7 +196,7 @@ public: /** * Returns direction in world. */ - Vec3 getDirectionInWorld() const; + const Vec3& getDirectionInWorld() const; /** * Sets the range of point or spot light.