How to make DirectionalLight follow TrackBall

Topics: User Forum
Sep 18, 2007 at 7:16 PM
I was really glad to find 3D Tools. I'm working on an editing program for carving machine patterns (which are really height maps). I've been playing with a simple 3d Viewer to get the hang of 3D (based on I was able to easily incorporate the TrackBall class just like the example in the source:

Dim trackball As New Trackball
trackball.EventSource = myElement
mainViewport.Camera.Transform = trackball.Transform

In the XAML I have a directional light source implemented like so:

<DirectionalLight Color="White" Direction="-2,-3,-1" />

As I move the camera around with the TrackBall class I would like the ability to have DirectionalLight follow the camera. I see that DirectionalLight has a Transform member. So I take it that I should be able to get a handle to the DirectionalLight and apply the same transform to it? I am struggling with obtaining a handle for the DirectionalLight.

I think should fist find the index of the DirectionalLight and then find it in the Children collection and then assign the transform something like:

handleOfDirectionalLight.Transform = trackball.Transform

Am I even close here? Would it be much easier to just create the DirectionalLight in the Code Behind so that I will already have a reference to it?
Sep 18, 2007 at 8:16 PM
Arg...I hate it when I make somethign way to complicated....

All I needed to do, was the following:

Add x:Name to the XAML
<DirectionalLight x:Name="Light" Color="White" Direction="-2,-3,-1" />

and add in the transform in the code behind:

Light.Transform = trackball.Transform

Sep 22, 2007 at 6:19 PM
Daniels Headlight in the Trackport example gives a good example of this for future ref...