首页 > 其他分享 >ogre_v13.6.1的Tutorial例子

ogre_v13.6.1的Tutorial例子

时间:2023-11-19 18:12:00浏览次数:39  
标签:OGRE v13.6 ogre Vector3 camNode cam evt Tutorial Ogre

这里使用的是Ogre官网提供的预编译的ogre-sdk-v13.6.1-msvc141-x64,假设解压在E:\ogre-sdk-v13.6.1-msvc141-x64, 环境变量设置

OGRE_HOME e:\ogre-sdk-v13.6.1-msvc141-x64

OGRE_CONFIG_DIR e:\ogre-sdk-v13.6.1-msvc141-x64\bin

PATH 添加: %OGRE_HOME%\bin

 

VC2019 C++ 控制台程序, toolset设置 VC142

属性页下面的配置: Release

调试->环境:  PATH=$(OGRE_HOME)\bin;$(PATH)

C/C++->常规->附加包含目录:  $(OGRE_HOME)\include;$(OGRE_HOME)\include\OGRE;$(OGRE_HOME)\include\OGRE\Bites;$(OGRE_HOME)\include\OGRE\RTShaderSystem;%(AdditionalIncludeDirectories)

C/C++->代码生成->运行库: 多线程 DLL (/MD)

连接器->常规-> 附加库目录:      $(OGRE_HOME)\lib

连接器->输入-> 附加依赖项:OgreBites.lib;OgreMain.lib;OgreRTShaderSystem.lib;%(AdditionalDependencies)

将下面的 txt内容拷贝为ogre.cfg 保存在 E:/ogrehome/

Render System=OpenGL 3+ Rendering Subsystem

[OpenGL Rendering Subsystem]
Colour Depth=
Display Frequency=N/A
FSAA=0
Fixed Pipeline Enabled=Yes
Full Screen=No
RTT Preferred Mode=FBO
VSync=Yes
VSync Interval=1
Video Mode= 800 x  600
sRGB Gamma Conversion=No

[OpenGL 3+ Rendering Subsystem]
Colour Depth=
Debug Layer=Off
Display Frequency=N/A
FSAA=0
Full Screen=No
Reversed Z-Buffer=No
Separate Shader Objects=Yes
VSync=Yes
VSync Interval=1
Video Mode= 800 x  600
sRGB Gamma Conversion=No

[Tiny Rendering Subsystem]
Full Screen=No
VSync=Yes
VSync Interval=1
Video Mode=800 x 600
sRGB Gamma Conversion=No

[Vulkan Rendering Subsystem]
Device=NVIDIA GeForce RTX 3060
FSAA=1
Full Screen=No
Reversed Z-Buffer=No
VSync=Yes
VSync Interval=1
Video Mode=800 x 600
sRGB Gamma Conversion=No

运行结果为:

 

main.cpp 内容

//! [starter]

#include <exception>
#include <iostream>

#include "Ogre.h"
#include "OgreApplicationContext.h"
#include "OgreInput.h"
#include "OgreRTShaderSystem.h"
#include "OgreCameraMan.h"


using namespace Ogre;
using namespace OgreBites;

class TutorialApplication
        : public ApplicationContext
        , public InputListener
{
public:
    TutorialApplication();
    virtual ~TutorialApplication();
    
    virtual void setup();
    
    bool keyPressed(const KeyboardEvent& evt);

    virtual bool mouseMoved(const MouseMotionEvent& evt)
    {
        return mCamMan->mouseMoved(evt);
    }

    virtual bool mouseWheelRolled(const MouseWheelEvent& evt)
    {
        return mCamMan->mouseWheelRolled(evt);
    }

    virtual bool mousePressed(const MouseButtonEvent& evt)
    {
        return mCamMan->mousePressed(evt);
    }

    virtual bool mouseReleased(const MouseButtonEvent& evt)
    {

        return mCamMan->mouseReleased(evt);
    }

    virtual void frameRendered(const Ogre::FrameEvent& evt)
    {
        mCamMan->frameRendered(evt);
    }

    virtual void windowResized(Ogre::RenderWindow* rw)
    {
        Viewport* vp = rw->getViewport(0);
        Ogre::Camera* cam = dynamic_cast<Ogre::Camera*>(mCamMan->getCamera()->getAttachedObject(0));
        cam->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
    }

    std::unique_ptr<CameraMan> mCamMan;
};


TutorialApplication::TutorialApplication()
    : ApplicationContext("Ogre13-Test00")
{
}


TutorialApplication::~TutorialApplication()
{
    mCamMan.reset();
}

