コード例 #1
0
 public virtual AsMatrix getTransformationMatrix()
 {
     if (mOrientationChanged)
     {
         mOrientationChanged = false;
         mTransformationMatrix.identity();
         if (mSkewX != 0.0f || mSkewY != 0.0f)
         {
             AsMatrixUtil.skew(mTransformationMatrix, mSkewX, mSkewY);
         }
         if (mScaleX != 1.0f || mScaleY != 1.0f)
         {
             mTransformationMatrix.scale(mScaleX, mScaleY);
         }
         if (mRotation != 0.0f)
         {
             mTransformationMatrix.rotate(mRotation);
         }
         if (mX != 0.0f || mY != 0.0f)
         {
             mTransformationMatrix.translate(mX, mY);
         }
         if (mPivotX != 0.0f || mPivotY != 0.0f)
         {
             mTransformationMatrix.tx = mX - mTransformationMatrix.a * mPivotX - mTransformationMatrix.c * mPivotY;
             mTransformationMatrix.ty = mY - mTransformationMatrix.b * mPivotX - mTransformationMatrix.d * mPivotY;
         }
     }
     return(mTransformationMatrix);
 }
コード例 #2
0
 public virtual AsPoint getPreviousLocation(AsDisplayObject space, AsPoint resultPoint)
 {
     if (resultPoint == null)
     {
         resultPoint = new AsPoint();
     }
     mTarget.get_base().getTransformationMatrix(space, sHelperMatrix);
     return(AsMatrixUtil.transformCoords(sHelperMatrix, mPreviousGlobalX, mPreviousGlobalY, resultPoint));
 }
コード例 #3
0
        public virtual void renderCustom(AsMatrix mvpMatrix, float parentAlpha, String blendMode)
        {
            if (mNumQuads == 0)
            {
                return;
            }
            if (mSyncRequired)
            {
                syncBuffers();
            }
            bool        pma         = mVertexData.getPremultipliedAlpha();
            AsContext3D context     = AsStarling.getContext();
            bool        tinted      = mTinted || (parentAlpha != 1.0f);
            String      programName = mTexture != null?getImageProgramName(tinted, mTexture.getMipMapping(), mTexture.getRepeat(), mTexture.getFormat(), mSmoothing) : QUAD_PROGRAM_NAME;

            sRenderAlpha[0] = sRenderAlpha[1] = sRenderAlpha[2] = pma ? parentAlpha : 1.0f;
            sRenderAlpha[3] = parentAlpha;
            AsMatrixUtil.convertTo3D(mvpMatrix, sRenderMatrix);
            AsRenderSupport.setBlendFactors(pma, blendMode != null ? blendMode : this.getBlendMode());
            context.setProgram(AsStarling.getCurrent().getProgram(programName));
            context.setProgramConstantsFromVector(AsContext3DProgramType.VERTEX, 0, sRenderAlpha, 1);
            context.setProgramConstantsFromMatrix(AsContext3DProgramType.VERTEX, 1, sRenderMatrix, true);
            context.setVertexBufferAt(0, mVertexBuffer, AsVertexData.POSITION_OFFSET, AsContext3DVertexBufferFormat.FLOAT_2);
            if (mTexture == null || tinted)
            {
                context.setVertexBufferAt(1, mVertexBuffer, AsVertexData.COLOR_OFFSET, AsContext3DVertexBufferFormat.FLOAT_4);
            }
            if (mTexture != null)
            {
                context.setTextureAt(0, mTexture.get_base());
                context.setVertexBufferAt(2, mVertexBuffer, AsVertexData.TEXCOORD_OFFSET, AsContext3DVertexBufferFormat.FLOAT_2);
            }
            context.drawTriangles(mIndexBuffer, 0, mNumQuads * 2);
            if (mTexture != null)
            {
                context.setTextureAt(0, null);
                context.setVertexBufferAt(2, null);
            }
            context.setVertexBufferAt(1, null);
            context.setVertexBufferAt(0, null);
        }
