Ejemplo n.º 1
0
    public void Transform()
    {
        LocalMat.SetTRS(Vector3.zero, Rotation, ScaleVector);
        if (Type == STYPE.BILLBOARD)
        {
            Transform transform = MainCamera.transform;
            MyTransform.LookAt(MyTransform.position + transform.rotation * Vector3.up, transform.rotation * Vector3.back);
        }
        WorldMat.SetTRS(MyTransform.position, MyTransform.rotation, Vector3.one);
        Matrix4x4  matrix4x  = WorldMat * LocalMat;
        VertexPool pool      = Vertexsegment.Pool;
        int        vertStart = Vertexsegment.VertStart;
        Vector3    vector    = matrix4x.MultiplyPoint3x4(v1);
        Vector3    vector2   = matrix4x.MultiplyPoint3x4(v2);
        Vector3    vector3   = matrix4x.MultiplyPoint3x4(v3);
        Vector3    vector4   = matrix4x.MultiplyPoint3x4(v4);

        if (Type == STYPE.BILLBOARD_SELF)
        {
            Vector3 zero  = Vector3.zero;
            Vector3 zero2 = Vector3.zero;
            float   num   = 0f;
            if (UVStretch == 0)
            {
                zero  = (vector + vector4) / 2f;
                zero2 = (vector2 + vector3) / 2f;
                num   = (vector4 - vector).magnitude;
            }
            else
            {
                zero  = (vector + vector2) / 2f;
                zero2 = (vector4 + vector3) / 2f;
                num   = (vector2 - vector).magnitude;
            }
            Vector3 lhs = zero - zero2;
            Vector3 rhs = MainCamera.transform.position - zero;
            Vector3 b   = Vector3.Cross(lhs, rhs);
            b.Normalize();
            b *= num * 0.5f;
            Vector3 rhs2 = MainCamera.transform.position - zero2;
            Vector3 b2   = Vector3.Cross(lhs, rhs2);
            b2.Normalize();
            b2 *= num * 0.5f;
            if (UVStretch == 0)
            {
                vector  = zero - b;
                vector4 = zero + b;
                vector2 = zero2 - b2;
                vector3 = zero2 + b2;
            }
            else
            {
                vector  = zero - b;
                vector2 = zero + b;
                vector4 = zero2 - b2;
                vector3 = zero2 + b2;
            }
        }
        pool.Vertices[vertStart]     = vector;
        pool.Vertices[vertStart + 1] = vector2;
        pool.Vertices[vertStart + 2] = vector3;
        pool.Vertices[vertStart + 3] = vector4;
    }
Ejemplo n.º 2
0
    //this function should be very optimized
    public void Transform()
    {
        LocalMat.SetTRS(Vector3.zero, Rotation, ScaleVector);

        if (Type == STYPE.BILLBOARD)
        {
            Transform t;
            t = MainCamera.transform;
            MyTransform.LookAt(MyTransform.position + t.rotation * Vector3.up, t.rotation * Vector3.back);
        }
        WorldMat.SetTRS(MyTransform.position, MyTransform.rotation, Vector3.one);
        Matrix4x4 mat = WorldMat * LocalMat;

        VertexPool pool  = Vertexsegment.Pool;
        int        index = Vertexsegment.VertStart;

        Vector3 v1w = mat.MultiplyPoint3x4(v1);
        Vector3 v2w = mat.MultiplyPoint3x4(v2);
        Vector3 v3w = mat.MultiplyPoint3x4(v3);
        Vector3 v4w = mat.MultiplyPoint3x4(v4);

        if (Type == STYPE.BILLBOARD_SELF)
        {
            Vector3 headElem = Vector3.zero;
            Vector3 tailElem = Vector3.zero;
            float   vWidth   = 0f;
            if (UVStretch == 0)
            {
                headElem = (v1w + v4w) / 2;
                tailElem = (v2w + v3w) / 2;
                vWidth   = (v4w - v1w).magnitude;
            }
            else
            {
                headElem = (v1w + v2w) / 2;
                tailElem = (v4w + v3w) / 2;
                vWidth   = (v2w - v1w).magnitude;
            }

            Vector3 chainTangent = headElem - tailElem;

            Vector3 vP1ToEye        = MainCamera.transform.position - headElem;
            Vector3 vPerpendicular1 = Vector3.Cross(chainTangent, vP1ToEye);
            vPerpendicular1.Normalize();
            vPerpendicular1 *= (vWidth * 0.5f);

            Vector3 vP2ToEye        = MainCamera.transform.position - tailElem;
            Vector3 vPerpendicular2 = Vector3.Cross(chainTangent, vP2ToEye);
            vPerpendicular2.Normalize();
            vPerpendicular2 *= (vWidth * 0.5f);

            if (UVStretch == 0)
            {
                v1w = headElem - vPerpendicular1;
                v4w = headElem + vPerpendicular1;
                v2w = tailElem - vPerpendicular2;
                v3w = tailElem + vPerpendicular2;
            }
            else
            {
                v1w = headElem - vPerpendicular1;
                v2w = headElem + vPerpendicular1;
                v4w = tailElem - vPerpendicular2;
                v3w = tailElem + vPerpendicular2;
            }
        }

        pool.Vertices[index + 0] = v1w;
        pool.Vertices[index + 1] = v2w;
        pool.Vertices[index + 2] = v3w;
        pool.Vertices[index + 3] = v4w;
    }
