// Update is called once per frame
    void FixedUpdate()
    {
        if (deformation_frames > 0)
        {
            for (int i = 0; i < particles.Length; i++)
            {
                particles[i].displace(displacements[i]);
                displacements[i] /= 4;
            }
            cluster.recalculate();

            for (int i = 0; i < particles.Length; i++)
            {
                particles[i].movePoints(cluster.origin_cm);
            }

            for (int i = 0; i < vertices.Length; i++)
            {
                Vector3 x = particle_container.transform.TransformPoint(original_vertices[i] - cluster.origin_cm);
                vertices[i] = MatrixFunctions.matrix_multiply_1x3_by_3x3(x, cluster.getTransformation());
            }

            gameObject.transform.position = cluster.cm;

            rigidbody.centerOfMass = cluster.cm;
            mesh.vertices          = vertices;

            deformation_frames--;
        }

        prev_velocity = rigidbody.velocity;
    }
Esempio n. 2
0
    public void updatePositions()
    {
        double [,] t = cluster.getTransformation();
        for (int i = 0; i < vertices.Length; i++)
        {
            vertices[i] = MatrixFunctions.matrix_multiply_1x3_by_3x3(vertices[i], t);
        }

        mesh.vertices = vertices;
    }
Esempio n. 3
0
    void run_test()
    {
        //randomize rotation of control spheres
        Quaternion rot = Random.rotation;

        print(rot.eulerAngles);
        duplicate.transform.rotation = rot;

        //Stores positions of particles post rotation
        Vector3 []   new_positions;
        Transform [] temp = duplicate.GetComponentsInChildren <Transform>();        //Get components in children creates unwanted first element in array, needs compensation
        new_positions = new Vector3[temp.Length - 1];

        //Instantiates spheres at particle locations
        destroy_markers();
        markers = new GameObject[temp.Length - 1];
        for (int i = 1; i < temp.Length; i++)         //i starts at one to compensate for problem descibed earlier
        {
            new_positions[i - 1] = duplicate.transform.TransformPoint(temp[i].position) + new Vector3(Random.Range(-randomness, randomness), Random.Range(-randomness, randomness), Random.Range(-randomness, randomness));;
            GameObject t = Instantiate(marker, new_positions[i - 1], Quaternion.identity);
            t.transform.parent = duplicate.transform;             //Parents new objects under Duplicate_Points
        }

        //ENTERY INTO SHAPE MATCH
        double [,] rotation_matrix;
        if (linear)
        {
            rotation_matrix = shape_match.generate_linear_matrix(new_positions, beta);
        }
        else
        {
            rotation_matrix = shape_match.generate_rotation_matrix(new_positions);
        }

        //print_matrix(rotation_matrix);

        //Multiplies rotation matrix recieved by shape matching to mesh's vertices
        Vector3 [] new_vertices = new Vector3 [vertices.Length];

        for (int i = 0; i < vertices.Length; i++)
        {
            new_vertices[i] = MatrixFunctions.matrix_multiply_1x3_by_3x3(vertices[i], rotation_matrix);
        }

        //Assigns altered vertice positions to object
        Mesh mesh = gameObject.GetComponent <MeshFilter>().mesh;

        mesh.vertices = new_vertices;
        // flipNormals();
        mesh.RecalculateNormals();
    }
Esempio n. 4
0
    public void movePoints(Vector3 cm0)
    {
        Vector3 x = gameObject.transform.parent.transform.TransformPoint(original_position - cm0);

        gameObject.transform.position = MatrixFunctions.matrix_multiply_1x3_by_3x3(x, transformation_matrix);
    }