コード例 #1
0
ファイル: MyStructures.cs プロジェクト: Pumpkikin/Orrery
    // Slerp Quaternion Method
    public static Quarts SLERP(Quarts A, Quarts B, float C)
    {
        C = Mathf.Clamp(C, 0.0f, 1.0f);

        Quarts  temp      = B * A.Inverse();
        Vectors AxisAngle = temp.GetAxisAngle();
        Quarts  temp2     = new Quarts(AxisAngle.w * C, new Vectors(AxisAngle.x, AxisAngle.y, AxisAngle.z));

        return(temp2 * A);
    }
コード例 #2
0
ファイル: MyStructures.cs プロジェクト: Pumpkikin/Orrery
    // 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);
    }
コード例 #3
0
ファイル: MyStructures.cs プロジェクト: Pumpkikin/Orrery
    // 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();
    }