transform position of mouseDown to 3D


19-07-2007 13:23:25

i want to put down mouse every pos under the screen and get the position by Vector2 mousePos = QuickGUI::MouseCursor::getSingleton().getPixelPosition(); then, i can put a model on this position. but i try some ways, it didn't work. anyone can give some advice?
thans a lot!


19-07-2007 21:02:08

This functionality is shown in Intermediate Tutorial 3:

// Setup the ray scene query, use CEGUI's mouse position
CEGUI::Point mousePos = CEGUI::MouseCursor::getSingleton().getPosition();
Ray mouseRay = mCamera->getCameraToViewportRay(mousePos.d_x/float(arg.state.width), mousePos.d_y/float(arg.state.height));

// Execute query
RaySceneQueryResult &result = mRaySceneQuery->execute();
RaySceneQueryResult::iterator itr = result.begin( );

// Get results, create a node/entity on the position
if (itr != result.end() && itr->worldFragment)

This code is using CEGUI, the only difference is that you need to derive the getCameraToViewportRay paramters from data QuickGUI gives you. Get the pixel position and divide width by screen width, height by screen height..


20-07-2007 03:06:40

thanks. but i don't use terrian. and i just tried another way. i don't know whether is passible.


20-07-2007 09:01:14

Actually the code works regardless of terrain. Just remove the "&& itr->worldFragment" part. Basically you will cast a ray through the camera, and all movable objects will be returned. You can also add masks to objects to distinguish movable objects, if you need.