| | 59 | class ChangeFOVHandler : public osgGA::GUIEventHandler |
| | 60 | { |
| | 61 | public: |
| | 62 | ChangeFOVHandler(osg::Camera* camera) |
| | 63 | : _camera(camera) |
| | 64 | { |
| | 65 | double fovy, aspectRatio, zNear, zFar; |
| | 66 | _camera->getProjectionMatrix().getPerspective(fovy, aspectRatio, zNear, zFar); |
| | 67 | std::cout << "FOV is " << fovy << std::endl; |
| | 68 | } |
| | 69 | |
| | 70 | /** Deprecated, Handle events, return true if handled, false otherwise. */ |
| | 71 | virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) |
| | 72 | { |
| | 73 | if (ea.getEventType() == osgGA::GUIEventAdapter::KEYUP) |
| | 74 | { |
| | 75 | if (ea.getKey() == '-' || ea.getKey() == '=' || ea.getKey() == '0') |
| | 76 | { |
| | 77 | double fovy, aspectRatio, zNear, zFar; |
| | 78 | _camera->getProjectionMatrix().getPerspective(fovy, aspectRatio, zNear, zFar); |
| | 79 | |
| | 80 | if (ea.getKey() == '-') |
| | 81 | { |
| | 82 | fovy -= 5.0; |
| | 83 | } |
| | 84 | |
| | 85 | if (ea.getKey() == '=') |
| | 86 | { |
| | 87 | fovy += 5.0; |
| | 88 | } |
| | 89 | |
| | 90 | if (ea.getKey() == '0') |
| | 91 | { |
| | 92 | fovy = 45.0; |
| | 93 | } |
| | 94 | |
| | 95 | std::cout << "Setting FOV to " << fovy << std::endl; |
| | 96 | _camera->getProjectionMatrix().makePerspective(fovy, aspectRatio, zNear, zFar); |
| | 97 | |
| | 98 | return true; |
| | 99 | } |
| | 100 | } |
| | 101 | |
| | 102 | return false; |
| | 103 | } |
| | 104 | |
| | 105 | osg::ref_ptr<osg::Camera> _camera; |
| | 106 | }; |
| | 107 | |
| | 108 | |
| | 109 | |