camera orientation mouse press event problem

Problems building or running the engine, queries about how to use features etc.
Post Reply
mielle
Greenskin
Posts: 113
Joined: Mon Feb 25, 2013 11:12 am
x 1

camera orientation mouse press event problem

Post by mielle »

HI,
i have strange problem (as always :D )
when the orientation of the camera it is

Code: Select all

  Ogre::Vector3 initorient=(Ogre::Vector3(0,0,0));
or

Code: Select all

 Ogre::Vector3 initorient=(Ogre::Vector3(0,-45,0));
my mouse press event detect the node, and

Code: Select all

  Ogre::Real offsetX =(double)evt->pos().x()/(double)width();
   Ogre::Real offsetY=(double) evt->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;
	 //target = itr;
	float shortestDistance = -1 ;
	    for( itr = result.begin() ;itr != result.end();++itr)
    {
       if (itr->movable)
       {
		   cout<<"name1======="<<itr->movable->getName();
          if( /*dbistance iterator*/itr->distance < shortestDistance || shortestDistance  < 0 )
          {
             // remember the closest
             shortestDistance  = itr->distance;
             target = itr;
          }
       }
    }
   if( target->movable )
    {
       //add sphere
    

				Ogre::AxisAlignedBox bb = target->movable->getBoundingBox();
				
				QString res;
nbman++;         




Ogre::SceneNode* node=target->movable->getParentSceneNode();
	cout<<"name1======="<<node->getName();
	cout<<"pos========"<<node->getPosition(); 
				Ogre:: Vector3 point=mouseRay.getPoint(target->distance);
but when i change the camera orientation in the y axisi to be in the range [-90,-180]( i tried many value in this range)
it do not dectect the node where i clic, it dectect another thing
and for this instruction

Code: Select all

cout<<"pos========"<<node->getPosition(); 
it print to me (0,0,0)!!
where is my problem?
the code does not change , just teh camera orientation
mielle
Greenskin
Posts: 113
Joined: Mon Feb 25, 2013 11:12 am
x 1

Re: camera orientation mouse press event problem

Post by mielle »

Hi,
the problem still exist, i can't see the influsence of the camera orientation and the mouse press event
why the same code work on specific camera orientation
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: camera orientation mouse press event problem

Post by Kojack »

What are the values of the ray when it hits the wrong thing?
What's the bounding box properties of the node it hit? (min corner / max corner / if it's infinite, etc)
What are the other properties of the node? (name, parent, etc)
How are you using the initorient vector to set the orientation of the camera?
mielle
Greenskin
Posts: 113
Joined: Mon Feb 25, 2013 11:12 am
x 1

Re: camera orientation mouse press event problem

Post by mielle »

Weh initorient of the camera is (0,0,0)
the offsetX==0.48
offsetY== 0.65
node name=lefthand
pos=-8,111,39
and he detect my objet
---
in the case when i put the camera in (0,-180,0) with the same code and i clic on the same object iget

the offsetX=0.46
offsetY=0.67
nodename=unnamed_1
pos=(0,0,0)
parent=0C3BB3D8
it's the same code, i clic on the same place where there is the object what i change is just the camera orientation
How are you using the initorient vector to set the orientation of the camera?

Code: Select all

mCamera->setOrientation(EulerToOgreQuat(initorient ));

Code: Select all

Ogre::Quaternion  myapp::EulerToOgreQuat( const Ogre::Vector3& degreesVector )
         {
            Ogre::Matrix3 mx;
			
		    mx.FromEulerAnglesXYZ
            (Ogre::Degree(degreesVector.x), Ogre::Degree(degreesVector.y), Ogre::Degree(degreesVector.z));
			
            Ogre::Quaternion result(mx);
            return result;
         }

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: camera orientation mouse press event problem

Post by Kojack »

Hmm, it's hitting an unnamed node at the origin.
That would be a node created with something like sceneManager->getRootSceneNode()->createChildSceneNode()
(no name given to createChildSceneNode)

Without knowing the start of the ray, direction of the ray and the bounding boxes of all the scene nodes, it's hard to tell what might be going on.
mielle
Greenskin
Posts: 113
Joined: Mon Feb 25, 2013 11:12 am
x 1

Re: camera orientation mouse press event problem

Post by mielle »

So what is the solution ?
it's big problem for me
Without knowing the start of the ray, direction of the ray and the bounding boxes of all the scene nodes, it's hard to tell what might be going on.
how i get them
User avatar
Daixiwen
Greenskin
Posts: 105
Joined: Fri Feb 08, 2013 11:30 am
Location: Oslo
x 16

Re: camera orientation mouse press event problem

Post by Daixiwen »

mielle wrote:
Without knowing the start of the ray, direction of the ray and the bounding boxes of all the scene nodes, it's hard to tell what might be going on.
how i get them

Code: Select all

const Vector3& Ogre::Ray::getOrigin ( void ) const
const Vector3& Ogre::Ray::getDirection ( void ) const

virtual const AxisAlignedBox& Ogre::MovableObject::getWorldBoundingBox ( bool derive = false ) const
Hardware, n.: part of the computer you can kick
mielle
Greenskin
Posts: 113
Joined: Mon Feb 25, 2013 11:12 am
x 1

