示例#1
0
void Transform::setModelMatrix(glm::mat4 matrix) {
    glm::vec3 new_position(matrix[3][0], matrix[3][1], matrix[3][2]);
    float xs =
            matrix[0][0] * matrix[0][1] * matrix[0][2] * matrix[0][3] < 0 ?
                    -1 : 1;
    float ys =
            matrix[1][0] * matrix[1][1] * matrix[1][2] * matrix[1][3] < 0 ?
                    -1 : 1;
    float zs =
            matrix[2][0] * matrix[2][1] * matrix[2][2] * matrix[2][3] < 0 ?
                    -1 : 1;
    glm::vec3 new_scale;
    new_scale.x = xs
            * glm::sqrt(
                    matrix[0][0] * matrix[0][0] + matrix[0][1] * matrix[0][1]
                            + matrix[0][2] * matrix[0][2]);
    new_scale.y = ys
            * glm::sqrt(
                    matrix[1][0] * matrix[1][0] + matrix[1][1] * matrix[1][1]
                            + matrix[1][2] * matrix[1][2]);
    new_scale.z = zs
            * glm::sqrt(
                    matrix[2][0] * matrix[2][0] + matrix[2][1] * matrix[2][1]
                            + matrix[2][2] * matrix[2][2]);
    glm::mat3 rotation_mat(matrix[0][0] / new_scale.x,
            matrix[0][1] / new_scale.y, matrix[0][2] / new_scale.z,
            matrix[1][0] / new_scale.x, matrix[1][1] / new_scale.y,
            matrix[1][2] / new_scale.z, matrix[2][0] / new_scale.x,
            matrix[2][1] / new_scale.y, matrix[2][2] / new_scale.z);

    position_ = new_position;
    scale_ = new_scale;
    rotation_ = glm::quat_cast(rotation_mat);
    invalidate();
}
    // Covers some bits that aren't covered in the tests above,
    void TestOtherCoverage() throw(Exception)
    {
        TetrahedralMesh<2,2> fine_mesh;
        fine_mesh.ConstructRegularSlabMesh(0.1, 1.0, 1.0);

        QuadraticMesh<2> coarse_mesh(1.0, 1.0, 1.0);

        /*
         * Rotate the mesh by 45 degrees, makes it possible (since boxes no
         * longer lined up with elements) for the containing element of a
         * quad point to be in a *local* box, ie not an element contained
         * in the box containing this point.
         */
        c_matrix<double,2,2> rotation_mat;
        rotation_mat(0,0) = 1.0/sqrt(2.0);
        rotation_mat(1,0) = -1.0/sqrt(2.0);
        rotation_mat(0,1) = 1.0/sqrt(2.0);
        rotation_mat(1,1) = 1.0/sqrt(2.0);

        fine_mesh.Rotate(rotation_mat);
        coarse_mesh.Rotate(rotation_mat);

        GaussianQuadratureRule<2> quad_rule(3);

        FineCoarseMeshPair<2> mesh_pair(fine_mesh,coarse_mesh);
        mesh_pair.SetUpBoxesOnFineMesh();
        mesh_pair.ComputeFineElementsAndWeightsForCoarseQuadPoints(quad_rule, true);
        TS_ASSERT_EQUALS(mesh_pair.mNotInMesh.size(), 0u);

        /*
         * Repeat again with smaller boxes, covers the bit requiring the whole
         * mesh to be searched to find an element for a particular quad point.
         */
        FineCoarseMeshPair<2> mesh_pair2(fine_mesh,coarse_mesh);
        mesh_pair2.SetUpBoxesOnFineMesh(0.01);
        mesh_pair2.ComputeFineElementsAndWeightsForCoarseQuadPoints(quad_rule, true);
        TS_ASSERT_EQUALS(mesh_pair.mNotInMesh.size(), 0u);
    }
示例#3
0
void Transform::setModelMatrix(glm::mat4 matrix) {

    glm::vec3 new_position(matrix[3][0], matrix[3][1], matrix[3][2]);

    glm::vec3 Xaxis(matrix[0][0],matrix[0][1],matrix[0][2]);
    glm::vec3 Yaxis(matrix[1][0],matrix[1][1],matrix[1][2]);
    glm::vec3 Zaxis(matrix[2][0],matrix[2][1],matrix[2][2]);

    double zs=glm::dot(glm::cross(Xaxis,Yaxis),Zaxis);
    double ys=glm::dot(glm::cross(Zaxis,Xaxis),Yaxis);
    double xs=glm::dot(glm::cross(Yaxis,Zaxis),Xaxis);


    xs=std::signbit(xs);
    ys=std::signbit(ys);
    zs=std::signbit(zs);

    xs =(xs > 0.0 ? -1 :1);
    ys =(ys > 0.0 ? -1 :1);
    zs =(zs > 0.0 ? -1 :1);

    glm::vec3 new_scale;
    new_scale.x = xs* glm::sqrt(
                      matrix[0][0] * matrix[0][0] + matrix[0][1] * matrix[0][1]
                      + matrix[0][2] * matrix[0][2]);
    new_scale.y = ys* glm::sqrt(
                      matrix[1][0] * matrix[1][0] + matrix[1][1] * matrix[1][1]
                      + matrix[1][2] * matrix[1][2]);
    new_scale.z = zs* glm::sqrt(
                      matrix[2][0] * matrix[2][0] + matrix[2][1] * matrix[2][1]
                      + matrix[2][2] * matrix[2][2]);


    glm::mat3 rotation_mat(matrix[0][0] / new_scale.x,
                           matrix[0][1] / new_scale.y, matrix[0][2] / new_scale.z,
                           matrix[1][0] / new_scale.x, matrix[1][1] / new_scale.y,
                           matrix[1][2] / new_scale.z, matrix[2][0] / new_scale.x,
                           matrix[2][1] / new_scale.y, matrix[2][2] / new_scale.z);

    position_ = new_position;
    scale_ = new_scale;
    rotation_ = glm::quat_cast(rotation_mat);

    invalidate(true);
}