public void Start(AnimContext animContext) { if (animContext != null) { _animQueue.Enqueue(animContext); } if (_inAnimation || !ReadyInQueue) { return; } if (_animQueue.Count > 0) { animContext = _animQueue.Dequeue(); if (_beforeTransform != null) { if (!_beforeTransform(animContext)) { return; } } _inAnimation = true; foreach (Transform transformParam in animContext.TransformParams) { transformParam.BeforeTransform(); _animContext = animContext; double intervalCounts = animContext.Frames;// animContext.Duration / _interval; transformParam.Delta = transformParam.ChangeAngle / intervalCounts; transformParam.Begin = 0; } } }
public void Update() { if (_inAnimation) { bool inAnimation = true; foreach (Transform transformParam in _animContext.TransformParams) { double delta = transformParam.Delta; inAnimation = true; if (transformParam.ChangeAngle > 0 && transformParam.Begin + transformParam.Delta > transformParam.ChangeAngle) { delta = transformParam.ChangeAngle - transformParam.Begin; inAnimation = false; } else if (transformParam.ChangeAngle < 0 && transformParam.Begin + transformParam.Delta < transformParam.ChangeAngle) { delta = transformParam.ChangeAngle - transformParam.Begin; inAnimation = false; } transformParam.DoTransform(delta); transformParam.Begin += delta; if (!inAnimation) { transformParam.Begin = 0; transformParam.AfterTransform(transformParam.ChangeAngle); } } if (!inAnimation) { if (_afterTransform != null && !_animContext.Silent) { _afterTransform(_animContext.Op); } _inAnimation = inAnimation; _animContext = null; } } }
private bool BeforeOp(AnimContext animContext) { string op = animContext.Op; if (op == CubeOperation.UndoOp) { //undo if (string.IsNullOrEmpty(_sequence)) { return(false); } op = CubeOperation.GetOp(ref _sequence, true, true); op = CubeOperation.GetReverseOp(op); if (!string.IsNullOrEmpty(op)) { animContext.Op = op; } } CubeSize size = CubeSize; double edgeX = CubieSize * size.Width / 2; double edgeY = CubieSize * size.Height / 2; double edgeZ = CubieSize * size.Depth / 2; if (op == CubeOperation.FoldOp || op == CubeOperation.UnFoldOp) { bool unfold = (op == CubeOperation.UnFoldOp); FaceTransform f = new FaceTransform("F", Axis.X, false, new Vector3D(0, edgeY, edgeZ), new Vector3D(), face => GetFaces(face)) { Silent = true, ChangeAngle = unfold ? -CubeOperation.PiOver2 : CubeOperation.PiOver2, Begin = 0, /* * Face = "F", * AxisTranslationFromOrigin = new Vector3D(0, edgeY, edgeZ), * Axis = Axis.X, * IsAxisMoving = false */ }; FaceTransform b = new FaceTransform("B", Axis.X, false, new Vector3D(0, edgeY, -edgeZ), new Vector3D(), face => GetFaces(face)) { Silent = true, ChangeAngle = unfold ? CubeOperation.PiOver2 : -CubeOperation.PiOver2, Begin = 0 /* * Face = "B", * AxisTranslationFromOrigin = new Vector3D(0, edgeY, -edgeZ), * Axis = Axis.X, * IsAxisMoving = false */ }; FaceTransform l = new FaceTransform("L", Axis.Z, false, new Vector3D(-edgeX, edgeY, 0), new Vector3D(), face => GetFaces(face)) { Silent = true, ChangeAngle = unfold ? -CubeOperation.PiOver2 : CubeOperation.PiOver2, Begin = 0, /* * Face = "L", * AxisTranslationFromOrigin = new Vector3D(-edgeX, edgeY, 0), * Axis = Axis.Z, * IsAxisMoving = false */ }; FaceTransform r = new FaceTransform("R", Axis.Z, false, new Vector3D(edgeX, edgeY, 0), new Vector3D(), face => GetFaces(face)) { Silent = true, ChangeAngle = unfold ? CubeOperation.PiOver2 : -CubeOperation.PiOver2, Begin = 0 /* * Face = "R", * AxisTranslationFromOrigin = new Vector3D(edgeX, edgeY, 0), * Axis = Axis.Z, * IsAxisMoving = false */ }; FaceTransform d; //if (unfold) { d = new FaceTransform("D", Axis.Z, true, new Vector3D(edgeX, -edgeY, 0), new Vector3D(edgeX, edgeY, 0), face => GetFaces(face)) { Silent = true, ChangeAngle = unfold ? CubeOperation.PiOver2 : -CubeOperation.PiOver2, Begin = 0 /* * Face = "D", * AxisTranslationFromOrigin = new Vector3D(edgeX, -edgeY, 0), * Axis2TranslationFromOrigin = new Vector3D(edgeX, edgeY, 0), * Axis = Axis.Z, * IsAxisMoving = true */ }; } animContext.TransformParams.Add(f); animContext.TransformParams.Add(b); animContext.TransformParams.Add(l); animContext.TransformParams.Add(r); animContext.TransformParams.Add(d); } else { if (!CubeOperation.IsValidOp(op)) { return(false); } BasicOp basicOp; bool isReverse; CubeOperation.GetBasicOp(op, out basicOp, out isReverse); CubieTransform transform = new CubieTransform(op, isReverse, basicOp, cn => Cubicles[cn]) { Silent = animContext.Silent }; transform.ChangeAngle = transform.RotateAngle - animContext.RotatedAngle; animContext.TransformParams.Add(transform); } return(true); }