• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: determining the result of a CAAnimation instance for time 't'
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: determining the result of a CAAnimation instance for time 't'


  • Subject: Re: determining the result of a CAAnimation instance for time 't'
  • From: John Clayton <email@hidden>
  • Date: Wed, 28 Nov 2007 22:42:48 +0100

Hi John,

I am already using CARenderer to render a layer into a CAOpenGLLayer (because I want to composite my results further), the problem comes when I want to render at any arbitrary time point, either in the future or in the past - in conjunction with animation.

Animations in a layer begin running, effect the presentation layer over time, and then 'expire' on their own (optionally removing themselves from the animation tree).

The example you provided (which is great by the way! thanks!) achieves exactly the effect I am looking for, with one catch. I don't have the luxury of setting the repeatCount of the animation to a really huge number. In my use case, that'd basically make all animations stretch on for eternity, and overlap each other.

If I set the repeatCount to 1 (or delete that line entirely), then the example animates correctly, once, in the forward direction. This is correct of course. The animation as it stands removes itself from the hierarchy and when I drag the slider backwards nothing (of course) happens. It does not matter if I tell the animation not to remove itself either, because it won't 'restart' itself ever again - because CACurrentMediaTime() marches forward, never backwards. (does that make sense what I just wrote there btw?).

This is the problem I'm trying to crack :-)

Also: I agree re: private methods - its a no no.

I was wondering if I could hold copies of animations, and insert those into the layer tree with appropriate negative timeOffset values, perform a render then remove the animations. That'd mean I get the full benefit of the CA library interpolation routines... I'll experiment with that idea and write a reply to this message with the results.

-
john

On 28/11/2007, at 6:39 PM, John Harper wrote:

Hi,

have you looked at the CARenderer class, it was added to support the kind of thing you're trying to do – drive the renderer timing by hand, and should be much faster.

Here's a simple project that does that:

<RendererSample.zip>


As for evaluating timing functions, you shouldn't use undocumented functions. In this case there's no need to, you can fetch the control points from the function and use a numerical root-finding method to solve the function for a given input or output time, e.g.: http://en.wikipedia.org/wiki/Newton's_method


	John


On Nov 27, 2007, at 9:50 PM, John Clayton wrote:

Hello all,

Another Core Anim question.

I'd like to be able to determine the result of any CAAnimation instance, given time 't', assuming that 't' is some time between the animation.beginTime and (animation.beginTime + animation.duration). The idea being, that I want to apply whatever modifications that an animation represents to my layer - then draw/ render a single frame. I do not want the animations to 'run' like normal.

Here's the 'use case' for this:
An arbitrarily complex layer containing animations is being drawn into a view. A slider is being used to scrub backward and forward in time, and the view draws one single frame based on the time represented by the slider. Any CALayer animations included in the layer tree must therefore also be taken into account and applied to the layer before the frame is rendered.


Here's the problem as I see it:
Core animation layers simply 'run' when they are added into the layer tree, applying modifications to the presentation layer in the background. There isn't a way to control their time as such. Sure, one can define their beginTime and duration, but controlling exactly *when* they fire/apply their effect is another matter.


I have made a spike solution already that controls the "transform.scale" property of a CALayer over time. It works well, however:

During the rendering of each frame, I disable animation on the layer, spin through all the CABasicAnimation instances, and then use a *private* method on CAMediaTimingFunction to solve for an input time (between 0 and 1). This provides me a %age complete value (of the timing function that is), which is then used to determine 'how far along' the animation we are. Then I create a CABasicAnimation, compute its values, and apply that single animation [of a keypath] to the layer tree.

It works well - my issues with this method are:

1) first and foremost, I'm using a private method - which I don't want to do in production code (many other discussion exist about this - I don't really want to duplicate them here)

2) it feels inefficient, because I am having to recompute the results of CAAnimation instances for each frame, and I'm concerned as to how this will scale. Then again, I've got no hard data/ performance stats to support my thoughts in this arena.

So my question is; does anyone have an idea of how I could do this *without* using a private method?

The method in question is:
// used SymbolExplorer to get this...
@interface CAMediaTimingFunction (CAMediaTimingFunction_PrivateMethods)
- (float) _solveForInput:(float)pcnt;
@end



Thanks in advance,

-
john clayton
http://www.coderage-software.com/

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >determining the result of a CAAnimation instance for time 't' (From: John Clayton <email@hidden>)

  • Prev by Date: NSTrackingArea + cursorUpdate: problem
  • Next by Date: Re: NSTextView and Click on Button
  • Previous by thread: determining the result of a CAAnimation instance for time 't'
  • Next by thread: Storing NSColor & NSData objects in an XML document
  • Index(es):
    • Date
    • Thread