コード例 #1
0
    // Update is called once per frame
    public void recalculate()
    {
        Vector3 [] new_positions = new Vector3[particles.Length];
        cm = Vector3.zero;
        for (int i = 0; i < particles.Length; i++)
        {
            new_positions[i] = particles[i].get_position();
            cm += new_positions[i];
            //print(particles[i].get_position());
        }
        cm /= (float)particles.Length;
        // foreach(Vector3 p in new_positions){
        //  print(p);
        // }
        for (int i = 0; i < new_positions.Length; i++)
        {
            new_positions[i] -= cm;
        }

        transformation = shapeMatch.generate_linear_matrix(new_positions, 0.95);
        //Rotation_test.print_matrix(transformation);
        foreach (Particle particle in particles)
        {
            particle.set_transformation(transformation);
        }
    }
コード例 #2
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();
    }