OGRE Tutorials 1

Guide to building OGREphp

一、Preparing the build environment html

  You should now create a build directory for Ogre somewhere outside Ogre's sources. This is the directory where CMake will create the build system for your chosen platform and compiler, and this is also where the Ogre libraries will be compiled. This way, the Ogre source dir stays clean, and you can have multiple build directories all working from the same Ogre source. linux

  建立一個不一樣於 Ogre 的目錄,用於CMake生成工程文件,好比叫 project_1。git

二、Getting dependencies github

  By default ogre will build the essential dependencies automatically when you run cmake the first time.api

  Ogre will install the dependencies into the subfolder Dependencies in the build dir by default. You can configure it by setting OGRE_DEPENDENCIES_DIR in cmake. For instance to point to a common dependencies folder for all of your projects. Inside this directory you must have the subdirectories bin, lib and include where you place .dll, .lib and header files of the dependencies, respectively.app

  CMake會自動構建基礎依賴,將依賴的 dll、libs、header files 放置在 project_1/Dependencies/ 目錄下。能夠經過 OGRE_DEPENDENCIES_DIR  來更改 Dependencies 目錄。ide

  若是是 linux 系統,還需安裝一些額外的依賴。ui

三、Running CMake this

  1) Now start the program cmake-gui

  2) In the field Where is the source code enter the path to the Ogre source directory (the directory which contains this file).

  3) In the field Where to build the binaries enter the path to the build directory you created.

  4) Hit Configure. A dialogue will appear asking you to select a generator.

  Click Finish. CMake will now gather some information about your build environment and try to locate the dependencies. It will then show a list of build options. You can adjust the settings to your liking; for example unchecking any of the OGRE_BUILD_XXX options will disable that particular component from being built. Once you are satisfied, hit Configure again and then click on Generate. CMake will then create the build system for you.

四、Building

  Go to your chosen build directory. CMake has generated a build system for you which you will now use to build Ogre.

  If you are using Visual Studio, you should find the file OGRE.sln. Open it and compile the target BUILD_ALL.

  打開 project_1中的 OGRE.sln,構建 BUILD_ALL。

五、Installing

  In Visual Studio, just select and build the target INSTALL. On Windows this will create the folder sdk inside your build directory and copy all the required libraries there. You can change the install location by changing the variable CMAKE_INSTALL_PREFIX in CMake.

  構建 INSTALL 工程,即會在 project_1 下生成 sdk 目錄,包含了 dll、lib、headers

Setting up an OGRE project

一、simply derive from OgreBites::ApplicationContext and if you want to get input events from OgreBites::InputListener

class MyTestApp : public OgreBites::ApplicationContext, public OgreBites::InputListener
{
    ...
}
MyTestApp::MyTestApp() : OgreBites::ApplicationContext("OgreTutorialApp")
{
}

二、handle input

bool MyTestApp::keyPressed(const OgreBites::KeyboardEvent& evt)
{
    if (evt.keysym.sym == OgreBites::SDLK_ESCAPE)
    {
        getRoot()->queueEndRendering();
    }
    return true;
}

三、main

int main(int argc, char *argv[])
{
    MyTestApp app;
    app.initApp();
    app.getRoot()->startRendering();
    app.closeApp();
    return 0;
}

Your First Scene

一、SceneManager

  There are multiples types of SceneManagers. There are managers focused on rendering terrain and other managers focused on rendering BSP maps. The different types of SceneManager are listed here.

二、SceneNode

  An Entity is not rendered in your scene until it is attached to a SceneNode. 

三、setAmbientLight

  root能夠建立 sceneManager,sceneManager能夠設置環境光。(注意不是經過light設置)

// get a pointer to the already created root
Root* root = getRoot();
SceneManager* scnMgr = root->createSceneManager();

scnMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));

四、createLight

  經過 sceneManager 建立 Light。

Light* light = scnMgr->createLight("MainLight");
SceneNode* lightNode = scnMgr->getRootSceneNode()->createChildSceneNode();
lightNode->attachObject(light);
lightNode->setPosition(20, 80, 50);

五、createCamera

  經過 sceneManager 建立 Camera

    SceneNode* camNode = scnMgr->getRootSceneNode()->createChildSceneNode();

    // create the camera
    Camera* cam = scnMgr->createCamera("myCam");
    cam->setNearClipDistance(5); // specific to this sample
    cam->setAutoAspectRatio(true);
    camNode->attachObject(cam);
    camNode->setPosition(0, 0, 140);

    // and tell it to render into the main window
    getRenderWindow()->addViewport(cam);

六、createEntity  

 Entity* ogreEntity = scnMgr->createEntity("ogrehead.mesh");

七、createChildSceneNode

SceneNode* ogreNode = scnMgr->getRootSceneNode()->createChildSceneNode();
ogreNode->attachObject(ogreEntity);

  SceneNodes are used to set a lot more than just position. They also manage the scale and rotation of objects.

