예제 #1
0
	public static MatrixVector convertToMatrix(Vector3[] points){

		MatrixVector m = new MatrixVector (points.Length, 1);
		for (int i=0; i<points.Length; i++)
			m.setValueAt (i, 0, points [i]);
		return m;
	}
예제 #2
0
        public static MatrixVector convertToMatrix(Vector3[] points)
        {
            MatrixVector m = new MatrixVector(points.Length, 1);

            for (int i = 0; i < points.Length; i++)
            {
                m.setValueAt(i, 0, points [i]);
            }
            return(m);
        }
예제 #3
0
        public static MatrixVector multiplyByMatrix(Matrix m, MatrixVector n)
        {
            MatrixVector res = new MatrixVector(m.getNrows(), 1);

            for (int i = 0; i < m.getNrows(); i++)
            {
                Vector3 sum = new Vector3(0, 0, 0);
                for (int j = 0; j < m.getNcols(); j++)
                {
                    sum += new Vector3((float)(m.getValueAt(i, j) * n.getValueAt(j, 0).x), (float)(m.getValueAt(i, j) * n.getValueAt(j, 0).y), (float)(m.getValueAt(i, j) * n.getValueAt(j, 0).z));
                }
                res.setValueAt(i, 0, sum);
            }
            return(res);
        }
예제 #4
0
	public static MatrixVector multiplyByMatrix(Matrix m, MatrixVector n)
	{

				MatrixVector res = new MatrixVector (m.getNrows(), 1);

				for (int i=0; i<m.getNrows(); i++) 
				{
						Vector3 sum = new Vector3 (0, 0, 0);
						for (int j=0; j<m.getNcols(); j++)
				sum += new Vector3 ((float)(m.getValueAt (i, j) * n.getValueAt(j,0).x), (float)(m.getValueAt (i, j) * n.getValueAt(j,0).y), (float)(m.getValueAt (i, j) * n.getValueAt(j,0).z));
			res.setValueAt(i,0,sum);

				}
		return res;

	}
예제 #5
0
	public static Vector3 followPath(Vector3[] vectors, bool mode, GameObject pathsColls){
		
		Npoints= new Vector3[11];

		C = new Matrix (11, 4);
		float k = 0f;
		for(int i=0;i<=10;i++)
		{
			C.setValueAt(i,0,Mathf.Pow(1-k,3));
			C.setValueAt(i,1,3*k*(1-k)*(1-k));
			C.setValueAt(i,2,3*k*k*(1-k));
			C.setValueAt(i,3, k*k*k);
			
			k+=0.1f;
		}
		
		T = Matrix.transpose (C);
		M = Matrix.multiply(Matrix.inverse(Matrix.multiply (T,C)),T);
		
		findNpoints(vectors);
		N = convertToMatrix (Npoints);
		
		P = MatrixVector.multiplyByMatrix (M, N);
		
		new Bezier (P.getValueAt (3, 0), P.getValueAt (2, 0), P.getValueAt (1, 0), P.getValueAt (0, 0), mode, pathsColls, 200);
		
		return P.getValueAt (2, 0);
	}
예제 #6
0
        public static Vector3 followPath(Vector3[] vectors, GameObject prefab, bool mode, GameObject pathsColls)
        {
            Npoints = new Vector3[11];

            for (int x = 0; x < vectors.Length; x++)
            {
                Vector3 temp = new Vector3(vectors[x].x, vectors[x].y, vectors[x].z);
                //GameObject sphere= GameObject.CreatePrimitive(PrimitiveType.Sphere);

                /*GameObject sphere = Instantiate(prefab);
                 * sphere.GetComponent<Renderer>().material.color = Color.yellow;
                 * sphere.transform.position = temp;*/
            }
            C = new Matrix(11, 4);
            float k = 0f;

            for (int i = 0; i <= 10; i++)
            {
                C.setValueAt(i, 0, Mathf.Pow(1 - k, 3));
                C.setValueAt(i, 1, 3 * k * (1 - k) * (1 - k));
                C.setValueAt(i, 2, 3 * k * k * (1 - k));
                C.setValueAt(i, 3, k * k * k);

                k += 0.1f;
            }

            T = Matrix.transpose(C);

            //		Matrix m = Matrix.multiply (T, C);
            //ispis (m);
            //		Matrix n = Matrix.inverse (m);
            //ispis (n);



            M = Matrix.multiply(Matrix.inverse(Matrix.multiply(T, C)), T);


            //Debug.Log("*******M*********");
            ispis(M);

            /*N = new MatrixVector (11,1);
             * N.setValueAt (0, 0, new Vector3 (1, 1, 1));
             * N.setValueAt (1, 0, new Vector3(1,3,5));
             * N.setValueAt (2, 0, new Vector3 (2, 2, 2));
             * N.setValueAt (3, 0, new Vector3 (5, 7, 6));
             * N.setValueAt (4, 0, new Vector3 (9, 10, 3));
             * N.setValueAt (5, 0, new Vector3(0,10,4));
             * N.setValueAt (6, 0, new Vector3 (1, 15, 10));
             * N.setValueAt (7, 0, new Vector3 (1, 0, 11));
             * N.setValueAt (8, 0, new Vector3 (-2, 0, 10));
             * N.setValueAt (9, 0, new Vector3 (5, 7, -3));
             * N.setValueAt (10, 0,new Vector3(9,-2,1));*/

            findNpoints(vectors);
            N = convertToMatrix(Npoints);

            P = MatrixVector.multiplyByMatrix(M, N);

            for (int x = 0; x < Npoints.Length; x++)
            {
                //Vector3 temp = new Vector3(vectors[x].x,vectors[x].y,vectors[x].z);
                //GameObject sphere= GameObject.CreatePrimitive(PrimitiveType.Sphere);

                /*GameObject sphere = Instantiate(prefab);
                 * sphere.GetComponent<Renderer>().material.color = Color.green;
                 *
                 * sphere.transform.position = Npoints[x];
                 */
            }

            new Bezier(P.getValueAt(3, 0), P.getValueAt(2, 0), P.getValueAt(1, 0), P.getValueAt(0, 0), prefab, null, mode, pathsColls, 200);

            //for (int i=0; i<4; i++)
            //	Debug.Log (P.getValueAt (i, 0));

            return(P.getValueAt(2, 0));
        }
