2D coordinates, CEGUI coordinates, and mouse coordinates of OGRE

Source: Internet
Author: User

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.

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.