osgEarth中的METRIC_BEGIN和METRIC_END

87 篇文章 38 订阅
#define METRIC_BEGIN(...) if (osgEarth::Metrics::enabled()) osgEarth::Metrics::begin(__VA_ARGS__)

#define METRIC_END(...)   if (osgEarth::Metrics::enabled()) osgEarth::Metrics::end(__VA_ARGS__)

1、C++部分

...为可变参数列表,__VA_ARGS__为是一个可变参数的宏,很少人知道这个宏,这个可变参数的宏是新的C99规范中新增的,目前似乎只有gcc支持(VC6.0的编译器不支持)。实现思想就是宏定义中参数列表的最后一个参数为省略号(也就是三个点)。需要注意的是,##__VA_ARGS__ 宏前面加上##的作用在于,当可变参数的个数为0时,这里的##起到把前面多余的","去掉的作用,否则会编译出错。

begin和end的参数可以使固定参数,也可以是可变参数,对于固定参数会自动和__VA_ARGS__对应起来。如果固定参数个数大于可变参数,剩下的参数按默认值或默认构造函数初始化;如果小于,则按顺序初始化固定参数。

 

2、功能部分

做一些测量工作

osgEarth中自带一个osgEarth::ChromeMetricsBackend做测量的类,通过观察其begin和end,应该是将一些信息输出的文件中。

启用osgEarth::ChromeMetricsBackend的代码在下:

osgEarth/Metrics.cpp
namespace
{
    static osg::ref_ptr< MetricsBackend > s_metrics_backend;
    class MetricsStartup
    {
    public:
        MetricsStartup()
        {
            const char* metricsFile = ::getenv("OSGEARTH_METRICS_FILE");
            if (metricsFile)
            {
                Metrics::setMetricsBackend(new ChromeMetricsBackend(std::string(metricsFile)));
            }
            const char* metricsVerbose = ::getenv("OSGEARTH_METRICS_DEBUG");
            if (metricsVerbose)
            {
                s_metrics_debug = true;
            }
        }

        ~MetricsStartup()
        {
            Metrics::setMetricsBackend(0);
        }
    };
    static MetricsStartup s_metricsStartup;
}

static MetricsStartup s_metricsStartup;保证在加载动态库是执行MatricsStartup的构造函数,如果有OSGEARTH_METRICS_FILE环境变量,则设置s_metrics_backend为osgEarth::ChromeMetricsBackend,这样所有的Metics都可以使用该测量类。

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The "Unity3D Book Page Curl" is a unity package that is used to create a book with page flip effect using unity3D native UI tools. Getting Started Create your first book:  Import the unity package  Create a canvas and EventSystem objects if you don't have one (the easiest way to create them is by adding any UI object -like a button- then you can delete it).  Drag a book prefab under the Canvas element  Resize the book on your scene and reposition the anchors as required.  Select the book from hierarchy to show it in inspector.  Assign the canvas to the canvas slot in inspector  Assign the background sprite with the sprite that you want to show on the right or left side when all pages flipped to the other side.  To edit the book pages, expand the Book Pages list in inspector, change the Size to your pages count, then start drag your pages in the Element boxes in order  Set the current page to the page that you want to be shown initially in the right side of the book.  If you want to call any function when any page flipped add it to the OnFlip Event List.  If you want to resize the area that the user can drag the page from it, open the Book node in inspector to show its children, you will find two objects "RightHotSpot" and "LeftHotSpot" resize them and set their anchors as required.  RUN and enjoy the page curl effect! Create Automatic Flipping Book:  After creating your book as mentioned above add an "Auto Flip" component on it.  Choose flipping direction( if you choose left to right make sure that the current page of the book component is equal to your page count "last page index + 1").  Uncheck the interactable check in the book component.  Specify the page flipping time parameters (Page Flip Time, Time Between Pages, Delay before Start flipping, Number of Animation frames for each page flip).  Check "Auto Start Flip" if you want the book to start flipping automatically, or uncheck it and call the StartFlipping() function in your code. Control Flipping Manually: This section will explore how to create a scene like the “Example_2_Controled Flipping” scene  To be able to let the user control page flipping using some buttons, create your book, add an "Auto Flip" component on it and configured them as mentioned above.  Uncheck the “interactable” of the book and "Auto Start Flip" of the “Auto Flip” components.  Add previous and next buttons to your scene (check Example_2_Controled Flipping scene if you have any issues setting them correctly).  Add a new slot on each button OnClick list by clicking the (+) sign, assign the Book as the game object then select the “AutoFlip->FlipRightPage” for the next button and “Auto Flip->Flip Left Page” to the previous button.  If you need to flip the page from code (based on custom action) you can call the FlipLeftPage() or FlipRightPage().

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值