Rotate object with mouse

Problems building or running the engine, queries about how to use features etc.
Post Reply
lerby
Gnoblar
Posts: 2
Joined: Sun Dec 14, 2014 8:11 pm

Rotate object with mouse

Post by lerby »

I wanna create an object, which will always look at mouse.
I am currently using OIS.
Malarkey
Halfling
Posts: 43
Joined: Sun Dec 07, 2014 12:44 pm

Re: Rotate object with mouse

Post by Malarkey »

You could use Billboards http://www.ogre3d.org/tikiwiki/tiki-ind ... -billboard for 2D planes
or just calculate it manually for meshes

Code: Select all

const OIS::MouseState& mouseState = mouse->getMouseState();
mouseState.X / .Z / .Y give you a point in space where the cursor "is". Than you can update the Orientation of your object to the mouse position with sceneNode->setOrientation(xxx). No warrantys, I am also still a beginner. ;)

And I think there was some inbuilt function to calculate an Quaternion which would rotate an Object automatically based on origin of the Object and the desired orientation target (but I don't remember the object / function name)

and may the subject should be "rotate object to mousePosition"
User avatar
Enhex
Gnoblar
Posts: 13
Joined: Sat Feb 22, 2014 7:56 am

Re: Rotate object with mouse

Post by Enhex »

You can get the mouse's world position using getCameraToViewportRay:

Code: Select all

Ogre::Ray ray = camera->getCameraToViewportRay(pixelX / camera->getViewport()->getActualWidth(),
									                    pixelY / camera->getViewport()->getActualHeight());
ray.getOrigin();
Where pixel(X/Y) is your mouse's screen position.

Then just use lookAt with the object that you want to look at it.
Post Reply