OGER SDK研究之五 Demo_SkyDemo 天空穹

 SkyDemo.h

/*
-----------------------------------------------------------------------------
This source file is part of OGRE
    (Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/

Copyright (c) 2000-2006 Torus Knot Software Ltd
Also see acknowledgements in Readme.html

You may use this sample code for anything you like, it is not covered by the
LGPL like the rest of the engine.

-----------------------------------------------------------------------------
*/

/**
    /file
        SkyDome.h
    /brief
        Specialisation of OGRE's framework application to show the
        skydome feature
  //加入一个天空穹
*/


#include "ExampleApplication.h"

// Event handler to add ability to alter curvature
class SkyDomeFrameListener : public ExampleFrameListener
{
protected:
    Real mCurvature;   //曲率
    Real mTiling;    //天顶位置
    SceneManager* mSceneMgr; //场管指针
public:
    SkyDomeFrameListener(RenderWindow* win, Camera* cam, SceneManager* mgr)
        : ExampleFrameListener(win, cam)
    {
        mSceneMgr = mgr;
        mCurvature = 1;
        mTiling = 15;

    }

    bool frameStarted(const FrameEvent& evt)
    {
        // Change curvature / tiling
        // Delay timer to stop too quick updates of curvature
        static Real timeDelay = 0;

        bool updateSky;
        updateSky = false;
       
        if(!ExampleFrameListener::frameStarted(evt))
            return false;
       
        if (mKeyboard->isKeyDown(OIS::KC_H) && timeDelay <= 0)
        {
   //按H增大曲率
            mCurvature += 1;
            timeDelay = 0.1;
            updateSky = true;
        }
        if (mKeyboard->isKeyDown(OIS::KC_G) && timeDelay <= 0)
        {
   //按G减小曲率
            mCurvature -= 1;
            timeDelay = 0.1;
            updateSky = true;
        }

        if (mKeyboard->isKeyDown(OIS::KC_U) && timeDelay <= 0)
        {
   //按U增大天顶
            mTiling += 1;
            timeDelay = 0.1;
            updateSky = true;
        }
        if (mKeyboard->isKeyDown(OIS::KC_Y) && timeDelay <= 0)
        {
   //按Y减小天顶
            mTiling -= 1;
            timeDelay = 0.1;
            updateSky = true;
        }

        if (timeDelay > 0)
            timeDelay -= evt.timeSinceLastFrame;

        if (updateSky)
        {
   //重设置天空DEMO
            mSceneMgr->setSkyDome(true, "Examples/CloudySky", mCurvature, mTiling);
        }

        return true;

    }
};

class SkyDomeApplication : public ExampleApplication
{
public:
    SkyDomeApplication()
    {
    }

protected:
    // Just override the mandatory create scene method
    void createScene(void)
    {
        // Set ambient light
  //设置环境光
        mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));

        // Create a skydome
  //创建一个天空盒(穹)
        mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);

        // Create a light
  //创建一个自定义灯光
        Light* l = mSceneMgr->createLight("MainLight");
        // Accept default settings: point light, white diffuse, just set position
        // NB I could attach the light to a SceneNode if I wanted it to move automatically with
        //  other objects, but I don't
  //设置灯光位置
        l->setPosition(20,80,50);

  //实体
        Entity *ent;

        // Define a floor plane mesh
  //定义一个层模型
        Plane p;
        p.normal = Vector3::UNIT_Y;
        p.d = 200;
  //创建一个自定义平面
        MeshManager::getSingleton().createPlane("FloorPlane",
            ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
            p,2000,2000,1,1,true,1,5,5,Vector3::UNIT_Z);

        // Create an entity (the floor)
  //由自定义创建实体
        ent = mSceneMgr->createEntity("floor", "FloorPlane");
  //设置材质
        ent->setMaterialName("Examples/RustySteel");
  //将实体加入场景
        mSceneMgr->getRootSceneNode()->attachObject(ent);
  //由模型创建一个实体
        ent = mSceneMgr->createEntity("head", "ogrehead.mesh");
        // Attach to child of root node, better for culling (otherwise bounds are the combination of the 2)
  //将实体加入场景(放在原点位置)
        mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);

    }
    // Create new frame listener
    void createFrameListener(void)
    {
  //创建自定义帧监听器并连接
        mFrameListener= new SkyDomeFrameListener(mWindow, mCamera, mSceneMgr);
        mRoot->addFrameListener(mFrameListener);
    }


    bool setup()
    {
  //在设置时
        ExampleApplication::setup();
  //记录所有信息,只有当需要细微的调试的时候可能才会需要
        LogManager::getSingleton().setLogDetail( LL_BOREME );
        return true;
    }
};

 

SkyDemo.cpp

/*
-----------------------------------------------------------------------------
This source file is part of OGRE
    (Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/

Copyright (c) 2000-2006 Torus Knot Software Ltd
Also see acknowledgements in Readme.html

You may use this sample code for anything you like, it is not covered by the
LGPL like the rest of the engine.
-----------------------------------------------------------------------------
*/

/**
    /file
        SkyDome.cpp
    /brief
        Show's Ogre's skydome feature
*/

#include "SkyDome.h"

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char *argv[])
#endif
{

    // Create application object
    SkyDomeApplication app;

    try {
        app.go();
    } catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
        MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
        std::cerr << "An exception has occured: " <<
            e.getFullDescription().c_str() << std::endl;
#endif
    }


    return 0;
}

#ifdef __cplusplus
}
#endif

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

火云洞红孩儿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值