Ejemplo n.º 3
0
    public void Transform()
    {
        LocalMat.SetTRS(Vector3.zero, Rotation, ScaleVector);
        if (Type == STYPE.BILLBOARD)
        {
            var transform = MainCamera.transform;
            MyTransform.LookAt(MyTransform.position + transform.rotation * Vector3.up, transform.rotation * Vector3.back);
        }

        WorldMat.SetTRS(MyTransform.position, MyTransform.rotation, Vector3.one);
        var matrixx   = WorldMat * LocalMat;
        var pool      = Vertexsegment.Pool;
        var vertStart = Vertexsegment.VertStart;
        var vector    = matrixx.MultiplyPoint3x4(v1);
        var vector2   = matrixx.MultiplyPoint3x4(v2);
        var vector3   = matrixx.MultiplyPoint3x4(v3);
        var vector4   = matrixx.MultiplyPoint3x4(v4);

        if (Type == STYPE.BILLBOARD_SELF)
        {
            var zero      = Vector3.zero;
            var vector6   = Vector3.zero;
            var magnitude = 0f;
            if (UVStretch == 0)
            {
                zero    = (vector + vector4) / 2f;
                vector6 = (vector2 + vector3) / 2f;
                var vector7 = vector4 - vector;
                magnitude = vector7.magnitude;
            }
            else
            {
                zero    = (vector + vector2) / 2f;
                vector6 = (vector4 + vector3) / 2f;
                var vector8 = vector2 - vector;
                magnitude = vector8.magnitude;
            }

            var lhs      = zero - vector6;
            var rhs      = MainCamera.transform.position - zero;
            var vector11 = Vector3.Cross(lhs, rhs);
            vector11.Normalize();
            vector11 = vector11 * (magnitude * 0.5f);
            var vector12 = MainCamera.transform.position - vector6;
            var vector13 = Vector3.Cross(lhs, vector12);
            vector13.Normalize();
            vector13 = vector13 * (magnitude * 0.5f);
            if (UVStretch == 0)
            {
                vector  = zero - vector11;
                vector4 = zero + vector11;
                vector2 = vector6 - vector13;
                vector3 = vector6 + vector13;
            }
            else
            {
                vector  = zero - vector11;
                vector2 = zero + vector11;
                vector4 = vector6 - vector13;
                vector3 = vector6 + vector13;
            }
        }

        pool.Vertices[vertStart]     = vector;
        pool.Vertices[vertStart + 1] = vector2;
        pool.Vertices[vertStart + 2] = vector3;
        pool.Vertices[vertStart + 3] = vector4;
    }