Under review

How to limit rotation

Anonymous 6 years ago updated by Øystein Bjørke 6 years ago 2
This discussion was imported from CodePlex

ejleigh wrote at 2012-06-12 03:28:

I have a terrain model with objects on top and I'm trying to find a good way to prevent the user from rotaing the scene such that he can look underneath the terrrain model. It seemed like the best way would be to derive a new class from CameraController and override the OnManipulationDelta method, but unfortunately you cannot set the camera contoller in the HelixViewPort3D. At the moment I'm setting the RotationSensitivity to a low value when the camera Up vector approaches level, but that only kindof works. It's not ideal. Is there a better way?


objo wrote at 2012-06-15 06:38:

The CameraController is created in the control template of the HelixViewport3D, so you have to override the control template. http://wpftutorial.net/templates.html

Or, use the Camera's Position and LookDirection coerce value callbacks, and enforce the Z values to to be positive and negative, respectively.


I have not tried this, but I think it should work.

lightxx wrote at 2013-02-26 10:11:

objo, could you please provide a simple example on how to do this? I guess limiting the rotation is quite a frequent requirement.
thank you very much!

objo wrote at 2013-03-13 07:12:

I think none of the above solutions are feasible.

By overriding coerce value callbacks the limitation would be applied on the camera not for rotation only. In real life scenarios, I might prevent my users from doing such things but I don't want to limit myself. The correct way of doing this would be to open the mouse handlers to be extended, or create a callback or handler that could modify the rotation delta before application.

I don't really understand why these handlers are completely hidden from the developers.
Under review
The issue is now at GitHub - and it may be better to discuss the implementation there :-)
Right, if you still want to set camera properties outside the 'valid' range, the coercing solution may not be good.
I think we need some real life examples/demos to solve this issue. I see a lot of possible requirements to what should be restricted (camera position, direction, field of view etc) and it would be great if we could cover them all...