// matrix transform from destination to source Matrix3x3 matInverseTransformCanonical(double translateX, double translateY, double scaleX, double scaleY, double skewX, double skewY, bool skewOrderYX, double rads, double centerX, double centerY) { ///1) We translate to the center of the transform. ///2) We scale ///3) We apply skewX and skewY in the right order ///4) We rotate ///5) We apply the global translation ///5) We translate back to the origin // since this is the inverse, oerations are in reverse order return matMul( matMul( matMul( matMul( matMul( matTranslation(centerX, centerY), matScale(1. / scaleX, 1. / scaleY) ), matSkewXY(-skewX, -skewY, !skewOrderYX) ), matRotation(rads) ), matTranslation(-translateX, -translateY) ), matTranslation(-centerX, -centerY) ); }
// matrix transform from source to destination Matrix3x3 matTransformCanonical(double translateX, double translateY, double scaleX, double scaleY, double skewX, double skewY, bool skewOrderYX, double rads, double centerX, double centerY) { ///1) We translate to the center of the transform. ///2) We scale ///3) We apply skewX and skewY in the right order ///4) We rotate ///5) We apply the global translation ///5) We translate back to the origin return matMul( matMul( matMul( matMul( matMul( matTranslation(centerX, centerY), matTranslation(translateX, translateY) ), matRotation(-rads) ), matSkewXY(skewX, skewY, skewOrderYX) ), matScale(scaleX, scaleY) ), matTranslation(-centerX, -centerY) ); }
static Matrix3x3 matRotationAroundPoint(double rads, double px, double py) { return matMul( matTranslation(px, py), matMul( matRotation(rads), matTranslation(-px, -py) ) ); }
void Camera::rotateY(float angle) { if (angle == 0.0f) return; mat4 matRotation(1.0f); matRotation = glm::rotate(matRotation, angle, up); vec4 dir = matRotation * vec4(lookAt-eye,1); lookAt = eye + vec3(dir.x, dir.y, dir.z); recalc(); }
//ds source: https://en.wikipedia.org/wiki/Rotation_matrix https://en.wikipedia.org/wiki/Rotation_formalisms_in_three_dimensions const Eigen::Matrix3d CMiniVisionToolbox::fromRotationAngles( const Eigen::Vector3d& p_vecRotationAnglesRadians ) { //ds rotation matrices /*Eigen::Matrix3d matRotationX( Eigen::Matrix3d::Identity( ) ); Eigen::Matrix3d matRotationY( Eigen::Matrix3d::Identity( ) ); Eigen::Matrix3d matRotationZ( Eigen::Matrix3d::Identity( ) );*/ //ds set X matrix const double dCosPhi = std::cos( p_vecRotationAnglesRadians.x( ) ); const double dSinPhi = std::sin( p_vecRotationAnglesRadians.x( ) ); /*matRotationX(1,1) = dCosineX; matRotationX(1,2) = -dSineX; matRotationX(2,1) = dSineX; matRotationX(2,2) = dCosineX;*/ //ds set Y matrix const double dCosThe = std::cos( p_vecRotationAnglesRadians.y( ) ); const double dSinThe = std::sin( p_vecRotationAnglesRadians.y( ) ); /*matRotationY(0,0) = dCosineY; matRotationY(0,2) = dSineY; matRotationY(2,0) = -dSineY; matRotationY(2,2) = dCosineY;*/ //ds set Z matrix const double dCosPsi = std::cos( p_vecRotationAnglesRadians.z( ) ); const double dSinPsi = std::sin( p_vecRotationAnglesRadians.z( ) ); /*matRotationZ(0,0) = dCosineZ; matRotationZ(0,1) = -dSineZ; matRotationZ(1,0) = dSineZ; matRotationZ(1,1) = dCosineZ;*/ //ds one-step computation Eigen::Matrix3d matRotation( Eigen::Matrix3d::Identity( ) ); matRotation << dCosThe*dCosPsi, dCosPhi*dSinPsi+dSinPhi*dSinThe*dCosPsi, dSinPhi*dSinPsi-dCosPhi*dSinThe*dCosPsi, -dCosThe*dSinPsi, dCosPhi*dCosPsi-dSinPhi*dSinThe*dSinPsi, dSinPhi*dCosPsi+dCosPhi*dSinThe*dSinPsi, dSinThe, -dSinPhi*dCosThe, dCosPhi*dCosThe; //return matRotationZ*matRotationY*matRotationX; return matRotation; }