void TutorialApplication::setup()
{
    // do not forget to call the base first
    ApplicationContext::setup();
    addInputListener(this);


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

    // register our scene with the RTSS
    RTShader::ShaderGenerator* shadergen = RTShader::ShaderGenerator::getSingletonPtr();
    shadergen->addSceneManager(scnMgr);

    // -- tutorial section start --
    //! [cameracreate]
    SceneNode* camNode = scnMgr->getRootSceneNode()->createChildSceneNode();
    Camera* cam = scnMgr->createCamera("myCam");
    //! [cameracreate]
    //! 
    //const auto& resloc = Ogre::ResourceGroupManager::getSingleton().listResourceLocations("Material");
    Ogre::ResourceManager::ResourceMapIterator res_i = Ogre::MaterialManager::getSingleton().getResourceIterator();

    Ogre::StringVector matnames;
    while (res_i.hasMoreElements())
    {
        
        auto sname = res_i.current()->second->getName();
        matnames.push_back(sname);

        res_i.moveNext();
    }

    //! [cameraposition]
    camNode->setPosition(0, 0, 1000);
    
    //camNode->setFixedYawAxis(true, Vector3::UNIT_Z);
    //camNode->lookAt(Vector3(0, 0, 0), Node::TransformSpace::TS_WORLD);

    Ogre::Quaternion rotq;
    rotq.FromAxes(Ogre::Vector3(1, 0, 0), Ogre::Vector3(0, 0, 1), Ogre::Vector3(0, -1, 0));
    camNode->setOrientation(rotq);

    // camNode->setFixedYawAxis(false, Vector3::UNIT_Z);

    //camNode->setFixedYawAxis(false);
    //camNode->setPosition(0, -500, 0);
    
    //camNode->setDirection(Ogre::Vector3(0, 1, 0));

    //! [cameraposition]

    //! [cameralaststep]
    cam->setNearClipDistance(5);
    camNode->attachObject(cam);

    auto rup = cam->getRealUp();
    auto rrt = cam->getRealRight();
    auto rto = cam->getRealDirection();
    auto pos = cam->getRealPosition();

    mCamMan.reset(new CameraMan(camNode));
    mCamMan->setFixedYaw(false);
    mCamMan->setStyle(CS_ORBIT);
    //! [cameralaststep]
    //! 
    //

    //camNode->lookAt(Vector3(0, 0, 0), Node::TransformSpace::TS_WORLD);
    //Ogre::Quaternion rotq;
    //rotq.FromAxes(Ogre::Vector3(1, 0, 0), Ogre::Vector3(0, 0, 1), Ogre::Vector3(0, 1, 0));
    //camNode->setOrientation(rotq);
    

    rup = cam->getRealUp();
    rrt = cam->getRealRight();
    rto = cam->getRealDirection();
    pos = cam->getRealPosition();

    //! [addviewport]
    Viewport* vp = getRenderWindow()->addViewport(cam);
    //! [addviewport]

    //! [viewportback]
    vp->setBackgroundColour(ColourValue(0.2, 0.2, 0.4));

    vp->setMaterialScheme(MSN_SHADERGEN);
    //! [viewportback]

    //! [cameraratio]
    cam->setAspectRatio(Real(vp->getActualWidth()) / Real(vp->getActualHeight()));
    //! [cameraratio]

    //! [lightingsset]
    scnMgr->setAmbientLight(ColourValue(0.65, 0.65, 0.85));
    scnMgr->setShadowTechnique(SHADOWTYPE_NONE/*SHADOWTYPE_STENCIL_ADDITIVE*/);

    // create a floor plane

    Plane plane(Vector3::UNIT_Z, 0);
    MeshManager::getSingleton().createPlane(
        "ground", RGN_DEFAULT,
        plane,
        1000, 1000, 50, 50,
        true,
        1, 1, 1,
        Vector3::UNIT_Y);
    Entity* groundEntity = scnMgr->createEntity("ground");
    scnMgr->getRootSceneNode()->createChildSceneNode()->attachObject(groundEntity);

    groundEntity->setCastShadows(false);
    groundEntity->setVisible(true);

    //
    {
        unsigned short src, dst;
        if (!groundEntity->getMesh()->suggestTangentVectorBuildParams(VES_TANGENT, src, dst))
        {
            // enforce that we have tangent vectors
            groundEntity->getMesh()->buildTangentVectors(VES_TANGENT, src, dst);
        }
    }
    groundEntity->setMaterialName("DamagedHelmet"/*"RustyBarrel"*/);
    groundEntity->getSubEntity(0)->getMaterial()->getTechnique(0)->getPass(0)->setCullingMode(CULL_NONE);

    Entity* ent1 = scnMgr->createEntity("uv_sphere.mesh"/*"knot.mesh"*/);
    SceneNode* node1 = scnMgr->getRootSceneNode()->createChildSceneNode();
    node1->attachObject(ent1);
    node1->setPosition(Ogre::Vector3(0, 0, 100));
    {    
        unsigned short src, dst;
        if (!ent1->getMesh()->suggestTangentVectorBuildParams(VES_TANGENT, src, dst))
        {
            // enforce that we have tangent vectors
            ent1->getMesh()->buildTangentVectors(VES_TANGENT, src, dst);
        }
    }
    ent1->setMaterialName("DamagedHelmet_RTSS");
}


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


