/** * \brief Tridiagonalizes a 3x3 matrix using a single * Householder transformation and returns the result. * * Based on "Geometric Tools" by David Eberly. */ static inline void tred3(Matrix3x3 &m, Float *diag, Float *subd) { Float m00 = m(0, 0), m01 = m(0, 1), m02 = m(0, 2), m11 = m(1, 1), m12 = m(1, 2), m22 = m(2, 2); diag[0] = m00; subd[2] = 0; if (std::abs(m02) > std::numeric_limits<Float>::epsilon()) { Float length = std::sqrt(m01*m01 + m02*m02), invLength = 1 / length; m01 *= invLength; m02 *= invLength; Float q = 2*m01*m12 + m02*(m22 - m11); diag[1] = m11 + m02*q; diag[2] = m22 - m02*q; subd[0] = length; subd[1] = m12 - m01*q; m = Matrix3x3( 1, 0, 0, 0, m01, m02, 0, m02, -m01); } else { /* The matrix is already tridiagonal, return an identity transformation matrix */ diag[1] = m11; diag[2] = m22; subd[0] = m01; subd[1] = m12; m = Matrix3x3( 1, 0, 0, 0, 1, 0, 0, 0, 1); } }
Matrix3x3 Matrix3x3::rotation(const Vector3& axis, float angleRadians) { float angle = -angleRadians; return Matrix3x3( (axis.x * axis.x) * (1 - cos(angle)) + cos(angle) , axis.x * axis.y * (1 - cos(angle)) + axis.z * sin(angle), (axis.x * axis.z) * (1 - cos(angle)) - axis.y * sin(angle), (axis.x * axis.y) * (1 - cos(angle)) - axis.z * sin(angle), axis.y * axis.y * (1 - cos(angle)) + cos(angle) , (axis.y * axis.z) * (1 - cos(angle)) + axis.x * sin(angle), (axis.x * axis.z) * (1 - cos(angle)) + axis.y * sin(angle), axis.y * axis.z * (1 - cos(angle)) - axis.x * sin(angle), (axis.z * axis.z) * (1 - cos(angle)) + cos(angle)); }
Matrix3x3 Quaternion::rotationMatrix3x3() const { Vector3 col1 = Vector3(1.0f - 2.0f * (y * y + z * z), 2.0f * (x * y + w * z), 2.0f * (x * z - w * y)); Vector3 col2 = Vector3(2.0f * (x * y - w * z), 1.0f - 2.0f * (x * x + z * z), 2.0f * (y * z + w * x)); Vector3 col3 = Vector3(2.0f * (x * z + w * y), 2.0f * (y * z - w * x), 1.0f - 2.0f * (x * x + y * y)); return Matrix3x3(col1, col2, col3); }
Matrix3x3 Matrix3x3::CompMax(const Matrix3x3& m1, const Matrix3x3& m2) { return Matrix3x3(Vector3::CompMax(m1[0], m2[0]), Vector3::CompMax(m1[1], m2[1]), Vector3::CompMax(m1[2], m2[2])); }
// Return the transpose matrix inline Matrix3x3 Matrix3x3::getTranspose() const { // Return the transpose matrix return Matrix3x3(mRows[0][0], mRows[1][0], mRows[2][0], mRows[0][1], mRows[1][1], mRows[2][1], mRows[0][2], mRows[1][2], mRows[2][2]); }
Matrix3x3 Matrix3x3::CompPow(const Matrix3x3& base, const Matrix3x3& exponent) { return Matrix3x3(Vector3::CompPow(base[0], exponent[0]), Vector3::CompPow(base[1], exponent[1]), Vector3::CompPow(base[2], exponent[2])); }
Matrix3x3 Matrix3x3::operator*(const Matrix3x3& m) const { return Matrix3x3( (*this)[0][0]*m[0][0] + (*this)[1][0]*m[0][1] + (*this)[2][0]*m[0][2], (*this)[0][0]*m[1][0] + (*this)[1][0]*m[1][1] + (*this)[2][0]*m[1][2], (*this)[0][0]*m[2][0] + (*this)[1][0]*m[2][1] + (*this)[2][0]*m[2][2], (*this)[0][1]*m[0][0] + (*this)[1][1]*m[0][1] + (*this)[2][1]*m[0][2], (*this)[0][1]*m[1][0] + (*this)[1][1]*m[1][1] + (*this)[2][1]*m[1][2], (*this)[0][1]*m[2][0] + (*this)[1][1]*m[2][1] + (*this)[2][1]*m[2][2], (*this)[0][2]*m[0][0] + (*this)[1][2]*m[0][1] + (*this)[2][2]*m[0][2], (*this)[0][2]*m[1][0] + (*this)[1][2]*m[1][1] + (*this)[2][2]*m[1][2], (*this)[0][2]*m[2][0] + (*this)[1][2]*m[2][1] + (*this)[2][2]*m[2][2] ); }
Matrix3x3 get_unistate_mat3(const char *name) { int sidx = get_unistate_index(name); if(sidx == -1) { return Matrix3x3(); } return get_unistate_mat3(sidx); }
Matrix3x3 Matrix3x3::operator+( const Matrix3x3& rhs ) const { return Matrix3x3( _00+rhs._00, _01+rhs._01, _02+rhs._02, _10+rhs._10, _11+rhs._11, _12+rhs._12, _20+rhs._20, _21+rhs._21, _22+rhs._22 ); }
Matrix3x3 matScale(double x, double y) { return Matrix3x3(x, 0., 0., 0., y, 0., 0., 0., 1.); }
Matrix3x3 Matrix3x3::Diagonal(const float& m00, const float& m11, const float& m22) { return Matrix3x3(m00, 0 , 0 , 0 , m11, 0 , 0 , 0 , m22); }
Matrix3x3 Matrix3x3::CompClamp(const Matrix3x3& m, const Matrix3x3& min, const Matrix3x3& max) { return Matrix3x3(Vector3::CompClamp(m[0], min[0], max[0]), Vector3::CompClamp(m[1], min[1], max[1]), Vector3::CompClamp(m[2], min[2], max[2])); }
// Overloaded operator for substraction inline Matrix3x3 operator-(const Matrix3x3& matrix1, const Matrix3x3& matrix2) { return Matrix3x3(matrix1.mRows[0][0] - matrix2.mRows[0][0], matrix1.mRows[0][1] - matrix2.mRows[0][1], matrix1.mRows[0][2] - matrix2.mRows[0][2], matrix1.mRows[1][0] - matrix2.mRows[1][0], matrix1.mRows[1][1] - matrix2.mRows[1][1], matrix1.mRows[1][2] - matrix2.mRows[1][2], matrix1.mRows[2][0] - matrix2.mRows[2][0], matrix1.mRows[2][1] - matrix2.mRows[2][1], matrix1.mRows[2][2] - matrix2.mRows[2][2]); }
Matrix3x3 Matrix3x3::operator-( const Matrix3x3& rhs ) const { return Matrix3x3( _00-rhs._00, _01-rhs._01, _02-rhs._02, _10-rhs._10, _11-rhs._11, _12-rhs._12, _20-rhs._20, _21-rhs._21, _22-rhs._22 ); }
Matrix3x3 matTranslation(double x, double y) { return Matrix3x3(1., 0., x, 0., 1., y, 0., 0., 1.); }
Matrix3x3 matRotation(double rads) { double c = std::cos(rads); double s = std::sin(rads); return Matrix3x3(c, s, 0, -s, c, 0, 0, 0, 1); }
Matrix3x3 Matrix3x3::RotationAboutY(const float& radians) { // do some precomputations float c = std::cos(radians); float s = std::sin(radians); return Matrix3x3( c, 0, s, 0, 1, 0, -s, 0, c); }
Matrix3x3 matSkewXY(double skewX, double skewY, bool skewOrderYX) { return Matrix3x3(skewOrderYX ? 1. : (1. + skewX * skewY), skewX, 0., skewY, skewOrderYX ? (1. + skewX * skewY) : 1, 0., 0., 0., 1.); }
void TargetCamera::set_camera(long time) { set_view_matrix(get_matrix()); set_unistate("st_view_matrix3",Matrix3x3(get_matrix())); //DEBUG Matrix4x4 view = get_matrix(); glMatrixMode(GL_MODELVIEW); glLoadTransposeMatrixf(view[0]); }
Matrix3x3 Matrix3x3::Transpose() const { float data[9]; int cnt = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { data[cnt++] = data_[j][i]; } } return Matrix3x3(data); }
Matrix3x3 matMul(const Matrix3x3 & m1, const Matrix3x3 & m2) { return Matrix3x3(m1.a * m2.a + m1.b * m2.d + m1.c * m2.g, m1.a * m2.b + m1.b * m2.e + m1.c * m2.h, m1.a * m2.c + m1.b * m2.f + m1.c * m2.i, m1.d * m2.a + m1.e * m2.d + m1.f * m2.g, m1.d * m2.b + m1.e * m2.e + m1.f * m2.h, m1.d * m2.c + m1.e * m2.f + m1.f * m2.i, m1.g * m2.a + m1.h * m2.d + m1.i * m2.g, m1.g * m2.b + m1.h * m2.e + m1.i * m2.h, m1.g * m2.c + m1.h * m2.f + m1.i * m2.i); }
Matrix3x3 Matrix3x3::getTranspose() { std::vector<float> tmp(9); for (int i = 0; i < 3; i++) { tmp[3 * i] = elements[i]; tmp[3 * i + 1] = elements[i + 3]; tmp[3 * i + 2] = elements[i + 6]; } return Matrix3x3(tmp); }
Matrix3x3 Matrix3x3::VectorRotation(const Vector3& unitFrom, const Vector3& unitTo) { // compute the unit rotation axis Vector3 v = Vector3::CrossProduct(unitFrom, unitTo); float e = Vector3::DotProduct(unitFrom, unitTo); float h = 1.0f / (1.0f + e); Vector3 hv = h*v; // return the matrix return Matrix3x3(e + hv[0]*v[0], hv[0]*v[1] - v[2], hv[0]*v[2] + v[1], hv[0]*v[1] + v[2], e + hv[1]*v[1], hv[1]*v[2] - v[0], hv[0]*v[2] - v[1], hv[1]*v[2] + v[0], e + hv[2]*v[2]); }
a2de::Matrix3x3 Matrix3x3::operator*(const Matrix3x3& rhs) { a2de::Vector3D r1(this->GetRowOne()); a2de::Vector3D r2(this->GetRowTwo()); a2de::Vector3D r3(this->GetRowThree()); a2de::Vector3D c1(rhs.GetColumnOne()); a2de::Vector3D c2(rhs.GetColumnTwo()); a2de::Vector3D c3(rhs.GetColumnThree()); return Matrix3x3(a2de::Vector3D::DotProduct(r1, c1), a2de::Vector3D::DotProduct(r1, c2), a2de::Vector3D::DotProduct(r1, c3), a2de::Vector3D::DotProduct(r2, c1), a2de::Vector3D::DotProduct(r2, c2), a2de::Vector3D::DotProduct(r2, c3), a2de::Vector3D::DotProduct(r3, c1), a2de::Vector3D::DotProduct(r3, c2), a2de::Vector3D::DotProduct(r3, c3)); }
void configure() { PhaseFunction::configure(); m_type = EAnisotropic | ENonSymmetric; Properties props("independent"); m_sampler = static_cast<Sampler*>(PluginManager::getInstance()->createObject(MTS_CLASS(Sampler), props)); m_sampler->configure(); if (m_stddev != -1.f) { Float sigma1 = m_fiberDistr.sigmaT(0.f) * 2.f; Float sigma2 = sigma1; Float sigma3 = m_fiberDistr.sigmaT(1.f) * 2.f; D = Matrix3x3(Vector(sigma1 * sigma1, 0, 0), Vector(0, sigma2 * sigma2, 0), Vector(0, 0, sigma3 * sigma3)); } }
static bool triangle_intersection(const Ray *ray, const Point3D &p0, const Point3D &p1, const Point3D &p2, double &beta, double &gamma) { Vector3D v1 = p1 - p0; Vector3D v2 = p2 - p0; Vector3D r = ray->get_pos() - p0; double d = Matrix3x3(v1,v2,ray->get_dir()).det(); double d1 = Matrix3x3(r,v2,ray->get_dir()).det(); beta = d1/d; if (beta < 0) return false; double d2 = Matrix3x3(v1, r, ray->get_dir()).det(); gamma = d2/d; if (gamma < 0 || (beta+gamma) >= 1) return false; return true; }
Matrix3x3 Matrix3x3::Multiply(const Matrix3x3& rhs) const { float newMatrix[] = { (_elements[0] * rhs._elements[0] + _elements[3] * rhs._elements[1] + _elements[6] * rhs._elements[2]), (_elements[1] * rhs._elements[0] + _elements[4] * rhs._elements[1] + _elements[7] * rhs._elements[2]), (_elements[2] * rhs._elements[0] + _elements[5] * rhs._elements[1] + _elements[8] * rhs._elements[2]), (_elements[0] * rhs._elements[3] + _elements[3] * rhs._elements[4] + _elements[6] * rhs._elements[5]), (_elements[1] * rhs._elements[3] + _elements[4] * rhs._elements[4] + _elements[7] * rhs._elements[5]), (_elements[2] * rhs._elements[3] + _elements[5] * rhs._elements[4] + _elements[8] * rhs._elements[5]), (_elements[0] * rhs._elements[6] + _elements[3] * rhs._elements[7] + _elements[6] * rhs._elements[8]), (_elements[1] * rhs._elements[6] + _elements[4] * rhs._elements[7] + _elements[7] * rhs._elements[8]), (_elements[2] * rhs._elements[6] + _elements[5] * rhs._elements[7] + _elements[8] * rhs._elements[8]) }; return Matrix3x3(newMatrix); }
Matrix3x3 Matrix3x3::LookAtRotation(const Vector3& eyePos, const Vector3& targetPos, const Vector3& unitUpVector) { #ifndef NDEBUG assert(eyePos != targetPos && unitUpVector != Vector3::ZERO); #endif // using OpenGL2.1 SDK (gluLookAt) Vector3 f((targetPos - eyePos).Normalize()); Vector3 s(Vector3::CrossProduct(f, unitUpVector)); Vector3 u(Vector3::CrossProduct(s, f)); return Matrix3x3(s[0], u[0], -f[0], s[1], u[1], -f[1], s[2], u[2], -f[2] ); }
void set_view_matrix(const Matrix4x4 &mat) { static int sidx = -1, sidx_transp, sidx_mat3, sidx_inv; if(sidx == -1) { sidx = add_unistate("st_view_matrix", ST_MATRIX4); sidx_mat3 = add_unistate("st_view_matrix3", ST_MATRIX3); sidx_transp = add_unistate("st_view_matrix_transpose", ST_MATRIX4); sidx_inv = add_unistate("st_view_matrix_inverse", ST_MATRIX4); } set_unistate(sidx, mat); set_unistate(sidx_mat3, Matrix3x3(mat)); set_unistate(sidx_transp, mat[0]); // by using the float* variant, we unset the transpose flag set_unistate(sidx_inv, mat.inverse()); }
Matrix3x3 Matrix3x3::operator*( const Matrix3x3& rhs ) const { return Matrix3x3( _00*rhs._00 + _01*rhs._10 + _02*rhs._20, _00*rhs._01 + _01*rhs._11 + _02*rhs._21, _00*rhs._02 + _01*rhs._12 + _02*rhs._22, _10*rhs._00 + _11*rhs._10 + _12*rhs._20, _10*rhs._01 + _11*rhs._11 + _12*rhs._21, _10*rhs._02 + _11*rhs._12 + _12*rhs._22, _20*rhs._00 + _21*rhs._10 + _22*rhs._20, _20*rhs._01 + _21*rhs._11 + _22*rhs._21, _20*rhs._02 + _21*rhs._12 + _22*rhs._22 ); }