Exemplo n.º 1
0
        public void Matrix4x4_Clone()
        {
            Matrix4x4 m = CreateRandomMatrix();
            Matrix    c = null;

            Assert.DoesNotThrow(() => c = m.Clone());
            Assert.AreNotSame(m, c);
            Assert.AreEqual(m.GetType(), c.GetType(), "Clone() mast return the same matrix type");
        }
Exemplo n.º 2
0
        private void UpdateChildrenMatrices()
        {
            var mat = Matrix4x4.Identity;

            mat.M14 = FloatHelpers.SignalingNaN;
            mat.M24 = FloatHelpers.SignalingNaN;
            mat.M34 = FloatHelpers.SignalingNaN;
            mat.M44 = FloatHelpers.SignalingNaN;

            Matrix4x4[] matrices = new Matrix4x4[NumBounds];
            matrices.AsSpan().Fill(mat);

            CurrentMatrices = new SimpleArray <Matrix4x4>(matrices);
            LastMatrices    = new SimpleArray <Matrix4x4>((Matrix4x4[])matrices.Clone());
        }
Exemplo n.º 3
0
    // Start is called before the first frame update
    void Start()
    {
        //Get the mesh and the material from the
        this.mesh = MeshGetters.getTriMesh(1f, 2f);
        this.grassRenderMaterial = Resources.Load <Material>("Materials/Grass");
        grassTransforms          = new List <Matrix4x4[]>();

        float grassDensity = 0.3f;//1 blade of grass per area unit

        int[]     triangles = MeshGetters.getMeshTriangles(this.gameObject);
        Vector3[] vertices  = MeshGetters.getMeshVertices(this.gameObject);

        Vector3[] curVertices = new Vector3[3];

        int gtbi = 0;

        Matrix4x4[] grassTransformBuffer = new Matrix4x4[1023];
        //Iterate through our triangles array three at a time (one triangle)
        for (int i = 0; i < triangles.Length; i += 3)
        {
            //Convert to vertices
            curVertices[0] = Vector3.Scale(vertices[triangles[i]], transform.localScale) + transform.position;
            curVertices[1] = Vector3.Scale(vertices[triangles[i + 1]], transform.localScale) + transform.position;
            curVertices[2] = Vector3.Scale(vertices[triangles[i + 2]], transform.localScale) + transform.position;

            float area = GeometryFunctions.getTriangleArea(curVertices);

            int       numBlades = (int)(area * grassDensity);
            Vector3[] grassLocs = GeometryFunctions.getNLocationsOnTriangle(curVertices, numBlades);

            for (int j = 0; j < grassLocs.Length; j++)
            {
                if (gtbi == 1023)
                {
                    gtbi = 0;
                    Matrix4x4[] gtBufferCopy = (Matrix4x4[])grassTransformBuffer.Clone();
                    grassTransforms.Add(gtBufferCopy);
                }
                Quaternion rotationQuat = Quaternion.FromToRotation(transform.up, GeometryFunctions.getTriangleNormal(curVertices));
                grassTransformBuffer[gtbi] = Matrix4x4.TRS(grassLocs[j], rotationQuat, new Vector3(1, 1, 1));
                gtbi++;
            }
        }
        //Get them leftovers
        grassTransforms.Add(grassTransformBuffer);//this should be truncated and then added to the dynamic list based on the current j
        //will deal with it later
    }
Exemplo n.º 4
0
        private static Matrix4x4 ComputeInverse_Numerics_Matrix4x4_2(Matrix4x4 matrix)
        {
            Matrix4x4 invMatrix4x4 = (Matrix4x4)matrix.Clone();

            unsafe
            {
                fixed(float *invVecPtr = invMatrix4x4.MatrixBuffer)
                fixed(float *mVecPtr = matrix.MatrixBuffer)
                {
                    Mat4x4 mVec = Unsafe.Read <Mat4x4>(mVecPtr), invVec;

                    if (Mat4x4.Invert(mVec, out invVec) == false)
                    {
                        throw new InvalidOperationException("not invertible");
                    }

                    Unsafe.Write(invVecPtr, invVec);
                }
            }

            return(invMatrix4x4);
        }