void AbstractGameCore::createDummyScene() { m_pRenderWindow->removeAllViewports(); Ogre::SceneManager* sm = m_pOgreRoot->createSceneManager(Ogre::ST_GENERIC, "DummyScene"); Ogre::Camera* cam = sm->createCamera("DummyCamera"); m_pRenderWindow->addViewport(cam); }
bool gkMouseSensor::rayTest(void) { // cannot test no movable data, if (m_type == MOUSE_MOUSE_OVER && (m_object->getType() == GK_OBJECT || m_object->getType() == GK_SKELETON)) return false; GK_ASSERT(m_object); gkCamera* cam = m_object->getOwner()->getMainCamera(); Ogre::Camera* oc = cam->getCamera(); gkMouse* mse = gkWindowSystem::getSingleton().getMouse(); gkScalar ncx = mse->position.x / mse->winsize.x; gkScalar ncy = mse->position.y / mse->winsize.y; Ogre::Ray dest; oc->getCameraToViewportRay(ncx, ncy, &dest); if (m_rayQuery == 0) { Ogre::SceneManager* mgr = m_object->getOwner()->getManager(); m_rayQuery = mgr->createRayQuery(dest); } else m_rayQuery->setRay(dest); // do the test Ogre::RaySceneQueryResult& res = m_rayQuery->execute(); bool result = false; for (Ogre::RaySceneQueryResult::iterator it = res.begin(); it != res.end(); ++it) { Ogre::RaySceneQueryResultEntry ent = (*it); if (ent.movable == oc) continue; if (ent.movable) { if (m_type == MOUSE_MOUSE_OVER) { if (ent.movable == m_object->getMovable()) { result = true; break; } } else { result = true; break; } } } return result; }
void EC_Mesh::RemoveMesh() { OgreWorldPtr world = world_.lock(); if (entity_) { emit MeshAboutToBeDestroyed(); RemoveAllAttachments(); DetachEntity(); Ogre::SceneManager* sceneMgr = world->OgreSceneManager(); sceneMgr->destroyEntity(entity_); entity_ = 0; } if (!cloned_mesh_name_.empty()) { try { Ogre::MeshManager::getSingleton().remove(cloned_mesh_name_); } catch(Ogre::Exception& e) { LogWarning("EC_Mesh::RemoveMesh: Could not remove cloned mesh:" + std::string(e.what())); } cloned_mesh_name_ = std::string(); } }
void MainGameState::enter() { // Create the scene m_pScene = new Scene("main"); Visual::World* pVisualWorld = new Visual::World("", m_pScene->getComponentsList()); Ogre::SceneManager* pSceneManager = pVisualWorld->createSceneManager(Ogre::ST_GENERIC); pSceneManager->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); pSceneManager->setShadowFarDistance(20.0f); pVisualWorld->setAmbientLight(Color(0.5f, 0.5f, 0.5f)); m_pCameraEntity = m_pScene->create("Camera"); Visual::Camera* pCamera = new Visual::Camera("Camera", m_pCameraEntity->getComponentsList()); pCamera->createViewport(Engine::getSingletonPtr()->getMainWindow()); pCamera->setAutoAspectRatio(true); pCamera->setNearClipDistance(1.0f); m_pCameraEntity->getTransforms()->setPosition(0.0f, 0.0f, 300.0f); m_pEntity = m_pScene->create("Head"); Visual::Object* pObject = new Visual::Object("Mesh", m_pEntity->getComponentsList()); pObject->loadMesh("ogrehead.mesh"); Entity* pLightEntity = m_pScene->create("Light"); pLightEntity->getTransforms()->setPosition(200.0f, 100.0f, 200.0f); Visual::PointLight* pLight = new Visual::PointLight("Light", pLightEntity->getComponentsList()); pLight->setDiffuseColor(Color(0.8f, 0.8f, 0.8f)); m_pScene->show(); }
NxNode::~NxNode() { LogMsg("Erasing NxNode : " + GetName() ); LogMsg("Erasing NxActors ... " ); NxActorListIterator NxActorsIter = GetNxActorIterator(); while( NxActorsIter.hasMoreElements() ){ delete NxActorsIter.getNext(); } mNxActors.clear(); LogMsg("Erasing NxActors : DONE" ); LogMsg("Erasing NxSounds ... " ); NxSoundMapIterator SoundIter = GetNxSoundIterator(); while( SoundIter.hasMoreElements() ){ delete SoundIter.getNext(); } LogMsg("Erasing NxSounds : DONE" ); LogMsg("Erasing NxEntities... " ); NxEntityListIterator EntityIter = GetNxEntityIterator(); while( EntityIter.hasMoreElements() ){ delete EntityIter.getNext(); } LogMsg("Erasing NxEntities : DONE" ); Ogre::SceneManager * mManager = mSceneNode->getCreator(); // detach child first ? mManager->destroySceneNode( mSceneNode ); LogMsg("Erasing NxNode : Done" ); LogMsg("-----------------------"); }
void LagomPlayerBase::AddConstructionCapability(LagomActorFactory* f) { if(!f) return; if(_actorFactories.find(f) != _actorFactories.end()) return; Ogre::SceneManager* manager = _state.GetSceneManager(); Ogre::SceneNode* node = manager->createSceneNode(); Ogre::Entity* constructionObject = manager->createEntity(f->Mesh.c_str()); Ogre::MaterialPtr materialPtr = Ogre::MaterialManager::getSingleton().getByName(getIntFactory().ConstructingMaterial); materialPtr->setSelfIllumination(1.0f,1.0f,1.0f); constructionObject->setCastShadows(false); constructionObject->setRenderQueueGroup(RENDER_QUEUE_SKIES_LATE); constructionObject->setMaterialName(getIntFactory().ConstructingMaterial); node->attachObject(constructionObject); node->setScale( f->MeshScale ); _actorFactories.insert(FactoryMap::value_type(f,node)); if( _selectedActorFactory ==_actorFactories.end()) _selectedActorFactory=_actorFactories.begin(); }
// Dibujado de raycast para depurar void CShootRaycast::drawRaycast(const Ray& raycast) { Graphics::CScene *scene = Graphics::CServer::getSingletonPtr()->getActiveScene(); Ogre::SceneManager *mSceneMgr = scene->getSceneMgr(); std::stringstream aux; aux << "laser" << _nameWeapon << _temporal; ++_temporal; std::string laser = aux.str(); Ogre::ManualObject* myManualObject = mSceneMgr->createManualObject(laser); Ogre::SceneNode* myManualObjectNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(laser+"_node"); myManualObject->begin("laser", Ogre::RenderOperation::OT_LINE_STRIP); Vector3 v = raycast.getOrigin(); myManualObject->position(v.x,v.y,v.z); for(int i=0; i < _distance;++i){ Vector3 v = raycast.getPoint(i); myManualObject->position(v.x,v.y,v.z); // etc } myManualObject->end(); myManualObjectNode->attachObject(myManualObject); }// drawRaycast
/* *Paint the board and the ships needed to place the ships * */ void MyFrameListener::paintPlaceShipMode() { Board* boardPS = new Board("MyFleetBoard", FLEET_BOARD); Ogre::Vector3* fleetBoardPosition = new Ogre::Vector3(-3, 1.0f, 0); Ogre::SceneManager* currentSM = Ogre::Root::getSingleton(). getSceneManager("mainSM"); boardPS->paintBoard(currentSM, currentSM->getRootSceneNode(), fleetBoardPosition); for ( int i = 0; i < 6; i++ ) { int size = 4; if (i < 2) { size = 1; } else if (i < 4) { size = 2; } else if (i < 5) { size = 3; } Ogre::Vector3* shipPos = new Ogre::Vector3(shipPositions[i][0] , shipPositions[i][1], shipPositions[i][2]); ShipOgreWrapper* ship = new ShipOgreWrapper(i, shipPos, size); ship->paintShip(currentSM, currentSM->getRootSceneNode(), NULL); boardPS->addShip(ship); } this->playerBoard = boardPS; }
void EC_MeshmoonWater::DestroyOcean() { #ifdef MESHMOON_TRITON if (!state_.IsCreated()) return; try { Ogre::SceneManager *ogreSceneManager = OgreSceneManager(); if (ogreSceneManager) { if (renderQueueListener_) ogreSceneManager->removeRenderQueueListener(renderQueueListener_); } else LogWarning(LC + "Failed to uninitialize Triton library cleanly from Ogre, rendering scene not available!"); if (renderSystemListener_) Ogre::Root::getSingleton().getRenderSystem()->removeListener(renderSystemListener_); } catch(const Ogre::Exception &ex) { LogError(LC + QString::fromStdString(ex.getDescription())); } SAFE_DELETE(renderQueueListener_); SAFE_DELETE(renderSystemListener_); SAFE_DELETE(renderTargetListener_); SAFE_DELETE(state_.environment); SAFE_DELETE(state_.ocean); SAFE_DELETE(state_.resourceLoader); state_.Reset(); #endif }
bool operator()() { Ogre::SceneManager* sm = GraphicsManager::get().sceneManager(); Ogre::SceneNode* sceneNode = positionComponent->sceneNode()->createChildSceneNode( Ogre::StringConverter::toString( component->localId()), offset, offsetRotation); Ogre::ParticleSystem* ps = sm->createParticleSystem( Ogre::StringConverter::toString(component->localId()), fileName); sceneNode->attachObject(ps); component->m_sceneNode = sceneNode; component->m_particleSystem = ps; ThreadPool::get().schedule(boost::bind( &ComponentContainer::componentAttachedCallback, component->parent(), component)); return true; }
void TerrainMaterialCompilationTask::updateSceneManagersAfterMaterialsChange() { //We need to do this to prevent stale hashes in Ogre, which will lead to crashes during rendering. if (Ogre::Pass::getDirtyHashList().size() != 0 || Ogre::Pass::getPassGraveyard().size() != 0) { Ogre::SceneManagerEnumerator::SceneManagerIterator scenesIter = Ogre::Root::getSingleton().getSceneManagerIterator(); while (scenesIter.hasMoreElements()) { Ogre::SceneManager* pScene = scenesIter.getNext(); if (pScene) { Ogre::RenderQueue* pQueue = pScene->getRenderQueue(); if (pQueue) { Ogre::RenderQueue::QueueGroupIterator groupIter = pQueue->_getQueueGroupIterator(); while (groupIter.hasMoreElements()) { Ogre::RenderQueueGroup* pGroup = groupIter.getNext(); if (pGroup) pGroup->clear(false); }//end_while(groupIter.hasMoreElements()) }//end_if(pScene) }//end_if(pScene) }//end_while(scenesIter.hasMoreElements()) // Now trigger the pending pass updates Ogre::Pass::processPendingPassUpdates(); }//end_if(m_Root.. }
bool operator()() { Ogre::SceneManager* sm = GraphicsManager::get().sceneManager(); Ogre::Entity* entity = sm->createEntity( Ogre::StringConverter::toString(component->localId()), fileName); Ogre::StaticGeometry* sg = sm->createStaticGeometry( Ogre::StringConverter::toString(component->localId())); sg->addEntity( entity, positionComponent->sceneNode()->getPosition() + offset, positionComponent->sceneNode()->getOrientation() * offsetRotation); sg->build(); component->m_entity = entity; component->m_staticGeometry = sg; ThreadPool::get().schedule(boost::bind( &ComponentContainer::componentAttachedCallback, component->parent(), component)); return true; }
OgreVehicle* OgreVehicle::createOgreVehicle(Ogre::SceneNode* parNode, std::string name, Ogre::Vector3 pos) { if (parNode) { OgreVehicle* vehicle = new OgreVehicle(); vehicle->mName = name; vehicle->mParNode = parNode; Ogre::SceneManager* sceneMgr = vehicle->mParNode->getCreator(); Ogre::String nodeName = "User_" + name; vehicle->mNode = vehicle->mParNode->createChildSceneNode(nodeName); Ogre::SceneNode* pNodeBody = vehicle->mNode->createChildSceneNode("Body" + nodeName); Ogre::SceneNode* pNodeCam = vehicle->mNode->createChildSceneNode("Cam" + nodeName); Ogre::Entity* eBody = sceneMgr->createEntity("eBody"+nodeName, OGRE_VEHICLE_FILE); pNodeBody->attachObject(eBody); pNodeBody->setScale(0.0002*SCALE_TERRAIN, 0.0002*SCALE_TERRAIN, 0.0002*SCALE_TERRAIN); vehicle->mNode->setPosition(pos); vehicle->mWheels[0] = OgreWheel::createOgreWheel(pNodeBody, Ogre::Vector3(1.02f, -0.3622f, 1.26)); vehicle->mWheels[1] = OgreWheel::createOgreWheel(pNodeBody, Ogre::Vector3(1.12f, -0.3622f,-1.54)); vehicle->mWheels[2] = OgreWheel::createOgreWheel(pNodeBody, Ogre::Vector3(-1.02f, -0.3622f, 1.26)); vehicle->mWheels[3] = OgreWheel::createOgreWheel(pNodeBody, Ogre::Vector3(-1.12f, -0.3622f,-1.54)); return vehicle; } return NULL; }
void DeferredLight::updateFromCamera(Ogre::Camera* camera) { const Ogre::MaterialPtr& mat = getMaterial(); if (!mat->isLoaded()) { mat->load(); } Ogre::Technique* tech = mat->getBestTechnique(); Ogre::Vector3 farCorner = camera->getViewMatrix(true) * camera->getWorldSpaceCorners()[4]; for (unsigned short i=0; i<tech->getNumPasses(); i++) { Ogre::Pass* pass = tech->getPass(i); Ogre::GpuProgramParametersSharedPtr params = pass->getVertexProgramParameters(); if (params->_findNamedConstantDefinition("farCorner")) params->setNamedConstant("farCorner", farCorner); params = pass->getFragmentProgramParameters(); if (params->_findNamedConstantDefinition("farCorner")) params->setNamedConstant("farCorner", farCorner); // If inside light geometry, render back faces with CMPF_GREATER, otherwise normally if (mParentLight->getType() == Ogre::Light::LT_DIRECTIONAL) { pass->setCullingMode(Ogre::CULL_CLOCKWISE); pass->setDepthCheckEnabled(false); } else { pass->setDepthCheckEnabled(true); if (isCameraInsideLight(camera)) { pass->setCullingMode(Ogre::CULL_ANTICLOCKWISE); pass->setDepthFunction(Ogre::CMPF_GREATER_EQUAL); } else { pass->setCullingMode(Ogre::CULL_CLOCKWISE); pass->setDepthFunction(Ogre::CMPF_LESS_EQUAL); } } Ogre::Camera shadowCam("ShadowCameraSetupCam", 0); shadowCam._notifyViewport(camera->getViewport()); Ogre::SceneManager* sm = mParentLight->_getManager(); sm->getShadowCameraSetup()->getShadowCamera(sm, camera, camera->getViewport(), mParentLight, &shadowCam, 0); //Get the shadow camera position if (params->_findNamedConstantDefinition("shadowCamPos")) { params->setNamedConstant("shadowCamPos", shadowCam.getPosition()); } if (params->_findNamedConstantDefinition("shadowFarClip")) { params->setNamedConstant("shadowFarClip", shadowCam.getFarClipDistance()); } } }
void Level::parseLevel (XmlFile *file, XMLElement *element) { Ogre::SceneManager *mSceneMgr = RadXML::getSingletonPtr ()->getSceneManager (); name = element->getAttributeValue ("name"); setJavascriptToEvent ("onload", element->getAttributeValue ("onload")); std::string strSkyBox = element->getAttributeValue ("skybox"); std::string strAmbientColor = element->getAttributeValue ("ambientcolor"); std::string strShadowColor = element->getAttributeValue ("shadowcolor"); if (name == "") { int iRandName = rand (); setName (RadXmlCommon::s13IntToString (iRandName)); } if (strSkyBox != "") mSceneMgr->setSkyBox (true, strSkyBox); if (strAmbientColor != "") { Ogre::ColourValue cvColor = RadXML::parseColourValue (strAmbientColor); mSceneMgr->setAmbientLight (cvColor); } if (strShadowColor != "") { Ogre::ColourValue cvColor = RadXML::parseColourValue (strAmbientColor); mSceneMgr->setShadowColour (cvColor); } parseXMLMovables (file, element); }
GameplayScreen::~GameplayScreen() { //Destroy our game objects delete mWhacker; for(unsigned int i=0; i<mDragons.size(); i++) { delete mDragons[i]; } //Destroy all entities created Ogre::SceneManager* mSceneManager = Ogre::Root::getSingletonPtr()->getSceneManager("ApplicationSceneManager"); mSceneManager->destroyEntity("Stage"); //Remove the stage mesh mStageNode->removeAndDestroyAllChildren(); mStageNode->getParentSceneNode()->removeAndDestroyChild(mStageNode->getName()); //Destroy our score overlay //To do this, we must traverse all elements contained within //the overlay and remove them one at a time. Ogre::OverlayManager* overlayMgr = Ogre::OverlayManager::getSingletonPtr(); Ogre::Overlay::Overlay2DElementsIterator iter = mOverlay->get2DElementsIterator(); for(;iter.hasMoreElements();) { Ogre::OverlayContainer * childContainer = iter.getNext(); Ogre::OverlayContainer::ChildIterator contIter = childContainer->getChildIterator(); for(;contIter.hasMoreElements();) { Ogre::OverlayElement* curElement = contIter.getNext(); overlayMgr->destroyOverlayElement(curElement->getName()); } overlayMgr->destroyOverlayElement(childContainer->getName()); } overlayMgr->destroy(mOverlay->getName()); }
//----------------------------------------------------------------------- void LightRenderer::_destroyAll(void) { if (!mParentTechnique) return; // Note: The created ChildSceneNodes are destroyed when the ParticleSystem is destroyed vector<LightRendererVisualData*>::const_iterator it; vector<LightRendererVisualData*>::const_iterator itEnd = mAllVisualData.end(); for (it = mAllVisualData.begin(); it != itEnd; ++it) { PU_DELETE_T(*it, LightRendererVisualData, MEMCATEGORY_SCENE_OBJECTS); } mAllVisualData.clear(); mVisualData.clear(); // Destroy the Lights. Do it like this, because it must be assured that the light still exists // and has not already been destroyed. Ogre::SceneManager* sceneManager = mParentTechnique->getParentSystem()->getSceneManager(); for (size_t i = 0; i < mQuota; i++) { if (sceneManager->hasLight(mLightName + StringConverter::toString(i))) { sceneManager->destroyLight(mLightName + StringConverter::toString(i)); } } mLights.clear(); // Reset the visual data in the pool mParentTechnique->initVisualDataInPool(); }
void EC_WaterPlane::CreateWaterPlane() { if (!ViewEnabled()) return; if (entity_) RemoveWaterPlane(); OgreWorldPtr world = world_.lock(); // Create water plane if (world) { Ogre::SceneManager *sceneMgr = world->GetSceneManager(); assert(sceneMgr); if (node_ != 0) { int x = xSize.Get(); int y = ySize.Get(); float uTile = scaleUfactor.Get() * x; /// Default x-size 5000 --> uTile 1.0 float vTile = scaleVfactor.Get() * y; Ogre::MeshPtr mesh = Ogre::MeshManager::getSingleton().createPlane(Name().toStdString().c_str(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::Plane(Ogre::Vector3::UNIT_Y, 0), x, y, xSegments.Get(), ySegments.Get(), true, 1, uTile, vTile, Ogre::Vector3::UNIT_X); entity_ = sceneMgr->createEntity(world->GetUniqueObjectName("EC_WaterPlane_entity"), Name().toStdString().c_str()); entity_->setMaterialName(materialName.Get().toStdString().c_str()); entity_->setCastShadows(false); // Tries to attach entity, if there is not EC_Placeable availible, it will not attach object AttachEntity(); } } }
void ProjectManager::onActorRemoved(const QString& actorName) { QOCamera* cameraNode = getCameraWithName("cam1"); if(!cameraNode) { qFatal("ProjectManager.onActorRemoved: Can't determine focused actor without " "a corresponding CameraNode."); } else { // Refocus the camera on the root scene node. if(cameraNode->focusedNode() == mScenarioManager.getCurrentScene()->getActorByName(actorName)->getSceneNode()) { Ogre::Root& root = Ogre::Root::getSingleton(); Ogre::SceneManager* mgr = root.getSceneManager(Application::sSceneManagerName); cameraNode->focus(mgr->getRootSceneNode()); } } if(mSelectedActor && mSelectedActor->getName() == actorName) { Scene* current = mScenarioManager.getCurrentScene(); changeInspectorSelection(current->getName(), current->getKnowledge(), current); mSelectedActor = NULL; } }
void EC_WaterPlane::AttachEntity() { if (attached_ || entity_ == 0) return; EC_Placeable* placeable = dynamic_cast<EC_Placeable* >(FindPlaceable().get()); // If there exist placeable attach node and entity to it if (placeable != 0 ) { Ogre::SceneNode* node = placeable->GetSceneNode(); node->addChild(node_); node_->attachObject(entity_); node_->setVisible(true); } else { // There is no placeable attacht entity to OgreSceneRoot Ogre::SceneManager* sceneMgr = world_.lock()->GetSceneManager(); node_->attachObject(entity_); sceneMgr->getRootSceneNode()->addChild(node_); node_->setVisible(true); attachedToRoot_ = true; } attached_ = true; }
void ModelMountTestCase::testModelMountScaling() { Ogre::Root root; Ogre::SceneManager* sceneManager = root.createSceneManager(Ogre::ST_GENERIC); TestModel model(*sceneManager); //First test with a straight forward case. Ogre::SceneNode* node = sceneManager->getRootSceneNode()->createChildSceneNode(); //We get an error when it's destroyed. So we don't destroy it. SceneNodeProvider* nodeProvider = new SceneNodeProvider(node, nullptr); Model::ModelMount mount(model, nodeProvider); scaleAndTestMount(model, mount, nodeProvider->getNode()); //Test with the parent node being scaled node->setScale(Ogre::Vector3(3.0f, 0.2f, 200.0f)); Ogre::SceneNode* subNode = node->createChildSceneNode(); nodeProvider = new SceneNodeProvider(subNode, nullptr); Model::ModelMount mount2(model, nodeProvider); scaleAndTestMount(model, mount2, nodeProvider->getNode()); //Test with the parent node being scaled and rotated node->setScale(Ogre::Vector3(3.0f, 0.2f, 200.0f)); node->yaw(Ogre::Degree(42)); node->pitch(Ogre::Degree(76)); node->roll(Ogre::Degree(98)); subNode = node->createChildSceneNode(); nodeProvider = new SceneNodeProvider(subNode, nullptr); Model::ModelMount mount3(model, nodeProvider); scaleAndTestMount(model, mount3, nodeProvider->getNode()); }
void EC_WaterPlane::DetachEntity() { if (!attached_ || entity_ == 0) return; EC_Placeable* placeable = dynamic_cast<EC_Placeable*>(FindPlaceable().get()); if (placeable != 0 && !attachedToRoot_) { Ogre::SceneNode* node = placeable->GetSceneNode(); node_->detachObject(entity_); node->removeChild(node_); } else { // Attached to root. // Sanity check.. if (entity_->isAttached() ) { Ogre::SceneManager* sceneMgr = world_.lock()->GetSceneManager(); node_->detachObject(entity_); sceneMgr->getRootSceneNode()->removeChild(node_); attachedToRoot_ = false; } } attached_ = false; }
void SoundEditAction::_createIndicatorInstance(void) { Ogre::SceneManager* sceneManager = mSceneManipulator->getSceneManager(); mSoundMovingEntity = sceneManager->createEntity("SoundMovingEntity", "axes.mesh"); mSoundNode = mSceneManipulator->getIndicatorRootSceneNode()->createChildSceneNode(); mSoundNode->setVisible(false); mSoundNode->createChildSceneNode()->attachObject(mSoundMovingEntity); mSoundMovingEntity->getParentSceneNode()->setScale(10,10,10); Real radius = 1; int rings = 16; int segments = 64; Ogre::MeshPtr sphereMesh = WX::createCommonSphere("SoundRadiusEntity", radius, rings, segments); Ogre::MaterialPtr material = WX::createPureColourMaterial( Ogre::ColourValue(1, 0, 0, 0.75) ); material->getTechnique(0)->getPass(0)->setPolygonMode(Ogre::PM_WIREFRAME); mSoundRadiusEntity = sceneManager->createEntity("SoundRadiusEntity", sphereMesh->getName()); mSoundNode->createChildSceneNode()->attachObject(mSoundRadiusEntity); mSoundRadiusEntity->setMaterialName(material->getName()); mSoundRadiusEntity->getParentSceneNode()->setVisible(false); mFirstInit = true; }
Entity* EntityFactory::createArena() { EntityManager* entityMgr = engine_->entityMgr_; Entity* entity = entityMgr->create(); float arenaHalfX = 150.f; float arenaHalfY = 75.f; b2BodyDef bd; bd.type = b2_staticBody; b2Body* body = engine_->sysPhysics_->getWorld()->CreateBody(&bd); b2EdgeShape shape; b2FixtureDef sd; sd.shape = &shape; sd.density = 0; sd.restitution = 0.4f; sd.filter.categoryBits = ComPhysics::CollisionCategory::CATEG_Wall; sd.filter.maskBits = ComPhysics::CollisionMask::MASK_Wall; // Left vertical shape.Set(b2Vec2(-arenaHalfX, -arenaHalfY), b2Vec2(-arenaHalfX, arenaHalfY)); body->CreateFixture(&sd); // Right vertical shape.Set(b2Vec2(arenaHalfX, -arenaHalfY), b2Vec2(arenaHalfX, arenaHalfY)); body->CreateFixture(&sd); // Top horizontal shape.Set(b2Vec2(-arenaHalfX, arenaHalfY), b2Vec2(arenaHalfX, arenaHalfY)); body->CreateFixture(&sd); // Bottom horizontal shape.Set(b2Vec2(-arenaHalfX, -arenaHalfY), b2Vec2(arenaHalfX, -arenaHalfY)); body->CreateFixture(&sd); ComPhysics* comPhysics = entityMgr->assignComponent<ComPhysics>(entity); comPhysics->setMainBody(body, entity); Ogre::SceneManager* sceneMgr = engine_->sysGraphics_->getSceneManager(); //Ogre::ManualObject* manual = sceneMgr->createManualObject(); //manual->begin("white", Ogre::RenderOperation::OT_LINE_STRIP); //manual->position(-arenaHalfX, -arenaHalfY, 0); //manual->position(arenaHalfX, -arenaHalfY, 0); //manual->position(arenaHalfX, arenaHalfY, 0); //manual->position(-arenaHalfX, arenaHalfY, 0); //manual->index(0); //manual->index(1); //manual->index(2); //manual->index(3); //manual->index(0); //manual->end(); Ogre::Entity* meshEntity = sceneMgr->createEntity("ArenaPlane.mesh"); Ogre::SceneNode* node = engine_->sysGraphics_->getSceneRoot()->createChildSceneNode( Ogre::Vector3(0, 0, 0)); ComGraphics* comGraphics = entityMgr->assignComponent<ComGraphics>(entity); comGraphics->sceneNode_ = node; comGraphics->attachMovableObject(meshEntity); return entity; }
Ogre::SceneNode * WheelAnimalSceneObj::getBaseCenter() { if(_sn == NULL) { _sn = Orz::OgreGraphicsManager::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode(getCenterPoint()); //_sn->yaw(Ogre::Radian(Ogre::Math::PI)); for(int i=0 ; i<(BASE_ALL-BASE_0); ++i) { Ogre::SceneNode * base = getBase(i); Ogre::Node * parent = base->getParent(); Ogre::Vector3 p = base->getPosition(); if(parent) { parent->removeChild(base); } base->translate(-getCenterPoint()); _sn->addChild(base); Ogre::SceneManager * sm = OgreGraphicsManager::getSingleton().getSceneManager(); Ogre::Entity * ent = sm->createEntity("ring"+Ogre::StringConverter::toString(i), "zp_dwdzgh.mesh"); Ogre::SceneNode * node = base->createChildSceneNode("ring"+Ogre::StringConverter::toString(i),Ogre::Vector3(0.f, 10.f, 0.f)); node->setScale(0.6f,0.6f,0.6f); node->attachObject(ent); Orz::OgreGraphicsManager::getSingleton().getSceneManager()->getSceneNode("ring"+Ogre::StringConverter::toString(i))->setVisible(false); } } return _sn; }
EC_Placeable::~EC_Placeable() { if (world_.expired()) { if (sceneNode_) LogError("EC_Placeable: World has expired, skipping uninitialization!"); return; } emit AboutToBeDestroyed(); OgreWorldPtr world = world_.lock(); Ogre::SceneManager* sceneMgr = world->GetSceneManager(); if (sceneNode_) { DetachNode(); sceneMgr->destroySceneNode(sceneNode_); sceneNode_ = 0; } // Destroy the attachment node if it was created if (boneAttachmentNode_) { sceneMgr->getRootSceneNode()->removeChild(boneAttachmentNode_); sceneMgr->destroySceneNode(boneAttachmentNode_); boneAttachmentNode_ = 0; } }
EC_Mesh::EC_Mesh(Scene* scene) : IComponent(scene), nodeTransformation(this, "Transform", Transform(float3(0,0,0),float3(0,0,0),float3(1,1,1))), meshRef(this, "Mesh ref", AssetReference("", "OgreMesh")), skeletonRef(this, "Skeleton ref", AssetReference("", "OgreSkeleton")), meshMaterial(this, "Mesh materials", AssetReferenceList("OgreMaterial")), drawDistance(this, "Draw distance", 0.0f), castShadows(this, "Cast shadows", false), entity_(0), attached_(false) { if (scene) world_ = scene->GetWorld<OgreWorld>(); static AttributeMetadata drawDistanceData("", "0", "10000"); drawDistance.SetMetadata(&drawDistanceData); static AttributeMetadata materialMetadata; materialMetadata.elementType = "assetreference"; meshMaterial.SetMetadata(&materialMetadata); meshAsset = AssetRefListenerPtr(new AssetRefListener()); skeletonAsset = AssetRefListenerPtr(new AssetRefListener()); OgreWorldPtr world = world_.lock(); if (world) { Ogre::SceneManager* sceneMgr = world->OgreSceneManager(); adjustment_node_ = sceneMgr->createSceneNode(world->GetUniqueObjectName("EC_Mesh_adjustment_node")); connect(this, SIGNAL(ParentEntitySet()), SLOT(UpdateSignals())); connect(meshAsset.get(), SIGNAL(Loaded(AssetPtr)), this, SLOT(OnMeshAssetLoaded(AssetPtr)), Qt::UniqueConnection); connect(skeletonAsset.get(), SIGNAL(Loaded(AssetPtr)), this, SLOT(OnSkeletonAssetLoaded(AssetPtr)), Qt::UniqueConnection); } }
void COgreManager::updateSceneManagersAfterMaterialsChange() { if(Root::getSingletonPtr() && (Ogre::Pass::getDirtyHashList().size()!=0 || Ogre::Pass::getPassGraveyard().size()!=0)) { Ogre::SceneManagerEnumerator::SceneManagerIterator scenesIter = Root::getSingletonPtr()->getSceneManagerIterator(); while(scenesIter.hasMoreElements()) { Ogre::SceneManager* pScene = scenesIter.getNext(); if(pScene) { Ogre::RenderQueue* pQueue = pScene->getRenderQueue(); if(pQueue) { Ogre::RenderQueue::QueueGroupIterator groupIter = pQueue->_getQueueGroupIterator(); while(groupIter.hasMoreElements()) { Ogre::RenderQueueGroup* pGroup = groupIter.getNext(); if(pGroup) pGroup->clear(false); }//end_while(groupIter.hasMoreElements()) }//end_if(pScene) }//end_if(pScene) }//end_while(scenesIter.hasMoreElements()) // Now trigger the pending pass updates Ogre::Pass::processPendingPassUpdates(); }//end_if(m_Root.. }
//! //! Create new scene. //! \return True if the scene was successfully created, otherwise False. //! bool Model2SceneNode::createSceneNode() { // obtain the OGRE scene manager Ogre::SceneManager *sceneManager = OgreManager::getSceneManager(); if (!sceneManager) { Log::error("Could not obtain OGRE scene manager.", "Model2SceneNode::loadMesh"); return false; } // create new scene node m_sceneNode = OgreManager::createSceneNode(m_name); // get the scene if it could not create it and if it already exists Ogre::String sceneNodeName = QString("%1SceneNode").arg(m_name).toStdString(); if (!m_sceneNode && sceneManager->hasSceneNode(sceneNodeName)) m_sceneNode = sceneManager->getSceneNode(sceneNodeName); // alert in case it could not be either created or loaded if (!m_sceneNode) { Log::error(QString("Scene node for node \"%1\" could not be created.").arg(m_name), "Model2SceneNode::loadMesh"); return false; } setValue(m_outputGeometryName, m_sceneNode, true); return m_sceneNode != 0; }
void updateSceneManagersAfterMaterialsChange() { Ogre::SceneManagerEnumerator::SceneManagerIterator scenesIter = Ogre::Root::getSingletonPtr()->getSceneManagerIterator(); while(scenesIter.hasMoreElements()) { Ogre::SceneManager* pScene = scenesIter.getNext(); if(pScene) { Ogre::RenderQueue* pQueue = pScene->getRenderQueue(); if(pQueue) { Ogre::RenderQueue::QueueGroupIterator groupIter = pQueue->_getQueueGroupIterator(); while(groupIter.hasMoreElements()) { Ogre::RenderQueueGroup* pGroup = groupIter.getNext(); if(pGroup) { pGroup->clear(true); } } } } } // Now trigger the pending pass updates Ogre::Pass::processPendingPassUpdates(); }