Ogre is a popular open-source 3D rendering engine for C++. The Ogre SceneManager is responsible for managing the objects in a 3D scene, allowing developers to create complex scenes with ease. It provides a hierarchical structure for grouping objects, allows for efficient rendering of large numbers of objects, and can handle the creation of multiple views or cameras.
Example 1: Creating a Scene In this example, we create a simple scene with a camera, a few objects, and a light source. The SceneManager is used to create the scene and manage the objects in it.
#include
int main() { // Create the Ogre root Ogre::Root* ogreRoot = new Ogre::Root();
// Create the SceneManager Ogre::SceneManager* sceneManager = ogreRoot->createSceneManager();
// Create a camera Ogre::Camera* camera = sceneManager->createCamera("camera");
// Create a few objects Ogre::Entity* entity1 = sceneManager->createEntity("object1", "cube.mesh"); Ogre::Entity* entity2 = sceneManager->createEntity("object2", "sphere.mesh");
// Create a light source Ogre::Light* light = sceneManager->createLight("light");
// Attach the objects to the scene Ogre::SceneNode* rootNode = sceneManager->getRootSceneNode(); Ogre::SceneNode* node1 = rootNode->createChildSceneNode(); node1->attachObject(entity1); Ogre::SceneNode* node2 = rootNode->createChildSceneNode(); node2->attachObject(entity2);
// Set up the camera and light camera->setPosition(Ogre::Vector3(0, 0, 500)); camera->lookAt(Ogre::Vector3(0, 0, 0)); light->setPosition(Ogre::Vector3(200, 200, 200));
// Render the scene ogreRoot->renderOneFrame(); }
Package/library: Ogre3D
Example 2: Using Multiple Views In this example, we create a scene with two cameras and render the objects from two different viewpoints. The SceneManager is used to create and manage the cameras and views.
#include
int main() { // Create the Ogre root Ogre::Root* ogreRoot = new Ogre::Root();
// Create the SceneManager Ogre::SceneManager* sceneManager = ogreRoot->createSceneManager();
// Create a camera and a view Ogre::Camera* camera1 = sceneManager->createCamera("camera1"); Ogre::Viewport* view1 = ogreRoot->getRenderTarget("window")->addViewport(camera1); view1->setDimensions(0, 0, 0.5, 1);
// Create a second camera and view Ogre::Camera* camera2 = sceneManager->createCamera("camera2"); Ogre::Viewport* view2 = ogreRoot->getRenderWindow()->addViewport(camera2); view2->setDimensions(0.5, 0, 0.5, 1);
// Create a few objects Ogre::Entity* entity1 = sceneManager->createEntity("object1", "cube.mesh"); ...
// Attach the objects to the scene Ogre::SceneNode* rootNode = sceneManager->getRootSceneNode(); ...
// Set up the cameras camera1->setPosition(Ogre::Vector3(0, 0, 500)); camera1->lookAt(Ogre::Vector3(0, 0, 0)); camera2->setPosition(Ogre::Vector3(500, 0, 0)); camera2->lookAt(Ogre::Vector3(0, 0, 0));
// Render the scene ogreRoot->renderOneFrame(); }
Package/library: Ogre3D
C++ (Cpp) SceneManager - 30 examples found. These are the top rated real world C++ (Cpp) examples of ogre::SceneManager extracted from open source projects. You can rate examples to help us improve the quality of examples.