How to rotate the 3d object with mouse moving

Category: windows metro apps games


halcyons on Fri, 01 Nov 2013 07:59:52

I would like control the 3d object's rotation by mouse.When i press on the object and move the mouse, the object rotate an angle.

Thanks in advance.


Dave A Gordon on Fri, 01 Nov 2013 10:55:34

You want MouseMove event

then change the Objects X, Y and Z according to the movement of the mouse... Z is normally associated with the mouse Scroll Wheel.

You may need to work out a comparison between the object and the Window Size ... as the mouse may scroll too much for you. But that's another story :P Get the basics first then make perfect.


halcyons on Fri, 01 Nov 2013 11:02:27

Thank you, But I want to press the object rather than anywhere. Is there any simple way to detect if I press the object.

Rob Caplan [MSFT] on Fri, 01 Nov 2013 14:03:53

Windows Store apps don't have a MouseMove event. You'll use pointer events for this. On PointerPressed you'll hit test to see if the user clicked on the object and then in PointerMoved you can rotate the object. Finish in PointerReleased.

To hit test you'll need to do a bit of math: cast a ray from the camera through the point on the view plane the upset clicked and intersect that ray with your object at whatever level of detail makes sense (bounding box or sphere may be sufficient or you may want to go down to individual rectangles).


Chuck Walbourn - MSFT on Fri, 01 Nov 2013 17:39:22

This is the 'picking' problem where you take the mouse location, and reverse project it into a ray in the scene, then use collision-detection to find the object 'hit'.

Here is an example of this technique