int main(int argc, char **argv)
{
    try
    {
        TutorialApplication app;
        app.getFSLayer().setHomePath("E:/ogrehome/");
        app.initApp();
        app.getRoot()->startRendering();
        app.closeApp();
    }
    catch (const std::exception& e)
    {
        std::cerr << "Error occurred during execution: " << e.what() << '\n';
        return 1;
    }

    return 0;
}

//! [starter]

 

标签:OGRE,v13.6,ogre,Vector3,camNode,cam,evt,Tutorial,Ogre
From: https://www.cnblogs.com/abcstar/p/17842356.html

相关文章

  • [940] Create a progress bar in Python
    TocreateaprogressbarinPython,youcanusethetqdmlibrary,whichisapopularlibraryforaddingprogressbarstoyourloops.Ifyouhaven'tinstalledityet,youcandosousing:pipinstalltqdmHere'sasimpleexampleofhowtousetqd......
  • 【随手记录】Llama Tutorial 大语言模型实践
    这个tutorial的契机是yy突然看到了一个workshop所以类似于一周大作业的形式,输入command输出使用了自动驾驶哪些模块,代码在这里所以就干一干,顺便写一个tutorial给大家参考和教程引申更多的应用参考资料:https://github.com/facebookresearch/codellama,https://github.com/fac......
  • 软件设计Tutorial 6_原型模式
    [实验任务一]:向量的原型用C++完成数学中向量的封装,其中,用指针和动态申请支持向量长度的改变,使用浅克隆和深克隆复制向量类,比较这两种克隆方式的异同。实验要求:1. 画出对应的类图;  2. 提交源代码(用C++完成); #include<iostream>#include<cstring>classVec......
  • 软件设计Tutorial 13_享元模式
    [实验任务一]:围棋设计一个围棋软件,在系统中只存在一个白棋对象和一个黑棋对象,但是它们可以在棋盘的不同位置显示多次。实验要求:1. 提交类图;  2.提交源代码;3.注意编程规范;4.要求用简单工厂模式和单例模式实现享元工厂类的设计。 packageXiang;publicclassBla......
  • ScholarAI ChatGPT Plugin Tutorial, Use Cases & Prompts
    https://roihacks.com/scholarai-chatgpt-plugin/?utm_source=youtube&utm_medium=social&utm_campaign=scholarai-chatgpt-plugin......
  • android ProgressBar样式
    **实现进度条由浅黄(#ffff33)到深黄色(#ff6600)的渐变样式。****与进度条自动从0加载到99,进度条每次加1**-`android:max`:进度条的最大值。-`android:progressDrawable`:设置轨道对应的`Drawable`对象。-style="@android:style/Widget.ProgressBar.Horizontal"设置**水平进度条*......
  • train_logReg_param.o:train_logReg_param.cc:(.text+0x3407): more undefined refere
     001、make编译报错:train_logReg_param.o:train_logReg_param.cc:(.text+0x3407):moreundefinedreferencesto`std::__throw_out_of_range_fmt(charconst*,...)'follow 002、解决方法(可能是gcc版本的问题)a、gcc当前版本:(py38)[[email protected]]#gcc......
  • WPF Video Tutorials
    WPFVideoTutorialsListofWPFvideotutorialsforfree…http://movielibrary.lynda.com/html/modPage.asp?ID=359http://www.bestechvideos.com/category/web-tech/wpf/http://windowsclient.net/learn/videos_wpf.aspx......
  • NProgress 使用
    简单使用案例一一、安装NProgress包方法一:npminstall--savenprogerss方法二:yarnaddnprogress方法三:在图形化界面中搜索nprogress安装运行依赖方法四:直接引入js、css或者通过cdn引入。<scriptsrc='nprogress.js'></script><linkrel='stylesheet'href='nprogress.css�......
  • Import SQL into MySQL with a progress meter
    Thereisnicetoolcalledpv#OnUbuntu/Debiansystem$sudoapt-getinstallpv#OnRedhat/CentOS$sudoyuminstallpvthene.g.youcanuseitlikethis.sql|-uxxx-pxxxxdbname$zcatdbpackfile.sql.gz|pv-cNzcat|mysql-uuser-ppassdbnamePlease......