You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
-fix vector rotation, fixes #1705
This commit is contained in:
@@ -27,27 +27,12 @@
|
|||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
#include "vector3.h"
|
#include "vector3.h"
|
||||||
|
#include "matrix3.h"
|
||||||
|
|
||||||
|
|
||||||
void Vector3::rotate(const Vector3& p_axis,float p_phi) {
|
void Vector3::rotate(const Vector3& p_axis,float p_phi) {
|
||||||
|
|
||||||
Vector3 axis1 = cross(p_axis);
|
*this=Matrix3(p_axis,p_phi).xform(*this);
|
||||||
float l = axis1.length();
|
|
||||||
if (l==0)
|
|
||||||
return;
|
|
||||||
axis1/=l;
|
|
||||||
Vector3 axis2 = axis1.cross(p_axis).normalized();
|
|
||||||
|
|
||||||
float _x = axis1.dot(*this);
|
|
||||||
float _y = axis2.dot(*this);
|
|
||||||
|
|
||||||
float ang = Math::atan2(_x,_y);
|
|
||||||
|
|
||||||
ang+=p_phi;
|
|
||||||
|
|
||||||
*this=((axis1 * Math::cos(ang)) + (axis2 * Math::sin(ang))) * length();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 Vector3::rotated(const Vector3& p_axis,float p_phi) const {
|
Vector3 Vector3::rotated(const Vector3& p_axis,float p_phi) const {
|
||||||
|
|||||||
Reference in New Issue
Block a user