Page 1 of 1

Small OgreBites bug?

Posted: Sun Jan 22, 2012 1:50 am
by lingfors
I think I just found a small bug in OgreBites/SdkTrays:

Code: Select all

/*-----------------------------------------------------------------------------
| Converts a 3D scene position to a 2D screen coordinate (in pixels).
-----------------------------------------------------------------------------*/
static Ogre::Vector2 sceneToScreen(const Ogre::Camera* cam, const Ogre::Vector3& pt)
{
	Ogre::Vector3 result = cam->getProjectionMatrix() * cam->getViewMatrix() * pt;
	return Ogre::Vector2((result.x + 1) / 2, -(result.y + 1) / 2);
}
should be

Code: Select all

/*-----------------------------------------------------------------------------
| Converts a 3D scene position to a 2D screen coordinate (in pixels).
-----------------------------------------------------------------------------*/
static Ogre::Vector2 sceneToScreen(const Ogre::Camera* cam, const Ogre::Vector3& pt)
{
	Ogre::Vector3 result = cam->getProjectionMatrix() * cam->getViewMatrix() * pt;
	return Ogre::Vector2((result.x + 1) / 2, (-result.y + 1) / 2);
}

Re: Small OgreBites bug?

Posted: Sun Jan 29, 2012 6:22 pm
by Mind Calamity
Aren't those two code blocks you just posted exactly the same ?

Re: Small OgreBites bug?

Posted: Sun Jan 29, 2012 6:36 pm
by syedhs
I think lingfors forget to multiply the return value by the screen dimension - which is what the patch is all about. :mrgreen:

Edit: Or maybe the code simply returns the 0.00 to 1.00 which works okay, but it is the comment that should be changed. I don't read actual source code though.

Re: Small OgreBites bug?

Posted: Sun Jan 29, 2012 6:37 pm
by spacegaier
Then please add it to the patch tracker. Otherwise it will get lot here...

Re: Small OgreBites bug?

Posted: Sun Jan 29, 2012 6:38 pm
by CABAListic
The difference is in the placement of the - sign before result.y.

Re: Small OgreBites bug?

Posted: Sun Jan 29, 2012 6:51 pm
by Mind Calamity
CABAListic wrote:The difference is in the placement of the - sign before result.y.
Oh, I missed that! The lengths of the return lines were exactly the same so I didn't even bother to read it.

Re: Small OgreBites bug?

Posted: Sun Jan 29, 2012 9:46 pm
by lingfors
Mind Calamity wrote:
CABAListic wrote:The difference is in the placement of the - sign before result.y.
Oh, I missed that! The lengths of the return lines were exactly the same so I didn't even bother to read it.
The devil is in the detail. ;)

Added to the bug tracker.

Although, as has been pointed out, the comment isn't correct either...