本文整理汇总了C++中ogre::Entity::getParentNode方法的典型用法代码示例。如果您正苦于以下问题:C++ Entity::getParentNode方法的具体用法?C++ Entity::getParentNode怎么用?C++ Entity::getParentNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::Entity
的用法示例。
在下文中一共展示了Entity::getParentNode方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: EngineSetup
void CUsingControllersView::EngineSetup(void)
{
Ogre::Root *Root = ((CUsingControllersApp*)AfxGetApp())->m_Engine->GetRoot();
Ogre::SceneManager *SceneManager = NULL;
SceneManager = Root->createSceneManager(Ogre::ST_GENERIC, "Walking");
//
// Create a render window
// This window should be the current ChildView window using the externalWindowHandle
// value pair option.
//
Ogre::NameValuePairList parms;
parms["externalWindowHandle"] = Ogre::StringConverter::toString((long)m_hWnd);
parms["vsync"] = "true";
CRect rect;
GetClientRect(&rect);
Ogre::RenderTarget *RenderWindow = Root->getRenderTarget("Mouse Input");
if (RenderWindow == NULL)
{
try
{
m_RenderWindow = Root->createRenderWindow("Mouse Input", rect.Width(), rect.Height(), false, &parms);
}
catch(...)
{
MessageBox("Cannot initialize\nCheck that graphic-card driver is up-to-date", "Initialize Render System", MB_OK | MB_ICONSTOP);
exit(EXIT_SUCCESS);
}
}
// Load resources
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
// Create the camera
m_Camera = SceneManager->createCamera("Camera");
m_Camera->setNearClipDistance(0.5);
m_Camera->setFarClipDistance(5000);
m_Camera->setCastShadows(false);
m_Camera->setUseRenderingDistance(true);
m_Camera->setPosition(Ogre::Vector3(0.0, 0.0, 1000.0));
Ogre::SceneNode *CameraNode = NULL;
CameraNode = SceneManager->getRootSceneNode()->createChildSceneNode("CameraNode");
Ogre::Viewport* Viewport = NULL;
if (0 == m_RenderWindow->getNumViewports())
{
Viewport = m_RenderWindow->addViewport(m_Camera);
Viewport->setBackgroundColour(Ogre::ColourValue(0.8f, 0.8f, 0.8f));
}
// Alter the camera aspect ratio to match the viewport
m_Camera->setAspectRatio(Ogre::Real(rect.Width()) / Ogre::Real(rect.Height()));
Ogre::SceneNode *SphereNode = SceneManager->getRootSceneNode()->createChildSceneNode("Sphere", Ogre::Vector3(0,0,0));
Ogre::Entity *SphereEntity = SceneManager->createEntity("Sphere", "sphere.mesh");
SphereEntity->setMaterialName("Wall/Screen");
SphereNode->attachObject(SphereEntity);
SphereEntity->getParentNode()->scale(0.2,0.2,0.2);
m_Camera->lookAt(Ogre::Vector3(0.0, 0.0, 0.0));
#undef new
Ogre::ControllerFunctionRealPtr func(OGRE_NEW Ogre::WaveformControllerFunction(Ogre::WFT_SINE, 0.0, 1.0));
Ogre::ControllerValueRealPtr dest(OGRE_NEW SphereScale(SphereNode, 1.0));
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
Ogre::ControllerManager& ControllerManager = Ogre::ControllerManager::getSingleton();
m_SphereController = ControllerManager.createController(ControllerManager.getFrameTimeSource(), dest, func);
Root->renderOneFrame();
}
开发者ID:southerlies,项目名称:OGRE-3D-1.7-Application-Development-Cookbook-Code,代码行数:78,代码来源:UsingControllersView.cpp
示例2: raycastFromPoint
/***************************************************************************//*!
* @brief Raycast from a point in to the scene.
* @param[in] point Point to analyse
* @param[in] normal Direction
* @param[out] result Result ( ONLY if return TRUE )
* @return TRUE if somethings found => {result} NOT EMPTY
*/
bool OgreMeshRay::raycastFromPoint(const Ogre::Vector3& point,
const Ogre::Vector3& normal, Ogre::Vector3& result,
std::string entityName) {
// create the ray to test
Ogre::Ray ray(point, normal);
if (!m_raySceneQuery)
return false;
// create a query object
m_raySceneQuery->setRay(ray);
// execute the query, returns a vector of hits
if (m_raySceneQuery->execute().size() <= 0) {
// raycast did not hit an objects bounding box
return false;
}
// at this point we have raycast to a series of different objects bounding boxes.
// we need to test these different objects to see which is the first polygon hit.
// there are some minor optimizations (distance based) that mean we wont have to
// check all of the objects most of the time, but the worst case scenario is that
// we need to test every triangle of every object.
Ogre::Real closest_distance = -1.0f;
Ogre::Vector3 closest_result;
Ogre::RaySceneQueryResult& query_result = m_raySceneQuery->getLastResults();
for (size_t qr_idx = 0, size = query_result.size(); qr_idx < size;
++qr_idx) {
// stop checking if we have found a raycast hit that is closer
// than all remaining entities
if (closest_distance >= 0.0f
&& closest_distance < query_result[qr_idx].distance)
break;
// only check this result if its a hit against an entity
if (query_result[qr_idx].movable) {
if (entityName != ""
&& query_result[qr_idx].movable->getName() != entityName) {
std::cout << query_result[qr_idx].movable->getName()
<< "is not " << entityName << std::endl;
continue;
}
std::cout << query_result[qr_idx].movable->getName() << "is truly "
<< entityName << std::endl;
const std::string& movableType =
query_result[qr_idx].movable->getMovableType();
// mesh data to retrieve
size_t vertex_count;
size_t index_count;
Ogre::Vector3* vertices;
unsigned long* indices;
if (movableType == "ManualObject") {
// get the entity to check
Ogre::ManualObject* pentity =
static_cast<Ogre::ManualObject*>(query_result[qr_idx].movable);
// get the mesh information
GetMeshInformation(pentity, vertex_count, vertices, index_count,
indices,
pentity->getParentNode()->_getDerivedPosition(),
pentity->getParentNode()->_getDerivedOrientation(),
pentity->getParentNode()->_getDerivedScale());
} else if (movableType == "Entity") {
// get the entity to check
Ogre::Entity *pentity =
static_cast<Ogre::Entity*>(query_result[qr_idx].movable);
// get the mesh information
GetMeshInformation(pentity, vertex_count, vertices, index_count,
indices,
pentity->getParentNode()->_getDerivedPosition(),
pentity->getParentNode()->_getDerivedOrientation(),
pentity->getParentNode()->_getDerivedScale());
} else {
continue;
}
// test for hitting individual triangles on the mesh
bool new_closest_found = false;
for (int i = 0; i < static_cast<int>(index_count); i += 3) {
// check for a hit against this triangle
std::pair<bool, Ogre::Real> hit = Ogre::Math::intersects(ray,
vertices[indices[i]], vertices[indices[i + 1]],
vertices[indices[i + 2]], true, false);
// if it was a hit check if its the closest
if (hit.first
&& (closest_distance < 0.0f
|| hit.second < closest_distance)) {
// this is the closest so far, save it off
closest_distance = hit.second;
new_closest_found = true;
}
}
//.........这里部分代码省略.........
示例3: frameRenderingQueued
bool OgreSmartBody::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
if(mWindow->isClosed())
return false;
//Need to capture/update each device
mKeyboard->capture();
mMouse->capture();
if(mKeyboard->isKeyDown(OIS::KC_ESCAPE))
return false;
// smartbody
if (!m_pScene)
return true;
SmartBody::SBSimulationManager* sim = m_pScene->getSimulationManager();
sim->setTime((Ogre::Root::getSingleton().getTimer()->getMilliseconds() / 1000.0f) - mStartTime);
m_pScene->update();
int numCharacters = m_pScene->getNumCharacters();
if (numCharacters == 0)
return true;
const std::vector<std::string>& characterNames = m_pScene->getCharacterNames();
for (size_t n = 0; n < characterNames.size(); n++)
{
SmartBody::SBCharacter* character = m_pScene->getCharacter(characterNames[n]);
if (!this->getSceneManager()->hasEntity(characterNames[n]))
continue;
Ogre::Entity* entity = this->getSceneManager()->getEntity(characterNames[n]);
Ogre::Skeleton* meshSkel = entity->getSkeleton();
Ogre::Node* node = entity->getParentNode();
SrVec pos = character->getPosition();
SrQuat ori = character->getOrientation();
//std::cout << ori.w << ori.x << " " << ori.y << " " << ori.z << std::endl;
node->setPosition(pos.x, pos.y, pos.z);
node->setOrientation(ori.w, ori.x, ori.y, ori.z);
// Update joints
SmartBody::SBSkeleton* sbSkel = character->getSkeleton();
int numJoints = sbSkel->getNumJoints();
for (int j = 0; j < numJoints; j++)
{
SmartBody::SBJoint* joint = sbSkel->getJoint(j);
try
{
SrQuat orientation = joint->quat()->value();
Ogre::Vector3 posDelta(joint->getPosition().x, joint->getPosition().y, joint->getPosition().z);
Ogre::Quaternion quatDelta(orientation.w, orientation.x, orientation.y, orientation.z);
Ogre::Bone* bone = meshSkel->getBone(joint->getName());
if (!bone)
continue;
bone->setPosition(bone->getInitialPosition() + posDelta);
bone->setOrientation(quatDelta);
}
catch (Ogre::ItemIdentityException& ex)
{
// Should not happen as we filtered using m_mValidBones
}
}
}
return true;
}
示例4: raycast
bool CollisionTools::raycast(const Ray &ray, Vector3 &result,unsigned long &target,float &closest_distance, const uint32 queryMask)
{
target = NULL;
// check we are initialised
if (mRaySceneQuery != NULL)
{
// create a query object
mRaySceneQuery->setRay(ray);
mRaySceneQuery->setSortByDistance(true);
mRaySceneQuery->setQueryMask(queryMask);
// execute the query, returns a vector of hits
if (mRaySceneQuery->execute().size() <= 0)
{
// raycast did not hit an objects bounding box
return (false);
}
}
else
{
//LOG_ERROR << "Cannot raycast without RaySceneQuery instance" << ENDLOG;
return (false);
}
// at this point we have raycast to a series of different objects bounding boxes.
// we need to test these different objects to see which is the first polygon hit.
// there are some minor optimizations (distance based) that mean we wont have to
// check all of the objects most of the time, but the worst case scenario is that
// we need to test every triangle of every object.
//Ogre::Real closest_distance = -1.0f;
closest_distance = -1.0f;
Ogre::Vector3 closest_result;
Ogre::RaySceneQueryResult &query_result = mRaySceneQuery->getLastResults();
for (size_t qr_idx = 0; qr_idx < query_result.size(); qr_idx++)
{
// stop checking if we have found a raycast hit that is closer
// than all remaining entities
if ((closest_distance >= 0.0f) &&
(closest_distance < query_result[qr_idx].distance))
{
break;
}
// only check this result if its a hit against an entity
if ((query_result[qr_idx].movable != NULL) &&
(query_result[qr_idx].movable->getMovableType().compare("Entity") == 0))
{
// get the entity to check
Ogre::Entity *pentity = static_cast<Ogre::Entity*>(query_result[qr_idx].movable);
// mesh data to retrieve
size_t vertex_count;
size_t index_count;
Ogre::Vector3 *vertices;
unsigned long *indices;
// get the mesh information
GetMeshInformation(pentity->getMesh(), vertex_count, vertices, index_count, indices,
pentity->getParentNode()->_getDerivedPosition(),
pentity->getParentNode()->_getDerivedOrientation(),
pentity->getParentNode()->getScale());
// test for hitting individual triangles on the mesh
bool new_closest_found = false;
for (int i = 0; i < static_cast<int>(index_count); i += 3)
{
// check for a hit against this triangle
std::pair<bool, Ogre::Real> hit = Ogre::Math::intersects(ray, vertices[indices[i]],
vertices[indices[i+1]], vertices[indices[i+2]], true, false);
// if it was a hit check if its the closest
if (hit.first)
{
if ((closest_distance < 0.0f) ||
(hit.second < closest_distance))
{
// this is the closest so far, save it off
closest_distance = hit.second;
new_closest_found = true;
}
}
}
// free the verticies and indicies memory
delete[] vertices;
delete[] indices;
// if we found a new closest raycast for this object, update the
// closest_result before moving on to the next object.
if (new_closest_found)
{
target = (unsigned long)pentity;
closest_result = ray.getPoint(closest_distance);
}
}
}
// return the result
if (closest_distance >= 0.0f)
{
//.........这里部分代码省略.........
示例5: saveAsDotScene
void saveAsDotScene(const QString& path, QFile& file, Ogre::SceneManager* sceneManager)
{
Ogre::MeshSerializer* mMeshSerializer = new Ogre::MeshSerializer();
Ogre::MaterialSerializer* mMaterialSerializer = new Ogre::MaterialSerializer();
int idCounter = 3;
if (!file.open(QIODevice::WriteOnly))
{
/* show wrror message if not able to open file */
QMessageBox::warning(0, "Read only", "The file is in read only mode");
}
else
{
Ogre::SceneManager::MovableObjectIterator iterator = sceneManager->getMovableObjectIterator("Entity");
QXmlStreamWriter* xmlWriter = new QXmlStreamWriter();
xmlWriter->setAutoFormatting(true);
xmlWriter->setDevice(&file);
xmlWriter->writeStartElement("scene");
xmlWriter->writeAttribute("formatVersion","");
xmlWriter->writeStartElement("nodes");
while(iterator.hasMoreElements())
{
Ogre::Entity* e = static_cast<Ogre::Entity*>(iterator.getNext());
Ogre::Any any = e->getParentNode()->getUserAny();
Ogre::String widgetType("");
if(!any.isEmpty()){
widgetType = any_cast<Ogre::String>(any);
}
Ogre::String tmp(widgetType + ":" + e->getParentNode()->getName());
QString nodeName(tmp.c_str());
xmlWriter->writeStartElement("node");
xmlWriter->writeAttribute("name", nodeName);
xmlWriter->writeAttribute("id", QString::number(idCounter++));
xmlWriter->writeStartElement("position");
xmlWriter->writeAttribute("x", QString::number(e->getParentNode()->getPosition().x));
xmlWriter->writeAttribute("y", QString::number(e->getParentNode()->getPosition().y));
xmlWriter->writeAttribute("z", QString::number(e->getParentNode()->getPosition().z));
xmlWriter->writeEndElement();
xmlWriter->writeStartElement("scale");
xmlWriter->writeAttribute("x", QString::number(e->getParentNode()->getScale().x));
xmlWriter->writeAttribute("y", QString::number(e->getParentNode()->getScale().y));
xmlWriter->writeAttribute("z", QString::number(e->getParentNode()->getScale().z));
xmlWriter->writeEndElement();
xmlWriter->writeStartElement("entity");
xmlWriter->writeAttribute("name", nodeName);
xmlWriter->writeAttribute("meshFile", nodeName.toLower() + QString(".mesh") );
xmlWriter->writeAttribute("static", QString("false"));
xmlWriter->writeEndElement();
const Mesh* mesh = e->getMesh().getPointer();
mMeshSerializer->exportMesh(mesh,String(path.toStdString() +
nodeName.toLower().toStdString() +
".mesh" ));
std::cout << "numeber" << mesh->getNumSubMeshes() << std::endl;
for(int i = 0; i < e->getNumSubEntities(); i++){
Ogre::Material *mat = static_cast<Ogre::Material*>
(Ogre::MaterialManager::getSingletonPtr()->getByName(e->getSubEntity(i)->getMaterialName()).getPointer());
//e->getMesh().get()->getSubMesh()
if(mat->getTechnique(0)->getPass(0)->getNumTextureUnitStates() !=0){
Ogre::String str = mat->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getTextureName();
Ogre::MaterialPtr mMatPtr =e->getSubEntity(i)->getMaterial() ;
mMaterialSerializer->exportMaterial(mMatPtr ,
String(path.toStdString() +
nodeName.toLower().toStdString() +
QString::number(i).toStdString() + ".material" ));
Ogre::TexturePtr* mTexPtr = new Ogre::TexturePtr(Ogre::TextureManager::getSingletonPtr()->getByName(str));
Ogre::Texture* mTex = mTexPtr->getPointer();
Ogre::PixelFormat pxf = mTex->getFormat();
Ogre::Image mImage;
mTex->convertToImage(mImage);
std::cout << str << std::endl;
mImage.save(String(path.toStdString() +
str));
}
}
//material file merge
for(int i = 0; i < e->getNumSubEntities(); i++){
Ogre::Material *mat = static_cast<Ogre::Material*>
(Ogre::MaterialManager::getSingletonPtr()->getByName(e->getSubEntity(i)->getMaterialName()).getPointer());
QString mMatFilePath = QString((path.toStdString() +
nodeName.toLower().toStdString() +
//.........这里部分代码省略.........
示例6: UpdateVisualEffects
void EC_OgreEnvironment::UpdateVisualEffects(f64 frametime)
{
if (renderer_.expired())
return;
RendererPtr renderer = renderer_.lock();
Ogre::Camera *camera = renderer->GetCurrentCamera();
Ogre::Viewport *viewport = renderer->GetViewport();
Ogre::SceneManager *sceneManager = renderer->GetSceneManager();
#ifdef CAELUM
// Set sunlight attenuation using diffuse multiplier.
// Seems to be working ok, but feel free to fix if you find better logic and/or values.
Ogre::ColourValue diffuseMultiplier(sunColorMultiplier_, sunColorMultiplier_, sunColorMultiplier_, 1);
caelumSystem_->getSun()->setDiffuseMultiplier(diffuseMultiplier);
Ogre::Light* sun = caelumSystem_->getSun()->getMainLight();
Ogre::Light* moon = caelumSystem_->getMoon()->getMainLight();
float sunDirZaxis = caelumSystem_->getSun()->getMainLight()->getDirection().z;
if (sunDirZaxis > 0)
{
sunColorMultiplier_ -= 0.005f;
if (sunColorMultiplier_ <= 0.05f)
sunColorMultiplier_ = 0.05f;
}
else if(sunDirZaxis < 0)
{
sunColorMultiplier_ += 0.010f;
if (sunColorMultiplier_ >= MAX_SUNLIGHT_MULTIPLIER)
sunColorMultiplier_ = MAX_SUNLIGHT_MULTIPLIER;
}
if ( !fog_color_override_)
fogColor_ = caelumSystem_->getGroundFog()->getColour();
#endif
#ifdef CAELUM
// Update Caelum system.
caelumSystem_->notifyCameraChanged(camera);
caelumSystem_->updateSubcomponents(frametime);
// Disable specular from the sun & moon for now, because it easily leads to too strong results
sun->setSpecularColour(0.0f, 0.0f, 0.0f);
moon->setSpecularColour(0.0f, 0.0f, 0.0f);
#endif
#ifdef HYDRAX
// Update Hydrax system.
hydraxSystem_->update(frametime);
sunPos = camera->getPosition();
sunPos -= caelumSystem_->getSun()->getLightDirection() * 80000;
hydraxSystem_->setSunPosition(sunPos);
#endif
Ogre::Entity* water = 0;
cameraFarClip_ = renderer->GetViewDistance();
if ( sceneManager->hasEntity("WaterEntity") )
water = sceneManager->getEntity("WaterEntity");
if (!water)
{
// No water entity, set fog value.
Real fogStart = fogStart_;
Real fogEnd = fogEnd_;
ClampFog(fogStart, fogEnd, cameraFarClip_);
sceneManager->setFog(Ogre::FOG_LINEAR, fogColor_, 0.001, fogStart, fogEnd);
viewport->setBackgroundColour(fogColor_);
camera->setFarClipDistance(cameraFarClip_);
}
else
{
if(camera->getDerivedPosition().z >= water->getParentNode()->getPosition().z)
{
// We're above the water.
Real fogStart = fogStart_;
Real fogEnd = fogEnd_;
ClampFog(fogStart, fogEnd, cameraFarClip_);
#ifdef CAELUM
caelumSystem_->forceSubcomponentVisibilityFlags(caelumComponents_);
#endif
sceneManager->setFog(Ogre::FOG_LINEAR, fogColor_, 0.001, fogStart, fogEnd);
viewport->setBackgroundColour(fogColor_);
camera->setFarClipDistance(cameraFarClip_);
cameraUnderWater_ = false;
}
else
{
// We're below the water.
Real fogStart = waterFogStart_;
Real fogEnd = waterFogEnd_;
Real farClip = waterFogEnd_ + 10.f;
if (farClip > cameraFarClip_)
farClip = cameraFarClip_;
//.........这里部分代码省略.........
示例7: EngineSetup
void CTerrainWalkingView::EngineSetup(void)
{
Ogre::Root *Root = ((CTerrainWalkingApp*)AfxGetApp())->m_Engine->GetRoot();
Ogre::SceneManager *SceneManager = NULL;
SceneManager = Root->createSceneManager(Ogre::ST_GENERIC, "Walking");
//
// Create a render window
// This window should be the current ChildView window using the externalWindowHandle
// value pair option.
//
Ogre::NameValuePairList parms;
parms["externalWindowHandle"] = Ogre::StringConverter::toString((long)m_hWnd);
parms["vsync"] = "true";
CRect rect;
GetClientRect(&rect);
Ogre::RenderTarget *RenderWindow = Root->getRenderTarget("Walking");
if (RenderWindow == NULL)
{
try
{
m_RenderWindow = Root->createRenderWindow("Walking", rect.Width(), rect.Height(), false, &parms);
}
catch(...)
{
MessageBox("Cannot initialize\nCheck that graphic-card driver is up-to-date", "Initialize Render System", MB_OK | MB_ICONSTOP);
exit(EXIT_SUCCESS);
}
}
// Load resources
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
// Create the camera
m_Camera = SceneManager->createCamera("Camera");
m_Camera->setNearClipDistance(10);
m_Camera->setFarClipDistance(10000);
m_Camera->setCastShadows(false);
m_Camera->setUseRenderingDistance(true);
Ogre::SceneNode *CameraNode = NULL;
CameraNode = SceneManager->getRootSceneNode()->createChildSceneNode("CameraNode");
Ogre::Viewport* Viewport = NULL;
if (0 == m_RenderWindow->getNumViewports())
{
Viewport = m_RenderWindow->addViewport(m_Camera);
Viewport->setBackgroundColour(Ogre::ColourValue(0.8f, 0.8f, 0.8f));
}
// Alter the camera aspect ratio to match the viewport
m_Camera->setAspectRatio(Ogre::Real(rect.Width()) / Ogre::Real(rect.Height()));
Ogre::SceneNode *TopographyNode = SceneManager->getRootSceneNode()->createChildSceneNode("Topography");
Ogre::Entity *TopographyEntity = SceneManager->createEntity("Topography", "Topography.mesh");
TopographyNode->attachObject(TopographyEntity);
Ogre::AxisAlignedBox TopographyBox = TopographyEntity->getBoundingBox();
Ogre::Vector3 Minimum = TopographyBox.getMinimum();
Ogre::Vector3 Center = TopographyBox.getCenter();
Ogre::SceneNode *RobotNode = SceneManager->getRootSceneNode()->createChildSceneNode("Robot");
Ogre::Entity *RobotEntity = SceneManager->createEntity("Robot", "robot.mesh");
RobotNode->attachObject(RobotEntity);
RobotEntity->getParentNode()->scale(10,10,10);
Ogre::AxisAlignedBox RobotBox = RobotEntity->getBoundingBox();
RobotNode->setPosition(Ogre::Vector3(Minimum[0], Minimum[1] + RobotBox.getSize()[1], Minimum[2]));
m_Camera->setPosition(Ogre::Vector3(Minimum[0], Minimum[1] + 5000, Minimum[2]));
m_Camera->lookAt(Center);
m_Camera->setPolygonMode(Ogre::PolygonMode::PM_WIREFRAME);
m_Animation = RobotEntity->getAnimationState("Walk");
m_Animation->setEnabled(true);
m_CollisionTools = new MOC::CollisionTools(SceneManager);
Root->renderOneFrame();
}
开发者ID:southerlies,项目名称:OGRE-3D-1.7-Application-Development-Cookbook-Code,代码行数:85,代码来源:TerrainWalkingView.cpp
示例8: updateLocomote
void Ninja::updateLocomote(Ogre::Real deltaTime)
{
int xOffset = ((this->grid->getRows() * this->grid->getHeight()) - this->grid->getHeight())/2;
int yOffset = ((this->grid->getCols() * this->grid->getHeight()) - this->grid->getHeight())/2;
int x = (xOffset + mDestination.x)/grid->getHeight();
int y = (yOffset + mDestination.z)/grid->getHeight();
if (mDirection == Ogre::Vector3::ZERO)
{
if (nextLocation()) // a check to see if there is another destination
{
// Set walking animation
this->setBaseAnimation(ANIM_WALK, true);
//this->setTopAnimation(ANIM_WALK, true);
}
}
else
{
Ogre::Real move = mWalkSpeed * deltaTime;
mDistance -= move;
if (mDistance <= 0.0f) // over shooting target
{
this->mBodyNode->setPosition(mDestination);
this->setCurrentNode(grid->getNode(x, y));
while(this->getCurrentNode()->getItemList()->size() > 0)
{
Ogre::Entity* ent = this->getCurrentNode()->getItemList()->front();
this->inventory->push_back(ent);
this->getCurrentNode()->getItemList()->pop();
ent->detachFromParent();
this->getmBodyEntity()->attachObjectToBone("Joint13", ent);
ent->getParentNode()->scale(1.15f,1.15f,1.15f);
ent->setVisible(true);
}
mDirection = Ogre::Vector3::ZERO;
if (!nextLocation()) // a check to see if there is another destination
{
this->setCurrentNode(grid->getNode(x, y));
this->setBaseAnimation(ANIM_IDLE_1, true);
//this->setTopAnimation(ANIM_IDLE_1, true);
}
else
{
Ogre::Vector3 src = this->mBodyNode->getOrientation() * Ogre::Vector3::UNIT_X;
if ((1.0f + src.dotProduct(mDirection)) < 0.0001f)
{
this->mBodyNode->yaw(Ogre::Degree(180));
}
else
{
Ogre::Quaternion quat = src.getRotationTo(mDirection);
this->mBodyNode->rotate(quat);
this->mBodyNode->yaw(Ogre::Degree(angleOffset)); // To correct for models facing different directions
}
}
}
else
{
this->mBodyNode->translate(mDirection * move);
}
}
}
示例9: EngineSetup
void CBlendingAnimationsView::EngineSetup(void)
{
Ogre::Root *Root = ((CBlendingAnimationsApp*)AfxGetApp())->m_Engine->GetRoot();
Ogre::SceneManager *SceneManager = NULL;
SceneManager = Root->createSceneManager(Ogre::ST_GENERIC, "Walking");
//
// Create a render window
// This window should be the current ChildView window using the externalWindowHandle
// value pair option.
//
Ogre::NameValuePairList parms;
parms["externalWindowHandle"] = Ogre::StringConverter::toString((long)m_hWnd);
parms["vsync"] = "true";
CRect rect;
GetClientRect(&rect);
Ogre::RenderTarget *RenderWindow = Root->getRenderTarget("Mouse Input");
if (RenderWindow == NULL)
{
try
{
m_RenderWindow = Root->createRenderWindow("Mouse Input", rect.Width(), rect.Height(), false, &parms);
}
catch(...)
{
MessageBox("Cannot initialize\nCheck that graphic-card driver is up-to-date", "Initialize Render System", MB_OK | MB_ICONSTOP);
exit(EXIT_SUCCESS);
}
}
// Load resources
Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
// Create the camera
m_Camera = SceneManager->createCamera("Camera");
m_Camera->setNearClipDistance(0.5);
m_Camera->setFarClipDistance(5000);
m_Camera->setCastShadows(false);
m_Camera->setUseRenderingDistance(true);
m_Camera->setPosition(Ogre::Vector3(/*20*/0.0, /*5*/0.0, 100.0));
Ogre::SceneNode *CameraNode = NULL;
CameraNode = SceneManager->getRootSceneNode()->createChildSceneNode("CameraNode");
Ogre::Viewport* Viewport = NULL;
if (0 == m_RenderWindow->getNumViewports())
{
Viewport = m_RenderWindow->addViewport(m_Camera);
Viewport->setBackgroundColour(Ogre::ColourValue(0.8f, 0.8f, 0.8f));
}
// Alter the camera aspect ratio to match the viewport
m_Camera->setAspectRatio(Ogre::Real(rect.Width()) / Ogre::Real(rect.Height()));
Ogre::SceneNode *RobotNode = SceneManager->getRootSceneNode()->createChildSceneNode("Robot", Ogre::Vector3(50,0,0));
Ogre::Entity *RobotEntity = SceneManager->createEntity("Robot", "robot.mesh");
Ogre::MeshPtr Mesh = RobotEntity->getMesh();
RobotNode->attachObject(RobotEntity);
RobotEntity->getParentNode()->scale(0.2,0.2,0.2);
m_Camera->lookAt(Ogre::Vector3(0.0, 0.0, 0.0));
RobotEntity->setDisplaySkeleton(true);
m_Camera->setPolygonMode(Ogre::PolygonMode::PM_WIREFRAME);
m_WalkAnimation = RobotEntity->getAnimationState("Walk");
m_WalkAnimation->setEnabled(true);
m_SlumpAnimation = RobotEntity->getAnimationState("Slump");
m_SlumpAnimation->setEnabled(true);
if (m_WeightDlg == NULL)
{
m_WeightDlg = new CWeightDlg();
m_WeightDlg->Create(IDD_WEIGHT_CONTROL);
}
m_WeightDlg->ShowWindow(SW_SHOW);
Root->renderOneFrame();
}
开发者ID:southerlies,项目名称:OGRE-3D-1.7-Application-Development-Cookbook-Code,代码行数:84,代码来源:BlendingAnimationsView.cpp
示例10: ray
// raycast from a point in to the scene.
// returns success or failure.
// on success the point is returned in the result.
bool
PolyMousePicker::RaycastFromPoint(
const Vector3 &point,
const Vector3 &normal,
Vector3 &result,
Ogre::MovableObject** out,
Ogre::uint32 mask)
{
//~ assert(filter);
// create the ray to test
Ogre::Ray ray(Ogre::Vector3(point.x, point.y, point.z),
Ogre::Vector3(normal.x, normal.y, normal.z));
// check we are initialised
if (mRayQuery != NULL)
{
// create a query object
mRayQuery->setRay(ray);
//~ mRayQuery->setQueryTypeMask(Ogre::SceneManager::USER_TYPE_MASK_LIMIT);
mRayQuery->setQueryMask(mask);
// execute the query, returns a vector of hits
if (mRayQuery->execute().size() <= 0)
{
// raycast did not hit an objects bounding box
return (false);
}
}
else
{
std::cerr << "Cannot raycast without RaySceneQuery instance\n";
return (false);
}
// at this point we have raycast to a series of different objects bounding boxes.
// we need to test these different objects to see which is the first polygon hit.
// there are some minor optimizations (distance based) that mean we wont have to
// check all of the objects most of the time, but the worst case scenario is that
// we need to test every triangle of every object.
Ogre::Real closest_distance = -1.0f;
Ogre::Vector3 closest_result;
Ogre::RaySceneQueryResult &query_result = mRayQuery->getLastResults();
for (size_t qr_idx = 0; qr_idx < query_result.size(); qr_idx++)
{
// stop checking if we have found a raycast hit that is closer
// than all remaining entities
if ((closest_distance >= 0.0f) &&
(closest_distance < query_result[qr_idx].distance))
{
break;
}
// only check this result if its a hit against an entity
if ((query_result[qr_idx].movable != NULL)
//~ && (*filter)(query_result[qr_idx].movable))
//~ && (query_result[qr_idx].movable->getMovableType().compare("Entity") == 0)
)
{
// get the entity to check
Ogre::Entity *pentity = static_cast<Ogre::Entity*>(query_result[qr_idx].movable);
// mesh data to retrieve
size_t vertex_count;
size_t index_count;
Ogre::Vector3 *vertices;
Ogre::uint32 *indices;
// get the mesh information
GetMeshInformation(pentity, vertex_count, vertices, index_count, indices,
pentity->getParentNode()->_getDerivedPosition(),
pentity->getParentNode()->_getDerivedOrientation(),
pentity->getParentNode()->_getDerivedScale());
// test for hitting individual triangles on the mesh
bool new_closest_found = false;
for (int i = 0; i < static_cast<int>(index_count); i += 3)
{
// check for a hit against this triangle
std::pair<bool, Ogre::Real> hit = Ogre::Math::intersects(ray, vertices[indices[i]],
vertices[indices[i+1]], vertices[indices[i+2]], true, false);
// if it was a hit check if its the closest
if (hit.first)
{
if ((closest_distance < 0.0f) ||
(hit.second < closest_distance))
{
// this is the closest so far, save it off
closest_distance = hit.second;
new_closest_found = true;
}
}
}
// free the verticies and indicies memory
//.........这里部分代码省略.........