public Object Clone()
        {
            PMatrix r = new PMatrix();

            r.Multiply(this);
            return(r);
        }
Esempio n. 2
0
		/// <summary>
		/// Pushes the given matrix onto the matrix stack.
		/// </summary>
		/// <param name="aMatrix">The matrix to push.</param>
		public virtual void PushMatrix(PMatrix aMatrix) {
			matrixStack.Push(new PTuple(PickedNode, aMatrix));
			if (aMatrix != null) {
				RectangleF newPickBounds = aMatrix.InverseTransform(PickBounds);
				pickBoundsStack.Push(newPickBounds);
			}
		}
 /// <summary>
 /// Pops a matrix from the transform stack.
 /// </summary>
 /// <param name="matrix">The matrix to pop.</param>
 /// <remarks>This method also pops a clip from the local clip stack.</remarks>
 public virtual void PopTransform(PMatrix matrix)
 {
     if (matrix == null)
     {
         return;
     }
     graphics.Matrix = (PMatrix)transformStack.Pop();
     localClipStack.Pop();
 }
        public override bool Equals(object obj)
        {
            PMatrix otherMatrix = (PMatrix)obj;

            return(offsetX == otherMatrix.offsetX &&
                   offsetY == otherMatrix.offsetY &&
                   //scale == otherMatrix.scale);
                   scaleX == otherMatrix.scaleX &&
                   scaleY == otherMatrix.scaleY);
        }
        public void Multiply(PMatrix aTransform)
        {
            ScaleBy(aTransform.scaleX, aTransform.scaleY);
            offsetX = aTransform.scaleX * offsetX + aTransform.OffsetX;
            offsetY = aTransform.scaleY * offsetY + aTransform.OffsetY;

            //ScaleBy(aTransform.scale);
            //offsetX = aTransform.scale * offsetX + aTransform.OffsetX;
            //offsetY = aTransform.scale * offsetY + aTransform.OffsetY;
        }
        /// <summary>
        /// Pushes the given matrix onto the transform stack.
        /// </summary>
        /// <param name="matrix">The matrix to push.</param>
        /// <remarks>
        /// This method also applies the matrix to the graphics context and the current local clip.
        /// The new local clip is then pushed onto the local clip stack.
        /// </remarks>
        public virtual void PushTransform(PMatrix matrix)
        {
            if (matrix == null)
            {
                return;
            }
            RectangleF newLocalClip = matrix.InverseTransform(LocalClip);

            transformStack.Push(graphics.Matrix);
            localClipStack.Push(newLocalClip);
            graphics.MultiplyTransform(matrix);
        }
Esempio n. 7
0
		/// <summary>
		/// Returns the product of the matrices from the top-most ancestor node (the last node
		/// in the list) to the given node.
		/// </summary>
		/// <param name="nodeOnPath">
		/// The bottom-most node in the path for which the matrix product will be computed.
		/// </param>
		/// <returns>
		/// The product of the matrices from the top-most node to the given node.
		/// </returns>
		public virtual PMatrix GetPathTransformTo(PNode nodeOnPath) {
			PMatrix aMatrix = new PMatrix();

			object[] matrices = matrixStack.ToArray();
			int count = matrices.Length;
			for (int i = count - 1; i >= 0; i--) {
				PTuple each = (PTuple) matrices[i];
				if (each.matrix != null) aMatrix.Multiply(each.matrix);
				if (nodeOnPath == each.node) {
					return aMatrix;
				}
			}
		
			return aMatrix;
		}
Esempio n. 8
0
 /// <summary>
 /// Animate this node's matrix from its current values when the activity
 /// starts to the new values specified in the given matrix.
 /// </summary>
 /// <param name="destMatrix">The final matrix value.</param>
 /// <param name="duration">The amount of time that the animation should take.</param>
 /// <returns>The newly scheduled activity</returns>
 /// <remarks>
 /// If this node descends from the root then the activity will be scheduled,
 /// else the returned activity should be scheduled manually. If two different
 /// transform activities are scheduled for the same node at the same time,
 /// they will both be applied to the node, but the last one scheduled will be
 /// applied last on each frame, so it will appear to have replaced the
 /// original. Generally you will not want to do that.
 /// </remarks>
 public virtual PTransformActivity AnimateToMatrix(PMatrix destMatrix, long duration)
 {
     PTransformActivity.Target t = new PNodeTransformTarget(this);
     PTransformActivity ta = new PTransformActivity(duration, PUtil.DEFAULT_ACTIVITY_STEP_RATE, t, destMatrix);
     AddActivity(ta);
     return ta;
 }
