Problems building or running the engine, queries about how to use features etc.
rrl
Halfling
Posts: 78 Joined: Sun Jun 04, 2017 12:33 am
Quote
0
login to like this post
Post
by rrl » Sat Apr 20, 2019 11:15 pm
Ogre Version: :2.1:
Operating System: :linux:
Render System: :GL3+:
When I click on a mesh, this mouseDown event eventually executes a ray scene query like so ...
Code: Select all
void MyWidget::mousePressEvent(QMouseEvent* e)
{
cMgr->injectMouseDown(e);
Ogre::Camera *cam = cMgr->getCamera();
Ogre::Ray ray = cam->getCameraToViewportRay(e->x(), e->y());
if (!gs->cast_ray(ray))
return;
}
bool MyGame::cast_ray(Ogre::Ray &ray)
{
if (!rSceneQuery)
return false;
rSceneQuery->setRay(ray);
if (rSceneQuery->execute().size() <= 0) // this returns zero
return false;
// ...
The problem is, rSceneQuery->execute().size() returns 0. Any ideas where I'm going wrong?
Tobse
Kobold
Posts: 26 Joined: Tue Apr 10, 2007 12:21 am
Quote
0
login to like this post
Post
by Tobse » Mon Apr 22, 2019 8:19 am
May be the ray calculation is wrong. Check that getCameraToViewportRay got values between 0 and 1.
rrl
Halfling
Posts: 78 Joined: Sun Jun 04, 2017 12:33 am
Quote
0
login to like this post
Post
by rrl » Sat Apr 27, 2019 6:10 pm
Maybe I'm misunderstanding, but the values that I'm passing in to getCameraToViewportRay() are x and y valued on where I clicked on the Ogre canvas.
How do I make these values between 0 and 1?
xrgo
OGRE Expert User
Posts: 1148 Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168
Quote
0
login to like this post
Post
by xrgo » Sat Apr 27, 2019 6:20 pm
the values are in pixel units? just normalize them:
Code: Select all
float x = e->x()/width
float y = e->y()/height
maybe you'll need to subtract an offset for the position of the window:
Code: Select all
float x = (e->x()-xwinpos)/width
float y = (e->y()-ywinpos)/height
not sure if that answer the question
rrl
Halfling
Posts: 78 Joined: Sun Jun 04, 2017 12:33 am
Quote
0
login to like this post
Post
by rrl » Sat Apr 27, 2019 6:48 pm
Yes, it helps, but I'm still unable to get the value between 0 and 1. Do I not have the same thing here?
Code: Select all
void MyWidget::mousePressEvent(QMouseEvent* e)
{
cameraMgr->injectMouseDown(e);
Ogre::Real x = Ogre::Math::Abs(e->x());
Ogre::Real y = Ogre::Math::Abs(e->y());
Ogre::Viewport *vport = ogreWindow->getViewport(0);
Ogre::Real width = e->x() / vport->getActualWidth();
Ogre::Real height = e->y() / vport->getActualHeight();
std::cout << "width = " << std::fixed << std::setprecision(3) << width << std::endl;
std::cout << "height = " << std::fixed << std::setprecision(3) << height << std::endl;
Ogre::Camera *camera = cameraMgr->getCamera();
Ogre::Ray ray = camera->getCameraToViewportRay(width, height);
// ...
xrgo
OGRE Expert User
Posts: 1148 Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168
Quote
0
login to like this post
Post
by xrgo » Sat Apr 27, 2019 8:10 pm
print the e->x() and e->y() values while your cursor is in the left top corner, and in the bottom right... that way you'll now if there's an offset going on, and if the width and height fit the ones that getActual_ gives you