bool LevelGeometryLoader::processNodes(TiXmlElement *XMLNode) { ASSERT(XMLNode); TiXmlElement *pElement; XMLNode = XMLNode->FirstChildElement("nodes"); if(!XMLNode){ debugWARNING("No entities found in the scene\n"); return false; } // Process node (*) pElement = XMLNode->FirstChildElement("node"); while(pElement) { Ogre::SceneNode *node = 0; if(!processNode(pElement, node)){ debugERROR("Error processing node\n"); ASSERT(false); return false; } pElement = pElement->NextSiblingElement("node"); ASSERT(node); ASSERT(node->getAttachedObject(0)); // we have something attached mEntities.push_back(node); } return true; }
//----------------------------------------------------------------------- void EntityRenderer::_updateRenderQueue(Ogre::RenderQueue* queue, ParticlePool* pool) { // Always perform this one ParticleRenderer::_updateRenderQueue(queue, pool); if (!mVisible) return; // Fast check to determine whether there are visual particles if (pool->isEmpty(Particle::PT_VISUAL)) return; VisualParticle* particle = static_cast<VisualParticle*>(pool->getFirst(Particle::PT_VISUAL)); while (!pool->end(Particle::PT_VISUAL)) { if (particle) { if (!particle->visualData && !mVisualData.empty()) { particle->visualData = mVisualData.back(); mVisualData.pop_back(); } if (particle->visualData) { Ogre::SceneNode* node = (static_cast<EntityRendererVisualData*>(particle->visualData))->node; if (node) { node->_setDerivedPosition(particle->position); if (mEntityOrientationType == ENT_ORIENTED_SHAPE) { // Use the orientation of the particle itself node->setOrientation(particle->orientation); } else if (mEntityOrientationType == ENT_ORIENTED_SELF) { // Rotate towards the direction node->setOrientation(Vector3::UNIT_X.getRotationTo(particle->direction)); } else if (mEntityOrientationType == ENT_ORIENTED_SELF_MIRRORED) { // Rotate towards the negative direction node->setOrientation(Vector3::UNIT_X.getRotationTo(-particle->direction)); } node->setVisible(true); node->setScale(particle->width / mBoxWidth, particle->height / mBoxHeight, particle->depth / mBoxDepth); if (mZRotated) { _rotateTexture(particle, static_cast<Ogre::Entity*>(node->getAttachedObject(0))); // We know for sure there is only one and it is an Entity* } } } } particle = static_cast<VisualParticle*>(pool->getNext(Particle::PT_VISUAL)); } }
void ProjectileManager::destroyProjectile(Projectile* projectile){ Ogre::SceneNode* snParticle = projectile->particleSn; Ogre::ParticleSystem* particleSys = static_cast<Ogre::ParticleSystem*>(snParticle->getAttachedObject(0)); // Detach the entity from the scene node snParticle->detachObject(particleSys); // Delete the entity and the scene node mSceneMgr->destroyParticleSystem(particleSys); mSceneMgr->destroySceneNode(snParticle); delete projectile; }
void ProjectileManager::destroyExplosion(Explosion* explosion){ Ogre::SceneNode* snParticle = explosion->snExplosion; Ogre::ParticleSystem* particleSys = static_cast<Ogre::ParticleSystem*>(snParticle->getAttachedObject(0)); // Detach the entity from the scene node snParticle->detachObject(particleSys); // Delete the entity and the scene node mSceneMgr->destroyParticleSystem(particleSys); mSceneMgr->destroySceneNode(snParticle); delete explosion; }
void CsCameraManager::Load (Ogre::SceneNode* ogreScene) { UnLoad(); SetupDefaultCamera(); if (ogreScene == NULL) return; Ogre::Node::ChildNodeIterator it = ogreScene->getChildIterator(); Ogre::SceneNode *tempNode; while (it.hasMoreElements()) { tempNode = static_cast <Ogre::SceneNode*> (it.getNext()); assert(tempNode); if ((tempNode->getName().find("Camera")) != std::string::npos) { ogreScene->removeChild(tempNode); if (tempNode->getName().find("Free") != std::string::npos) AddCamera((Ogre::Camera*)tempNode->getAttachedObject(0), Chaos::FREE_CAMERA); else if (tempNode->getName().find("Track") != std::string::npos) AddCamera((Ogre::Camera*)tempNode->getAttachedObject(0), Chaos::TRACK_CAMERA); else if (tempNode->getName().find("Chase") != std::string::npos) { AddCamera((Ogre::Camera*)tempNode->getAttachedObject(0), Chaos::CHASE_CAMERA); if (tempNode->getName().find("001") != std::string::npos) { mCurrentCamera = mCameraList.size() - 1; ApplyCamera(); } } else if (tempNode->getName().find("Cockpit") != std::string::npos) AddCamera((Ogre::Camera*)tempNode->getAttachedObject(0), Chaos::COCKPIT_CAMERA); } } mCurrentCamera = 0; ApplyCamera(); }
bool SnapToMovement::testSnapTo(const WFMath::Point<3>& position, const WFMath::Quaternion& orientation, WFMath::Vector<3>& adjustment, EmberEntity* snappedToEntity) { try { for (std::vector<Ogre::SceneNode*>::iterator I = mDebugNodes.begin(); I != mDebugNodes.end(); ++I) { Ogre::SceneNode* node = *I; node->setVisible(false); Ogre::Entity* sphereEntity = static_cast<Ogre::Entity*> (node->getAttachedObject(0)); sphereEntity->setMaterialName("/global/authoring/point"); } } catch (const std::exception& ex) { S_LOG_WARNING("Error when setting up debug nodes for snapping." << ex); } std::vector<Ogre::SceneNode*>::iterator nodeIterator = mDebugNodes.begin(); //Use an auto pointer to allow both for undefined values and automatic cleanup when exiting the method. std::auto_ptr<SnapPointCandidate> closestSnapping(0); WFMath::AxisBox<3> currentBbox = mEntity.getBBox(); //Translate the bbox into a rotbox WFMath::RotBox<3> currentRotbox; currentRotbox.size() = currentBbox.highCorner() - currentBbox.lowCorner(); currentRotbox.corner0() = currentBbox.lowCorner(); currentRotbox.orientation().identity(); currentRotbox.rotatePoint(orientation, WFMath::Point<3>(0, 0, 0)); currentRotbox.shift(WFMath::Vector<3>(position)); //See if we should visualize debug nodes for the moved entity for (size_t j = 0; j < currentRotbox.numCorners(); ++j) { WFMath::Point<3> currentPoint = currentRotbox.getCorner(j); if (currentPoint.isValid() && nodeIterator != mDebugNodes.end()) { Ogre::SceneNode* node = *nodeIterator; node->setPosition(Convert::toOgre(currentPoint)); node->setVisible(true); nodeIterator++; } } //First find all entities which are close enough //Then try to do a snap movement based on the points of the eris bounding boxes. I.e. we only provide support for snapping one corner of a bounding box to another corner (for now). WFMath::Ball<3> boundingSphere = mEntity.getBBox().boundingSphere(); Ogre::Sphere sphere(mNode._getDerivedPosition(), boundingSphere.radius() * 2); Ogre::SphereSceneQuery* query = mSceneManager.createSphereQuery(sphere); Ogre::SceneQueryResult& result = query->execute(); for (Ogre::SceneQueryResultMovableList::const_iterator I = result.movables.begin(); I != result.movables.end(); ++I) { Ogre::MovableObject* movable = *I; if (movable->getUserAny().getType() == typeid(EmberEntityUserObject::SharedPtr)) { EmberEntityUserObject* anUserObject = Ogre::any_cast<EmberEntityUserObject::SharedPtr>(movable->getUserAny()).get(); EmberEntity& entity = anUserObject->getEmberEntity(); if (&entity != &mEntity && entity.hasBBox()) { //Ok, we have an entity which is close to our entity. Now check if any of the points of the bounding box is close. WFMath::AxisBox<3> bbox = entity.getBBox(); if (bbox.isValid()) { WFMath::RotBox<3> rotbox; rotbox.size() = bbox.highCorner() - bbox.lowCorner(); rotbox.corner0() = bbox.lowCorner(); rotbox.orientation().identity(); rotbox.rotatePoint(entity.getViewOrientation(), WFMath::Point<3>(0, 0, 0)); rotbox.shift(WFMath::Vector<3>(entity.getViewPosition())); for (size_t i = 0; i < rotbox.numCorners(); ++i) { WFMath::Point<3> point = rotbox.getCorner(i); Ogre::SceneNode* currentNode(0); //If there is any unclaimed debug node left we'll use it to visualize the corner if (nodeIterator != mDebugNodes.end()) { currentNode = *nodeIterator; currentNode->setPosition(Convert::toOgre(point)); currentNode->setVisible(true); nodeIterator++; } point.z() = 0; for (size_t j = 0; j < currentRotbox.numCorners(); ++j) { WFMath::Point<3> currentPoint = currentRotbox.getCorner(j); currentPoint.z() = 0; WFMath::CoordType distance = WFMath::Distance(currentPoint, point); if (distance <= mSnapThreshold) { if (currentNode) { Ogre::Entity* sphereEntity = static_cast<Ogre::Entity*> (currentNode->getAttachedObject(0)); if (sphereEntity) { try { sphereEntity->setMaterialName("/global/authoring/point/moved"); } catch (const std::exception& ex) { S_LOG_WARNING("Error when setting material for point." << ex); } } } if (!closestSnapping.get()) { closestSnapping = std::auto_ptr<SnapPointCandidate>(new SnapPointCandidate()); closestSnapping->entity = &entity; closestSnapping->distance = distance; closestSnapping->adjustment = point - currentPoint; } else if (distance < closestSnapping->distance) { closestSnapping->entity = &entity; closestSnapping->distance = distance; closestSnapping->adjustment = point - currentPoint; } } } } } } } } mSceneManager.destroyQuery(query); if (closestSnapping.get()) { adjustment = closestSnapping->adjustment; snappedToEntity = closestSnapping->entity; return true; } return false; }
Entity Factory::createTank(entityx::ptr<entityx::EntityManager> entityMgr, std::string prefix,Ogre::Real velocity,Ogre::Real angularVelocity ,Ogre::Vector3 overHating,int health,bool ai) { DotSceneLoader loader; Ogre::SceneManager* sceneMgr = RenderManager::getPtr()->getSceneManager(); loader.parseDotScene("tank.scene", "General", sceneMgr, 0, prefix); Ogre::SceneNode* ctl = sceneMgr->getSceneNode(prefix + "TankControl"); Ogre::SceneNode* body = sceneMgr->getSceneNode(prefix + "TankBody"); Ogre::SceneNode* turret = sceneMgr->getSceneNode(prefix + "TankTurret"); Ogre::SceneNode* cannon = sceneMgr->getSceneNode(prefix +"TankCannon"); Entity tankEmptyControl = entityMgr->create(); Entity tankTurret = entityMgr->create(); Entity tankBody = entityMgr->create(); Entity tankCannon = entityMgr->create(); tankEmptyControl.assign<Position>(ctl->getPosition()); tankEmptyControl.assign<Orientation>(ctl->getOrientation()); tankEmptyControl.assign<Velocity>(0, 0, velocity); tankEmptyControl.assign<AngularVelocity>(0, angularVelocity, 0); tankEmptyControl.assign<Renderable>(ctl); tankEmptyControl.assign<OverHeating>(overHating.x,overHating.y,overHating.z); tankEmptyControl.assign<Destroyable>(health,health); tankEmptyControl.assign<Collidable>(); tankEmptyControl.assign<Name>(prefix); if(ai){ tankEmptyControl.assign<AI>(); Ogre::Entity *model = static_cast<Ogre::Entity*>(body->getAttachedObject(0)); model->getSubEntity(1)->setMaterialName("Red"); model = static_cast<Ogre::Entity*>(turret->getAttachedObject(0)); model->getSubEntity(1)->setMaterialName("Red"); model = static_cast<Ogre::Entity*>(cannon->getAttachedObject(0)); model->getSubEntity(1)->setMaterialName("Red"); } ptr<Children> child = tankEmptyControl.assign<Children>(); child->children["body"] = tankBody; child->children["turret"] = tankTurret; //child->children.push_back(tankBody); //child->children.push_back(tankTurret); tankTurret.assign<Position>(turret->getPosition()); tankTurret.assign<Orientation>(turret->getOrientation()); tankTurret.assign<Renderable>(turret); child = tankTurret.assign<Children>(); child->children["cannon"] = tankCannon; tankBody.assign<Position>(body->getPosition()); tankBody.assign<Orientation>(body->getOrientation()); tankBody.assign<Renderable>(body); tankCannon.assign<Position>(cannon->getPosition()); tankCannon.assign<Renderable>(cannon); tankCannon.assign<Orientation>(cannon->getOrientation()); ctl->scale(.35, .55, .35); return tankEmptyControl; }
void TutorialApplication::loadMap(l2p::StringRef name) { l2p::Package *package = l2p::Package::GetPackage(name); if (!package) return; std::vector<std::shared_ptr<l2p::UModel>> models; package->GetObjects("Model", models); // Find the largest model. The others aren't right or something like that... std::shared_ptr<l2p::UModel> m = nullptr; for (auto i = models.begin(), e = models.end(); i != e; ++i) { if (!m) { m = *i; continue; } if ((*i)->nodes.size() > m->nodes.size()) m = *i; } // Get region from path. { name.substr(0, 2).getAsInteger(10, m->regionX); name.substr(3, 2).getAsInteger(10, m->regionY); mLoadedRegions.push_back(std::make_pair(m->regionX, m->regionY)); } if (m->points.size() != 0) loadBSP(m); std::vector<std::shared_ptr<l2p::ABlockingVolume>> blocking_volumes; package->GetObjects("BlockingVolume", blocking_volumes); for (auto i = blocking_volumes.begin(), e = blocking_volumes.end(); i != e; ++i) { std::shared_ptr<l2p::UModel> m = (*i)->brush; if (m) { Ogre::SceneNode *n = loadBSP(m, false); if (n) { assignActorPropsToNode(*i, n); n->showBoundingBox(true); dynamic_cast<Ogre::Entity*>( n->getAttachedObject(0))->setMaterialName("Volume/Display"); } } } std::vector<std::shared_ptr<l2p::ATerrainInfo>> terrains; package->GetObjects("TerrainInfo", terrains); for (auto i = terrains.begin(), e = terrains.end(); i != e; ++i) { loadTerrain(*i); } std::vector<std::shared_ptr<l2p::AStaticMeshActor>> smeshes; package->GetObjects("StaticMeshActor", smeshes); package->GetObjects("MovableStaticMeshActor", smeshes); for (auto i = smeshes.begin(), e = smeshes.end(); i != e; ++i) { if ( (*i)->bHidden || (*i)->bDeleteMe || !(*i)->bCollideActors || !(*i)->bBlockActors || !(*i)->bBlockPlayers ) continue; loadStaticMeshActor(*i); } }
bool MyFrameListener::frameStarted(const FrameEvent& evt) { bool mbleft; // Botones del raton pulsados _keyboard->capture(); _mouse->capture(); // Captura eventos int posx = _mouse->getMouseState().X.abs; // Posicion del puntero int posy = _mouse->getMouseState().Y.abs; // en pixeles. // Botones del raton pulsados? ------------------------------------- mbleft = _mouse->getMouseState().buttonDown(OIS::MB_Left); if(_keyboard->isKeyDown(OIS::KC_ESCAPE)) return false; switch(_estado){ case 1: if(_keyboard->isKeyDown(OIS::KC_1)){ _sceneManager->destroySceneNode("ninicio"); _juego->generarTablero(); _juego->generarPlayers(); _juego->colocarBarcos(); _estado = 5; } if(_keyboard->isKeyDown(OIS::KC_2)){ _sceneManager->destroySceneNode("ninicio"); _juego->crearCreditos(); _estado = 2; } break; case 2: if(_keyboard->isKeyDown(OIS::KC_B)){ _sceneManager->destroySceneNode("ncreditos"); _juego->crearMenu(); _estado = 1; } break; // Exit! case 5: if (mbleft) { uint32 mask; mask = CUBE1 | STAGE; // Podemos elegir todo setRayQuery(posx, posy, mask); Ogre::RaySceneQueryResult &result = _raySceneQuery->execute(); Ogre::RaySceneQueryResult::iterator it; if(result.begin()!=result.end()){ it = result.begin(); Ogre::SceneNode* nodo = it->movable->getParentSceneNode(); Ogre::MovableObject* clickado = nodo->getAttachedObject(0); if(clickado->getQueryFlags()==CUBE1){ if(_turno==1 && (int)it->movable->getParentSceneNode()->getName()[3]-48>=0 && (int)it->movable->getParentSceneNode()->getName()[3]-48<8 && (int)it->movable->getParentSceneNode()->getName()[5]-48>=0 && (int)it->movable->getParentSceneNode()->getName()[5]-48<8){ _turno = _juego->simular((int)it->movable->getParentSceneNode()->getName()[3]-48, (int)it->movable->getParentSceneNode()->getName()[5 ]-48);//tabla ascii } if(_turno == 2){ _estado = 6; } } } } break; case 6: if(_keyboard->isKeyDown(OIS::KC_RETURN)){ _juego->reiniciar(); _juego->generarPlayers(); _juego->colocarBarcos(); _estado = 5; _turno = 1; std::cout << _estado << std::endl; } break; } return true; }
// Given a scene node for a terrain, find the manual object on that scene node and // update the manual object with the heightmap passed. If there is no manual object on // the scene node, remove all it's attachments and add the manual object. // The heightmap is passed in a 1D array ordered by width rows (for(width) {for(length) {hm[w,l]}}) // This must be called between frames since it touches the scene graph // BETWEEN FRAME OPERATION void Region::UpdateTerrain(const int hmWidth, const int hmLength, const float* hm) { Ogre::SceneNode* node = this->TerrainSceneNode; LG::Log("Region::UpdateTerrain: updating terrain for region %s", this->Name.c_str()); if (node == NULL) { LG::Log("Region::UpdateTerrain: terrain scene node doesn't exist. Not updating terrain."); return; } // Find the movable object attached to the scene node. If not found remove all. if (node->numAttachedObjects() > 0) { Ogre::MovableObject* attached = node->getAttachedObject(0); if (attached->getMovableType() != "ManualObject") { // don't know why this would ever happen but clean out the odd stuff LG::Log("Found extra stuff on terrain scene node"); node->detachAllObjects(); } } // if there is not a manual object on the node, create a new one if (node->numAttachedObjects() == 0) { LG::Log("Region::UpdateTerrain: creating terrain ManualObject for region %s", this->Name.c_str()); // if no attached objects, we add our dynamic ManualObject Ogre::ManualObject* mob = LG::RendererOgre::Instance()->m_sceneMgr->createManualObject("ManualObject/" + node->getName()); mob->addQueryFlags(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK); mob->setDynamic(true); mob->setCastShadows(true); mob->setVisible(true); node->attachObject(mob); // m_visCalc->RecalculateVisibility(); } Ogre::ManualObject* mo = (Ogre::ManualObject*)node->getAttachedObject(0); // stuff our heightmap information into the dynamic manual object mo->estimateVertexCount(hmWidth * hmLength); mo->estimateIndexCount(hmWidth * hmLength * 6); if (mo->getNumSections() == 0) { // if first time mo->begin(LG::GetParameter("Renderer.Ogre.DefaultTerrainMaterial")); } else { mo->beginUpdate(0); // we've been here before } int loc = 0; for (int xx = 0; xx < hmWidth; xx++) { for (int yy = 0; yy < hmLength; yy++) { mo->position((Ogre::Real)xx, (Ogre::Real)yy, hm[loc++]); mo->textureCoord((float)xx / (float)hmWidth, (float)yy / (float)hmLength); mo->normal(0.0, 1.0, 0.0); // always up (for the moment) } } for (int px = 0; px < hmLength-1; px++) { for (int py = 0; py < hmWidth-1; py++) { mo->quad(px + py * hmWidth, px + (py + 1) * hmWidth, (px + 1) + (py + 1) * hmWidth, (px + 1) + py * hmWidth ); } } mo->end(); return; }
void Map::Load(std::string sceneFile) { this->mLoader = new Utilities::DotSceneLoader(); this->mLoader->parseDotScene(sceneFile, "General", GameFramework::getSingletonPtr()->sceneManager); std::vector<Ogre::Entity*> mNavmeshEnts; /*Ogre::Entity* mapE = GameFramework::getSingletonPtr()->sceneManager->createEntity("Map", "dungeon.mesh"); Ogre::SceneNode* mapNode = GameFramework::getSingletonPtr()->sceneManager->getRootSceneNode()->createChildSceneNode("MapNode"); mapNode->scale(Vector3(2,2,2)); mapNode->attachObject(mapE); mNavmeshEnts.push_back(mapE);*/ mRecast = new OgreRecast(GameFramework::getSingletonPtr()->sceneManager); mDetourTileCache = new OgreDetourTileCache(mRecast); if (this->mLoader != 0) { if (this->mLoader->entityList->size() > 0) { ConfigFile cf; std::vector<Ogre::Entity*> srcMeshes;// = std::vector<Ogre::Entity*>(this->mLoader->entityList->begin(), this->mLoader->entityList->end()); bool could_find_plane = false; for (int i = 0; i < this->mLoader->entityList->size(); i++ ) { Ogre::Entity* ent = this->mLoader->entityList->at(i); if (ent->getName() == "Plane#0") { //ent->setMaterialName("MyMaterial"); ent->setMaterialName("PlaneMaterial"); ent->setCastShadows(false); //ent->setVisible(false); //ent->getParentSceneNode()->setPosition(Vector3(0,0,0)); srcMeshes.clear(); srcMeshes.push_back(ent); could_find_plane = true; } } if (could_find_plane) { inputGeom = new InputGeom(srcMeshes); } else { //srcMeshes = std::vector<Ogre::Entity*>(this->mLoader->entityList->begin(), this->mLoader->entityList->end()); if (this->mLoader->getTerrainGroup() != 0) { inputGeom = new InputGeom(this->mLoader->getTerrainGroup(), srcMeshes); } else { inputGeom = new InputGeom(srcMeshes); } } if(mDetourTileCache->TileCacheBuild(inputGeom)) { mDetourTileCache->drawNavMesh(); } else { Ogre::LogManager::getSingletonPtr()->logMessage("ERROR: could not generate useable navmesh from mesh using detourTileCache."); return; } } } Ogre::SceneNode* mNavMeshNode = (Ogre::SceneNode*)GameFramework::getSingletonPtr()->sceneManager->getRootSceneNode()->getChild("RecastSN"); int ttt = mNavMeshNode->numAttachedObjects(); //mNavMeshNode->setVisible(true); for (int i = 0; i < mNavMeshNode->numAttachedObjects(); i++) { Ogre::MovableObject *obj = mNavMeshNode->getAttachedObject(i); obj->setVisible(false); obj->setQueryFlags(QueryFlags::NAVMESH_MASK); } this->isLoaded = true; }
Ogre::WireBoundingBox* ManipulatorObject::GetEntityAABBGizmo(Ogre::Entity* pEntity) { assert(pEntity); Ogre::SceneNode* aabbNode = dynamic_cast<Ogre::SceneNode*>(pEntity->getParentSceneNode()->getChild(pEntity->getName())); return dynamic_cast<Ogre::WireBoundingBox*>(aabbNode->getAttachedObject(0)); }