Camera Rotation Around Objects

Sep 28, 2010 at 8:44 PM


I am a newbie trying to learn how to use Balder within Silverlight.  Basically, I want to have a group of objects and be able to rotate a camera around the objects and zoom on the objects.  The example I found was in the Sample browser code for view->CameraManipulation.  When you run the sample and change the X Axis, at about 90 the camera flips.  I searched the discussion area and found a reference to this issue:

In the discussion thread a possible solution was to add this code:
    var up = Vector.Normalize(Camera.Target - Camera.Position);
    Camera.Up = up;

I tried to add it but it did not work.  I have been searching for the last 2 days but have not found a solution.  I believe that the function below requires some code but I have no idea how to fix this behavior to allow full rotation (vertical and horizontal) and zooming so the camera can fly around the objects.
Any help would be greatly appreciated.


private void CalculateCameraPosition()
  var rotationX = Matrix.CreateRotationX((float)_xSlider.Value);
  var rotationY = Matrix.CreateRotationY((float)_ySlider.Value);

  var combined = rotationX * rotationY;
  var forward = Vector.Forward;
  var zoomedForward = forward * (float)_zoomSlider.Value;
  var position = zoomedForward * combined;

  var target = new Vector((float)_game.Camera.Target.X,
  var actualPosition = target - position;

  _game.Camera.Position.X = actualPosition.X;
  _game.Camera.Position.Y = actualPosition.Y;
  _game.Camera.Position.Z = actualPosition.Z; 

//    var up = Vector.Normalize(Camera.Target - Camera.Position);
//    Camera.Up = up;


Sep 29, 2010 at 6:02 PM


you might be able to achieve the same with a different approach. 

You could use the Container object in Balder and just add your objects into the Container and then use the Rotation property to rotate the container, which will rotate the objects within it as well. And also the same technique for Scale. 


That is of course if you don't have a big world of objects and you want to be able to just rotate around selected objects. 


Sep 29, 2010 at 7:04 PM


Thanks for replying.  If the container contained 5,000 box primitives, would that be considered a big world? 

I am trying to create an object similar to a neural network with over 5000 nodes and many links between the nodes.  I then wanted to display the model in 3d so I  could rotate around it and zoom in on it.  I could then select a node or link to display more detailed data about the object in a side canvas.  Basically,  the Silverlight interface basically works like a 3d CAD program for displaying the neural network.  The rotation issue is the first the part, displaying the nodes and linking to layout correctly in 3d is another big challenge.  Do you have any suggestions or know of any example code to accomplish this?


Sep 29, 2010 at 7:24 PM

Hi again,

5000 does not necessarily mean its a big world, it depends on wether or not all these 5000 nodes are visible at all times. 

There is a bit of overhead per node - although something I'm working on minimizing. If they are all visible on the screen at the same time, performance would be the biggest challenge.

If every node looks the same, InstancingNodes in the latest source of Balder is something that might be worth looking at for you. It has databinding capabilitiies and was built for faster ways of getting a lot of objects rendered. In the latest source you'll find a InstancingNodes sample in the SampleBrowser as well that shows how to use it. It supports the event model in Balder, so every node fires mouse events as well, if that is something you'd need. 

It sounds a bit to me that my suggestion of creating a container and rotate/scale it is not the way to go. But rather move the camera around, which brings you back to the flipping problem I guess - which I really don't have a good answer for you right now. 


Another thing worth mentioning - there is something called PassiveMode, which is an option on the Game. With it, rendering will only occur if something changes. So if your model is for the most part just sitting there and you only need tooltips and such when hovering over Nodes, PassiveMode is the way to go. 

Also, every node has a Tooltip property, which lets you define the tooltip directly - the Silverlight TooltipService does not work with Balder nodes.