选中物体
这次对于所有的鼠标事件,我创建了封闭函数来处理它们。当用户按下鼠标左键,"onLeftPressed"函数被调用,当按下右键时"onRightReleased"函数被调用,等等。
一如既往,首先给出框架代码:
#include
<CEGUI/CEGUISystem.h>
#include
<CEGUI/CEGUISchemeManager.h>
#include
<OgreCEGUIRenderer.h>
#include
"ExampleApplication.h"
class MouseQueryListener :
public ExampleFrameListener, public OIS::MouseListener
{
public:
MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager
*sceneManager, CEGUI::Renderer *renderer)
: ExampleFrameListener(win, cam, false, true),
mGUIRenderer(renderer)
{
// Setup default variables
mCount = 0;
mCurrentObject = NULL;
mLMouseDown = false;
mRMouseDown = false;
mSceneMgr = sceneManager;
// Reduce move speed
mMoveSpeed = 50;
mRotateSpeed /= 500;
// Register this so that we get mouse events.
mMouse->setEventCallback(this);
// Create RaySceneQuery
mRaySceneQuery =
mSceneMgr->createRayQuery(Ray());
} // MouseQueryListener
~MouseQueryListener()
{
mSceneMgr->destroyQuery(mRaySceneQuery);
}
bool frameStarted(const FrameEvent &evt)
{
// Process the base frame listener code. Since we
are going to be
// manipulating the translate vector, we need this to happen
first.