Example #1
0
    public void SetHole0(FSprite spriteHole)
    {
        _hole0Sprite=spriteHole;

        _hole0Texture=spriteHole.element.atlas.texture;

        spriteHole.UpdateMatrix();

        float factorX=Futile.resourceScale/spriteHole.element.atlas.textureSize.x;
        float factorY=Futile.resourceScale/spriteHole.element.atlas.textureSize.y;
        //do this if you have modified version of FElement that keeps the frame info
        _hole0LocalToUVParams=new Vector4( factorX , (spriteHole.element.frame.x+(-spriteHole.textureRect.x-spriteHole.element.sourceRect.x)*Futile.resourceScale)/spriteHole.element.atlas.textureSize.x , factorY , 1+(-(spriteHole.element.frame.y+spriteHole.element.frame.height)+(-spriteHole.textureRect.y-spriteHole.element.sourceRect.y)*Futile.resourceScale)/spriteHole.element.atlas.textureSize.y );
        //float elementFrameX=spriteHole.element.uvRect.x*spriteHole.element.atlas.textureSize.x;
        //float elementFrameY=-spriteHole.element.uvRect.y*spriteHole.element.atlas.textureSize.y+spriteHole.element.atlas.textureSize.y-spriteHole.element.uvRect.height*spriteHole.element.atlas.textureSize.y;
        //_hole0LocalToUVParams=new Vector4( factorX , (elementFrameX+(-spriteHole.textureRect.x-spriteHole.element.sourceRect.x)*Futile.resourceScale)/spriteHole.element.atlas.textureSize.x , factorY , 1+(-(elementFrameY+spriteHole.element.frame.height)+(-spriteHole.textureRect.y-spriteHole.element.sourceRect.y)*Futile.resourceScale)/spriteHole.element.atlas.textureSize.y );

        _hole0UVRect.x=spriteHole.element.uvRect.xMin;
        _hole0UVRect.y=spriteHole.element.uvRect.yMin;
        _hole0UVRect.z=spriteHole.element.uvRect.xMax;
        _hole0UVRect.w=spriteHole.element.uvRect.yMax;

        //test
        /* the old way of computing the uv in shader
        _hole0MatrixABCD=new Vector4(spriteHole.screenInverseConcatenatedMatrix.a,spriteHole.screenInverseConcatenatedMatrix.b,spriteHole.screenInverseConcatenatedMatrix.c,spriteHole.screenInverseConcatenatedMatrix.d);
        _hole0MatrixTxTy=new Vector4(spriteHole.screenInverseConcatenatedMatrix.tx,spriteHole.screenInverseConcatenatedMatrix.ty,0,0);
        Vector2 vertex=new Vector2(spriteHole.x,spriteHole.y);
        //vertex.x+=100;
        Vector2 tmp=new Vector2 ( (vertex.x+_screenParams.x)*_screenParams.z , (vertex.y+_screenParams.y)*_screenParams.z );
        //futile local sprite coords
        Vector2 local=new Vector2  ( tmp.x*_hole0MatrixABCD.x + tmp.y*_hole0MatrixABCD.z + _hole0MatrixTxTy.x , tmp.x*_hole0MatrixABCD.y + tmp.y*_hole0MatrixABCD.w + _hole0MatrixTxTy.y );
        //uv
        Vector2 uv=new Vector2 (local.x*_hole0LocalToUVParams.x + _hole0LocalToUVParams.y , local.y*_hole0LocalToUVParams.z + _hole0LocalToUVParams.w );

        Vector2 uv2=new Vector2 (

            //((vertex.x+_screenParams.x)*_screenParams.z*_hole0MatrixABCD.x + (vertex.y+_screenParams.y)*_screenParams.z*_hole0MatrixABCD.z + _hole0MatrixTxTy.x)*_hole0LocalToUVParams.x + _hole0LocalToUVParams.y ,

            vertex.x*_screenParams.z*_hole0MatrixABCD.x*_hole0LocalToUVParams.x    +    vertex.y*_screenParams.z*_hole0MatrixABCD.z*_hole0LocalToUVParams.x    +    (_screenParams.x*_screenParams.z*_hole0MatrixABCD.x + _screenParams.y*_screenParams.z*_hole0MatrixABCD.z + _hole0MatrixTxTy.x)*_hole0LocalToUVParams.x + _hole0LocalToUVParams.y,

            //((vertex.x+_screenParams.x)*_screenParams.z*_hole0MatrixABCD.y + (vertex.y+_screenParams.y)*_screenParams.z*_hole0MatrixABCD.w + _hole0MatrixTxTy.y)*_hole0LocalToUVParams.z + _hole0LocalToUVParams.w ,

            vertex.x*_screenParams.z*_hole0MatrixABCD.y*_hole0LocalToUVParams.z    +    vertex.y*_screenParams.z*_hole0MatrixABCD.w*_hole0LocalToUVParams.z    +    (_screenParams.x*_screenParams.z*_hole0MatrixABCD.y + _screenParams.y*_screenParams.z*_hole0MatrixABCD.w + _hole0MatrixTxTy.y)*_hole0LocalToUVParams.z + _hole0LocalToUVParams.w

            );
        /**/

        Hole0NeedUpdate();
        /*
        _hole0MatrixABCD.x=_screenParams.z*spriteHole.screenInverseConcatenatedMatrix.a*_hole0LocalToUVParams.x;
        _hole0MatrixABCD.z=_screenParams.z*spriteHole.screenInverseConcatenatedMatrix.c*_hole0LocalToUVParams.x;
        _hole0MatrixTxTy.x=(_screenParams.x*_screenParams.z*spriteHole.screenInverseConcatenatedMatrix.a + _screenParams.y*_screenParams.z*spriteHole.screenInverseConcatenatedMatrix.c + _hole0MatrixTxTy.x)*_hole0LocalToUVParams.x + _hole0LocalToUVParams.y;

        _hole0MatrixABCD.y=_screenParams.z*spriteHole.screenInverseConcatenatedMatrix.b*_hole0LocalToUVParams.z;
        _hole0MatrixABCD.w=_screenParams.z*spriteHole.screenInverseConcatenatedMatrix.d*_hole0LocalToUVParams.z;
        _hole0MatrixTxTy.y=(_screenParams.x*_screenParams.z*spriteHole.screenInverseConcatenatedMatrix.b + _screenParams.y*_screenParams.z*spriteHole.screenInverseConcatenatedMatrix.d + _hole0MatrixTxTy.y)*_hole0LocalToUVParams.z + _hole0LocalToUVParams.w;

        Vector2 uv3=new Vector2  ( _hole0Sprite.x*_hole0MatrixABCD.x + _hole0Sprite.y*_hole0MatrixABCD.z + _hole0MatrixTxTy.x , _hole0Sprite.x*_hole0MatrixABCD.y + _hole0Sprite.y*_hole0MatrixABCD.w + _hole0MatrixTxTy.y );
        */

        needsApply = true;
    }