OGRE的2D坐标、CEGUI坐标、鼠标坐标

屏幕坐标系:左上角为(0, 0)右下角为(1, 1)

OGRE的2D坐标系:左上角为(-1, 1)右下角为(1, -1)

CEGUI坐标系:左上角为(0, 0),单位像素

 

转换公式(鼠标坐标=>OGRE的2D坐标)

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;
}

 

对于根据鼠标位置来产生射线:

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));

...
}

其中函数

Ray getCameraToViewportRay(Real x, Real y) const;

// x and y are in “normalized” (0.0 to 1.0) screen coordinates

其中两个参数是对屏幕坐标系来说的,

所以

x = mousePos.d_x / float(arg.state.width)

y = mousePos.d_y / float(arg.state.height)

 

arg.state.width是渲染窗口的宽单位为像素

arg.state.height是渲染窗口的高单位为像素

mousePos.d_x是鼠标所在位置到渲染窗口左边界的距离单位为像素

mousePos.d_y是鼠标所在位置到渲染窗口上边界的距离单位为像素

 

 

 

你可能感兴趣的:(float)