コード例 #4
0
        public override AsRectangle getBounds(AsDisplayObject targetSpace, AsRectangle resultRect)
        {
            if (resultRect == null)
            {
                resultRect = new AsRectangle();
            }
            int numChildren = (int)(mChildren.getLength());

            if (numChildren == 0)
            {
                getTransformationMatrix(targetSpace, sHelperMatrix);
                AsMatrixUtil.transformCoords(sHelperMatrix, 0.0f, 0.0f, sHelperPoint);
                resultRect.setTo(sHelperPoint.x, sHelperPoint.y, 0, 0);
                return(resultRect);
            }
            else
            {
                if (numChildren == 1)
                {
                    return(mChildren[0].getBounds(targetSpace, resultRect));
                }
                else
                {
                    float minX = AsNumber.MAX_VALUE;
                    float maxX = -AsNumber.MAX_VALUE;
                    float minY = AsNumber.MAX_VALUE;
                    float maxY = -AsNumber.MAX_VALUE;
                    int   i    = 0;
                    for (; i < numChildren; ++i)
                    {
                        mChildren[i].getBounds(targetSpace, resultRect);
                        minX = minX < resultRect.x ? minX : resultRect.x;
                        maxX = maxX > resultRect.getRight() ? maxX : resultRect.getRight();
                        minY = minY < resultRect.y ? minY : resultRect.y;
                        maxY = maxY > resultRect.getBottom() ? maxY : resultRect.getBottom();
                    }
                    resultRect.setTo(minX, minY, maxX - minX, maxY - minY);
                    return(resultRect);
                }
            }
        }
コード例 #5
0
        public override AsDisplayObject hitTest(AsPoint localPoint, bool forTouch)
        {
            if (forTouch && (!getVisible() || !getTouchable()))
            {
                return(null);
            }
            float localX      = localPoint.x;
            float localY      = localPoint.y;
            int   numChildren = (int)(mChildren.getLength());
            int   i           = numChildren - 1;

            for (; i >= 0; --i)
            {
                AsDisplayObject child = mChildren[i];
                getTransformationMatrix(child, sHelperMatrix);
                AsMatrixUtil.transformCoords(sHelperMatrix, localX, localY, sHelperPoint);
                AsDisplayObject target = child.hitTest(sHelperPoint, forTouch);
                if (target != null)
                {
                    return(target);
                }
            }
            return(null);
        }
コード例 #6
0
 public virtual AsPoint globalToLocal(AsPoint globalPoint, AsPoint resultPoint)
 {
     getTransformationMatrix(get_base(), sHelperMatrix);
     sHelperMatrix.invert();
     return(AsMatrixUtil.transformCoords(sHelperMatrix, globalPoint.x, globalPoint.y, resultPoint));
 }
