Panning Camera by changing target

Dec 2, 2009 at 6:39 PM

I am trying different interactive ways to change the camera position and target.  Zooming in and out was no problem, but I am having trouble isolating how to transform the Camera.Target values dynamically.  It was straight forward to connect the relative position of zooming the Camera by changing its position.  Now I am trying to keep the position constant and change the target. 

Has anyone done this?  Can you suggest a method?

Coordinator
Dec 2, 2009 at 7:26 PM
Edited Dec 2, 2009 at 7:27 PM

The Camera has a Target property which is a Vector, all its components can be manipulated. If you're doing this from Xaml, you can actually storyboard it, something like this: 

 

<UserControl 
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
   xmlns:balder="clr-namespace:Balder.Silverlight.Controls;assembly=Balder.Silverlight" 
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Balder.Silverlight.TestApp" >

<UserControl.Resources> 

 <Storyboard x:Name="_cameraStoryboard">
 <DoubleAnimationUsingKeyFrames 
    Storyboard.TargetName="_game" 
    Storyboard.TargetProperty="(Game.Camera).(Camera.Target).(Vector.Y)" 
    AutoReverse="True" 
    RepeatBehavior="Forever">
 <EasingDoubleKeyFrame KeyTime="00:00:00" Value="5" >
 <EasingDoubleKeyFrame.EasingFunction>
 <CircleEase EasingMode="EaseOut"/>
 </EasingDoubleKeyFrame.EasingFunction>
 </EasingDoubleKeyFrame>
 <EasingDoubleKeyFrame KeyTime="00:00:02" Value="0" >
 <EasingDoubleKeyFrame.EasingFunction>
 <CircleEase EasingMode="EaseIn"/>
 </EasingDoubleKeyFrame.EasingFunction>
 </EasingDoubleKeyFrame>
 </DoubleAnimationUsingKeyFrames>
 </Storyboard>
</UserControl.Resources> 

 <Grid x:Name="LayoutRoot">

 <balder:Game x:Name="_game" Width="800" Height="600" DebugLevel="BoundingSpheres">
 <balder:Mesh x:Name="_teapot"  AssetName="teapot.ASE"/>
 </balder:Game>
  </Grid>

</UserControl> 

{

 

 

Coordinator
Dec 2, 2009 at 8:16 PM
Edited Dec 2, 2009 at 8:17 PM

Also worth mentioning, is that Tutorials are now bubbling up on the site: 

You'll find them here

Dec 3, 2009 at 2:42 PM

I treid this, attaching it to the left mouse button down event of a slider.  Event never fired.  I have the event wired in the mainpage.xaml and my calback is in mainpage.xaml.cs files.

 I think I am missing something in defining the left mouse button event.  Do I need to define it within the xaml code for the game and game class?

Coordinator
Dec 5, 2009 at 1:42 PM

Sorry for the late answer - missed this post. 

For a Slider, I'd go with the ValueChanged event. 

As for the left mouse button event - I can't see why this shouldn't work. Would it be possible for you to send me a sample that doesn't work ?