mirror of https://github.com/axmolengine/axmol.git
fix wrong look at
This commit is contained in:
parent
e87e0290fd
commit
642a601502
|
@ -130,12 +130,15 @@ void Camera::lookAt(const Vec3& lookAtPos, const Vec3& up)
|
|||
rotation.m[9] = zaxis.y;
|
||||
rotation.m[10] = zaxis.z;
|
||||
rotation.m[11] = 0;
|
||||
|
||||
Quaternion quaternion;
|
||||
Quaternion::createFromRotationMatrix(rotation,&quaternion);
|
||||
float fRoll = atan2(2 * (quaternion.w * quaternion.z + quaternion.x * quaternion.y) , 1 - 2 * (quaternion.z * quaternion.z + quaternion.x * quaternion.x));
|
||||
float fPitch = asin(clampf(2 * (quaternion.w * quaternion.x - quaternion.y * quaternion.z) , -1.0f , 1.0f));
|
||||
float fYaw = atan2(2 * (quaternion.w * quaternion.y + quaternion.z * quaternion.x) , 1 - 2 * (quaternion.x * quaternion.x + quaternion.y * quaternion.y));
|
||||
setRotation3D(Vec3(CC_RADIANS_TO_DEGREES(fPitch),CC_RADIANS_TO_DEGREES(fYaw),CC_RADIANS_TO_DEGREES(fRoll)));
|
||||
|
||||
float rotx = atan2f(2 * (quaternion.w * quaternion.x + quaternion.y * quaternion.z), 1 - 2 * (quaternion.x * quaternion.x + quaternion.y * quaternion.y));
|
||||
float roty = asin(clampf(2 * (quaternion.w * quaternion.y - quaternion.z * quaternion.x) , -1.0f , 1.0f));
|
||||
float rotz = -atan2(2 * (quaternion.w * quaternion.z + quaternion.x * quaternion.y) , 1 - 2 * (quaternion.y * quaternion.y + quaternion.z * quaternion.z));
|
||||
|
||||
setRotation3D(Vec3(CC_RADIANS_TO_DEGREES(rotx),CC_RADIANS_TO_DEGREES(roty),CC_RADIANS_TO_DEGREES(rotz)));
|
||||
}
|
||||
|
||||
const Mat4& Camera::getViewProjectionMatrix() const
|
||||
|
|
Loading…
Reference in New Issue