コード例 #7
0
        private AsQuadBatch renderPasses(AsDisplayObject _object, AsRenderSupport support, float parentAlpha, bool intoCache)
        {
            AsTexture   cacheTexture = null;
            AsStage     stage        = _object.getStage();
            AsContext3D context      = AsStarling.getContext();
            float       scale        = AsStarling.getCurrent().getContentScaleFactor();

            if (stage == null)
            {
                throw new AsError("Filtered object must be on the stage.");
            }
            if (context == null)
            {
                throw new AsMissingContextError();
            }
            support.finishQuadBatch();
            support.raiseDrawCount((uint)(mNumPasses));
            support.pushMatrix();
            support.setBlendMode(AsBlendMode.NORMAL);
            AsRenderSupport.setBlendFactors(PMA);
            mProjMatrix.copyFrom(support.getProjectionMatrix());
            AsTexture previousRenderTarget = support.getRenderTarget();

            if (previousRenderTarget != null)
            {
                throw new AsIllegalOperationError("It's currently not possible to stack filters! " + "This limitation will be removed in a future Stage3D version.");
            }
            calculateBounds(_object, stage, sBounds);
            updateBuffers(context, sBounds);
            updatePassTextures((int)(sBounds.width), (int)(sBounds.height), mResolution * scale);
            if (intoCache)
            {
                cacheTexture = AsTexture.empty((int)(sBounds.width), (int)(sBounds.height), PMA, true, mResolution * scale);
            }
            support.setRenderTarget(mPassTextures[0]);
            support.clear();
            support.setOrthographicProjection(sBounds.x, sBounds.y, sBounds.width, sBounds.height);
            _object.render(support, parentAlpha);
            support.finishQuadBatch();
            AsRenderSupport.setBlendFactors(PMA);
            support.loadIdentity();
            context.setVertexBufferAt(0, mVertexBuffer, AsVertexData.POSITION_OFFSET, AsContext3DVertexBufferFormat.FLOAT_2);
            context.setVertexBufferAt(1, mVertexBuffer, AsVertexData.TEXCOORD_OFFSET, AsContext3DVertexBufferFormat.FLOAT_2);
            int i = 0;

            for (; i < mNumPasses; ++i)
            {
                if (i < mNumPasses - 1)
                {
                    support.setRenderTarget(getPassTexture(i + 1));
                    support.clear();
                }
                else
                {
                    if (intoCache)
                    {
                        support.setRenderTarget(cacheTexture);
                        support.clear();
                    }
                    else
                    {
                        support.setRenderTarget(previousRenderTarget);
                        support.getProjectionMatrix().copyFrom(mProjMatrix);
                        support.translateMatrix(mOffsetX, mOffsetY);
                        support.setBlendMode(_object.getBlendMode());
                        support.applyBlendMode(PMA);
                    }
                }
                AsTexture passTexture = getPassTexture(i);
                context.setProgramConstantsFromMatrix(AsContext3DProgramType.VERTEX, 0, support.getMvpMatrix3D(), true);
                context.setTextureAt(0, passTexture.get_base());
                activate(i, context, passTexture);
                context.drawTriangles(mIndexBuffer, 0, 2);
                deactivate(i, context, passTexture);
            }
            context.setVertexBufferAt(0, null);
            context.setVertexBufferAt(1, null);
            context.setTextureAt(0, null);
            support.popMatrix();
            if (intoCache)
            {
                support.setRenderTarget(previousRenderTarget);
                support.getProjectionMatrix().copyFrom(mProjMatrix);
                AsQuadBatch quadBatch = new AsQuadBatch();
                AsImage     image     = new AsImage(cacheTexture);
                stage.getTransformationMatrix(_object, sTransformationMatrix);
                AsMatrixUtil.prependTranslation(sTransformationMatrix, sBounds.x + mOffsetX, sBounds.y + mOffsetY);
                quadBatch.addImage(image, 1.0f, sTransformationMatrix);
                return(quadBatch);
            }
            else
            {
                return(null);
            }
        }
コード例 #8
0
 public virtual void prependMatrix(AsMatrix matrix)
 {
     AsMatrixUtil.prependMatrix(mModelViewMatrix, matrix);
 }
コード例 #9
0
 public virtual void transformMatrix(AsDisplayObject _object)
 {
     AsMatrixUtil.prependMatrix(mModelViewMatrix, _object.getTransformationMatrix());
 }
コード例 #10
0
 public virtual void scaleMatrix(float sx, float sy)
 {
     AsMatrixUtil.prependScale(mModelViewMatrix, sx, sy);
 }
コード例 #11
0
 public virtual void rotateMatrix(float angle)
 {
     AsMatrixUtil.prependRotation(mModelViewMatrix, angle);
 }
コード例 #12
0
 public virtual void translateMatrix(float dx, float dy)
 {
     AsMatrixUtil.prependTranslation(mModelViewMatrix, dx, dy);
 }
コード例 #13
0
 public virtual AsMatrix3D getMvpMatrix3D()
 {
     return(AsMatrixUtil.convertTo3D(getMvpMatrix(), mMvpMatrix3D));
 }
コード例 #14
0
 public static void transformMatrixForObject(AsMatrix matrix, AsDisplayObject _object)
 {
     AsMatrixUtil.prependMatrix(matrix, _object.getTransformationMatrix());
 }