Hi,
i want when i clic on object and drag the mouse cursor the object move to the new position
i have
{
if(e->buttons().testFlag(Qt::LeftButton))
{
Ogre::Real offsetX =(double)e->pos().x()/(double)width();
Ogre::Real offsetY=(double) e->pos().y()/(double)height();
mRayScnQuery = mSceneMgr->createRayQuery(Ogre::Ray());
Ogre::Ray mouseRay = mCamera->getCameraToViewportRay(offsetX, offsetY);
mRayScnQuery->setRay(mouseRay);
// Execute query
Ogre::RaySceneQueryResult &result =mRayScnQuery->execute();
Ogre::RaySceneQueryResult::iterator itr;
Ogre::RaySceneQueryResult::iterator target;
float shortestDistance = -1 ;
for( itr = result.begin() ;itr != result.end();++itr)
{
if( itr->distance < shortestDistance || shortestDistance < 0 )
{
// remember the closest
shortestDistance = itr->distance;
target = itr;
}
}
Ogre:: Vector3 point=mouseRay.getPoint(target->distance);
emit move_object(point);
}
void My_app:mousePressEvent(QMouseEvent* evt)
void My_app::mouseMoveEvent(QMouseEvent *e)
{
if(e->buttons().testFlag(Qt::LeftButton))
{
Ogre::Real offsetX =(double)e->pos().x()/(double)width();
Ogre::Real offsetY=(double) e->pos().y()/(double)height();
mRayScnQuery = mSceneMgr->createRayQuery(Ogre::Ray());
Ogre::Ray mouseRay = mCamera->getCameraToViewportRay(offsetX, offsetY);
mRayScnQuery->setRay(mouseRay);
// Execute query
Ogre::RaySceneQueryResult &result =mRayScnQuery->execute();
Ogre::RaySceneQueryResult::iterator itr;
Ogre::RaySceneQueryResult::iterator target;
float shortestDistance = -1 ;
for( itr = result.begin() ;itr != result.end();++itr)
{
if( itr->distance < shortestDistance || shortestDistance < 0 )
{
// remember the closest
shortestDistance = itr->distance;
target = itr;
}
}
Ogre:: Vector3 point=mouseRay.getPoint(target->distance);
emit move_object(point);
}
To copy to clipboard, switch view to plain text mode
the problem is the mouse move event do not work exactelly , it give me always the same position( point posiiton is the same) even if i move the mouse
i know that's maybe i do
Bookmarks