mNode->setPosition(mDestination);
mNode->translate(mDirection * move);
Ogre::Quaternion quat = src.getRotationTo(mDirection); mNode->rotate(quat);
mNode->yaw(Ogre::Degree(180));节点的平移和旋转功能的函数。
// Set idle animation mAnimationState = mEntity->getAnimationState("Idle"); mAnimationState->setLoop(true); mAnimationState->setEnabled(true);(2)在 bool IntermediateTutorial1::frameRenderingQueued(const Ogre::FrameEvent &evt)函数中添加代码:
mAnimationState->addTime(evt.timeSinceLastFrame);
Ogre::Ray mouseRay = mCamera->getCameraToViewportRay( mousePos.d_x/float(arg.state.width), mousePos.d_y/float(arg.state.height)); mRaySceneQuery->setRay(mouseRay);// Execute queryOgre::RaySceneQueryResult&result = mRaySceneQuery->execute(); Ogre::RaySceneQueryResult::iterator itr = result.begin(); // Get results, create a node/entity on the position if(itr != result.end()&& itr->worldFragment) { //关于 itr->worldFragment->singleIntersection的处理代码略 }
ent->setQueryFlags(ROBOT_MASK);
mRayScnQuery->setSortByDistance(true);
mRayScnQuery->setQueryMask(bRobotMode ? ROBOT_MASK : NINJA_MASK);
Intermediate Tutorial 4 Volume Selection and Basic Manual Objects
mVolQuery = mSceneMgr->createPlaneBoundedVolumeQuery(Ogre::PlaneBoundedVolumeList());
float left = first.x, right = second.x, top = first.y, bottom = second.y; if(left > right) swap(left, right); if(top > bottom) swap(top, bottom);
if((right - left)*(bottom - top)<0.0001)return;
Ogre::Ray topLeft = mCamera->getCameraToViewportRay(left, top); Ogre::Ray topRight = mCamera->getCameraToViewportRay(right, top); Ogre::Ray bottomLeft = mCamera->getCameraToViewportRay(left, bottom); Ogre::Ray bottomRight = mCamera->getCameraToViewportRay(right, bottom);
Ogre::PlaneBoundedVolumeList volList; volList.push_back(vol); mVolQuery->setVolumes(volList); Ogre::SceneQueryResult result = mVolQuery->execute();
deselectObjects(); Ogre::SceneQueryResultMovableList::iterator iter;for(iter = result.movables.begin(); iter != result.movables.end();++iter) selectObject(*iter);
There are two ways to create your own mesh within Ogre. The first way is to subclass the SimpleRenderable object and provide it with the vertex and index buffers directly. This is the most direct way to create one, but it's also the most cryptic. The Generating A Mesh code snippet shows an example of this. To make things easier, Ogre provides a much nicer interface called ManualObject, which allows you to use some simple functions to define a mesh instead of writing raw data to the buffer objects. Instead of dropping the position, color, and so on into a buffer, you simply call the "position" and "colour" functions.
In this tutorial we need to create a white rectangle to display when we are dragging the mouse to select objects. There really isn't a class in Ogre we could use to display a 2D rectangle. We will have to come up with a way of doing it on our own. We could use an Overlay and resize it to display the selection rectangle, but the problem with doing it this way is that the image you use for the selection rectangle could get stretched out of shape and look awkward. Instead, we will generate a very simple 2D mesh to act as our selection rectangle.