Aug 29, 2012 at 7:41 AM
Edited Aug 29, 2012 at 11:05 PM
I've created a matlab style 3D plot with a lot of help from Helix Toolkit.
For axes labels, grid lines, tick marks etc, I used WPF 2D geometry and text objects, and transformed the 3D points to 2D in a similar way to the OverlayDemo. (These lines look cleaner than screen space 3D lines, especially since I can apply SnapsToDevicePixels).
In the OverlayDemo, the transformation of coordinates is performed in the window's CompositionTarget.Rendering event. In my case I have a serious amount of layout logic and coordinates to transform, and having all of this called every frame is wasting CPU.
I'd like to just update the coordinates when something changes - the camera, the host layout control resizes etc.
So that's cool, I can update coordinates on CameraChanged event (and a few other places). That seems to work with normal mouse interaction (rotation, zooming etc). But when I try and set the camera view in another way (e.g. with HelixViewport3D.SetView()),
the 3D to 2D transformation blows up and my 2D coords end up with infinity and NaN. I'm unsure, but I think what happens is one aspect of the camera is changed (e.g. lookDirection), and then this fires the camera changed event. Since coordinates are transformed
inside this event handler, that code tries to execute but the transformation matrix isn't formed properly yet (still requires position and upDirection to be set?). Specifically the matrix offset data seems to be wrong. Anyway, this yields incorrect values
and the program fails.
(1) Is there a more sensible place to transform 3D to 2D coordinates?
(2) Why doesn't this fail with normal mouse interaction? Are all camera settings set before the CameraChanged event is fired?
(3) Is there some way to keep this logic in CompositionTarget.Rendering but unhook the event handler when nothing is happening and hook it back up when something does change? What should it depend on? - relying on CameraChanged would still cause the transformation
to blow up.
Any ideas will be very much appreciated. I'm totally new at this stuff, so please excuse me.