Re: camera orientation mouse press event problem

Post by mielle »

Ok,
in the case where it work i get

mouseRay.getOrigin()=(-0.04,179,458)
mouseRay.getDirection()=(-0.02,-0.2,-0.98)
bb(Ogre::AxisAlignedBox bb = target->movable->getBoundingBox();)=min(--50,-50,-50),max(50,50,50)


in the acse where it does not work i get
mouseRay.getOrigin()=(0.11,179,-438)
mouseRay.getDirection()=(0.05,-0.17,0.98)
bb(Ogre::AxisAlignedBox bb = target->movable->getBoundingBox();)=min(-63,-3,-8),max(63,129,10)

that's the code

Code: Select all

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;
	 //target = itr;
	float shortestDistance = -1 ;
	    for( itr = result.begin() ;itr != result.end();++itr)
    {
       if (itr->movable)
       {
		   //cout<<"name1======="<<itr->movable->getName();
          if( /*dbistance iterator*/itr->distance < shortestDistance || shortestDistance  < 0 )
          {
             // remember the closest
             shortestDistance  = itr->distance;
             target = itr/*->movable*/;
          }
       }
    }

    // if an object is found
    if( target->movable )
    {
       //add sphere
    

				Ogre::AxisAlignedBox bb = target->movable->getBoundingBox();
				
				QString res;
nbman++;         




Ogre::SceneNode* node=target->movable->getParentSceneNode();
	cout<<"name1======="<<node->getName();cout<<"\n";
	cout<<"pos========"<<node->getPosition(); cout<<"\n";
	cout<<"parent======"<<node->getParent();cout<<"\n";
	cout<<"Ogre::Ray::getOrigin "<<mouseRay.getOrigin();cout<<"\n";
	cout<<"Ogre::Ray::getDirection "<<mouseRay.getDirection();cout<<"\n";
	cout<<"bb"<<bb;cout<<"\n";
				Ogre:: Vector3 point=mouseRay.getPoint(target->distance);
				
so where is my problem ?
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: camera orientation mouse press event problem

Post by Kojack »

The two bounding boxes you are dealing with are overlapping and you moved the camera along the z axis by almost 900m, so it's not too surprising that the giant "unnamed_1" box is catching the ray. What is it? Ogre (at least before 2.1) doesn't make scene nodes on it's own, so at some point you made a large scene node (without a name) that is overlapping the one you really want to hit.
mielle
Greenskin
Posts: 113
Joined: Mon Feb 25, 2013 11:12 am
x 1

Re: camera orientation mouse press event problem

Post by mielle »

The two bounding boxes you are dealing with are overlapping and you moved the camera along the z axis by almost 900m, so it's not too surprising that the giant "unnamed_1" box is catching the ray. What is it?
i do not know, but i did not create it
i will check another time
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 534

Re: camera orientation mouse press event problem

Post by Kojack »

Just to check, you know that ogre raycasting is just against bounding boxes, not meshes? Clicking on a mesh may actually hit a bounding box of another object that looks like it should be out of the way.
If you need accurate raycasting, you need to use something like MOC (Minimal Ogre Collision). It's slower, but much more accurate.
mielle
Greenskin
Posts: 113
Joined: Mon Feb 25, 2013 11:12 am
x 1

Re: camera orientation mouse press event problem

Post by mielle »

Yes i know that's it work with the bounding box
so it's not too surprising that the giant "unnamed_1" box is catching the ray. What is it?
i checked all the program, i can't get that's node ,
:roll:
mielle
Greenskin
Posts: 113
Joined: Mon Feb 25, 2013 11:12 am
x 1

Re: camera orientation mouse press event problem

Post by mielle »

Hi,
finaly i get the box that it detect when i clic by the mouse. it's the character bounding box. i will explain what i am going to made
- As i know we can not clic on bone then control it by the mouse, for that i add small node in the same place to the character bone , thoses node have the same bones names,
so when i clic on the node , the correspanding bone change position

so it worked with my pervious camera position without problem

but when i change camera orienttaion, when i clic on the node, it detect the character boundng box not the node

now i know the problem , but not the solution

P.S: i see the character bouding box do not update hen the character walk, maybe it's the problem?
i add

Code: Select all

 mCharSceneNode->_update(true,true);
		mCharSceneNode->_updateBounds();
but nothing change, the character walk but the bounding box stay in the same place
mielle
Greenskin
Posts: 113
Joined: Mon Feb 25, 2013 11:12 am
x 1

Re: camera orientation mouse press event problem

Post by mielle »

Hi
the problem still exist,
and when i pick with mouse it detect the character bounding bonx, is there a method to delet it ?
or something to do ?
mielle
Greenskin
Posts: 113
Joined: Mon Feb 25, 2013 11:12 am
x 1

Re: camera orientation mouse press event problem

Post by mielle »

Hi,
i create another subject
to explain my real problem
http://www.ogre3d.org/forums/viewtopic.php?f=2&t=84467
Post Reply