ccGLMatrixd ccGLUtils::GenerateGLRotationMatrixFromVectors(const CCVector3d& sourceVec, const CCVector3d& destVec) { //we compute scalar prod between the two vectors double ps = sourceVec.dot(destVec); //we bound result (in case vecors are not exactly unit) if (ps > 1.0) ps = 1.0; else if (ps < -1.0) ps = -1.0; //we deduce angle from scalar prod double angle_deg = acos(ps) * CC_RAD_TO_DEG; //we compute rotation axis with scalar prod CCVector3d axis = sourceVec.cross(destVec); //we eventually compute the rotation matrix with axis and angle return GenerateGLRotationMatrixFromAxisAndAngle(axis, angle_deg); }
DcGp::DcGpMatrix DcGp::DcGpTools::GenerateGLRotationMatrixFromVectors(const float* sourceVec, const float* destVec) { //we compute scalar prod between the two vectors float ps = DCVector3D::VDot(sourceVec,destVec); //we bound result (in case vecors are not exactly unit) if (ps > 1.0f) ps = 1.0f; else if (ps < -1.0f) ps = -1.0f; //we deduce angle from scalar prod float angle_deg = acos(ps) * DC_RAD_TO_DEG; //we compute rotation axis with scalar prod float axis[3]; DCVector3D::VCross(sourceVec, destVec, axis); //we eventually compute the rotation matrix with axis and angle return GenerateGLRotationMatrixFromAxisAndAngle(axis, angle_deg); }