Entity* ogreEntity3 = scnMgr->createEntity("ogrehead.mesh");
    SceneNode* ogreNode3 = scnMgr->getRootSceneNode()->createChildSceneNode();
    ogreNode3->setPosition(0, 104, 0);
    ogreNode3->setScale(2, 1.2, 1);
    ogreNode3->attachObject(ogreEntity3);

 

八、OGRE使用右手座標系

九、Rotating An Entity.

  

十、Libraries and Plugins

  Ogre is divided into three shared library groups: main library, plugins, and third-party libraries.

  1)Main library

    The Ogre library is contained within OgreMain.dll or libOgreMain.so depending on your platform. This library must be included in all of your Ogre applications. 

  2)Plugins

    The core plugins that are included with Ogre have names that start with "Plugin_" and "Codec_". 

    Ogre also uses plugins for the different render systems (such as OpenGL, DirectX, etc). These plugins start with "RenderSystem_". 

 

十一、Configuration Files

  Ogre uses several configuration files (*.cfg).  You can place these files the same directory as your executable or in any of the default lookup paths described here.

  Ogre must find 'plugins.cfg' and 'resources.cfg' to function properly. 

  1)plugins.cfg

    This file tells Ogre which plugins to load. You modify this file when you want to load a different set of plugins. 

# Plugin=RenderSystem_Direct3D9
# Plugin=RenderSystem_Direct3D10
# Plugin=RenderSystem_Direct3D11
Plugin=RenderSystem_GL

    You can also decide where Ogre looks for plugins by changing the 'PluginFolder' variable. 

PluginFolder=/usr/local/lib/OGRE

  2)resources.cfg

  This file contains a list of the directories Ogre will use to search for resources. Resources include scripts, meshes, textures, GUI layouts, and others.  Ogre will not search subdirectories, so you have to manually enter them.

[General]
FileSystem=../media
FileSystem=../media/materials/scripts
FileSystem=../media/materials/textures
FileSystem=../media/models

  3)ogre.cfg

    This file is generated by the Render Settings dialog that appears when you run your application. Do not distribute this file with your application. This file will be specific to your own setup.

Lights, Cameras, and Shadows

一、addViewport

Viewport* vp = getRenderWindow()->addViewport(cam);
vp->setBackgroundColour(ColourValue(0, 0, 0));
cam->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));

二、setCastShadows(true)

 Entity* ninjaEntity = scnMgr->createEntity("ninja.mesh");
 ninjaEntity->setCastShadows(true);

 scnMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ninjaEntity);

三、createPlane

  The first thing we'll do is create an abstract Plane object. This is not the mesh, it is more of a blueprint. We create a plane by supplying a vector that is normal to our plane and its distance from the origin. So we have created a plane that is perpendicular to the y-axis and zero units from the origin.

  Plane plane(Vector3::UNIT_Y, 0);

  Now we'll ask the MeshManager to create us a mesh using our Plane blueprint. The MeshManager is already keeping track of the resources we loaded when initializing our application.

MeshManager::getSingleton().createPlane(
            "ground", RGN_DEFAULT,
            plane,
            1500, 1500, 20, 20,
            true,
            1, 5, 5,
            Vector3::UNIT_Z);
Entity* groundEntity = scnMgr->createEntity("ground");
scnMgr->getRootSceneNode()->createChildSceneNode()->attachObject(groundEntity);
groundEntity->setCastShadows(false);
groundEntity->setMaterialName("Examples/Rockwall");

四、setShadowTechnique

  Enabling shadows in Ogre is easy. The SceneManager class has a Ogre::SceneManager::setShadowTechnique method we can use.  

  Ogre does not provide soft shadows as part of the engine. You can write your own vertex and fragment programs to implement soft shadows and many other things.

五、Light->setType

  Ogre provides three types of lighting.

  • Ogre::Light::LT_POINT - This Light speads out equally in all directions from a point.
  • Ogre::Light::LT_SPOTLIGHT - This Light works like a flashlight. It produces a solid cylinder of light that is brighter at the center and fades off.
  • Ogre::Light::LT_DIRECTIONAL - This Light simulates a huge source that is very far away - like daylight. Light hits the entire scene at the same angle everywhere.
Light* spotLight = scnMgr->createLight("SpotLight");
spotLight->setDiffuseColour(0, 0, 1.0);
spotLight->setSpecularColour(0, 0, 1.0);
spotLight->setType(Light::LT_SPOTLIGHT);
SceneNode* spotLightNode = scnMgr->getRootSceneNode()->createChildSceneNode();
spotLightNode->attachObject(spotLight);
spotLightNode->setDirection(-1, -1, 0);
spotLightNode->setPosition(Vector3(200, 200, 0));

  注意:OGRE中的Light比較奇怪,須要設置兩種光,diffuse、specular。

Trays GUI System

一、

二、

三、

四、

五、

 

參考:

一、https://ogrecave.github.io/ogre/api/latest/building-ogre.html

相關文章
相關標籤/搜索