public void TranslateTest() { AsMatrix matrix = new AsMatrix(); matrix.translate(100, 200); Assert.AreEqual(matrix.tx == 100 && matrix.ty == 200, true); }
public virtual void addQuad(AsQuad quad, float parentAlpha, AsTexture texture, String smoothing, AsMatrix modelViewMatrix, String blendMode) { if(modelViewMatrix == null) { modelViewMatrix = quad.getTransformationMatrix(); } bool tinted = texture != null ? quad.getTinted() || parentAlpha != 1.0f : false; float alpha = parentAlpha * quad.getAlpha(); int vertexID = mNumQuads * 4; if(mNumQuads + 1 > mVertexData.getNumVertices() / 4) { expand(); } if(mNumQuads == 0) { this.setBlendMode(blendMode != null ? blendMode : quad.getBlendMode()); mTexture = texture; mTinted = tinted; mSmoothing = smoothing; mVertexData.setPremultipliedAlpha(texture != null ? texture.getPremultipliedAlpha() : true, false); } quad.copyVertexDataTo(mVertexData, vertexID); mVertexData.transformVertex(vertexID, modelViewMatrix, 4); if(alpha != 1.0f) { mVertexData.scaleAlpha(vertexID, alpha, 4); } mSyncRequired = true; mNumQuads++; }
public AsDisplayObject() { if(AsCapabilities.getIsDebugger() && AsGlobal.getQualifiedClassName(this) == "starling.display::DisplayObject") { throw new AsAbstractClassError(); } mX = mY = mPivotX = mPivotY = mRotation = mSkewX = mSkewY = 0.0f; mScaleX = mScaleY = mAlpha = 1.0f; mVisible = mTouchable = true; mBlendMode = AsBlendMode.AUTO; mTransformationMatrix = new AsMatrix(); mOrientationChanged = mUseHandCursor = false; }
public static AsMatrix3D convertTo3D(AsMatrix matrix, AsMatrix3D resultMatrix) { if(resultMatrix == null) { resultMatrix = new AsMatrix3D(); } sRawData[0] = matrix.a; sRawData[1] = matrix.b; sRawData[4] = matrix.c; sRawData[5] = matrix.d; sRawData[12] = matrix.tx; sRawData[13] = matrix.ty; resultMatrix.copyRawDataFrom(sRawData); return resultMatrix; }
public AsRenderSupport() { mProjectionMatrix = new AsMatrix(); mModelViewMatrix = new AsMatrix(); mMvpMatrix = new AsMatrix(); mMvpMatrix3D = new AsMatrix3D(); mMatrixStack = new AsVector<AsMatrix>(); mMatrixStackSize = 0; mDrawCount = 0; mRenderTarget = null; mBlendMode = AsBlendMode.NORMAL; mCurrentQuadBatchID = 0; mQuadBatches = new AsVector<AsQuadBatch>(); loadIdentity(); setOrthographicProjection(0, 0, 400, 300); }
public static void skew(AsMatrix matrix, float skewX, float skewY) { float a = matrix.a; float b = matrix.b; float c = matrix.c; float d = matrix.d; float tx = matrix.tx; float ty = matrix.ty; float sinX = AsMath.sin(skewX); float cosX = AsMath.cos(skewX); float sinY = AsMath.sin(skewY); float cosY = AsMath.cos(skewY); matrix.a = a * cosY + c * sinY; matrix.b = b * cosY + d * sinY; matrix.c = c * cosX - a * sinX; matrix.d = d * cosX - b * sinX; }
public virtual void addImage(AsImage image, float parentAlpha, AsMatrix modelViewMatrix) { addImage(image, parentAlpha, modelViewMatrix, null); }
private static int compileObject(AsDisplayObject _object, AsVector<AsQuadBatch> quadBatches, int quadBatchID, AsMatrix transformationMatrix) { return compileObject(_object, quadBatches, quadBatchID, transformationMatrix, 1.0f, null, false); }
private static int compileObject(AsDisplayObject _object, AsVector<AsQuadBatch> quadBatches, int quadBatchID, AsMatrix transformationMatrix, float alpha, String blendMode, bool ignoreCurrentFilter) { int i = 0; AsQuadBatch quadBatch = null; bool isRootObject = false; float objectAlpha = _object.getAlpha(); AsDisplayObjectContainer container = _object as AsDisplayObjectContainer; AsQuad quad = _object as AsQuad; AsQuadBatch batch = _object as AsQuadBatch; AsFragmentFilter filter = _object.getFilter(); if(quadBatchID == -1) { isRootObject = true; quadBatchID = 0; objectAlpha = 1.0f; blendMode = _object.getBlendMode(); if(quadBatches.getLength() == 0) { quadBatches.push(new AsQuadBatch()); } else { quadBatches[0].reset(); } } if(filter != null && !ignoreCurrentFilter) { if(filter.getMode() == AsFragmentFilterMode.ABOVE) { quadBatchID = compileObject(_object, quadBatches, quadBatchID, transformationMatrix, alpha, blendMode, true); } quadBatchID = compileObject(filter.compile(_object), quadBatches, quadBatchID, transformationMatrix, alpha, blendMode); if(filter.getMode() == AsFragmentFilterMode.BELOW) { quadBatchID = compileObject(_object, quadBatches, quadBatchID, transformationMatrix, alpha, blendMode, true); } } else { if(container != null) { int numChildren = container.getNumChildren(); AsMatrix childMatrix = new AsMatrix(); for (i = 0; i < numChildren; ++i) { AsDisplayObject child = container.getChildAt(i); bool childVisible = child.getAlpha() != 0.0f && child.getVisible() && child.getScaleX() != 0.0f && child.getScaleY() != 0.0f; if(childVisible) { String childBlendMode = child.getBlendMode() == AsBlendMode.AUTO ? blendMode : child.getBlendMode(); childMatrix.copyFrom(transformationMatrix); AsRenderSupport.transformMatrixForObject(childMatrix, child); quadBatchID = compileObject(child, quadBatches, quadBatchID, childMatrix, alpha * objectAlpha, childBlendMode); } } } else { if(quad != null || batch != null) { AsTexture texture = null; String smoothing = null; bool tinted = false; int numQuads = 0; if(quad != null) { AsImage image = quad as AsImage; texture = image != null ? image.getTexture() : null; smoothing = image != null ? image.getSmoothing() : null; tinted = quad.getTinted(); numQuads = 1; } else { texture = batch.mTexture; smoothing = batch.mSmoothing; tinted = batch.mTinted; numQuads = batch.mNumQuads; } quadBatch = quadBatches[quadBatchID]; if(quadBatch.isStateChange(tinted, alpha * objectAlpha, texture, smoothing, blendMode, numQuads)) { quadBatchID++; if(quadBatches.getLength() <= quadBatchID) { quadBatches.push(new AsQuadBatch()); } quadBatch = quadBatches[quadBatchID]; quadBatch.reset(); } if(quad != null) { quadBatch.addQuad(quad, alpha, texture, smoothing, transformationMatrix, blendMode); } else { quadBatch.addQuadBatch(batch, alpha, transformationMatrix, blendMode); } } else { throw new AsError("Unsupported display object: " + AsGlobal.getQualifiedClassName(_object)); } } } if(isRootObject) { for (i = (int)(quadBatches.getLength() - 1); i > quadBatchID; --i) { quadBatches.pop().dispose(); } } return quadBatchID; }
public virtual void renderCustom(AsMatrix mvpMatrix, float parentAlpha) { renderCustom(mvpMatrix, parentAlpha, null); }
public virtual void addQuadBatch(AsQuadBatch quadBatch, float parentAlpha, AsMatrix modelViewMatrix) { addQuadBatch(quadBatch, parentAlpha, modelViewMatrix, null); }
public virtual void addQuad(AsQuad quad, float parentAlpha, AsTexture texture, String smoothing, AsMatrix modelViewMatrix) { addQuad(quad, parentAlpha, texture, smoothing, modelViewMatrix, null); }
public virtual void draw(AsIBitmapDrawable source, AsMatrix matrix, AsColorTransform colorTransform) { draw(source, null, null, null); }
public virtual void transform(AsMatrix matrix) { mCurrentMatrix.concat(matrix); }
public AsRenderSupport() { mMatrixStack = new AsVector<AsMatrix>(); mMatrixStackSize = 0; mCurrentMatrix = new AsMatrix(); }
public static AsPoint transformCoords(AsMatrix matrix, float x, float y, AsPoint resultPoint) { if (resultPoint == null) resultPoint = new AsPoint(); matrix.transformPointCords(x, y, resultPoint); return resultPoint; }
public void copyFrom(AsMatrix sourceMatrix) { internalMatrix = sourceMatrix.internalMatrix; }
public void concat(AsMatrix m) { concat(ref m.internalMatrix); }
public virtual AsMatrix getMatrix() { mMatrix = mDisplayObject.getTransformationMatrix(mDisplayObject.getParent(), mMatrix); return(mMatrix); }
public virtual void draw(AsIBitmapDrawable source, AsMatrix matrix, AsColorTransform colorTransform, String blendMode, AsRectangle clipRect) { draw(source, null, null, null, null, false); }
public static void uploadBitmapData(bc.flash.display3D.textures.AsTexture nativeTexture, AsBitmapData data, bool generateMipmaps) { nativeTexture.uploadFromBitmapData(data); if(generateMipmaps && data.getWidth() > 1 && data.getHeight() > 1) { int currentWidth = data.getWidth() >> 1; int currentHeight = data.getHeight() >> 1; int level = 1; AsBitmapData canvas = new AsBitmapData(currentWidth, currentHeight, true, 0); AsMatrix transform = new AsMatrix(.5f, 0, 0, .5f); AsRectangle bounds = new AsRectangle(); while(currentWidth >= 1 || currentHeight >= 1) { bounds.width = currentWidth; bounds.height = currentHeight; canvas.fillRect(bounds, (uint)(0)); canvas.draw(data, transform, null, null, null, true); nativeTexture.uploadFromBitmapData(canvas, (uint)(level++)); transform.scale(0.5f, 0.5f); currentWidth = currentWidth >> 1; currentHeight = currentHeight >> 1; } canvas.dispose(); } }
public virtual void draw(AsIBitmapDrawable source, AsMatrix matrix) { draw(source, null, null); }
public AsTransform(AsDisplayObject displayObject) { mDisplayObject = displayObject; mColorTransform = new AsColorTransform(); mMatrix = new AsMatrix(); }
public virtual void addQuadBatch(AsQuadBatch quadBatch, float parentAlpha, AsMatrix modelViewMatrix, String blendMode) { if(modelViewMatrix == null) { modelViewMatrix = quadBatch.getTransformationMatrix(); } bool tinted = quadBatch.mTinted || parentAlpha != 1.0f; float alpha = parentAlpha * quadBatch.getAlpha(); int vertexID = mNumQuads * 4; int numQuads = quadBatch.getNumQuads(); if(mNumQuads + numQuads > getCapacity()) { expand(mNumQuads + numQuads); } if(mNumQuads == 0) { this.setBlendMode(blendMode != null ? blendMode : quadBatch.getBlendMode()); mTexture = quadBatch.mTexture; mTinted = tinted; mSmoothing = quadBatch.mSmoothing; mVertexData.setPremultipliedAlpha(quadBatch.mVertexData.getPremultipliedAlpha(), false); } quadBatch.mVertexData.copyTo(mVertexData, vertexID, 0, numQuads * 4); mVertexData.transformVertex(vertexID, modelViewMatrix, numQuads * 4); if(alpha != 1.0f) { mVertexData.scaleAlpha(vertexID, alpha, numQuads * 4); } mSyncRequired = true; mNumQuads = mNumQuads + numQuads; }
public virtual AsMatrix getMatrix() { mMatrix = mDisplayObject.getTransformationMatrix(mDisplayObject.getParent()); return mMatrix; }
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); }
public virtual void setMatrix(AsMatrix _value) { mMatrix = _value; }
public virtual void renderCustom(AsMatrix mvpMatrix) { renderCustom(mvpMatrix, 1.0f, null); }
public virtual void transform(AsMatrix matrix) { BcRenderSupport.Transform(ref matrix.internalMatrix); }
private static int compileObject(AsDisplayObject _object, AsVector<AsQuadBatch> quadBatches, int quadBatchID, AsMatrix transformationMatrix, float alpha, String blendMode) { return compileObject(_object, quadBatches, quadBatchID, transformationMatrix, alpha, blendMode, false); }
public virtual void addImage(AsImage image, float parentAlpha, AsMatrix modelViewMatrix, String blendMode) { addQuad(image, parentAlpha, image.getTexture(), image.getSmoothing(), modelViewMatrix, blendMode); }
public virtual void draw(AsIBitmapDrawable source, AsMatrix matrix, AsColorTransform colorTransform, String blendMode, AsRectangle clipRect, bool smoothing) { }
public virtual AsMatrix getTransformationMatrix(AsDisplayObject targetSpace, AsMatrix resultMatrix) { if(resultMatrix != null) { resultMatrix.identity(); } else { resultMatrix = new AsMatrix(); } AsDisplayObject currentObject = this; if(targetSpace == this) { return resultMatrix; } else { if(targetSpace == mParent || (targetSpace == null && mParent == null)) { if(mPivotX != 0.0f || mPivotY != 0.0f) { resultMatrix.translate(-mPivotX, -mPivotY); } if(mScaleX != 1.0f || mScaleY != 1.0f) { resultMatrix.scale(mScaleX, mScaleY); } if(mRotation != 0.0f) { resultMatrix.rotate(AsMathHelper.toRadians(mRotation)); } if(mX != 0.0f || mY != 0.0f) { resultMatrix.translate(mX, mY); } return resultMatrix; } else { if(targetSpace == null) { currentObject = this; while(currentObject != null) { currentObject.getTransformationMatrix(currentObject.mParent, sHelperMatrix); resultMatrix.concat(sHelperMatrix); currentObject = currentObject.getParent(); } return resultMatrix; } else { if(targetSpace.mParent == this) { targetSpace.getTransformationMatrix(this, resultMatrix); resultMatrix.invert(); return resultMatrix; } } } } sAncestors.setLength(0); AsDisplayObject commonParent = null; while(currentObject != null) { sAncestors.push(currentObject); currentObject = currentObject.getParent(); } currentObject = targetSpace; while(currentObject != null && sAncestors.indexOf(currentObject) == -1) { currentObject = currentObject.getParent(); } if(currentObject == null) { throw new AsArgumentError("Object not connected to target"); } else { commonParent = currentObject; } currentObject = this; while(currentObject != commonParent) { currentObject.getTransformationMatrix(currentObject.mParent, sHelperMatrix); resultMatrix.concat(sHelperMatrix); currentObject = currentObject.getParent(); } sTargetMatrix.identity(); currentObject = targetSpace; while(currentObject != commonParent) { currentObject.getTransformationMatrix(currentObject.mParent, sHelperMatrix); sTargetMatrix.concat(sHelperMatrix); currentObject = currentObject.getParent(); } sTargetMatrix.invert(); resultMatrix.concat(sTargetMatrix); return resultMatrix; }