Screen coordinate system: the bottom right corner of the upper left corner is (0, 0) (1, 1)
2D Coordinate System of OGRE: in the upper left corner, the lower right corner is (1,-1)
CEGUI coordinate system: the upper left corner is (0, 0), in pixels.
Conversion Formula (mouse coordinates => 2D coordinates of OGRE)
Void setCorners (float left, float top, float right, float bottom)
{
Left = left * 2-1;
Right = right * 2-1;
Top = 1-top * 2;
Bottom = 1-bottom * 2;
}
For rays generated based on the mouse position:
Bool mousePressed (const OIS: MouseEvent & arg, OIS: MouseButtonID id)
{
...
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 ));
...
}
Functions
Ray getcameratoviewportray (real X, real y) const;
// X and Y are in "normalized" (0.0 to 1.0) screen coordinates
The two parameters are for the screen coordinate system,
So
X = mousepos. D_x/float (Arg. state. width)
Y = mousepos. d_y/float (Arg. state. Height)
Arg. state. width indicates the width of the rendering window, measured in pixels.
Arg. state. Height indicates the height of the rendering window in pixels.
Mousepos. D_x is the distance from the mouse position to the left border of the rendering window, measured in pixels.
Mousepos. d_y is the distance from the mouse position to the upper boundary of the rendering window, measured in pixels.