void OgreCameraSystem::update(int) { for (EntityId entityId : m_impl->m_entities.removedEntities()) { Ogre::Camera* camera = m_impl->m_cameras[entityId]; if (camera) { Ogre::SceneNode* sceneNode = camera->getParentSceneNode(); sceneNode->detachObject(camera); m_impl->m_sceneManager->destroyCamera(camera); } m_impl->m_cameras.erase(entityId); } for (auto& value : m_impl->m_entities.addedEntities()) { EntityId entityId = value.first; OgreSceneNodeComponent* sceneNodeComponent = std::get<0>(value.second); OgreCameraComponent* cameraComponent = std::get<1>(value.second); Ogre::Camera* camera = m_impl->m_sceneManager->createCamera( cameraComponent->name() ); camera->setAutoAspectRatio(true); cameraComponent->m_camera = camera; m_impl->m_cameras[entityId] = camera; sceneNodeComponent->m_sceneNode->attachObject(camera); } m_impl->m_entities.clearChanges(); for (auto& value : m_impl->m_entities) { OgreCameraComponent* cameraComponent = std::get<1>(value.second); auto& properties = cameraComponent->m_properties; if (properties.hasChanges()) { Ogre::Camera* camera = cameraComponent->m_camera; // Update camera camera->setPolygonMode(properties.polygonMode); camera->setFOVy(properties.fovY); camera->setNearClipDistance(properties.nearClipDistance); camera->setFarClipDistance(properties.farClipDistance); // Untouch properties.untouch(); } } }
void WheelAnimalSceneObj::load(const std::string & filename) { //Ogre::ru * s = Orz::OgreGraphicsManager::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0, 0 ,0)); //导入场景资源 _impl = BaseSceneImpl::create(_osm, filename); //创建总场景节点 _senceNode = Orz::OgreGraphicsManager::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode(); //创建场景 _osm->createScene(_senceNode); _senceNode->setVisible(true); //s->setVisible(false); /*_impl->getCamera(SCENE_CAMERA)->setPosition(Ogre::Vector3(-98.851, 164.283, 237.886)); _impl->getCamera(SCENE_CAMERA)->setOrientation(Ogre::Quaternion(0.999578, -0.0192806, -0.0226839));*/ //创建摄像机的节点 _cameraSn = OgreGraphicsManager::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode(); //获取场景的摄像机 Ogre::Camera * camera = _impl->getCamera(SCENE_CAMERA); //创建摄像机的节点并设置它的位置 _cameraSn = camera->getParentSceneNode()->createChildSceneNode(Ogre::Vector3(0.f, 164.283f, 237.886f)); //_cameraSn->setPosition(Ogre::Vector3(-98.851, 164.283, 237.886)); //_cameraSn->setOrientation(Ogre::Quaternion(0.999578, -0.0192806, -0.0226839)); //camera->detatchFromParent(); //脱离原有的节点 camera->detachFromParent(); //摄像机绑定在节点上 _cameraSn->attachObject(_impl->getCamera(SCENE_CAMERA)); //创建场景的中心节点 Ogre::SceneNode * sn = getBaseCenter()->createChildSceneNode(Ogre::Vector3(0, 100,0)); //setAutoTracking可以让你的摄像机总是盯着你场景中的某一个节点 //方法中第一个参数确定是否打开自动跟踪,在任何一帧渲染之前都可以重新设置它。 //二个参数是被跟踪节点得指针,除非你第一个参数是false(这时候可以用NULL),否则你必须确定调用的时候指针指向的节点必须有效 camera->setAutoTracking(true, sn); // std::cout<<_camera->getPosition()<<"!"<<_camera->getOrientation()<<std::endl; //获取场景管理器 Ogre::SceneManager * sm = Orz::OgreGraphicsManager::getSingleton().getSceneManager(); // set up spline animation of node //定义动画,指定动画的名称及长度(这里为4秒) _anim = sm->createAnimation("Cam_", 4); //// Spline it for nice curves // // 指定动画关键帧之间的插值方式(包括线性插值和样条插值) _anim->setInterpolationMode(Ogre::Animation::IM_LINEAR); //定义动画的一个动画轨迹,并指定这个轨迹是作用到_cameraSn节点上的 //// Create a track to animate the camera's node Ogre::NodeAnimationTrack * track = _anim->createNodeTrack(0, _cameraSn); // 定义动画轨迹包含的关键帧,下面定义了3个关键帧,加上起始帧 // 4个关健帧形成了一个曲线的动画 Ogre::TransformKeyFrame* key = track->createNodeKeyFrame(0); // startposition key->setTranslate(Ogre::Vector3(0.f, 0.3f, 237.886f)); key = track->createNodeKeyFrame(3); // startposition key->setTranslate(Ogre::Vector3(0.f, 0.3f, 237.886f)); key = track->createNodeKeyFrame(4); key->setTranslate(Ogre::Vector3(0.f, -80.f, -400.f)); ////////////////////////////////// //定义动画的一个动画轨迹,并指定这个轨迹是作用到创建场景的中心节点sn上的 track = _anim->createNodeTrack(1, sn); key = track->createNodeKeyFrame(0); // startposition key->setTranslate(Ogre::Vector3(0, 0,0)); key = track->createNodeKeyFrame(3); // startposition key->setTranslate(Ogre::Vector3(0, 0,0)); key = track->createNodeKeyFrame(4); key->setTranslate(Ogre::Vector3(0, 200,0)); //// Create a new animation state to track this //定义AnimationState类的对象,它和刚才定义的动画类相对应。设置动画的状态为启用: _animState = sm->createAnimationState("Cam_"); _animState->setEnabled(true);// 启用该动画 _animState->setLoop(false); /* Ogre::MaterialPtr material = Ogre::MaterialPtr(Ogre::MaterialManager::getSingleton().getByName("Material_#11/lanseshuijing")); material->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setTextureName("shuijing-lv.dds");*/ }