Is there a BeforeRendering event or similar, where I can modify my objects before each frame?

Nov 5, 2010 at 8:15 AM
Edited Nov 5, 2010 at 8:15 AM

I'd like to apply a custom world matrix to some objects before rendering each frame, as part of an animation. However, I cannot find an appropriate event exposed for this. What would be the best way to approach this scenario?

Coordinator
Nov 5, 2010 at 8:27 AM
Edited Nov 5, 2010 at 8:27 AM

There is an event called Update on the Game  that you can hook into.

Coordinator
Nov 5, 2010 at 9:02 AM
Edited Nov 5, 2010 at 9:03 AM

If you want to animate things like Position, Rotation or Scale or any of the other properties of an object, you can use Storyboards as well. There is a Storyboard extension that allows you to easily animate the Position, Rotation and Scale types, which are of type Coordinate.

E.g. : 

 

<Grid x:Name="LayoutRoot">
	<Grid.Triggers>
		<EventTrigger RoutedEvent="Grid.Loaded">
			<BeginStoryboard>
				<Storyboard RepeatBehavior="Forever">
					<Animation:StoryboardExtensions.CoordinateAnimation>
						<Animation:CoordinateAnimation From="0,0,0" To="0,359,0" Duration="00:00:10" TargetName="Box" TargetProperty="(Node.Rotation)"/>
					</Animation:StoryboardExtensions.CoordinateAnimation>
				</Storyboard>
			</BeginStoryboard>
		</EventTrigger>
	</Grid.Triggers>

 

And just add the namespace at the top : 

xmlns:Animation="clr-namespace:Balder.Animation.Silverlight;assembly=Balder"


 

Nov 5, 2010 at 1:23 PM

Thanks, Update covers my needs nicely.

I'm not able to use the built-in properties, since my animation involves multiplying multiple rotation matrices. Hmm... I wonder if it would be possible to create an animation type for something like that. For example, make World also take a MultiplyingMAtrix that has multiple child matrices, which can be animated. Might work...

But it's actually simpler for me to use the Update method, so I'm not sure how useful that scenario would be.