public Quat GetRotation()
    {
        //Convert Rotation to radians
        MyVector3 RotationInRadians = new MyVector3();         //Creates Rotation in radians

        RotationInRadians.x = VectorMaths.Deg2Rad(Rotation.x); //Converts Rotation x to Radians
        RotationInRadians.y = VectorMaths.Deg2Rad(Rotation.y); //Converts Rotation y to Radians
        RotationInRadians.z = VectorMaths.Deg2Rad(Rotation.z); //Converts Rotation z to Radians

        //Convert Rotation to Quat
        Quat RET = Quat.EulerToQuat(RotationInRadians);

        //Return rotation
        return(RET); //Create RET
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        Camera AlphaCam;

        AlphaCam = GetComponent <Camera>();
        myTransformation Focus       = SFocus;
        MyVector3        Camera      = new MyVector3(Focus.Rotation.x, Focus.Rotation.y, Focus.Rotation.z);
        MyVector3        CameraInRad = new MyVector3();

        CameraInRad.x = VectorMaths.Deg2Rad(Camera.x);
        CameraInRad.y = VectorMaths.Deg2Rad(Camera.y);
        CameraInRad.z = VectorMaths.Deg2Rad(Camera.z);
        Quat Temp = Quat.EulerToQuat(CameraInRad);

        AlphaCam.transform.position = new Vector3(Focus.Translation.x, Focus.Translation.y, Focus.Translation.z);
        AlphaCam.transform.rotation = new Quaternion(
            -Temp.x,
            -Temp.y,
            Temp.z,
            Temp.w);
    }
    void Update()
    {
        Vector3[] TransformedVertices = new Vector3[ModelSpaceVertices.Length];   //Creates Transformed Vertices And sets array length to stop memory leak issues
        //Scale MAtrix created by setting scale diagonaly down a matrix
        Matrix4B4 scaleMatrix = new Matrix4B4(
            new MyVector3(Scale.x, 0, 0),
            new MyVector3(0, Scale.y, 0),
            new MyVector3(0, 0, Scale.z),
            MyVector3.zero
            );
        //Translation Matrix, created by using an identity matrix for first 3 rows then set last row to be translation
        Matrix4B4 translationMatrix = new Matrix4B4(
            new MyVector3(1, 0, 0),
            new MyVector3(0, 1, 0),
            new MyVector3(0, 0, 1),
            new MyVector3(Translation.x, Translation.y, Translation.z)
            );

        //Rotatio
        MyVector3 RotationInRadians = new MyVector3();  //Creates Rotation in radians

        //Convert Rotation to Radians
        RotationInRadians.x = VectorMaths.Deg2Rad(Rotation.x);          //Converts Rotation x to Radians
        RotationInRadians.y = VectorMaths.Deg2Rad(Rotation.y);          //Converts Rotation y to Radians
        RotationInRadians.z = VectorMaths.Deg2Rad(Rotation.z);          //Converts Rotation z to Radians

        QuatRotation   = Quat.EulerToQuat(RotationInRadians);           //Convert Euler Rotation To Quat Rotation
        RotationMatrix = Matrix4B4.QuatToMatrix(QuatRotation);          //Convert Quat rotation to matrix
        Matrix4B4 M = translationMatrix * RotationMatrix * scaleMatrix; //Transformation matrix set my multiplying matrcies in TRS ordeer

        //Loop through Model points and transform them from local to world
        for (int i = 0; i < TransformedVertices.Length; i++)
        {
            TransformedVertices[i] = M * ModelSpaceVertices[i];   //Transform vertices by multiplying matrix by Model spacee verticies
        }

        //Goes through all model space vertices to create model bounds
        for (int i = 0; i < ModelSpaceVertices.Length; i++)
        {
            //If Model space vertice is less then model min extent then set model min extent to be model space verticies repeats for x y and z

            if (ModelSpaceVertices[i].x < ModelMinExtent.x)
            {
                ModelMinExtent.x = ModelSpaceVertices[i].x;  //Set Model Min Extent x to model space vertices x
            }
            if (ModelSpaceVertices[i].y < ModelMinExtent.y)
            {
                ModelMinExtent.y = ModelSpaceVertices[i].y;   //Set Model Min Extent y to model space vertices y
            }
            if (ModelSpaceVertices[i].z < ModelMinExtent.z)
            {
                ModelMinExtent.z = ModelSpaceVertices[i].z;   //Set Model Min Extent z to model space vertices z
            }

            //If Model space vertice is more then model max extent then set model max extent to be model space verticies repeats for x y and z
            if (ModelSpaceVertices[i].x > ModelMaxExtent.x)
            {
                ModelMaxExtent.x = ModelSpaceVertices[i].x;  //Set Model Max Extent x to model space vertices x
            }
            if (ModelSpaceVertices[i].y > ModelMaxExtent.y)
            {
                ModelMaxExtent.y = ModelSpaceVertices[i].y;   //Set Model Max Extent y to model space vertices y
            }
            if (ModelSpaceVertices[i].z > ModelMaxExtent.z)
            {
                ModelMaxExtent.z = ModelSpaceVertices[i].z;   //Set Model Max Extent z to model space vertices z
            }
        }

        //Unity Mesh Filter
        MeshFilter MF = GetComponent <MeshFilter>(); //Gets mesh filter

        MF.mesh.vertices = TransformedVertices;      //Sets vertices to be the transformed vertices
        MF.mesh.RecalculateNormals();                //Calls Recalculate Normal
        MF.mesh.RecalculateBounds();                 //Calls Recalculate bounds
    }