Esempio n. 1
0
    // Combine all quarternions without putting them into matrices first (except Scale)  -  this routine was made because theres an issue with plugging them into matrices that makes them shrink and enlarge when rotating
    public static Vectors QCombine(Vectors Translation, Vectors CurrentLocation, Vectors Scale, Vectors AxisRots, Vector3[] ModelSpaceVertices, MeshFilter MF)
    {
        Vectors r = new Vectors(0, 0, 0);

        // Create Qauternions from raw data
        Quarts S   = QScale(Scale);
        Quarts R   = new Quarts(AxisRots.x, new Vectors(0, 0, 1));
        Quarts P   = new Quarts(AxisRots.y, new Vectors(1, 0, 0));
        Quarts Y   = new Quarts(AxisRots.z, new Vectors(0, 1, 0));
        Quarts RPY = R * P * Y;
        // Remember TRS order (T omitted for now because its being weird)
        Quarts Combined = RPY * S;

        // Define array of vertices
        Vector3[] TransformedVertices = new Vector3[ModelSpaceVertices.Length];

        // move vertexs to new position
        for (int i = 0; i < TransformedVertices.Length; i++)
        {
            // Convert Vertexs into Quaternions
            Vectors temp    = new Vectors(ModelSpaceVertices[i].x, ModelSpaceVertices[i].y, ModelSpaceVertices[i].z);
            Quarts  Vertexs = new Quarts(0, new Vectors(0, 0, 0));
            Vertexs.SetAxis(temp);

            // Rotate & Scale vertexs - Using slerp
            Quarts slerped = SLERP(Combined, Vertexs, Time.deltaTime);
            slerped = Combined * Vertexs * Combined.Inverse();
            Vectors finalV = GetAxis(slerped);

            //// This is our basic vertex mover - just added onto the result of the Q matrix
            //// LERP for that nice smooth movement (Dont forget to add vertex position onto translation amount, u dummy)
            //Vectors NewLocation = new Vectors(Translation.x + finalV.x, Translation.y + finalV.y, Translation.z + finalV.z);
            //Vectors Move = Vectors.VLerp(NewLocation, finalV, Time.deltaTime);

            // Move the Vertex to its new position
            TransformedVertices[i] = new Vector3(finalV.x, finalV.y, finalV.z);
        }

        // Assign new Vertices
        MF.mesh.vertices = TransformedVertices;

        // Sometimes needed to clean up mesh
        MF.mesh.RecalculateNormals();
        MF.mesh.RecalculateBounds();



        /// return world position
        Vectors NewOriginLocation = CurrentLocation + Translation;
        Vectors NewOrigin         = Vectors.VLerp(NewOriginLocation, CurrentLocation, Time.deltaTime);

        r = NewOrigin;
        return(r);
    }
Esempio n. 2
0
    // Combine all quarternions (T * RPY * S) through matrices
    public static void QCombineM(Vectors Translation, Vectors Scale, Vectors AxisRots, Vector3[] ModelSpaceVertices, MeshFilter MF)
    {
        // Create Qauternions from raw data
        Quarts T   = QTrans(Translation);           // Not used because not working
        Quarts S   = QScale(Scale);
        Quarts RPY = QCombinedAxis(AxisRots);

        // Multiply in correct order
        //Quarts Order = T * RPY * S;

        // Define array of vertices
        Vector3[] TransformedVertices = new Vector3[ModelSpaceVertices.Length];


        // move vertexs to new position
        for (int i = 0; i < TransformedVertices.Length; i++)
        {
            // Convert Vertexs into Quaternions
            Vectors temp    = new Vectors(ModelSpaceVertices[i].x, ModelSpaceVertices[i].y, ModelSpaceVertices[i].z);
            Quarts  Vertexs = new Quarts(0, new Vectors(0, 0, 0));
            Vertexs.SetAxis(temp);

            // Remember TRS order (T omitted for now because its being weird)
            Quarts Combined = RPY * S;

            // Rotate & Scale vertexs
            Quarts  result = Combined * Vertexs * Combined.Inverse();
            Vectors finalV = GetAxis(result);

            // This is our basic vertex mover - just added onto the result of the Q matrix
            Vectors Move = new Vectors(Translation.x + finalV.x, Translation.y + finalV.y, Translation.z + finalV.z);

            // Move the Vertex to its new position
            TransformedVertices[i] = new Vector3(Move.x, Move.y, Move.z);
        }
        // Assign new Vertices
        MF.mesh.vertices = TransformedVertices;

        // Sometimes needed to clean up mesh
        MF.mesh.RecalculateNormals();
        MF.mesh.RecalculateBounds();
    }
Esempio n. 3
0
    // Create a quaternion translation from vector
    public static Quarts QTrans(Vectors A)
    {
        Quarts r     = new Quarts(0, new Vectors(0, 0, 0));
        Quarts TQ    = new Quarts(0, new Vectors(0, 0, 0));
        Quarts Angle = new Quarts(0, new Vectors(0, 1, 0));

        // Create matrices from axes
        //Matrix4X4 T = Matrix4X4.CreateTrans(A);   For some reason translation matrix not working
        //Vectors Translated = T * A;

        // Convert to quaternion
        //Quarts TQ = MatToQuat(T);

        // Create quaternion from vector
        TQ.SetAxis(A);
        //TQ = Angle * TQ * Angle.Inverse();

        // Set return value to the new position
        r = TQ;
        //r.SetAxis(Translated);
        return(r);
    }