public void CopyFrom(RenderState renderState) { if (OnDrawRequired != null) { uint currentTarget = _renderTarget != null ? _renderTarget.Base : 0; uint nextTarget = renderState._renderTarget != null ? renderState._renderTarget.Base : 0; bool clipRectChanges = _clipRect != null || renderState._clipRect != null ? !Rectangle.Compare(_clipRect, renderState._clipRect) : false; if (_blendMode != renderState._blendMode || _culling != renderState._culling || currentTarget != nextTarget || clipRectChanges) { OnDrawRequired(); } } Alpha = renderState.Alpha; _blendMode = renderState._blendMode; _renderTarget = renderState._renderTarget; _renderTargetOptions = renderState._renderTargetOptions; _culling = renderState._culling; _modelviewMatrix.CopyFromMatrix(renderState._modelviewMatrix); _projectionMatrix3D.CopyFrom(renderState._projectionMatrix3D); if (_clipRect != null || renderState._clipRect != null) { ClipRect = renderState._clipRect; } }
// 3D transformation /// <summary> /// Creates a matrix that represents the transformation from the local coordinate system /// to another. This method supports three dimensional objects created via 'Sprite3D'. /// </summary> public Matrix3D GetTransformationMatrix3D(DisplayObject targetSpace) { DisplayObject currentObject; Matrix3D outM = Matrix3D.Create(); if (targetSpace == this) { return(outM); } if (targetSpace == _parent || (targetSpace == null && _parent == null)) { outM.CopyFrom(TransformationMatrix3D); return(outM); } if (targetSpace == null || targetSpace == Base) { // targetCoordinateSpace 'null' represents the target space of the base object. // -> move up from this to base currentObject = this; while (currentObject != targetSpace) { outM.Append(currentObject.TransformationMatrix3D); currentObject = currentObject._parent; } return(outM); } if (targetSpace._parent == this) // optimization { outM = targetSpace.GetTransformationMatrix3D(this); outM.Invert(); return(outM); } // 1. find a common parent of this and the target space var commonParent = FindCommonParent(this, targetSpace); // 2. move up from this to common parent currentObject = this; while (currentObject != commonParent) { outM.Append(currentObject.TransformationMatrix3D); currentObject = currentObject._parent; } if (commonParent == targetSpace) { return(outM); } // 3. now move up from target until we reach the common parent var sHelperMatrix3D = Matrix3D.Create(); currentObject = targetSpace; while (currentObject != commonParent) { sHelperMatrix3D.Append(currentObject.TransformationMatrix3D); currentObject = currentObject._parent; } // 4. now combine the two matrices sHelperMatrix3D.Invert(); outM.Append(sHelperMatrix3D); return(outM); }