예제 #7
0
	public static Vector3 followPath(Vector3[] vectors, GameObject prefab, bool mode, GameObject pathsColls){
		
		Npoints= new Vector3[11];
		
		for(int x=0; x<vectors.Length; x++)
		{
		Vector3 temp = new Vector3(vectors[x].x,vectors[x].y,vectors[x].z);
			//GameObject sphere= GameObject.CreatePrimitive(PrimitiveType.Sphere);
			/*GameObject sphere = Instantiate(prefab);
		sphere.GetComponent<Renderer>().material.color = Color.yellow;
		sphere.transform.position = temp;*/
			
		}
		C = new Matrix (11, 4);
		float k = 0f;
		for(int i=0;i<=10;i++)
		{
			
			C.setValueAt(i,0,Mathf.Pow(1-k,3));
			C.setValueAt(i,1,3*k*(1-k)*(1-k));
			C.setValueAt(i,2,3*k*k*(1-k));
			C.setValueAt(i,3, k*k*k);
			
			k+=0.1f;
		}
		
		T = Matrix.transpose (C);
		
		//		Matrix m = Matrix.multiply (T, C);
		//ispis (m);
		//		Matrix n = Matrix.inverse (m);
		//ispis (n);
		
		
		
		M = Matrix.multiply(Matrix.inverse(Matrix.multiply (T,C)),T);
		
		
		//Debug.Log("*******M*********");
		ispis (M);
		
		/*N = new MatrixVector (11,1);
	N.setValueAt (0, 0, new Vector3 (1, 1, 1)); 
	N.setValueAt (1, 0, new Vector3(1,3,5)); 
	N.setValueAt (2, 0, new Vector3 (2, 2, 2));
	N.setValueAt (3, 0, new Vector3 (5, 7, 6));
	N.setValueAt (4, 0, new Vector3 (9, 10, 3));
	N.setValueAt (5, 0, new Vector3(0,10,4));
	N.setValueAt (6, 0, new Vector3 (1, 15, 10));
	N.setValueAt (7, 0, new Vector3 (1, 0, 11));
	N.setValueAt (8, 0, new Vector3 (-2, 0, 10));
	N.setValueAt (9, 0, new Vector3 (5, 7, -3));
	N.setValueAt (10, 0,new Vector3(9,-2,1));*/
		
		findNpoints(vectors);
		N = convertToMatrix (Npoints);
		
		P = MatrixVector.multiplyByMatrix (M, N);
		
		for(int x=0;x<Npoints.Length; x++)
		{
			//Vector3 temp = new Vector3(vectors[x].x,vectors[x].y,vectors[x].z);
			//GameObject sphere= GameObject.CreatePrimitive(PrimitiveType.Sphere);
			/*GameObject sphere = Instantiate(prefab);
		sphere.GetComponent<Renderer>().material.color = Color.green;
		
		sphere.transform.position = Npoints[x];
		*/
			
		}
		
		new Bezier (P.getValueAt (3, 0), P.getValueAt (2, 0), P.getValueAt (1, 0), P.getValueAt (0, 0), prefab, null, mode, pathsColls, 200);
		
		//for (int i=0; i<4; i++)
		//	Debug.Log (P.getValueAt (i, 0));
		
		return P.getValueAt (2, 0);
	}