Esempio n. 9
0
 public Object Clone()
 {
     PMatrix r = new PMatrix();
     r.Multiply(this);
     return r;
 }
        /// <summary>
        /// Animate the camera's view matrix from its current value when the activity
        /// starts to the new destination matrix value.
        /// </summary>
        /// <param name="aCamera">The camera whose view matrix will be animated.</param>
        /// <param name="aMatrix">The final matrix value.</param>
        /// <param name="duration">
        /// The amount of time that the animation should take.
        /// </param>
        /// <returns>
        /// The newly scheduled activity, if the duration is greater than 0; else null.
        /// </returns>
        protected virtual PActivity AnimateCameraViewMatrixTo(PCamera aCamera, PMatrix aMatrix, int duration)
        {
            bool wasOldAnimation = false;

            // first stop any old animations.
            if (navigationActivity != null) {
                navigationActivity.Terminate();
                wasOldAnimation = true;
            }

            if (duration == 0) {
                aCamera.ViewMatrix = aMatrix;
                return null;
            }

            PMatrix source = aCamera.ViewMatrixReference;

            //if (!source.MatrixReference.Equals(aMatrix.MatrixReference)) {
            if (!source.Equals(aMatrix)) {
                navigationActivity = aCamera.AnimateViewToMatrix(aMatrix, duration);
                ((PTransformActivity)navigationActivity).SlowInSlowOut = !wasOldAnimation;
                return navigationActivity;
            }

            return null;
        }
Esempio n. 11
0
 /// <summary>
 /// Overridden.  See <see cref="PInterpolatingActivity.OnActivityStarted">
 /// PInterpolatingActivity.OnActivityStarted</see>.
 /// </summary>
 protected override void OnActivityStarted()
 {
     //if (FirstLoop) source = target.GetMatrix().MatrixReference.Elements;
     if (FirstLoop) source = (PMatrix)target.Matrix.Clone(); //.MatrixReference.Elements;
     base.OnActivityStarted();
 }
Esempio n. 12
0
        public void Multiply(PMatrix aTransform)
        {
            ScaleBy(aTransform.scaleX, aTransform.scaleY);
            offsetX = aTransform.scaleX * offsetX + aTransform.OffsetX;
            offsetY = aTransform.scaleY * offsetY + aTransform.OffsetY;

            //ScaleBy(aTransform.scale);
            //offsetX = aTransform.scale * offsetX + aTransform.OffsetX;
            //offsetY = aTransform.scale * offsetY + aTransform.OffsetY;
        }
Esempio n. 13
0
        /// <summary>
        /// Constructs a new PTransformActivity that animate between the source and destination
        /// matrices in the order specified by the mode, looping the given number of iterations.
        /// </summary>
        /// <param name="duration">The length of one loop of the activity.</param>
        /// <param name="stepInterval">
        /// The minimum number of milliseconds that this activity should delay between steps.
        /// </param>
        /// <param name="loopCount">
        /// The number of times the activity should reschedule itself.
        /// </param>
        /// <param name="mode">
        /// Defines how the activity interpolates between states.
        /// </param>
        /// <param name="aTarget">
        /// The object that the activity will be applied to and where the source
        /// state will be taken from.
        /// </param>
        /// <param name="aDestination">The destination matrix.</param>
        public PTransformActivity(long duration, long stepInterval, int loopCount, ActivityMode mode, Target aTarget, PMatrix aDestination)
            : base(duration, stepInterval, loopCount, mode)
        {
            //source = new float[6];
            //destination = new float[6];
            target = aTarget;
            //if (aDestination != null) {
            //	destination = aDestination.MatrixReference.Elements;
            //}

            source = new PMatrix();
            destination = new PMatrix();
            destination.Multiply(aDestination);
        }
Esempio n. 14
0
        /// <summary>
        /// Gets a string representation of the elements of a matrix.
        /// </summary>
        /// <param name="elements">The elements of a matrix.</param>
        /// <returns>A string representation of the elements of a matrix.</returns>
        protected static String GetElementString(PMatrix elements)
        {
            return (elements.OffsetX + " " + elements.OffsetY + " " + elements.Scale);
            /*
            StringBuilder result = new StringBuilder();

            int length = elements.Length;
            for (int i = 0; i < elements.Length; i++) {
                result.Append(elements[i].ToString());
                if (i < length-1) result.Append(", ");
            }

            return result.ToString();
            */
        }
Esempio n. 15
0
 public Graphics2D(Graphics graphics)
 {
     this.graphics = graphics;
     matrix = new PMatrix();
 }
Esempio n. 16
0
 /// <summary>
 /// Constructs a new PTransformActivity that will animate from the source matrix
 /// to the destination matrix.
 /// </summary>
 /// <param name="duration">The length of one loop of the activity.</param>
 /// <param name="stepInterval">
 /// The minimum number of milliseconds that this activity should delay between
 /// steps.
 /// </param>
 /// <param name="aTarget">
 /// The object that the activity will be applied to and where the source
 /// state will be taken from.
 /// </param>
 /// <param name="aDestination">The destination matrix.</param>
 public PTransformActivity(long duration, long stepInterval, Target aTarget, PMatrix aDestination)
     : this(duration, stepInterval, 1, ActivityMode.SourceToDestination, aTarget, aDestination)
 {
 }
