本文整理汇总了C++中osgviewer::Viewer::getCamera方法的典型用法代码示例。如果您正苦于以下问题:C++ Viewer::getCamera方法的具体用法?C++ Viewer::getCamera怎么用?C++ Viewer::getCamera使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osgviewer::Viewer
的用法示例。
在下文中一共展示了Viewer::getCamera方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
viewerSetUp( osgViewer::Viewer& viewer, double aspect, osg::Node* node )
{
viewer.getCamera()->setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR );
viewer.getCamera()->setProjectionMatrixAsPerspective( 35., aspect, .1, 50. );
viewer.getCamera()->setClearMask( 0 );
viewer.setSceneData( backdropFX::Manager::instance()->getManagedRoot() );
// No longer needed, apparently. Seems like Viewer used to focus the
// camera manipulator on the entire SkyDome, putting it too far away from
// the scene. This code compensated for that.
//osgGA::TrackballManipulator* tb = new osgGA::TrackballManipulator();
//viewer.setCameraManipulator( tb );
//tb->setNode( root.get() );
//tb->home( 0 );
viewer.addEventHandler( new osgViewer::StatsHandler );
viewer.addEventHandler( new osgViewer::ThreadingHandler );
osgGA::TrackballManipulator* tbm = new osgGA::TrackballManipulator;
viewer.setCameraManipulator( tbm );
tbm->setNode( node );
tbm->home( 0 );
}
示例2: createProjection
void
viewerSetUp( osgViewer::Viewer& viewer, unsigned int width, unsigned int height, osg::Node* node )
{
double aspect = (double)width / (double)height;
viewer.setThreadingModel( osgViewer::ViewerBase::SingleThreaded );
viewer.getCamera()->setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR );
viewer.getCamera()->setProjectionMatrix( createProjection( aspect ) );
viewer.getCamera()->setClearMask( 0 );
viewer.setSceneData( backdropFX::Manager::instance()->getManagedRoot() );
// No longer needed, apparently. Seems like Viewer used to focus the
// camera manipulator on the entire SkyDome, putting it too far away from
// the scene. This code compensated for that.
//osgGA::TrackballManipulator* tb = new osgGA::TrackballManipulator();
//viewer.setCameraManipulator( tb );
//tb->setNode( root.get() );
//tb->home( 0 );
viewer.addEventHandler( new osgViewer::StatsHandler );
viewer.addEventHandler( new osgViewer::ThreadingHandler );
viewer.addEventHandler( new ResizeHandler( viewer, width, height ) );
osgGA::TrackballManipulator* tbm = new osgGA::TrackballManipulator;
viewer.setCameraManipulator( tbm );
tbm->setNode( node );
tbm->home( 0 );
}
示例3: updateNear
void AppState::updateNear()
{
// Assume that the viewing frustum is symmetric.
double fovy, aspectRatio, cNear, cFar;
viewer->getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio,
cNear, cFar);
viewer->getCamera()->setProjectionMatrixAsPerspective(fovy, aspectRatio,
zNear, cFar);
stringstream nearStream;
nearStream << "near: " << zNear;
zNearText->setText(nearStream.str());
zNearText->update();
}
示例4: updateUserStats
void updateUserStats(osgViewer::Viewer& viewer)
{
// Test the custom stats line by just adding up the update and cull
// times for the viewer main camera for the previous frame.
if (viewer.getViewerStats()->collectStats("update") && viewer.getCamera()->getStats()->collectStats("rendering"))
{
// First get the frame number. The code below assumes that
// updateUserStats() is called after advance(), so the frame number
// that will be returned is for the frame that has just started and is
// not rendered yet. The previous frame is framenumber-1, but we can't
// use that frame's timings because it's probably not finished
// rendering yet (in multithreaded viewer modes). So we'll use the
// timings for framenumber-2 for this demo.
int framenumber = viewer.getFrameStamp()->getFrameNumber();
// Get the update time and the viewer main camera's cull time. We use
// getAveragedAttribute() in order to get the actual time elapsed as
// calculated by the stats.
double update = 0.0, cull = 0.0;
viewer.getViewerStats()->getAveragedAttribute("Update traversal time taken", update);
viewer.getCamera()->getStats()->getAveragedAttribute("Cull traversal time taken", cull);
// Get various begin and end times, note these are not elapsed times
// in a frame but rather the simulation time at those moments.
double eventBegin = 0.0, updateBegin = 0.0, cullEnd = 0.0, drawEnd = 0.0;
viewer.getViewerStats()->getAttribute(framenumber-2, "Event traversal begin time", eventBegin);
viewer.getViewerStats()->getAttribute(framenumber-2, "Update traversal begin time", updateBegin);
viewer.getCamera()->getStats()->getAttribute(framenumber-2, "Cull traversal end time", cullEnd);
viewer.getCamera()->getStats()->getAttribute(framenumber-2, "Draw traversal end time", drawEnd);
// This line displays the frame number. It's not averaged, just displayed as is.
viewer.getViewerStats()->setAttribute(framenumber, frameNumberName, framenumber);
// This line displays the frame time (from beginning of event to end of draw). No bars.
viewer.getViewerStats()->setAttribute(framenumber-1, frameTimeName, drawEnd - eventBegin);
// This line displays the sum of update and main camera cull times.
viewer.getViewerStats()->setAttribute(framenumber-1, customTimeName + " time taken", update+cull);
// Since we give begin and end times that correspond to the begin of
// the update phase and the end of the cull phase, the bar in the
// graph will not correspond to the summed times above if something
// happened between update and cull (as in this demo). Also, we need
// to translate the updateBegin and cullEnd times by one frame since
// we're taking the times for framenumber-2 but using them to display
// in the framenumber-1 graph.
viewer.getViewerStats()->setAttribute(framenumber-1, customTimeName + " begin", updateBegin + (1.0/60.0));
viewer.getViewerStats()->setAttribute(framenumber-1, customTimeName + " end", cullEnd + (1.0/60.0));
}
}
示例5: setViewer
void setViewer(osgViewer::Viewer& viewer, float width, float height, float distance)
{
double vfov = osg::RadiansToDegrees(atan2(height/2.0f,distance)*2.0);
// double hfov = osg::RadiansToDegrees(atan2(width/2.0f,distance)*2.0);
viewer.getCamera()->setProjectionMatrixAsPerspective( vfov, width/height, 0.1, 1000.0);
}
示例6: main
int main(int argc, char* argv[]) {
ref_ptr<Group> root = new Group;
viewer.setUpViewInWindow(0, 0, 640, 480);
viewer.realize();
ref_ptr<Camera> cam = viewer.getCamera();
ref_ptr<Geode> geode = new Geode;
root->addChild(geode.get());
for (int i=0; i < 10; i++) {
osg::Sphere* sphere = new osg::Sphere( Vec3f(i+1,10,0), .1*i);
osg::ShapeDrawable* sphereDrawable = new osg::ShapeDrawable(sphere);
geode->addDrawable(sphereDrawable);
}
// osg::Sphere* sphere = new osg::Sphere( Vec3f(10,10,0), .2);
// osg::ShapeDrawable* sphereDrawable = new osg::ShapeDrawable(sphere);
// sphereDrawable->setColor(osg::Vec4f(1,0,0,1));
// geode->addDrawable(sphereDrawable);
ref_ptr<osgGA::TrackballManipulator> manip = new osgGA::TrackballManipulator();
viewer.setCameraManipulator(manip);
viewer.setSceneData(root.get());
cam->setViewMatrixAsLookAt(Vec3f(10,0,0), Vec3f(10,1,0), Vec3f(0,0,1));
//manip->setHomePosition(Vec3f(10,0,0), Vec3f(11,1,0), Vec3f(10,0,1));
// cam->setProjectionMatrixAsPerspective(49,640/480., .1, 10);
viewer.run();
}
示例7: loadLevels
void LevelMenu::loadLevels()
{
_itemsPat = new osg::PositionAttitudeTransform();
_itemsPat->setPosition(osg::Vec3(viewer.getCamera()->getViewport()->width() - 400, viewer.getCamera()->getViewport()->height() - 250, 0));
// load XML document
rapidxml::file<> mf(LEVEL_OVERVIEW_FILE);
rapidxml::xml_document<> xml_doc;
xml_doc.parse<0>(mf.data());
int itemIndex = 0;
// parse XML document
for(rapidxml::node_iterator<char> it(xml_doc.first_node()); it.dereference() != NULL; ++it, ++itemIndex)
{
if(strcmp(it->name(), "road") == 0)
{
std::string name = it->first_attribute("name")->value();
osg::Geode *itemNode = new osg::Geode();
osgText::Text *text = new osgText::Text();
text->setFont(MENU_FONT);
text->setPosition(osg::Vec3(0, - (itemIndex * MENU_ITEM_HEIGHT), 0));
text->setText(name);
itemNode->addDrawable(text);
_itemsPat->addChild(itemNode);
std::map<std::string, std::string> item;
item["name"] = it->first_attribute("name")->value();
item["filename"] = it->first_attribute("filename")->value();
item["besttime"] = it->first_attribute("besttime")->value();
item["completions"] = it->first_attribute("completions")->value();
item["deaths"] = it->first_attribute("deaths")->value();
_items.push_back(item);
}
else
{
throw std::runtime_error("Error: Unrecognized element in level file!");
}
}
_menuPat->addChild(_itemsPat);
}
示例8: SetCameraProjectionMatrix
void SetCameraProjectionMatrix (osgViewer::Viewer& viewer, dFloat viewAngleInDegress, dFloat aspectRatio, dFloat nearPlane, dFloat farPlane)
{
osg::Camera* const camera = viewer.getCamera();
camera->setProjectionMatrixAsPerspective (viewAngleInDegress, aspectRatio, nearPlane, farPlane);
// camera->setViewMatrixAsLookAt (osg::Vec3 (-3.0f, -5.0f, 2.0f), osg::Vec3 (0.0f, 0.0f, 2.0f), osg::Vec3 (0.0f, 0.0f, 1.0f));
camera->setViewMatrixAsLookAt (osg::Vec3 (-0.0f, -5.0f, 2.0f), osg::Vec3 (0.0f, 0.0f, 2.0f), osg::Vec3 (0.0f, 0.0f, 1.0f));
}
示例9: setViewer
void setViewer(osgViewer::Viewer& viewer, float width, float height, float distance)
{
double vfov = osg::RadiansToDegrees(atan2(height/2.0f,distance)*2.0);
// double hfov = osg::RadiansToDegrees(atan2(width/2.0f,distance)*2.0);
viewer.getCamera()->setProjectionMatrixAsPerspective( vfov, width/height, 0.1, 1000.0);
OSG_NOTICE<<"setProjectionMatrixAsPerspective( "<<vfov<<", "<<width/height<<", "<<0.1<<", "<<1000.0<<");"<<std::endl;
}
示例10: initializeHeader
void LevelMenu::initializeHeader()
{
osg::PositionAttitudeTransform *headerPat = new osg::PositionAttitudeTransform();
osg::Geode *headerGeode = new osg::Geode();
osg::Geometry *textureDrawable = new osg::Geometry();
osg::Texture2D *texture;
osg::Vec3Array *vertices = new osg::Vec3Array();
{
vertices->push_back(osg::Vec3(0, 0, 0));
vertices->push_back(osg::Vec3(436, 0, 0));
vertices->push_back(osg::Vec3(436, 75, 0));
vertices->push_back(osg::Vec3(0, 75, 0));
}
textureDrawable->setVertexArray( vertices );
osg::DrawElementsUInt *face = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
face->push_back(0);
face->push_back(1);
face->push_back(2);
face->push_back(3);
textureDrawable->addPrimitiveSet(face);
osg::Vec2Array* texcoords = new osg::Vec2Array(4);
{
(*texcoords)[0].set(0.0f, 0.0f);
(*texcoords)[1].set(1.0f, 0.0f);
(*texcoords)[2].set(1.0f, 1.0f);
(*texcoords)[3].set(0.0f, 1.0f);
textureDrawable->setTexCoordArray(0, texcoords);
}
texture = new osg::Texture2D;
texture->setDataVariance(osg::Object::DYNAMIC);
texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
osg::StateSet* stateSet = new osg::StateSet();
stateSet->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);
textureDrawable->setStateSet(stateSet);
headerGeode->addDrawable(textureDrawable);
headerPat->addChild(headerGeode);
_menuPat->addChild(headerPat);
headerPat->setPosition(osg::Vec3(100, viewer.getCamera()->getViewport()->height() - 125, -0.01));
osg::Image *image = osgDB::readImageFile(LEVEL_HEADER_TEXTURE);
texture->setImage(image);
}
示例11: initializeCamera
void Sky::initializeCamera()
{
_camera = new osg::Camera();
_camera->setProjectionMatrix(osg::Matrix::ortho2D(0, viewer.getCamera()->getViewport()->width(), 0, viewer.getCamera()->getViewport()->height()));
_camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
_camera->setViewMatrix(osg::Matrix::identity());
_camera->setClearColor(osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f));
_camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
_camera->setRenderOrder(osg::Camera::PRE_RENDER);
_camera->addChild(_skyPat);
}
示例12: main
int main(void){
osg::DisplaySettings::instance()->setNumMultiSamples( 4 );
viewer.setUpViewInWindow( 100, 50, 800, 600 );
viewer.getCamera()->setClearColor( osg::Vec4( 0.5,0.5,0.5,1) );
viewer.addEventHandler(new osgViewer::StatsHandler);
scene = new osg::Group;
osg::ref_ptr<osg::LightSource> lumiere = new osg::LightSource;
lumiere->getLight()->setLightNum(0); // GL_LIGHT1
lumiere->getLight()->setPosition(osg::Vec4(1, -1, 10, 0)); // 0 = directionnel
lumiere->getLight()->setAmbient(osg::Vec4(0.5, 0.5, 0.5, 1.0));
lumiere->getLight()->setDiffuse(osg::Vec4(0.9, 0.9, 0.9, 1.0));
lumiere->getLight()->setSpecular(osg::Vec4(1.0, 1.0, 1.0, 1.0));
scene->addChild(lumiere.get());
terrain = creation_terrain();
scene->addChild(terrain.get());
scene->addChild(creation_foret(terrain, 500));
LECHARRR = creation_CHARRR(0,0,terrain);
scene->addChild(LECHARRR);
LECHARRR->accept(rechercheTourelle);
fumeeTank = new osgParticle::SmokeEffect;
fumeeTank->setTextureFileName("fumee.tga");
fumeeTank->setIntensity(2);
fumeeTank->setScale(4);
fumeeTank->setPosition(LECHARRR->getPosition());
scene->addChild(fumeeTank.get());
posCanonX = LECHARRR->getPosition().x();
posCanonY = LECHARRR->getPosition().y() + 3.5;
posCanonZ = LECHARRR->getPosition().z() + 4.0;
viewer.setSceneData(scene);
osg::ref_ptr<GestionEvenements> gestionnaire = new GestionEvenements();
viewer.addEventHandler(gestionnaire.get());
return viewer.run();
}
示例13: returnFromLevel
void LevelMenu::returnFromLevel()
{
if(_currentLevel->playerReachedFinish())
{
// update completions
{
std::stringstream ss;
ss << atoi(_items[_currentItemIndex]["completions"].c_str()) + 1;
_items[_currentItemIndex]["completions"] = ss.str();
}
// update best time
{
time_t t = _currentLevel->getTime();
if(_items[_currentItemIndex]["besttime"] == "" | t < atol(_items[_currentItemIndex]["besttime"].c_str()))
{
std::stringstream ss;
ss << t;
_items[_currentItemIndex]["besttime"] = ss.str();
}
}
}
// update number of deaths
{
std::stringstream ss;
ss << atoi(_items[_currentItemIndex]["deaths"].c_str()) + _currentLevel->getNumDeaths();
_items[_currentItemIndex]["deaths"] = ss.str();
}
viewer.setCameraManipulator(NULL);
viewer.getCamera()->setViewMatrixAsLookAt(MENU_CAMERA_HOME_EYE, MENU_CAMERA_HOME_CENTER, MENU_CAMERA_HOME_UP);
_currentLevel->resetScene();
viewer.setSceneData(this);
_currentLevel = NULL;
Player::getInstance()->reset();
updateDetails();
Sound::getInstance()->stop(LEVEL_MUSIC_FILE);
Sound::getInstance()->playInLoop(MENU_MUSIC_FILE);
}
示例14: InitWindowsSystem
void InitWindowsSystem (osgViewer::Viewer& viewer, const char* const title, int x, int y, int width, int height)
{
viewer.setUpViewInWindow(x, y, width, height);
//Get the traits of the current window
osg::ref_ptr< osg::GraphicsContext::Traits > traits = new osg::GraphicsContext::Traits( *viewer.getCamera()->getGraphicsContext()->getTraits());
//Set the title
traits->windowName = title;
// disable vertical sync
traits->vsync = false;
//Create a new graphics context with the modified traits
osg::ref_ptr< osg::GraphicsContext > gc = osg::GraphicsContext::createGraphicsContext( traits.get() );
gc->realize();
gc->makeCurrent();
// set the vertical black off by default
osgViewer::Viewer::Windows windows;
viewer.getWindows(windows);
for(osgViewer::Viewer::Windows::iterator itr = windows.begin(); itr != windows.end(); ++itr) {
osgViewer::GraphicsWindow* const graphicsWindow = (*itr);
graphicsWindow->setSyncToVBlank (false);
}
//Create the new camera which is a copy of the current camera in the viewer
osg::ref_ptr<osg::Camera> cam = new osg::Camera( *viewer.getCamera() );
//Set the cameras graphics context to the gc we made above
cam->setGraphicsContext( gc );
//assign the viewer the new camera
viewer.setCamera( cam.get() );
// int the camera default perspective matrix
SetCameraProjectionMatrix (viewer, 60.0f, dFloat (width) / height, 0.01, 1000.0f);
// set the file find callback
osg::ref_ptr<DemosFindFileCallback> filecallback = new DemosFindFileCallback;
osgDB::Registry::instance()->setFindFileCallback (filecallback.get());
}
示例15: MenuKeyboardHandler
LevelMenu::LevelMenu() :
_currentLevel(NULL),
_currentItemIndex(0)
{
_menuPat = new osg::PositionAttitudeTransform();
_menuPat->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
_keyboardHandler = new MenuKeyboardHandler(this);
viewer.addEventHandler(_keyboardHandler);
initializeCamera();
initializeHeader();
initializeBackgroundAnimation();
initializeSelector();
loadLevels();
updateDetails();
viewer.getCamera()->setUpdateCallback(new LevelMenuUpdater(this));
Sound::getInstance()->playInLoop(MENU_MUSIC_FILE);
}