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是鼠标所在位置到渲染窗口上边界的距离单位为像素

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值