Esempio n. 17
0
        /// <summary>
        /// Constructs a new camera with no layers and a default white color.
        /// </summary>
        public PCamera()
            : base()
        {
            viewMatrix = new PMatrix();
            layers = new PLayerList();
            viewConstraint = CameraViewConstraint.None;

            Brush = new SolidBrush(Color.White);
        }
Esempio n. 18
0
 /// <summary>
 /// Pops a matrix from the transform stack.
 /// </summary>
 /// <param name="matrix">The matrix to pop.</param>
 /// <remarks>This method also pops a clip from the local clip stack.</remarks>
 public virtual void PopTransform(PMatrix matrix)
 {
     if (matrix == null) return;
     graphics.Matrix = (PMatrix) transformStack.Pop();
     localClipStack.Pop();
 }
Esempio n. 19
0
 /// <summary>
 /// Constructs a new PNode.
 /// </summary>
 /// <Remarks>
 /// By default a node's brush is null, and bounds are empty. These values
 /// must be set for the node to show up on the screen once it's added to
 /// a scene graph.
 /// </Remarks>
 public PNode()
 {
     bounds = RectangleF.Empty;
     fullBoundsCache = RectangleF.Empty;
     //transparency = 1.0f;
     pickable = true;
     childrenPickable = true;
     matrix = new PMatrix();
     handlers = new EventHandlerList();
     Visible = true;
 }
Esempio n. 20
0
		/// <summary>
		/// Pops a matrix from the matrix stack.
		/// </summary>
		/// <param name="aMatrix">The matrix to pop.</param>
		public virtual void PopMatrix(PMatrix aMatrix) {
			matrixStack.Pop();
			if (aMatrix != null) {
				pickBoundsStack.Pop();
			}
		}
Esempio n. 21
0
 /// <summary>
 /// Pushes the given matrix onto the transform stack.
 /// </summary>
 /// <param name="matrix">The matrix to push.</param>
 /// <remarks>
 /// This method also applies the matrix to the graphics context and the current local clip.
 /// The new local clip is then pushed onto the local clip stack.
 /// </remarks>
 public virtual void PushTransform(PMatrix matrix)
 {
     if (matrix == null) return;
     RectangleF newLocalClip = matrix.InverseTransform(LocalClip);
     transformStack.Push(graphics.Matrix);
     localClipStack.Push(newLocalClip);
     graphics.MultiplyTransform(matrix);
 }
Esempio n. 22
0
 public virtual void MultiplyTransform(PMatrix matrix)
 {
     TranslateTransform(matrix.OffsetX, matrix.OffsetY);
     ScaleTransform(matrix.Scale);
 }
Esempio n. 23
0
 public Graphics2D(Graphics graphics)
 {
     this.graphics = graphics;
     matrix        = new PMatrix();
 }
Esempio n. 24
0
 /// <summary>
 /// Transform this node's matrix by the given matrix.
 /// </summary>
 /// <param name="matrix">The transform to apply.</param>
 public virtual void TransformBy(PMatrix matrix)
 {
     this.matrix.Multiply(matrix);
     InvalidatePaint();
     InvalidateFullBounds();
     FirePropertyChangedEvent(transformEventKey, null, matrix);
 }
Esempio n. 25
0
		/// <summary>
		/// Creates a new PTuple that associates the given node witht he given matrix.
		/// </summary>
		/// <param name="n">The node to associate with the matrix.</param>
		/// <param name="m">The matrix to associate with the node.</param>
		public PTuple(PNode n, PMatrix m) {
			node = n;
			matrix = m;
		}
Esempio n. 26
0
        /// <summary>
        /// Animate the camera's view matrix from its current value when the activity starts
        /// to the new destination matrix value.
        /// </summary>
        /// <param name="destination">The final matrix value.</param>
        /// <param name="duration">The amount of time that the animation should take.</param>
        /// <returns>
        /// The newly scheduled activity, if the duration is greater than 0; else null.
        /// </returns>
        public virtual PTransformActivity AnimateViewToMatrix(PMatrix destination, long duration)
        {
            if (duration == 0) {
                ViewMatrix = destination;
                return null;
            }

            PTransformActivity ta = new PTransformActivity(duration, PUtil.DEFAULT_ACTIVITY_STEP_RATE, new PCameraTransformTarget(this), destination);

            PRoot r = Root;
            if (r != null) {
                r.AddActivity(ta);
            }

            return ta;
        }
Esempio n. 27
0
 public virtual void MultiplyTransform(PMatrix matrix)
 {
     TranslateTransform(matrix.OffsetX, matrix.OffsetY);
     ScaleTransform(matrix.Scale);
 }