void AApplication::LinkCamera(Player *players_object) { PlayersObject = players_object; Ogre::SceneNode *CameraTransformationNode; CameraTransformationNode = PlayersObject->GetNode()->createChildSceneNode("CameraTransformation"); CameraTransformationNode->setInheritOrientation(false); // /*Ogre::Light *mLight = mSceneMgr->createLight("Light2"); mLight->setDiffuseColour(Ogre::ColourValue(1, 1, 1)); mLight->setSpecularColour(1, 1, 1); mLight->setAttenuation(80000,1,1,0);*/ // Create light node //Ogre::SceneNode *mLightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode( // "MovingLightNode"); // mLightNode->setInheritOrientation(false); //mLightNode->attachObject(mLight); //mLightNode->setPosition(0, 0, -96000); // BillboardSet* bbs = mSceneMgr->createBillboardSet("lightbbs", 1); // bbs->setMaterialName("Bullets/Bullet1"); // Billboard* bb = bbs->createBillboard(0,0,0,Ogre::ColourValue(0.5, 0.1, 0.0)); // // attach // mLightNode->attachObject(bbs); // Put an Ogre head in the middle //MeshPtr m = MeshManager::getSingleton().load("ogrehead.mesh", // ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); //unsigned short src, dest; //if (!m->suggestTangentVectorBuildParams(VES_TANGENT, src, dest)) //{ // m->buildTangentVectors(VES_TANGENT, src, dest); //} //Entity* e; //e = mSceneMgr->createEntity("head", "ogrehead.mesh"); //e->setMaterialName("Examples/OffsetMapping/Specular"); ////e->setMaterialName("FxNormalMap"); //SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); //headNode->attachObject(e); //headNode->setScale(7,7,7); //headNode->setPosition(0,0,-95000); //e->setNormaliseNormals(true); // PlayersCamera->SetNode(CameraTransformationNode); //Core::GetInstance()->SetCamera(PlayersCamera); CameraTransformationNode->setPosition(Ogre::Vector3::ZERO); PlayersCamera->GetOgreCamera()->setOrientation(Ogre::Quaternion::IDENTITY); PlayersCamera->SetInitialOrientation(); PlayersCamera->SetPlayersObject(PlayersObject); Core::GetInstance()->AddObjectRequest(PlayersCamera); }
void SkyManager::updateRain(float dt) { // Move existing rain // Note: if rain gets disabled, we let the existing rain drops finish falling down. float minHeight = 200; for (std::map<Ogre::SceneNode*, NifOgre::ObjectScenePtr>::iterator it = mRainModels.begin(); it != mRainModels.end();) { Ogre::Vector3 pos = it->first->getPosition(); pos.z -= mRainSpeed * dt; it->first->setPosition(pos); if (pos.z < -minHeight) { it->second.setNull(); Ogre::SceneNode* parent = it->first->getParentSceneNode(); mSceneMgr->destroySceneNode(it->first); mSceneMgr->destroySceneNode(parent); mRainModels.erase(it++); } else ++it; } // Spawn new rain float rainFrequency = mRainFrequency; float startHeight = 700; if (mRainEnabled) { mRainTimer += dt; if (mRainTimer >= 1.f/rainFrequency) { mRainTimer = 0; const float rangeRandom = 100; float xOffs = (std::rand()/(RAND_MAX+1.0)) * rangeRandom - (rangeRandom/2); float yOffs = (std::rand()/(RAND_MAX+1.0)) * rangeRandom - (rangeRandom/2); Ogre::SceneNode* sceneNode = mCamera->getParentSceneNode()->createChildSceneNode(); sceneNode->setInheritOrientation(false); // Create a separate node to control the offset, since a node with setInheritOrientation(false) will still // consider the orientation of the parent node for its position, just not for its orientation Ogre::SceneNode* offsetNode = sceneNode->createChildSceneNode(Ogre::Vector3(xOffs,yOffs,startHeight)); NifOgre::ObjectScenePtr objects = NifOgre::Loader::createObjects(offsetNode, mRainEffect); for (unsigned int i=0; i<objects->mEntities.size(); ++i) { objects->mEntities[i]->setRenderQueueGroup(RQG_Alpha); objects->mEntities[i]->setVisibilityFlags(RV_Sky); } for (unsigned int i=0; i<objects->mParticles.size(); ++i) { objects->mParticles[i]->setRenderQueueGroup(RQG_Alpha); objects->mParticles[i]->setVisibilityFlags(RV_Sky); } mRainModels[offsetNode] = objects; } } }
// Create the scene node for the terrain. We don't need to make the mesh as the later calls // will do that. Ogre::SceneNode* Region::CreateTerrain(Ogre::SceneNode* regionNode, const float width, const float length, Ogre::String terrainName) { LG::Log("Region::CreateTerrain: r=%s, w=%f, l=%f, n=%s", this->Name.c_str(), width, length, terrainName.c_str()); Ogre::SceneNode* terrainNode = regionNode->createChildSceneNode("TerrainSceneNode/" + terrainName); terrainNode->setInheritOrientation(true); terrainNode->setInheritScale(false); terrainNode->translate(0.0, 0.0, 0.0); return terrainNode; }
void CsDestructibleObject::InitParticleFX() { mSmokeFX = CsGame::GetSingletonPtr()->GetSceneMgr()->createParticleSystem(mNode->getName() + "Smoke", "HeavySmoke"); mSmokeFX->setEmitting(false); mSmokeFX->setKeepParticlesInLocalSpace(true); Ogre::SceneNode *smokeNode = mNode->createChildSceneNode(); smokeNode->setInheritOrientation(false); smokeNode->attachObject(mSmokeFX); }
// Create the scene node for the ocean. We create a plane, add the ocean material, create a scene node // and add the plane to the scene node and return that scene node. // BETWEEN FRAME OPERATION Ogre::SceneNode* Region::CreateOcean(Ogre::SceneNode* regionNode, const float width, const float length, const float waterHeight, Ogre::String waterName) { Ogre::Plane* oceanPlane = new Ogre::Plane(0.0, 0.0, 1.0, 0); Ogre::MeshPtr oceanMesh = Ogre::MeshManager::getSingleton().createPlane(waterName, OLResourceGroupName, *oceanPlane, width, length, 2, 2, true, 2, 2.0, 2.0, Ogre::Vector3::UNIT_Y); Ogre::String oceanMaterialName = LG::GetParameter("Renderer.Ogre.OceanMaterialName"); LG::Log("Region::CreateOcean: r=%s, h=%f, n=%s, m=%s", regionNode->getName().c_str(), waterHeight, waterName.c_str(), oceanMaterialName.c_str()); oceanMesh->getSubMesh(0)->setMaterialName(oceanMaterialName); Ogre::Entity* oceanEntity = LG::RendererOgre::Instance()->m_sceneMgr->createEntity("WaterEntity/" + waterName, oceanMesh->getName()); oceanEntity->addQueryFlags(Ogre::SceneManager::WORLD_GEOMETRY_TYPE_MASK); oceanEntity->setCastShadows(false); Ogre::SceneNode* oceanNode = regionNode->createChildSceneNode("WaterSceneNode/" + waterName); oceanNode->setInheritOrientation(true); oceanNode->setInheritScale(false); oceanNode->translate(width/2.0f, length/2.0f, waterHeight); oceanNode->attachObject(oceanEntity); return oceanNode; }
void CsCameraManager::SetupDefaultCamera() { //for proper orientation Ogre::Quaternion q(Ogre::Radian(Ogre::Degree(0.0)), Ogre::Vector3::UNIT_Z); // Free movable Camera mDefaultCamNode = mSceneMgr->createSceneNode("DefaultCamNode"); mDefaultCam = mSceneMgr->createCamera("DefaultCam"); mDefaultCam->setNearClipDistance(0.1); mDefaultCam->setFarClipDistance(5000); mDefaultCam->setAspectRatio(Ogre::Real(mViewport->getActualWidth()) / Ogre::Real(mViewport->getActualHeight())); mDefaultCam->setPosition(0,0,0); mDefaultCam->setFixedYawAxis(false); mDefaultCamNode->translate(0, 200, -600); mDefaultCamNode->setFixedYawAxis(false); //mDefaultCamNode->lookAt(Ogre::Vector3(0,0,0), Ogre::Node::TS_LOCAL); mDefaultCamNode->attachObject(mDefaultCam); AddCamera(mDefaultCam, Chaos::FREE_CAMERA); mCurrentCamera = mCameraList.size() - 1; ApplyCamera(); mViewport->setCamera(mCameraList[mCurrentCamera].first); Ogre::SceneNode *orbitNode = mSceneMgr->createSceneNode("OrbitCamera"); Ogre::Camera *orbitCam = mSceneMgr->createCamera("OrbitCamera"); orbitCam->setAspectRatio(Ogre::Real(mViewport->getActualWidth()) / Ogre::Real(mViewport->getActualHeight())); orbitCam->setFixedYawAxis(true); orbitNode->attachObject(orbitCam); orbitNode->setInheritOrientation(false); AddCamera(orbitCam, Chaos::ORBIT_CAMERA); }
//! //! Creates a copy of the given scene node. //! //! \param sceneNode The scene node to copy. //! \param name The name to use for the copied scene node. //! \param sceneManager The scene manager to use for creating the scene node. //! \return A copy of the given scene node. //! Ogre::SceneNode * OgreTools::copySceneNode ( Ogre::SceneNode *sceneNode, const QString &name, Ogre::SceneManager *sceneManager /* = 0 */ ) { // make sure the given scene node is valid if (!sceneNode) { Log::error("The given scene node is invalid.", "OgreTools::copySceneNode"); return 0; } // make sure a valid scene manager is available if (!sceneManager) sceneManager = sceneNode->getCreator(); if (!sceneManager) { Log::error("No valid scene manager available.", "OgreTools::copySceneNode"); return 0; } // check if a scene node of the given name already exists if (sceneManager->hasSceneNode(name.toStdString())) { Log::error(QString("The scene manager already contains a scene node named \"%1\".").arg(name), "OgreTools::copySceneNode"); return 0; } // create the scene node copy Ogre::SceneNode *sceneNodeCopy = sceneManager->createSceneNode(name.toStdString()); if (!sceneNodeCopy) { Log::error("The scene node copy could not be created.", "OgreTools::copySceneNode"); return 0; } // create a container for the scene node copy OgreContainer *sceneNodeCopyContainer = new OgreContainer(sceneNodeCopy); sceneNodeCopy->setUserAny(Ogre::Any(sceneNodeCopyContainer)); const Ogre::Any &userAny = sceneNode->getUserAny(); userAny.isEmpty(); if (!sceneNode->getUserAny().isEmpty()) { OgreContainer *sceneNodeContainer = Ogre::any_cast<OgreContainer *>(sceneNode->getUserAny()); if (sceneNodeContainer) QObject::connect(sceneNodeContainer, SIGNAL(sceneNodeUpdated()), sceneNodeCopyContainer, SLOT(updateSceneNode())); } // copy parameters from scene node to scene node copy //sceneNodeCopy->setAutoTracking(...); //sceneNodeCopy->setCustomParameter(...); //sceneNodeCopy->setDebugDisplayEnabled(...); //sceneNodeCopy->setDirection(...); //sceneNodeCopy->setFixedYawAxis(...); sceneNodeCopy->setInheritOrientation(sceneNode->getInheritOrientation()); sceneNodeCopy->setInheritScale(sceneNode->getInheritScale()); //sceneNodeCopy->setInitialState(...); //sceneNodeCopy->setInSceneGraph(...); sceneNodeCopy->setListener(sceneNode->getListener()); sceneNodeCopy->setOrientation(sceneNode->getOrientation()); //sceneNodeCopy->setParent(...); sceneNodeCopy->setPolygonModeOverrideable(sceneNode->getPolygonModeOverrideable()); sceneNodeCopy->setPosition(sceneNode->getPosition()); //sceneNodeCopy->setRenderSystemData(...); sceneNodeCopy->setScale(sceneNode->getScale()); sceneNodeCopy->setUseIdentityProjection(sceneNode->getUseIdentityProjection()); sceneNodeCopy->setUseIdentityView(sceneNode->getUseIdentityView()); //sceneNodeCopy->getUserAny(...); //sceneNodeCopy->setVisible(...); return sceneNodeCopy; }