Exemple #1
0
Boolean
calculate_transformation(CheapPointType new1_pt, CheapPointType new2_pt,
                         CheapPointType old1_pt, CheapPointType old2_pt,
                         Boolean reflect,
                         double angle,
                         Matrix3x3 new_to_old_mat)
{
  Matrix3x3 t;

  /* Translation of new1_pt to origin. */
  Matrix3x3 new_to_origin_mat;
  make_translation_matrix(new_to_origin_mat, -new1_pt.X, -new1_pt.Y);
  if (reflect) {
    /* If components are not on same side of board, reflect through
       the y-axis. */
    make_reflection_matrix_y_axis(t);
    multiply_matrix_matrix_inplace(t, new_to_origin_mat);
  }

  Matrix3x3 result;
  /* Start with translation of new1_pt to origin. */
  copy_matrix(new_to_origin_mat, result);
  /* Rotate from new element angle to old element angle. */
  make_rotation_matrix(t, angle);
  multiply_matrix_matrix_inplace(t, result);
  /* Translate from origin to old1_pt. */
  make_translation_matrix(t, old1_pt.X, old1_pt.Y);
  multiply_matrix_matrix_inplace(t, result);

  copy_matrix(result, new_to_old_mat);
  return True;
}
Exemple #2
0
const char*
scale_scene_node(const char *node, point_t center, scalar_t factor[3] ) 
{
    scene_node_t *nodePtr;
    matrixgl_t matrix;

    if ( get_scene_node( node, &nodePtr ) != TCL_OK ) {
        return "No such node";
    } 

    make_translation_matrix( matrix, -center.x, -center.y, -center.z );
    multiply_matrices( nodePtr->trans, nodePtr->trans, matrix );
    make_translation_matrix( matrix, center.x, center.y, center.z );
    multiply_matrices( nodePtr->invtrans, matrix, nodePtr->invtrans );

    make_scaling_matrix( matrix, factor[0], factor[1], factor[2] );
    multiply_matrices( nodePtr->trans, nodePtr->trans, matrix );
    make_scaling_matrix( matrix, 1./factor[0], 1./factor[1], 1./factor[2] );
    multiply_matrices( nodePtr->invtrans, matrix, nodePtr->invtrans );

    make_translation_matrix( matrix, center.x, center.y, center.z );
    multiply_matrices( nodePtr->trans, nodePtr->trans, matrix );
    make_translation_matrix( matrix, -center.x, -center.y, -center.z );
    multiply_matrices( nodePtr->invtrans, matrix, nodePtr->invtrans );

    return NULL;
}
Exemple #3
0
const char*
translate_scene_node(const char *node, vector_t vec ) 
{
    scene_node_t *nodePtr;
    matrixgl_t xlateMatrix;

    if ( get_scene_node( node, &nodePtr ) != TCL_OK ) {
        return "No such node";
    } 

    make_translation_matrix( xlateMatrix, vec.x, vec.y, vec.z );
    multiply_matrices( nodePtr->trans, nodePtr->trans, xlateMatrix );
    make_translation_matrix( xlateMatrix, -vec.x, -vec.y, -vec.z );
    multiply_matrices( nodePtr->invtrans, xlateMatrix, nodePtr->invtrans );

    return NULL;
}
Exemple #4
0
void make_inverse_transformation_matrix(
    Matrix4* mat, const Vector3& pos, const Quaternion& ori, const Vector3& scl )
{
    // assumes orientation is normalized
    Matrix4 sclmat, orimat, trnmat;

    make_scaling_matrix( &sclmat, Vector3( 1.0 / scl.x, 1.0 / scl.y, 1.0 / scl.z ) );
    conjugate( ori ).to_matrix( &orimat );
    make_translation_matrix( &trnmat, -pos );

    *mat = sclmat * orimat * trnmat;
}
    ExperimentalApp() : GLFWApp(1280, 800, "Geometric Algorithm Development App")
    {
        glfwSwapInterval(0);

        igm.reset(new gui::ImGuiManager(window));
        gui::make_dark_theme();

        fixedTimer.start();

        lights[0] = {{0, 10, -10}, {0, 0, 1}};
        lights[1] = {{0, 10, 10}, {0, 1, 0}};

        int width, height;
        glfwGetWindowSize(window, &width, &height);
        glViewport(0, 0, width, height);

        grid = RenderableGrid(1, 100, 100);
        cameraController.set_camera(&camera);
        camera.look_at({0, 2.5, -2.5}, {0, 2.0, 0});

        simpleShader = make_watched_shader(shaderMonitor, "../assets/shaders/simple_vert.glsl", "assets/shaders/simple_frag.glsl");
        normalDebugShader = make_watched_shader(shaderMonitor, "../assets/shaders/normal_debug_vert.glsl", "assets/shaders/normal_debug_frag.glsl");

        Renderable debugAxis = Renderable(make_axis(), false, GL_LINES);
        debugAxis.pose = Pose(float4(0, 0, 0, 1), float3(0, 1, 0));
        debugModels.push_back(std::move(debugAxis));

        // Initial supershape settings
        supershape = Renderable(make_supershape_3d(16, 5, 7, 4, 12));
        supershape.pose.position = {0, 2, -2};

        // Initialize PTF stuff
        {
            std::array<float3, 4> controlPoints = {float3(0.0f, 0.0f, 0.0f), float3(0.667f, 0.25f, 0.0f), float3(1.33f, 0.25f, 0.0f), float3(2.0f, 0.0f, 0.0f)};
            ptf = make_parallel_transport_frame_bezier(controlPoints, 32);

            for (int i = 0; i < ptf.size(); ++i)
            {
                Renderable p = Renderable(make_cube());
                ptfBoxes.push_back(std::move(p));
            }
        }

        // Initialize Parabolic pointer stuff
        {
            // Set up the ground plane used as a nav mesh for the parabolic pointer
            worldSurface = make_plane(48, 48, 96, 96);
            for (auto & p : worldSurface.vertices)
            {
                float4x4 model = make_rotation_matrix({1, 0, 0}, -ANVIL_PI / 2);
                p = transform_coord(model, p);
            }
            worldSurfaceRenderable = Renderable(worldSurface);

            parabolicPointer = make_parabolic_pointer(worldSurface, params);
        }

        // Initialize objects for ballistic trajectory tests
        {
            turret.source = Renderable(make_tetrahedron());
            turret.source.pose = Pose({-5, 2, 5});

            turret.target = Renderable(make_cube());
            turret.target.pose = Pose({0, 0, 40});

            turret.bullet = Renderable(make_sphere(1.0f));
        }

        float4x4 tMat = mul(make_translation_matrix({3, 4, 5}), make_rotation_matrix({0, 0, 1}, ANVIL_PI / 2));
        auto p = make_pose_from_transform_matrix(tMat);
        std::cout << tMat << std::endl;
        std::cout << p << std::endl;

        gl_check_error(__FILE__, __LINE__);
    }